using System;
using Netron.Diagramming.Core.Analysis;
namespace Netron.Diagramming.Core {
public abstract partial class ShapeBase : INode {
#region Fields
///
/// the parent node
///
private INode mParentNode = null;
private IEdge mParentEdge = null;
private bool mIsExpanded = true;
private CollectionBase treeChildren = null;
private int mDepth = -1;
#endregion
#region Properties
///
/// Gets or sets whether this shape is fixed with respect to diagram layout
///
///
bool INode.IsFixed {
get { return mIsFixed; }
set { mIsFixed = value; }
}
///
/// Gets or sets the IsExpanded
///
public bool IsExpanded {
get { return treeChildren.Count != 0; }
set { mIsExpanded = value; }
}
///
/// Get the in-degree of the node, the number of edges for which this node
/// is the target.
///
///
int INode.InDegree {
get {
return (this as INode).InEdges.Count;
}
}
///
/// Get the out-degree of the node, the number of edges for which this node
/// is the source.
///
///
int INode.OutDegree {
get {
return (this as INode).OutEdges.Count;
}
}
///
/// Get the degree of the node, the number of edges for which this node
/// is either the source or the target.
///
///
int INode.Degree {
get {
return (this as INode).Edges.Count;
}
}
///
/// Gets the collection of all incoming edges, those for which this node
/// is the target.
///
///
CollectionBase INode.InEdges {
get {
CollectionBase col = (this as INode).Edges;
CollectionBase ret = new CollectionBase();
col.ForEach(
delegate(IEdge edge) {
if (edge.TargetNode == this)
ret.Add(edge);
}
);
return ret;
}
}
///
/// Gets the collection of all outgoing edges, those for which this node
/// is the source.
///
///
CollectionBase INode.OutEdges {
get {
CollectionBase col = (this as INode).Edges;
CollectionBase ret = new CollectionBase();
col.ForEach(
delegate(IEdge edge) {
if (edge.SourceNode == this)
ret.Add(edge);
}
);
return ret;
}
}
///
/// Gets the collection of all incident edges, those for which this node
/// is either the source or the target.
///
///
CollectionBase INode.Edges {
get {
CollectionBase col = new CollectionBase();
this.Connectors.ForEach(
delegate(IConnector cn) {
foreach (IConnector cnn in cn.AttachedConnectors)
if (cnn.Parent is IEdge)
col.Add(cnn.Parent as IEdge);
}
);
return col;
}
}
///
/// Gets the collection of all adjacent nodes connected to this node by an
/// incoming edge (i.e., all nodes that "point" at this one).
///
///
CollectionBase INode.InNeighbors {
get {
CollectionBase edges = (this as INode).InEdges;
CollectionBase ret = new CollectionBase();
edges.ForEach(
delegate(IEdge edge) {
ret.Add(edge.SourceNode);
}
);
return ret;
}
}
///
/// Gets the collection of adjacent nodes connected to this node by an
/// outgoing edge (i.e., all nodes "pointed" to by this one).
///
///
CollectionBase INode.OutNeighbors {
get {
CollectionBase edges = (this as INode).OutEdges;
CollectionBase ret = new CollectionBase();
edges.ForEach(
delegate(IEdge edge) {
ret.Add(edge.TargetNode);
}
);
return ret;
}
}
///
/// Get an iterator over all nodes connected to this node.
///
///
CollectionBase INode.Neighbors {
get {
CollectionBase edges = (this as INode).Edges;
CollectionBase ret = new CollectionBase();
edges.ForEach(
delegate(IEdge edge) {
if (edge.SourceNode == this)
ret.Add(edge.TargetNode);
else
ret.Add(edge.SourceNode);
}
);
return ret;
}
}
///
/// Gets or sets the parent of the entity
///
///
INode INode.ParentNode {
get {
return mParentNode;
;
}
set {
mParentNode = value;
}
}
///
/// Get the edge between this node and its parent node in a tree
/// structure.
///
///
IEdge INode.ParentEdge {
get {
//return (this.Model as IGraph).SpanningTree.ParentEdge(this);
return mParentEdge;
}
set {
mParentEdge = value;
}
}
///
/// Get the tree depth of this node.
/// The root's tree depth is
/// zero, and each level of the tree is one depth level greater.
///
///
///
int INode.Depth {
get { return mDepth; }
set { mDepth = value; }
}
///
/// Get the number of tree children of this node.
///
///
int INode.ChildCount {
get {
if (this.treeChildren == null)
return 0;
else
return this.treeChildren.Count;
}
}
///
/// Get this node's first tree child.
///
///
INode INode.FirstChild {
get {
if (this.treeChildren == null)
return null;
else
return treeChildren[0];
}
}
///
/// Get this node's last tree child.
///
///
INode INode.LastChild {
get {
if (this.treeChildren == null)
return null;
else
return treeChildren[this.treeChildren.Count - 1];
}
}
///
/// Get this node's previous tree sibling.
///
///
INode INode.PreviousSibling {
get {
if ((this as INode).ParentNode == null)
return null;
else {
CollectionBase ch = (this as INode).ParentNode.Children;
int chi = ch.IndexOf(this as INode);
if (chi < 0 || chi > ch.Count - 1)
throw new IndexOutOfRangeException();
if (chi == 0)
return null;
else
return ch[chi - 1];
}
}
}
///
/// Get this node's next tree sibling.
///
///
INode INode.NextSibling {
get {
if ((this as INode).ParentNode == null)
return null;
else {
CollectionBase ch = (this as INode).ParentNode.Children;
int chi = ch.IndexOf(this as INode);
if (chi < 0 || chi > ch.Count - 1)
throw new IndexOutOfRangeException();
if (chi == ch.Count - 1)
return null;
else
return ch[chi + 1];
}
}
}
///
/// Gets the collection of this node's tree children.
///
///
CollectionBase INode.Children {
get { return treeChildren; }
set { treeChildren = value; }
}
///
/// Gets the edges from this node to its tree children.
///
///
CollectionBase INode.ChildEdges {
get { return (this.Model as IGraph).SpanningTree.ChildEdges(this); }
}
#endregion
}
}