Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Analysis/ShapeBase.Analysis.cs

Last change on this file was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 8.6 KB
Line 
1using System;
2using Netron.Diagramming.Core.Analysis;
3namespace Netron.Diagramming.Core {
4  public abstract partial class ShapeBase : INode {
5    #region Fields
6    /// <summary>
7    /// the parent node
8    /// </summary>
9    private INode mParentNode = null;
10    private IEdge mParentEdge = null;
11    private bool mIsExpanded = true;
12    private CollectionBase<INode> treeChildren = null;
13    private int mDepth = -1;
14    #endregion
15
16    #region Properties
17
18    /// <summary>
19    /// Gets or sets whether this shape is fixed with respect to diagram layout
20    /// </summary>
21    /// <value></value>
22    bool INode.IsFixed {
23      get { return mIsFixed; }
24      set { mIsFixed = value; }
25    }
26
27    /// <summary>
28    /// Gets or sets the IsExpanded
29    /// </summary>
30    public bool IsExpanded {
31      get { return treeChildren.Count != 0; }
32      set { mIsExpanded = value; }
33    }
34
35
36    /// <summary>
37    /// Get the in-degree of the node, the number of edges for which this node
38    /// is the target.
39    /// </summary>
40    /// <value></value>
41    int INode.InDegree {
42      get {
43        return (this as INode).InEdges.Count;
44      }
45    }
46
47    /// <summary>
48    /// Get the out-degree of the node, the number of edges for which this node
49    /// is the source.
50    /// </summary>
51    /// <value></value>
52    int INode.OutDegree {
53      get {
54        return (this as INode).OutEdges.Count;
55      }
56    }
57
58    /// <summary>
59    /// Get the degree of the node, the number of edges for which this node
60    /// is either the source or the target.
61    /// </summary>
62    /// <value></value>
63    int INode.Degree {
64      get {
65        return (this as INode).Edges.Count;
66      }
67    }
68
69
70    /// <summary>
71    /// Gets the collection of all incoming edges, those for which this node
72    /// is the target.
73    /// </summary>
74    /// <value></value>
75    CollectionBase<IEdge> INode.InEdges {
76      get {
77
78        CollectionBase<IEdge> col = (this as INode).Edges;
79        CollectionBase<IEdge> ret = new CollectionBase<IEdge>();
80        col.ForEach(
81              delegate(IEdge edge) {
82                if (edge.TargetNode == this)
83                  ret.Add(edge);
84              }
85            );
86        return ret;
87      }
88    }
89
90    /// <summary>
91    /// Gets the collection of all outgoing edges, those for which this node
92    /// is the source.
93    /// </summary>
94    /// <value></value>
95    CollectionBase<IEdge> INode.OutEdges {
96      get {
97
98        CollectionBase<IEdge> col = (this as INode).Edges;
99        CollectionBase<IEdge> ret = new CollectionBase<IEdge>();
100        col.ForEach(
101              delegate(IEdge edge) {
102                if (edge.SourceNode == this)
103                  ret.Add(edge);
104              }
105            );
106        return ret;
107      }
108    }
109
110    /// <summary>
111    /// Gets the collection of all incident edges, those for which this node
112    /// is either the source or the target.
113    /// </summary>
114    /// <value></value>
115    CollectionBase<IEdge> INode.Edges {
116      get {
117        CollectionBase<IEdge> col = new CollectionBase<IEdge>();
118        this.Connectors.ForEach(
119            delegate(IConnector cn) {
120              foreach (IConnector cnn in cn.AttachedConnectors)
121                if (cnn.Parent is IEdge)
122                  col.Add(cnn.Parent as IEdge);
123            }
124        );
125
126        return col;
127      }
128    }
129
130    /// <summary>
131    /// Gets the collection of all adjacent nodes connected to this node by an
132    /// incoming edge (i.e., all nodes that "point" at this one).
133    /// </summary>
134    /// <value></value>
135    CollectionBase<INode> INode.InNeighbors {
136      get {
137        CollectionBase<IEdge> edges = (this as INode).InEdges;
138        CollectionBase<INode> ret = new CollectionBase<INode>();
139        edges.ForEach(
140              delegate(IEdge edge) {
141                ret.Add(edge.SourceNode);
142              }
143            );
144        return ret;
145      }
146    }
147
148    /// <summary>
149    /// Gets the collection of adjacent nodes connected to this node by an
150    /// outgoing edge (i.e., all nodes "pointed" to by this one).
151    /// </summary>
152    /// <value></value>
153    CollectionBase<INode> INode.OutNeighbors {
154      get {
155        CollectionBase<IEdge> edges = (this as INode).OutEdges;
156        CollectionBase<INode> ret = new CollectionBase<INode>();
157        edges.ForEach(
158              delegate(IEdge edge) {
159                ret.Add(edge.TargetNode);
160              }
161            );
162        return ret;
163      }
164    }
165
166
167    /// <summary>
168    /// Get an iterator over all nodes connected to this node.
169    /// </summary>
170    /// <value></value>
171    CollectionBase<INode> INode.Neighbors {
172      get {
173        CollectionBase<IEdge> edges = (this as INode).Edges;
174        CollectionBase<INode> ret = new CollectionBase<INode>();
175        edges.ForEach(
176            delegate(IEdge edge) {
177              if (edge.SourceNode == this)
178                ret.Add(edge.TargetNode);
179              else
180                ret.Add(edge.SourceNode);
181            }
182            );
183
184        return ret;
185      }
186    }
187
188    /// <summary>
189    /// Gets or sets the parent of the entity
190    /// </summary>
191    /// <value></value>
192    INode INode.ParentNode {
193      get {
194        return mParentNode;
195        ;
196      }
197      set {
198        mParentNode = value;
199      }
200    }
201
202    /// <summary>
203    /// Get the edge between this node and its parent node in a tree
204    /// structure.
205    /// </summary>
206    /// <value></value>
207    IEdge INode.ParentEdge {
208      get {
209        //return (this.Model as IGraph).SpanningTree.ParentEdge(this);
210        return mParentEdge;
211      }
212      set {
213        mParentEdge = value;
214      }
215
216    }
217
218    /// <summary>
219    /// Get the tree depth of this node.
220    /// <remarks>The root's tree depth is
221    /// zero, and each level of the tree is one depth level greater.
222    /// </remarks>
223    /// </summary>
224    /// <value></value>
225    int INode.Depth {
226      get { return mDepth; }
227      set { mDepth = value; }
228    }
229
230    /// <summary>
231    /// Get the number of tree children of this node.
232    /// </summary>
233    /// <value></value>
234    int INode.ChildCount {
235      get {
236        if (this.treeChildren == null)
237          return 0;
238        else
239          return this.treeChildren.Count;
240      }
241    }
242
243    /// <summary>
244    /// Get this node's first tree child.
245    /// </summary>
246    /// <value></value>
247    INode INode.FirstChild {
248      get {
249        if (this.treeChildren == null)
250          return null;
251        else
252          return treeChildren[0];
253      }
254    }
255
256    /// <summary>
257    /// Get this node's last tree child.
258    /// </summary>
259    /// <value></value>
260    INode INode.LastChild {
261      get {
262        if (this.treeChildren == null)
263          return null;
264        else
265          return treeChildren[this.treeChildren.Count - 1];
266      }
267    }
268
269    /// <summary>
270    /// Get this node's previous tree sibling.
271    /// </summary>
272    /// <value></value>
273    INode INode.PreviousSibling {
274      get {
275        if ((this as INode).ParentNode == null)
276          return null;
277        else {
278          CollectionBase<INode> ch = (this as INode).ParentNode.Children;
279          int chi = ch.IndexOf(this as INode);
280          if (chi < 0 || chi > ch.Count - 1)
281            throw new IndexOutOfRangeException();
282
283          if (chi == 0)
284            return null;
285          else
286            return ch[chi - 1];
287        }
288      }
289    }
290
291    /// <summary>
292    /// Get this node's next tree sibling.
293    /// </summary>
294    /// <value></value>
295    INode INode.NextSibling {
296      get {
297        if ((this as INode).ParentNode == null)
298          return null;
299        else {
300          CollectionBase<INode> ch = (this as INode).ParentNode.Children;
301          int chi = ch.IndexOf(this as INode);
302          if (chi < 0 || chi > ch.Count - 1)
303            throw new IndexOutOfRangeException();
304
305          if (chi == ch.Count - 1)
306            return null;
307          else
308            return ch[chi + 1];
309        }
310      }
311    }
312
313    /// <summary>
314    /// Gets the collection of this node's tree children.
315    /// </summary>
316    /// <value></value>
317    CollectionBase<INode> INode.Children {
318      get { return treeChildren; }
319      set { treeChildren = value; }
320    }
321
322    /// <summary>
323    /// Gets the edges from this node to its tree children.
324    /// </summary>
325    /// <value></value>
326    CollectionBase<IEdge> INode.ChildEdges {
327      get { return (this.Model as IGraph).SpanningTree.ChildEdges(this); }
328    }
329
330    #endregion
331  }
332}
Note: See TracBrowser for help on using the repository browser.