Esempio n. 1
0
        public void MoveToNode(TreeNodeViewModel from, TreeNodeViewModel to)
        {
            // from节点不能是to节点的父级节点
            TreeNodeViewModel tmpNode = to;

            while (tmpNode != null)
            {
                if (tmpNode.IsRoot)
                {
                    break;
                }
                if (tmpNode.Id == from.Id)
                {
                    return;
                }
                tmpNode = tmpNode.Parent;
            }

            if (from.IsFold)
            {
                this.UnFold(from);
            }

            if (to.IsFold)
            {
                this.UnFold(to);
            }
            from.Parent.Children.Remove(from);
            to.Children.Add(from);
            from.Parent = to;
            TreeLayout treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 2
0
        private void MenuItem_New(object sender, RoutedEventArgs e)
        {
            if (this.ViewModel == null)
            {
                return;
            }

            Point point = Mouse.GetPosition(this.listBox);

            // one root node
            if (this.ViewModel.AllNodes.Count == 0)
            {
                TreeNodeViewModel addTreeNode = new TreeNodeViewModel(this.ViewModel, point.X, point.Y)
                {
                    Type = (int)NodeType.Selector
                };
                this.ViewModel.Add(addTreeNode, null);
            }
            else
            {
                if (this.listBox.SelectedItem != null)
                {
                    TreeNodeViewModel parentNode  = this.listBox.SelectedItem as TreeNodeViewModel;
                    TreeNodeViewModel addTreeNode = new TreeNodeViewModel(this.ViewModel, parentNode)
                    {
                        Type = (int)NodeType.Selector,
                    };
                    this.ViewModel.Add(addTreeNode, parentNode);
                }
            }
            this.listBox.SelectedItem = null;
            e.Handled = true;
        }
Esempio n. 3
0
        public void Paste(TreeNodeViewModel pasteTreeNodeViewModel)
        {
            if (this.copy == null)
            {
                return;
            }

            TreeNodeViewModel copyTreeNodeViewModel = this.copy;
            // copy节点不能是paste节点的父级节点
            TreeNodeViewModel tmpNode = pasteTreeNodeViewModel;

            while (tmpNode != null)
            {
                if (tmpNode.IsRoot)
                {
                    break;
                }
                if (tmpNode.Id == copyTreeNodeViewModel.Id)
                {
                    return;
                }
                tmpNode = tmpNode.Parent;
            }
            this.copy = null;
            this.CopyTree(copyTreeNodeViewModel, pasteTreeNodeViewModel);
        }
Esempio n. 4
0
 private void GetAllChildrenId(TreeNodeViewModel treeNodeViewModel, List <TreeNodeViewModel> children)
 {
     foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
     {
         children.Add(child);
         this.GetAllChildrenId(child, children);
     }
 }
Esempio n. 5
0
		public TreeNodeViewModel(TreeViewModel treeViewModel, TreeNodeViewModel parent)
		{
			this.TreeViewModel = treeViewModel;
			this.Id = ++treeViewModel.MaxNodeId;
			this.Parent = parent;

			this.connectorX2 = Width + this.Parent.XX - this.XX;
			this.connectorY2 = Height / 2 + this.Parent.YY - this.YY;
		}
Esempio n. 6
0
        public TreeNodeViewModel(TreeViewModel treeViewModel, TreeNodeViewModel parent)
        {
            this.TreeViewModel = treeViewModel;
            this.Id            = ++treeViewModel.MaxNodeId;
            this.Parent        = parent;

            this.connectorX2 = Width + this.Parent.XX - this.XX;
            this.connectorY2 = Height / 2 + this.Parent.YY - this.YY;
        }
Esempio n. 7
0
 private void GetAllChildrenId(TreeNodeViewModel treeNodeViewModel, List <int> children)
 {
     foreach (int childId in treeNodeViewModel.Children)
     {
         TreeNodeViewModel child = this.Get(childId);
         children.Add(child.Id);
         this.GetAllChildrenId(child, children);
     }
 }
Esempio n. 8
0
 private void FixXAndY(TreeNodeViewModel treeNode)
 {
     treeNode.XX += this.rootOffsetX;
     treeNode.YY += this.rootOffsetY;
     foreach (TreeNodeViewModel child in treeNode.Children)
     {
         this.FixXAndY(child);
     }
 }
Esempio n. 9
0
 private void RecursionMove(TreeNodeViewModel treeNodeViewModel, double offsetX, double offsetY)
 {
     treeNodeViewModel.XX += offsetX;
     treeNodeViewModel.YY += offsetY;
     foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
     {
         this.RecursionMove(child, offsetX, offsetY);
     }
 }
Esempio n. 10
0
 private void RecursionMove(TreeNodeViewModel treeNodeViewModel, double offsetX, double offsetY)
 {
     treeNodeViewModel.X += offsetX;
     treeNodeViewModel.Y += offsetY;
     foreach (var childId in treeNodeViewModel.Children)
     {
         TreeNodeViewModel child = this.Get(childId);
         this.RecursionMove(child, offsetX, offsetY);
     }
 }
Esempio n. 11
0
        private void MenuItem_Paste(object sender, RoutedEventArgs e)
        {
            if (this.listBox.SelectedItem == null)
            {
                return;
            }
            TreeNodeViewModel treeNodeViewModel = this.listBox.SelectedItem as TreeNodeViewModel;

            this.ViewModel.Paste(treeNodeViewModel);
        }
Esempio n. 12
0
        private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseEventArgs e)
        {
            this.origMouseDownPoint = e.GetPosition(this);
            FrameworkElement  item = (FrameworkElement)sender;
            TreeNodeViewModel treeNodeViewModel = item.DataContext as TreeNodeViewModel;

            this.listBox.SelectedItem = treeNodeViewModel;
            this.moveFromNode         = treeNodeViewModel;

            this.AllTreeView.nodeDataEditor.DataContext = treeNodeViewModel;
        }
