[2768] | 1 | using System;
|
---|
| 2 | using Netron.Diagramming.Core.Analysis;
|
---|
[4068] | 3 | namespace 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
|
---|
[2768] | 15 |
|
---|
[4068] | 16 | #region Properties
|
---|
[2768] | 17 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 26 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 34 |
|
---|
| 35 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 46 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 57 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 68 |
|
---|
| 69 |
|
---|
[4068] | 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 {
|
---|
[2768] | 77 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 89 |
|
---|
[4068] | 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 {
|
---|
[2768] | 97 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 109 |
|
---|
[4068] | 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);
|
---|
[2768] | 123 | }
|
---|
[4068] | 124 | );
|
---|
[2768] | 125 |
|
---|
[4068] | 126 | return col;
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
[2768] | 129 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 147 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 165 |
|
---|
| 166 |
|
---|
[4068] | 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);
|
---|
[2768] | 181 | }
|
---|
[4068] | 182 | );
|
---|
[2768] | 183 |
|
---|
[4068] | 184 | return ret;
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
[2768] | 187 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 201 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 215 |
|
---|
[4068] | 216 | }
|
---|
[2768] | 217 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 229 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 242 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 255 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 268 |
|
---|
[4068] | 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];
|
---|
[2768] | 287 | }
|
---|
[4068] | 288 | }
|
---|
| 289 | }
|
---|
[2768] | 290 |
|
---|
[4068] | 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];
|
---|
[2768] | 309 | }
|
---|
[4068] | 310 | }
|
---|
| 311 | }
|
---|
[2768] | 312 |
|
---|
[4068] | 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; }
|
---|
[2768] | 320 | }
|
---|
[4068] | 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 | }
|
---|
[2768] | 332 | }
|
---|