Class Network<V, E, Y>
- Namespace
- Northwoods.Go.Layouts
- Assembly
- Northwoods.GoDiagram.WinForms.dll
This provides an abstract view of a diagram as a network (graph) of vertexes and directed edges. The network contains vertexes and edges corresponding to Nodes and Links.
public class Network<V, E, Y> where V : Network<V, E, Y>.Vertex where E : Network<V, E, Y>.Edge where Y : Layout
Type Parameters
V
E
Y
- Inheritance
-
Network<V, E, Y>
- Derived
- Inherited Members
Remarks
This class provides a framework for manipulating the state of nodes and links without modifying the structure of the diagram. Having a separate representation also permits adding or removing vertexes or edges from the network so that the graph that is laid out is not isomorphic to the diagram's graph.
For each kind of layout that uses a Network there is a subclass of Network<V, E, Y>.Vertex and a subclass of Network<V, E, Y>.Edge:
- CircularLayout: CircularVertex and CircularEdge
- ForceDirectedLayout: ForceDirectedVertex and ForceDirectedEdge
- LayeredDigraphLayout: LayeredDigraphVertex and LayeredDigraphEdge
- TreeLayout: TreeVertex and TreeEdge
Modifying a Network<V, E, Y> or a Network<V, E, Y>.Vertex or an Network<V, E, Y>.Edge does not invalidate the Layout or raise any changed events.
Constructors
Network(Y)
This constructs an empty network associated with a given layout.
public Network(Y layout)
Parameters
layout
Y
Remarks
It is commonplace to call AddParts(IEnumerable<Part>, bool, Predicate<Part>) to build up the network to have the same structure as a Diagram's or Group's nodes and links.
Properties
Edges
Gets a collection of all of the Network<V, E, Y>.Edges in this network.
public IReadOnlyCollection<E> Edges { get; }
Property Value
Remarks
Do not modify this collection directly. Instead, call AddEdge(E), DeleteEdge(E), AddLink(Link), or DeleteLink(Link).
Layout
Gets the Layout that uses this network of Network<V, E, Y>.Vertexes and Network<V, E, Y>.Edges.
public Y Layout { get; set; }
Property Value
- Y
Remarks
The default value is null. It is set automatically for you when setting Network.
Vertexes
Gets a collection of all of the Network<V, E, Y>.Vertexes in this network.
public IReadOnlyCollection<V> Vertexes { get; }
Property Value
Remarks
Do not modify this collection directly. Instead, call AddVertex(V), DeleteVertex(V), AddNode(Node), or DeleteNode(Node).
Methods
AddEdge(E)
Adds an Network<V, E, Y>.Edge to the network.
public void AddEdge(E edge)
Parameters
edge
E
Remarks
Although this method is provided for completeness, LinkVertexes(V, V, Link) provides a more efficient manner of linking vertexes already in the network.
AddLink(Link)
This convenience method makes sure there is an Network<V, E, Y>.Edge in this network corresponding to a Link.
public E AddLink(Link link)
Parameters
link
Link
Returns
- E
an edge in this network.
Remarks
If FindEdge(Link) returns null, this method creates a new Network<V, E, Y>.Edge, makes sure the FromNode and ToNode have corresponding Network<V, E, Y>.Vertexes in the network, and adds the edge itself to the network.
AddNode(Node)
This convenience method makes sure there is a Network<V, E, Y>.Vertex in this network corresponding to a Node.
public V AddNode(Node node)
Parameters
node
Node
Returns
- V
a vertex in this network.
AddParts(IEnumerable<Part>, bool, Predicate<Part>)
Creates a network of Network<V, E, Y>.Vertexes and Network<V, E, Y>.Edges corresponding to the given Nodes and Links.
public void AddParts(IEnumerable<Part> parts, bool toplevelonly = false, Predicate<Part> pred = null)
Parameters
parts
IEnumerable<Part>toplevelonly
boolwhether to skip Parts in the given collection that are contained by Groups; default is false
pred
Predicate<Part>optional predicate to apply to each Part -- if it returns false do not include Vertex or Edge in the network; default ignores link label nodes or links connecting with them
Remarks
This is usually more convenient than repeatedly calling AddNode(Node) and AddLink(Link). This method ignores all instances of Parts that are not Nodes or Links. This will recurse through Groups that have no Layout.
AddVertex(V)
Adds a Network<V, E, Y>.Vertex to the network.
public void AddVertex(V vertex)
Parameters
vertex
V
CreateEdge()
Allocate a new instance of Network<V, E, Y>.Edge.
public virtual E CreateEdge()
Returns
- E
Remarks
This is overridden in Network subclasses to create instances of subclasses of Network<V, E, Y>.Edge. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
CreateVertex()
Allocate a new instance of Network<V, E, Y>.Vertex.
public virtual V CreateVertex()
Returns
- V
Remarks
This is overridden in Network subclasses to create instances of subclasses of Network<V, E, Y>.Vertex. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
DeleteArtificialVertexes()
Deletes all vertexes and edges that have no Part associated with them.
public virtual void DeleteArtificialVertexes()
DeleteEdge(E)
Removes an Network<V, E, Y>.Edge from the network.
public void DeleteEdge(E edge)
Parameters
edge
E
DeleteLink(Link)
This convenience method deletes from this network any Network<V, E, Y>.Edge corresponding to a Link.
public void DeleteLink(Link link)
Parameters
link
Link
DeleteNode(Node)
This convenience method deletes any Network<V, E, Y>.Vertex corresponding to a Node.
public void DeleteNode(Node node)
Parameters
node
Node
DeleteSelfEdges()
Deletes all Network<V, E, Y>.Edges whose "to vertex" and "from vertex" are the same vertex.
public void DeleteSelfEdges()
DeleteVertex(V)
Removes a Network<V, E, Y>.Vertex from the network.
public void DeleteVertex(V vertex)
Parameters
vertex
V
Remarks
This function also deletes all edges to or from the vertex.
FindAllParts()
Retrieve all of the Nodes and Links from the Network<V, E, Y>.Vertexes and Network<V, E, Y>.Edges that are in this network.
public IEnumerable<Part> FindAllParts()
Returns
- IEnumerable<Part>
A collection of Parts.
FindEdge(Link)
Returns the Network<V, E, Y>.Edge that was constructed for the Link.
public E FindEdge(Link link)
Parameters
link
Link
Returns
- E
an edge in this network, or null if no such edge exists.
FindVertex(Node)
Returns the Network<V, E, Y>.Vertex that was constructed for the Node.
public V FindVertex(Node node)
Parameters
node
Node
Returns
- V
a vertex in this network, or null if no such vertex exists.
LinkVertexes(V, V, Link)
Links two vertexes already in the network and returns the created Network<V, E, Y>.Edge.
public E LinkVertexes(V fromVertex, V toVertex, Link link)
Parameters
fromVertex
VtoVertex
Vlink
Link
Returns
- E
an edge in this network, or null if both vertexes don't exist.
ReverseEdge(E)
Reverses the direction of a Network<V, E, Y>.Edge in the network.
public void ReverseEdge(E edge)
Parameters
edge
E
SplitIntoSubNetworks<G>(bool)
Modify this network by splitting it up into separate subnetworks, each of which has all of its vertexes connected to each other, but not to any vertexes in any other subnetworks.
public IEnumerator<G> SplitIntoSubNetworks<G>(bool clean = true) where G : Network<V, E, Y>
Parameters
clean
boolwhether to delete artificial vertexes and edges, disconnected edges, and reflexive edges; default is true
Returns
- IEnumerator<G>
a collection of Network<V, E, Y>s, sorted in order of decreasing vertex count.
Type Parameters
G
Remarks
This method will first delete from this network all artificial vertexes and all edges that do not connect two different vertexes. Afterwards, this original network may be empty or may contain all of the singleton vertexes, each of which had no edges connecting it to any other vertexes.