Esempio n. 13
0
        public TreeNodeViewModel(TreeViewModel treeViewModel, TreeNodeViewModel parent)
        {
            this.treeViewModel = treeViewModel;
            this.data          = new TreeNodeData();
            this.data.Id       = ++treeViewModel.AllTreeViewModel.MaxNodeId;
            this.data.TreeId   = treeViewModel.TreeId;
            this.Parent        = parent;

            this.connectorX2 = Width + this.Parent.X - this.X;
            this.connectorY2 = Height / 2 + this.Parent.Y - this.Y;
        }
Esempio n. 14
0
 private void AjustTreeGap(TreeNodeViewModel treeNodeViewModel)
 {
     for (int i = 0; i < treeNodeViewModel.Children.Count - 1; ++i)
     {
         for (int j = i + 1; j < treeNodeViewModel.Children.Count; ++j)
         {
             TreeNodeViewModel left  = treeNodeViewModel.Children[i];
             TreeNodeViewModel right = treeNodeViewModel.Children[j];
             this.AjustSubTreeGap(left, right);
         }
     }
 }
Esempio n. 15
0
        public TreeViewModel(List <TreeNodeData> treeNodeDatas)
        {
            foreach (TreeNodeData treeNodeData in treeNodeDatas)
            {
                TreeNodeViewModel treeNodeViewModel = new TreeNodeViewModel(this, treeNodeData);
                this.treeNodes.Add(treeNodeViewModel);
                this.treeNodeDict[treeNodeViewModel.Id] = treeNodeViewModel;
            }
            var treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 16
0
		private void AjustTreeGap(TreeNodeViewModel treeNodeViewModel)
		{
			for (int i = 0; i < treeNodeViewModel.Children.Count - 1; ++i)
			{
				for (int j = i + 1; j < treeNodeViewModel.Children.Count; ++j)
				{
					TreeNodeViewModel left = treeNodeViewModel.Children[i];
					TreeNodeViewModel right = treeNodeViewModel.Children[j];
					this.AjustSubTreeGap(left, right);
				}
			}
		}
Esempio n. 17
0
        private void CopyTree(TreeNodeViewModel copyTreeNodeViewModel, TreeNodeViewModel parent)
        {
            TreeNodeViewModel newTreeNodeViewModel = (TreeNodeViewModel)copyTreeNodeViewModel.Clone();

            newTreeNodeViewModel.Id = ++this.MaxNodeId;

            this.Add(newTreeNodeViewModel, parent);

            foreach (TreeNodeViewModel child in copyTreeNodeViewModel.Children)
            {
                this.CopyTree(child, newTreeNodeViewModel);
            }
        }
Esempio n. 18
0
        public TreeViewModel(AllTreeViewModel allTreeViewModel)
        {
            this.AllTreeViewModel = allTreeViewModel;
            this.TreeId           = ++allTreeViewModel.MaxTreeId;
            TreeNodeViewModel treeNodeViewModel = new TreeNodeViewModel(this, 300, 100);

            this.treeNodes.Add(treeNodeViewModel);
            this.treeNodeDict[treeNodeViewModel.Id] = treeNodeViewModel;

            var treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 19
0
 private void SetChildParent(TreeNodeViewModel node)
 {
     if (node == null)
     {
         return;
     }
     node.TreeViewModel = this;
     allNodes.Add(node);
     foreach (TreeNodeViewModel child in node.Children)
     {
         child.Parent = node;
         SetChildParent(child);
     }
 }
Esempio n. 20
0
        private void MenuItem_Remove(object sender, RoutedEventArgs e)
        {
            if (this.listBox.SelectedItem == null)
            {
                return;
            }
            TreeNodeViewModel treeNodeViewModel = this.listBox.SelectedItem as TreeNodeViewModel;

            if (treeNodeViewModel.IsRoot)
            {
                return;
            }
            this.ViewModel.Remove(treeNodeViewModel);
            this.listBox.SelectedItem = null;
            e.Handled = true;
        }
Esempio n. 21
0
        /// <summary>
        /// 折叠节点
        /// </summary>
        /// <param name="treeNodeViewModel"></param>
        public void Fold(TreeNodeViewModel treeNodeViewModel)
        {
            var allChild = new List <TreeNodeViewModel>();

            this.GetAllChildrenId(treeNodeViewModel, allChild);

            foreach (TreeNodeViewModel child in allChild)
            {
                this.allNodes.Remove(child);
            }

            treeNodeViewModel.IsFold = true;

            TreeLayout treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 22
0
        /// <summary>
        /// 展开节点,一级一级展开,一次只展开下层子节点,比如下层节点是折叠的,那下下层节点不展开
        /// </summary>
        /// <param name="treeNodeViewModel"></param>
        public void UnFold(TreeNodeViewModel treeNodeViewModel)
        {
            treeNodeViewModel.IsFold = false;

            var allChild = new List <TreeNodeViewModel>();

            this.GetAllChildrenId(treeNodeViewModel, allChild);

            foreach (TreeNodeViewModel child in allChild)
            {
                this.allNodes.Add(child);
            }

            TreeLayout treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 23
0
        public void ExcuteLayout()
        {
            TreeNodeViewModel root = this.treeViewModel.Root;

            if (root == null)
            {
                return;
            }
            this.rootOrigX = root.XX;
            this.rootOrigY = root.YY;
            this.CalculatePrelimAndModify(root);
            this.CalculateRelativeXAndY(root, 0, 0);

            this.rootOffsetX = this.rootOrigX - root.XX;
            this.rootOffsetY = this.rootOrigY - root.YY;
            this.FixXAndY(root);
        }
Esempio n. 24
0
        private void MenuItem_Fold(object sender, RoutedEventArgs e)
        {
            if (this.listBox.SelectedItem == null)
            {
                return;
            }
            TreeNodeViewModel treeNodeViewModel = this.listBox.SelectedItem as TreeNodeViewModel;

            if (treeNodeViewModel.IsFold)
            {
                this.ViewModel.UnFold(treeNodeViewModel);
            }
            else
            {
                this.ViewModel.Fold(treeNodeViewModel);
            }
        }
Esempio n. 25
0
 private void CalculateRelativeXAndY(
     TreeNodeViewModel treeNodeViewModel, int level, double totalModify)
 {
     foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
     {
         this.CalculateRelativeXAndY(child, level + 1, treeNodeViewModel.Modify + totalModify);
     }
     if (treeNodeViewModel.IsLeaf)
     {
         treeNodeViewModel.XX = treeNodeViewModel.Prelim + totalModify;
     }
     else
     {
         treeNodeViewModel.XX = (treeNodeViewModel.FirstChild.XX + treeNodeViewModel.LastChild.XX) / 2;
     }
     treeNodeViewModel.YY = level * (TreeNodeViewModel.Height + YGap);
 }
Esempio n. 26
0
        private void ListBoxItem_MouseMove(object sender, MouseEventArgs e)
        {
            var item = (FrameworkElement)sender;
            var treeNodeViewModel = item.DataContext as TreeNodeViewModel;

            if (treeNodeViewModel == null)
            {
                return;
            }

            Point  curMouseDownPoint;
            Vector dragDelta;

            // 拖动根节点,移动整个树
            if (this.IsDragging && treeNodeViewModel.IsRoot)
            {
                if (this.moveFromNode == null || !this.moveFromNode.IsRoot)
                {
                    return;
                }
                curMouseDownPoint = e.GetPosition(this);
                dragDelta         = curMouseDownPoint - this.origMouseDownPoint;

                this.origMouseDownPoint = curMouseDownPoint;

                this.ViewModel.MoveToPosition(dragDelta.X, dragDelta.Y);
                return;
            }

            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.IsDragging   = false;
                this.moveFromNode = null;
                return;
            }

            curMouseDownPoint = e.GetPosition(this);
            dragDelta         = curMouseDownPoint - this.origMouseDownPoint;
            double dragDistance = Math.Abs(dragDelta.Length);

            if (dragDistance > DragThreshold)
            {
                this.IsDragging = true;
            }
            e.Handled = true;
        }
Esempio n. 27
0
        /// <summary>
        /// 展开节点,一级一级展开,一次只展开下层子节点,比如下层节点是折叠的,那下下层节点不展开
        /// </summary>
        /// <param name="treeNodeViewModel"></param>
        public void UnFold(TreeNodeViewModel treeNodeViewModel)
        {
            treeNodeViewModel.IsFold = false;

            List <int> allChildId = new List <int>();

            this.GetAllChildrenId(treeNodeViewModel, allChildId);

            foreach (int childId in allChildId)
            {
                TreeNodeViewModel child = this.Get(childId);
                this.treeNodes.Add(child);
            }

            var treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 28
0
        /// <summary>
        /// 折叠节点
        /// </summary>
        /// <param name="treeNodeViewModel"></param>
        public void Fold(TreeNodeViewModel treeNodeViewModel)
        {
            List <int> allChildId = new List <int>();

            this.GetAllChildrenId(treeNodeViewModel, allChildId);

            foreach (int childId in allChildId)
            {
                TreeNodeViewModel child = this.Get(childId);
                this.treeNodes.Remove(child);
            }

            treeNodeViewModel.IsFold = true;

            var treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 29
0
        private void CalculatePrelimAndModify(TreeNodeViewModel treeNodeViewModel)
        {
            foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
            {
                this.CalculatePrelimAndModify(child);
            }

            double prelim = 0;
            double modify = 0;

            if (treeNodeViewModel.IsLeaf)
            {
                if (treeNodeViewModel.LeftSibling == null)
                {
                    // 如果没有左邻居,不需要设置modify
                    prelim = 0;
                }
                else
                {
                    prelim = treeNodeViewModel.LeftSibling.Prelim + TreeNodeViewModel.Width + XGap;
                }
            }
            else
            {
                // 调整子树间的间距
                this.AjustTreeGap(treeNodeViewModel);
                double childrenCenter = (treeNodeViewModel.FirstChild.Prelim +
                                         treeNodeViewModel.LastChild.Prelim) / 2;
                if (treeNodeViewModel.LeftSibling == null)
                {
                    // 如果没有左邻居,不需要设置modify
                    prelim = childrenCenter;
                }
                else
                {
                    prelim = treeNodeViewModel.LeftSibling.Prelim + TreeNodeViewModel.Width + XGap;
                    modify = prelim - childrenCenter;
                }
            }
            treeNodeViewModel.Prelim = prelim;
            treeNodeViewModel.Modify = modify;

            Log.Debug("Id: " + treeNodeViewModel.Id + " Prelim: " + treeNodeViewModel.Prelim + " Modify: " + treeNodeViewModel.Modify);
        }
Esempio n. 30
0
		private void AjustSubTreeGap(TreeNodeViewModel left, TreeNodeViewModel right)
		{
			double offset = 0;
			TreeNodeViewModel tLeft = left;
			TreeNodeViewModel tRight = right;
			left.AncestorModify = 0;
			right.AncestorModify = 0;
			for (int i = 0; tLeft != null && tRight != null; ++i)
			{
				double tGap = (tRight.Prelim + tRight.AncestorModify) - (tLeft.Prelim + tLeft.AncestorModify);
				if (XGap + TreeNodeViewModel.Width - tGap > offset)
				{
					offset = XGap + TreeNodeViewModel.Width - tGap;
				}
				tLeft = this.RightMostOffspring(left, 0, i + 1);
				tRight = this.LeftMostOffspring(right, 0, i + 1);
			}
			right.Modify += offset;
			right.Prelim += offset;
		}
Esempio n. 31
0
        public void Add(TreeNodeViewModel treeNode, TreeNodeViewModel parent)
        {
            // 如果父节点是折叠的,需要先展开父节点
            if (parent != null && parent.IsFold)
            {
                this.UnFold(parent);
            }

            this.treeNodes.Add(treeNode);
            this.treeNodeDict[treeNode.Id] = treeNode;

            if (parent != null)
            {
                parent.Children.Add(treeNode.Id);
            }

            var treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 32
0
 private TreeNodeViewModel RightMostOffspring(
     TreeNodeViewModel treeNodeViewModel, int currentLevel, int searchLevel)
 {
     if (currentLevel == searchLevel)
     {
         return(treeNodeViewModel);
     }
     for (int i = treeNodeViewModel.Children.Count - 1; i >= 0; --i)
     {
         TreeNodeViewModel child = treeNodeViewModel.Children[i];
         child.AncestorModify = treeNodeViewModel.Modify + treeNodeViewModel.AncestorModify;
         TreeNodeViewModel offspring = this.RightMostOffspring(child, currentLevel + 1, searchLevel);
         if (offspring == null)
         {
             continue;
         }
         return(offspring);
     }
     return(null);
 }
Esempio n. 33
0
		private TreeNodeViewModel RightMostOffspring(
				TreeNodeViewModel treeNodeViewModel, int currentLevel, int searchLevel)
		{
			if (currentLevel == searchLevel)
			{
				return treeNodeViewModel;
			}
			for (int i = treeNodeViewModel.Children.Count - 1; i >= 0; --i)
			{
				TreeNodeViewModel child = treeNodeViewModel.Children[i];
				child.AncestorModify = treeNodeViewModel.Modify + treeNodeViewModel.AncestorModify;
				TreeNodeViewModel offspring = this.RightMostOffspring(child, currentLevel + 1, searchLevel);
				if (offspring == null)
				{
					continue;
				}
				return offspring;
			}
			return null;
		}
Esempio n. 34
0
        public void MoveRight(TreeNodeViewModel treeNodeViewModel)
        {
            if (treeNodeViewModel.IsRoot)
            {
                return;
            }
            TreeNodeViewModel parent = treeNodeViewModel.Parent;
            int index = parent.Children.IndexOf(treeNodeViewModel);

            if (index == parent.Children.Count - 1)
            {
                return;
            }
            parent.Children.Remove(treeNodeViewModel);
            parent.Children.Insert(index + 1, treeNodeViewModel);

            TreeLayout treeLayout = new TreeLayout(this);

            treeLayout.ExcuteLayout();
        }
Esempio n. 35
0
		/// <summary>
		/// 折叠节点
		/// </summary>
		/// <param name="treeNodeViewModel"></param>
		public void Fold(TreeNodeViewModel treeNodeViewModel)
		{
			var allChild = new List<TreeNodeViewModel>();
			this.GetAllChildrenId(treeNodeViewModel, allChild);

			foreach (TreeNodeViewModel child in allChild)
			{
				this.allNodes.Remove(child);
			}

			treeNodeViewModel.IsFold = true;

			TreeLayout treeLayout = new TreeLayout(this);
			treeLayout.ExcuteLayout();
		}
Esempio n. 36
0
		private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseEventArgs e)
		{
			this.origMouseDownPoint = e.GetPosition(this);
			FrameworkElement item = (FrameworkElement) sender;
			TreeNodeViewModel treeNodeViewModel = item.DataContext as TreeNodeViewModel;

			this.listBox.SelectedItem = treeNodeViewModel;
			this.moveFromNode = treeNodeViewModel;

			this.AllTreeView.nodeDataEditor.DataContext = treeNodeViewModel;
		}
Esempio n. 37
0
		private void ListBoxItem_PreviewMouseLeftButtonUp(object sender, MouseEventArgs e)
		{
			if (this.moveFromNode == null)
			{
				return;
			}
			if (this.moveFromNode.IsRoot)
			{
				return;
			}
			FrameworkElement item = (FrameworkElement) sender;
			TreeNodeViewModel moveToNode = item.DataContext as TreeNodeViewModel;
			Log.Debug("move to node: {0} {1}", this.moveFromNode.Id, moveToNode.Id);
			if (this.moveFromNode.Id == moveToNode.Id)
			{
				return;
			}
			this.ViewModel.MoveToNode(this.moveFromNode, moveToNode);
			this.moveFromNode = null;
		}
Esempio n. 38
0
		public void Add(TreeNodeViewModel treeNode, TreeNodeViewModel parent)
		{
			// 如果父节点是折叠的,需要先展开父节点
			if (parent != null)
			{
				if (parent.IsFold)
				{
					this.UnFold(parent);
				}
				treeNode.Parent = parent;
				parent.Children.Add(treeNode);
			}
			else
			{
				this.root = treeNode;
			}

			treeNode.TreeViewModel = this;
			allNodes.Add(treeNode);

			TreeLayout treeLayout = new TreeLayout(this);
			treeLayout.ExcuteLayout();
		}
Esempio n. 39
0
		private void SetChildParent(TreeNodeViewModel node)
		{
			if (node == null)
			{
				return;
			}
			node.TreeViewModel = this;
            allNodes.Add(node);
			foreach (TreeNodeViewModel child in node.Children)
			{
				child.Parent = node;
				SetChildParent(child);
			}
		}
Esempio n. 40
0
		private void CopyTree(TreeNodeViewModel copyTreeNodeViewModel, TreeNodeViewModel parent)
		{
			TreeNodeViewModel newTreeNodeViewModel = (TreeNodeViewModel)copyTreeNodeViewModel.Clone();
			newTreeNodeViewModel.Id = ++this.MaxNodeId;

			this.Add(newTreeNodeViewModel, parent);

			foreach (TreeNodeViewModel child in copyTreeNodeViewModel.Children)
			{
				this.CopyTree(child, newTreeNodeViewModel);
			}
		}
Esempio n. 41
0
		public void Paste(TreeNodeViewModel pasteTreeNodeViewModel)
		{
			if (this.copy == null)
			{
				return;
			}

			TreeNodeViewModel copyTreeNodeViewModel = this.copy;
			// copy节点不能是paste节点的父级节点
			TreeNodeViewModel tmpNode = pasteTreeNodeViewModel;
			while (tmpNode != null)
			{
				if (tmpNode.IsRoot)
				{
					break;
				}
				if (tmpNode.Id == copyTreeNodeViewModel.Id)
				{
					return;
				}
				tmpNode = tmpNode.Parent;
			}
			this.copy = null;
			this.CopyTree(copyTreeNodeViewModel, pasteTreeNodeViewModel);
		}
Esempio n. 42
0
		public void Copy(TreeNodeViewModel copyTreeNodeViewModel)
		{
			this.copy = copyTreeNodeViewModel;
		}
Esempio n. 43
0
		private void MenuItem_New(object sender, RoutedEventArgs e)
		{
			if (this.ViewModel == null)
			{
				return;
			}

			Point point = Mouse.GetPosition(this.listBox);

			// one root node
			if (this.ViewModel.AllNodes.Count == 0)
			{
				TreeNodeViewModel addTreeNode = new TreeNodeViewModel(this.ViewModel, point.X, point.Y)
				{
					Type = (int) NodeType.Selector
				};
				this.ViewModel.Add(addTreeNode, null);
			}
			else
			{
				if (this.listBox.SelectedItem != null)
				{
					TreeNodeViewModel parentNode = this.listBox.SelectedItem as TreeNodeViewModel;
					TreeNodeViewModel addTreeNode = new TreeNodeViewModel(this.ViewModel, parentNode)
					{
						Type = (int) NodeType.Selector,
					};
					this.ViewModel.Add(addTreeNode, parentNode);
				}
			}
			this.listBox.SelectedItem = null;
			e.Handled = true;
		}
Esempio n. 44
0
		private void CalculateRelativeXAndY(
				TreeNodeViewModel treeNodeViewModel, int level, double totalModify)
		{
			foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
			{
				this.CalculateRelativeXAndY(child, level + 1, treeNodeViewModel.Modify + totalModify);
			}
			if (treeNodeViewModel.IsLeaf)
			{
				treeNodeViewModel.XX = treeNodeViewModel.Prelim + totalModify;
			}
			else
			{
				treeNodeViewModel.XX = (treeNodeViewModel.FirstChild.XX + treeNodeViewModel.LastChild.XX) / 2;
			}
			treeNodeViewModel.YY = level * (TreeNodeViewModel.Height + YGap);
		}
Esempio n. 45
0
		private void CalculatePrelimAndModify(TreeNodeViewModel treeNodeViewModel)
		{
			foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
			{
				this.CalculatePrelimAndModify(child);
			}

			double prelim = 0;
			double modify = 0;

			if (treeNodeViewModel.IsLeaf)
			{
				if (treeNodeViewModel.LeftSibling == null)
				{
					// 如果没有左邻居,不需要设置modify
					prelim = 0;
				}
				else
				{
					prelim = treeNodeViewModel.LeftSibling.Prelim + TreeNodeViewModel.Width + XGap;
				}
			}
			else
			{
				// 调整子树间的间距
				this.AjustTreeGap(treeNodeViewModel);
				double childrenCenter = (treeNodeViewModel.FirstChild.Prelim +
				                         treeNodeViewModel.LastChild.Prelim) / 2;
				if (treeNodeViewModel.LeftSibling == null)
				{
					// 如果没有左邻居,不需要设置modify
					prelim = childrenCenter;
				}
				else
				{
					prelim = treeNodeViewModel.LeftSibling.Prelim + TreeNodeViewModel.Width + XGap;
					modify = prelim - childrenCenter;
				}
			}
			treeNodeViewModel.Prelim = prelim;
			treeNodeViewModel.Modify = modify;

			Log.Debug("Id: " + treeNodeViewModel.Id + " Prelim: " + treeNodeViewModel.Prelim + " Modify: " + treeNodeViewModel.Modify);
		}
Esempio n. 46
0
		public void Remove(TreeNodeViewModel treeNodeViewModel)
		{
			var all = new List<TreeNodeViewModel>();
			this.GetChildrenIdAndSelf(treeNodeViewModel, all);

			foreach (TreeNodeViewModel child in all)
			{
				this.allNodes.Remove(child);
			}

			TreeNodeViewModel parent = treeNodeViewModel.Parent;
			if (parent != null)
			{
				parent.Children.Remove(treeNodeViewModel);
			}

			TreeLayout treeLayout = new TreeLayout(this);
			treeLayout.ExcuteLayout();
		}
Esempio n. 47
0
		private void GetAllChildrenId(TreeNodeViewModel treeNodeViewModel, List<TreeNodeViewModel> children)
		{
			foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
			{
				children.Add(child);
				this.GetAllChildrenId(child, children);
			}
		}
Esempio n. 48
0
		private void GetChildrenIdAndSelf(TreeNodeViewModel treeNodeViewModel, List<TreeNodeViewModel> children)
		{
			children.Add(treeNodeViewModel);
			this.GetAllChildrenId(treeNodeViewModel, children);
		}
Esempio n. 49
0
		/// <summary>
		/// 展开节点,一级一级展开,一次只展开下层子节点,比如下层节点是折叠的,那下下层节点不展开
		/// </summary>
		/// <param name="treeNodeViewModel"></param>
		public void UnFold(TreeNodeViewModel treeNodeViewModel)
		{
			treeNodeViewModel.IsFold = false;

			var allChild = new List<TreeNodeViewModel>();
			this.GetAllChildrenId(treeNodeViewModel, allChild);

			foreach (TreeNodeViewModel child in allChild)
			{
				this.allNodes.Add(child);
			}

			TreeLayout treeLayout = new TreeLayout(this);
			treeLayout.ExcuteLayout();
		}
Esempio n. 50
0
		public void MoveRight(TreeNodeViewModel treeNodeViewModel)
		{
			if (treeNodeViewModel.IsRoot)
			{
				return;
			}
			TreeNodeViewModel parent = treeNodeViewModel.Parent;
			int index = parent.Children.IndexOf(treeNodeViewModel);
			if (index == parent.Children.Count - 1)
			{
				return;
			}
			parent.Children.Remove(treeNodeViewModel);
			parent.Children.Insert(index + 1, treeNodeViewModel);

			TreeLayout treeLayout = new TreeLayout(this);
			treeLayout.ExcuteLayout();
		}
Esempio n. 51
0
		private void RecursionMove(TreeNodeViewModel treeNodeViewModel, double offsetX, double offsetY)
		{
			treeNodeViewModel.XX += offsetX;
			treeNodeViewModel.YY += offsetY;
			foreach (TreeNodeViewModel child in treeNodeViewModel.Children)
			{
				this.RecursionMove(child, offsetX, offsetY);
			}
		}
Esempio n. 52
0
		private void ListBoxItem_MouseMove(object sender, MouseEventArgs e)
		{
			var item = (FrameworkElement) sender;
			var treeNodeViewModel = item.DataContext as TreeNodeViewModel;
			if (treeNodeViewModel == null)
			{
				return;
			}

			Point curMouseDownPoint;
			Vector dragDelta;
			// 拖动根节点,移动整个树
			if (this.IsDragging && treeNodeViewModel.IsRoot)
			{
				if (this.moveFromNode == null || !this.moveFromNode.IsRoot)
				{
					return;
				}
				curMouseDownPoint = e.GetPosition(this);
				dragDelta = curMouseDownPoint - this.origMouseDownPoint;

				this.origMouseDownPoint = curMouseDownPoint;

				this.ViewModel.MoveToPosition(dragDelta.X, dragDelta.Y);
				return;
			}

			if (e.LeftButton != MouseButtonState.Pressed)
			{
				this.IsDragging = false;
				this.moveFromNode = null;
				return;
			}

			curMouseDownPoint = e.GetPosition(this);
			dragDelta = curMouseDownPoint - this.origMouseDownPoint;
			double dragDistance = Math.Abs(dragDelta.Length);
			if (dragDistance > DragThreshold)
			{
				this.IsDragging = true;
			}
			e.Handled = true;
		}
Esempio n. 53
0
		private void FixXAndY(TreeNodeViewModel treeNode)
		{
			treeNode.XX += this.rootOffsetX;
			treeNode.YY += this.rootOffsetY;
			foreach (TreeNodeViewModel child in treeNode.Children)
			{
				this.FixXAndY(child);
			}
		}
Esempio n. 54
0
		public void MoveToNode(TreeNodeViewModel from, TreeNodeViewModel to)
		{
			// from节点不能是to节点的父级节点
			TreeNodeViewModel tmpNode = to;
			while (tmpNode != null)
			{
				if (tmpNode.IsRoot)
				{
					break;
				}
				if (tmpNode.Id == from.Id)
				{
					return;
				}
				tmpNode = tmpNode.Parent;
			}

			if (from.IsFold)
			{
				this.UnFold(from);
			}

			if (to.IsFold)
			{
				this.UnFold(to);
			}
			from.Parent.Children.Remove(from);
			to.Children.Add(from);
			from.Parent = to;
			TreeLayout treeLayout = new TreeLayout(this);
			treeLayout.ExcuteLayout();
		}