Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Analysis/ShapeBase.Analysis.cs @ 2768

Last change on this file since 2768 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

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