private void FindMaxLevel(TreeNode node, MethodCallVisitor visitor) { visitor.SetData(_MaxLevelData, Math.Max(node.Level, (int)visitor.GetData(_MaxLevelData))); }
private void AssignLevel(TreeNode node, MethodCallVisitor visitor) { ArrayList levels = (ArrayList)visitor.GetData(_LevelAssignData); ((ArrayList)levels[node.Level]).Add(node); }
/// <summary> /// Recursive child-building function. /// </summary> protected bool BuildChildren(TreeNode parent) { TreeNode tn; INode node = parent.Node; foreach(object link in node.OutLinks) { INode child = ((ILink)link).Destination; // Check if this child is already visited to prevent loops. if (!IsVisited(child)) { parent.Children.Add(tn = new TreeNode(parent, child)); _visited.Add(child); BuildChildren(tn); } // In case of ignore arrow direction we have to inspect the // arrow's origin as well. If ignore arrow direction is off // then in OutLinks there are only outgoing links, // and their origin is the current node, which is already visited and // nothing bad will happen. child = ((ILink)link).Origin; if (!IsVisited(child)) { parent.Children.Add(tn = new TreeNode(parent, child)); _visited.Add(child); BuildChildren(tn); } } return true; }
/// <summary> /// Build the tree. /// </summary> public bool Build(INode rootNode) { _root = new TreeNode(null, rootNode); _visited = new ArrayList(); _visited.Add(rootNode); if(!BuildChildren(_root)) return false; BuildLevels(); return true; }
/// <summary> /// Perform a operation over all tree nodes in the /// specified order. The operation is specified /// through a visitor object. /// </summary> public void WalkTree(TreeNode nodeFrom, ITreeNodeVisitor visitor) { visitor.Visit(nodeFrom); foreach(TreeNode child in nodeFrom.Children) WalkTree(child, visitor); }
/// <summary> /// Create a tree node with a given parent and an adapter, /// containing interface to access the client's tree node. /// </summary> /// <param name="parent">The parent node of this node.</param> /// <param name="node">The adapter object.</param> public TreeNode(TreeNode parent, INode node) : base(node) { // Offset the bounding rectangle to (0, 0) RectangleF bounds = Bounds; bounds.Offset(-bounds.Left, -bounds.Top); Bounds = bounds; _parent = parent; if(_parent == null) _level = 0; else _level = _parent.Level + 1; _children = new ArrayList(); }
public virtual void Visit(TreeNode node) { _operation(node, this); }