예제 #1
0
        /// <summary>
        /// Offset a branch of the tree with the specified values.
        /// </summary>
        /// <param name="tiFrom">The root node of the branch to offset.</param>
        /// <param name="xoff">The x-axis offset.</param>
        /// <param name="yoff">The y-axis offset.</param>
        private void OffsetBranch(TreeNode nodeFrom, float xoff, float yoff)
        {
            MethodCallVisitor visitor =
                new MethodCallVisitor(new VisitOperation(this.Offset));

            visitor.SetData(_XOffsetData, xoff);
            visitor.SetData(_YOffsetData, yoff);
            _tree.WalkTree(nodeFrom, visitor);
        }
예제 #2
0
        private void CalcBounds(TreeNode node, MethodCallVisitor visitor)
        {
            object     data = visitor.GetData(_CalcBoundsData);
            RectangleF rc;

            if (data == null)
            {
                rc = node.Bounds;
            }
            else
            {
                rc = Utilities.UnionRects((RectangleF)data, node.Bounds);
            }
            visitor.SetData(_CalcBoundsData, rc);
        }
예제 #3
0
        /// <summary>
        /// Build the levels of the tree. Each level contain all the nodes from that level.
        /// </summary>
        protected void BuildLevels()
        {
            int levels;
            MethodCallVisitor visitor;

            // Find the number of levels in the tree, i.e. tree depth.
            visitor = new MethodCallVisitor(new VisitOperation(this.FindMaxLevel));
            visitor.SetData(_MaxLevelData, 0);
            WalkTree(_root, visitor);
            levels = (int)visitor.GetData(_MaxLevelData) + 1;

            _treeLevels = new ArrayList();
            for (int i = 0; i < levels; i++)
            {
                _treeLevels.Add(new ArrayList());
            }

            // Assign each node to its appropriate level.
            visitor = new MethodCallVisitor(new VisitOperation(this.AssignLevel));
            visitor.SetData(_LevelAssignData, _treeLevels);
            WalkTree(_root, visitor);
        }
예제 #4
0
		private void FindMaxLevel(TreeNode node, MethodCallVisitor visitor)
		{
			visitor.SetData(_MaxLevelData,
				Math.Max(node.Level, (int)visitor.GetData(_MaxLevelData)));
		}
예제 #5
0
		/// <summary>
		/// Build the levels of the tree. Each level contain all the nodes from that level.
		/// </summary>
		protected void BuildLevels()
		{
			int levels;
			MethodCallVisitor visitor;
			// Find the number of levels in the tree, i.e. tree depth.
			visitor = new MethodCallVisitor(new VisitOperation(this.FindMaxLevel));
			visitor.SetData(_MaxLevelData, 0);
			WalkTree(_root, visitor);
			levels = (int)visitor.GetData(_MaxLevelData) + 1;

			_treeLevels = new ArrayList();
			for(int i = 0; i < levels; i++)
				_treeLevels.Add(new ArrayList());

			// Assign each node to its appropriate level.
			visitor = new MethodCallVisitor(new VisitOperation(this.AssignLevel));
			visitor.SetData(_LevelAssignData, _treeLevels);
			WalkTree(_root, visitor);
		}
예제 #6
0
 private void FindMaxLevel(TreeNode node, MethodCallVisitor visitor)
 {
     visitor.SetData(_MaxLevelData,
                     Math.Max(node.Level, (int)visitor.GetData(_MaxLevelData)));
 }
예제 #7
0
        public bool Arrange(INode rootNode,
                            TreeLayoutInfo info, LayoutProgress progress)
        {
            // Preserve the root position.
            RectangleF rcRoot = rootNode.Bounds;

            _tree = new Tree();
            if (!_tree.Build(rootNode))
            {
                return(false);
            }

            // Place the root at (0, 0)
            TreeNode root = _tree.Root;

            root.Center = new PointF(0, 0);

            // Set root's bisectors
            double deg = 0;

            switch (info.Direction)
            {
            case TreeLayoutDirection.TopToBottom:
                deg = 270;
                break;

            case TreeLayoutDirection.BottomToTop:
                deg = 90;
                break;

            case TreeLayoutDirection.LeftToRight:
                deg = 180;
                break;

            case TreeLayoutDirection.RightToLeft:
                deg = 0;
                break;
            }
            root.SetData(_LeftBisectorData, deg);
            root.SetData(_RightBisectorData, deg + 360);

            // Update progress
            int total   = _tree.TreeLevels.Count;
            int current = 0;

            if (progress != null)
            {
                progress(current++, total);
            }

            // Iterate through all levels and arrange them
            for (int l = 0; l < _tree.TreeLevels.Count - 1; l++)
            {
                // Update progress
                if (progress != null)
                {
                    progress(current++, total);
                }
                ArrangeLevel(l, info);
            }

            // Offset the whole tree structure
            float             xOff = 0;
            float             yOff = 0;
            MethodCallVisitor visitor;

            if (info.KeepRootPosition)
            {
                xOff = rcRoot.Left - root.Bounds.Left;
                yOff = rcRoot.Top - root.Bounds.Top;
            }
            else
            {
                // Calculate the bounding rect of the entire tree's
                visitor = new MethodCallVisitor(new VisitOperation(this.CalcBounds));
                _tree.WalkTree(root, visitor);
                RectangleF rc = (RectangleF)visitor.GetData(_CalcBoundsData);

                xOff = -rc.Left + info.XGap;
                yOff = -rc.Top + info.YGap;
            }
            visitor = new MethodCallVisitor(new VisitOperation(this.Offset));
            visitor.SetData(_XOffsetData, xOff);
            visitor.SetData(_YOffsetData, yOff);
            _tree.WalkTree(root, visitor);

            // Apply the stretch factor
            visitor = new MethodCallVisitor(new VisitOperation(this.Stretch));
            visitor.SetData(_StretchFactor, info.StretchFactor);
            if (info.KeepRootPosition)
            {
                visitor.SetData(_StretchCenter, _tree.Root.Center);
            }
            else
            {
                visitor.SetData(_StretchCenter, new PointF(info.XGap, info.YGap));
            }
            _tree.WalkTree(root, visitor);

            // Apply the arrangement
            visitor = new MethodCallVisitor(new VisitOperation(this.Apply));
            _tree.WalkTree(_tree.Root, visitor);

            // Update progress
            if (progress != null)
            {
                progress(total, total);
            }

            return(true);
        }