예제 #1
0
 public void AddElement(Nodepair pair, Point p)
 {
     pair.Child.OffsetX = p.X;
     pair.Child.OffsetY = p.Y;
     pair.Child.Angle   = FindAngle(pair.Child);
     Pair = pair;
     if (!AllowUpdate)
     {
         //if (pair.Root.OffsetX < p.X)
         //    Animate(pair.Child, p.X - 100, p.X, "OffsetX");
         //if (pair.Root.OffsetX > p.X)
         //    Animate(pair.Child, p.X + 100, p.X, "OffsetX");
         //if (pair.Root.OffsetY < p.Y)
         //    Animate(pair.Child, p.Y - 100, p.Y, "OffsetY");
         //if (pair.Root.OffsetY > p.Y)
         //    Animate(pair.Child, p.Y + 100, p.Y, "OffsetY");
     }
     pair.Link.SourceNode = pair.Root;
     pair.Link.TargetNode = pair.Child;
 }
예제 #2
0
        public bool Check(Nodepair root, Point p)
        {
            Rect r1 = new Rect(new Point(p.X - 60, p.Y - 30), new Point(p.X + 60, p.Y + 30));

            foreach (CustomNode n in Nodes)
            {
                Rect r = (n.Info as INodeInfo).Bounds;
                //Rect r = new Rect(n.OffsetX, n.OffsetY, (n.Info as INodeInfo).ActualWidth, (n.Info as INodeInfo).ActualHeight);
                if (n != root.Child)
                {
                    if (r1.Contains(new Point((n.Info as INodeInfo).Bounds.Left, (n.Info as INodeInfo).Bounds.Top)) || r1.Contains(new Point((n.Info as INodeInfo).Bounds.Right, (n.Info as INodeInfo).Bounds.Top)) || r1.Contains(new Point((n.Info as INodeInfo).Bounds.Left, (n.Info as INodeInfo).Bounds.Bottom)) || r1.Contains(new Point((n.Info as INodeInfo).Bounds.Right, (n.Info as INodeInfo).Bounds.Bottom)) || r.Contains(new Point(p.X, p.Y)))
                    {
                        // if (r.Contains(new Point(p.X,p.Y)) || r1.Contains(new Point((n.Info as INodeInfo).Bounds.Left, (n.Info as INodeInfo).Bounds.Top)) || r1.Contains(new Point(n.OffsetX + (n.Info as INodeInfo).Bounds.Width, n.OffsetY + (n.Info as INodeInfo).Bounds.Height)) || r1.Contains(new Point(n.OffsetX - (n.Info as INodeInfo).Bounds.Width, n.OffsetY - (n.Info as INodeInfo).Bounds.Height)))
                        return(false);
                    }
                }
            }
            //Rect r2 = new Rect(root.Root.OffsetX, root.Root.OffsetY, (root.Root.Info as INodeInfo).ActualWidth, (root.Root.Info as INodeInfo).ActualHeight);
            //if(r2.Contains(new Point(p.X - 50, p.Y - 50))|| r2.Contains(new Point(p.X + 50, p.Y + 50)))
            //    return false;
            return(true);
        }
예제 #3
0
        public void AddNode(Nodepair root)
        {
            double x  = root.Root.OffsetX;
            double y  = root.Root.OffsetY;
            double x1 = 0;
            double y1 = 0;
            double x2 = 0;
            string angle;

            if (root.Root.Pair == null)
            {
                root.Root.Pair = root.Root.InitialPair;
            }
            if (root.Root.Pair.Root == null)
            {
                for (int i = 1; i < 100; i++)
                {
                    x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                    y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                    x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                    if (Check(root, new Point(x + x1, y - y1)))
                    {
                        AddElement(root, new Point(x + x1, y - y1));
                        break;
                    }

                    else if (Check(root, new Point(x + x1, y + y1)))
                    {
                        AddElement(root, new Point(x + x1, y + y1));
                        break;
                    }

                    else if (Check(root, new Point(x - x1, y + y1)))
                    {
                        AddElement(root, new Point(x - x1, y + y1));
                        break;
                    }

                    else if (Check(root, new Point(x - x1, y - y1)))
                    {
                        AddElement(root, new Point(x - x1, y - y1));
                        break;
                    }

                    else if (Check(root, new Point(x + x2, y)))
                    {
                        AddElement(root, new Point(x + x2, y));
                        break;
                    }

                    else if (Check(root, new Point(x, y + y1)))
                    {
                        AddElement(root, new Point(x, y + y1));
                        break;
                    }

                    else if (Check(root, new Point(x - x2, y)))
                    {
                        AddElement(root, new Point(x - x2, y));
                        break;
                    }

                    else if (Check(root, new Point(x, y - y1)))
                    {
                        AddElement(root, new Point(x, y - y1));
                        break;
                    }
                }
            }
            else
            {
                angle = root.Root.Angle.ToString();
                switch (angle)
                {
                case "-90":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;

                        if (Check(root, new Point(x, y - y1)))
                        {
                            AddElement(root, new Point(x, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x1, y - y1)))
                        {
                            AddElement(root, new Point(x - x1, y - y1));
                            break;
                        }
                        else if (Check(root, new Point(x + x1, y - y1)))
                        {
                            AddElement(root, new Point(x + x1, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x2, y)))
                        {
                            AddElement(root, new Point(x - x2, y));
                            break;
                        }

                        else if (Check(root, new Point(x + x2, y)))
                        {
                            AddElement(root, new Point(x + x2, y));
                            break;
                        }
                        else if (Check(root, new Point(x - x1, y + y1)))
                        {
                            AddElement(root, new Point(x - x1, y + y1));
                            break;
                        }
                        else if (Check(root, new Point(x + x1, y + y1)))
                        {
                            AddElement(root, new Point(x + x1, y + y1));
                            break;
                        }
                    }
                }
                break;

                case "-45":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;

                        if (Check(root, new Point(x + x1, y - y1)))
                        {
                            AddElement(root, new Point(x + x1, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x2, y)))
                        {
                            AddElement(root, new Point(x + x2, y));
                            break;
                        }
                        else if (Check(root, new Point(x, y - y1)))
                        {
                            AddElement(root, new Point(x, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x1, y + y1)))
                        {
                            AddElement(root, new Point(x + x1, y + y1));
                            break;
                        }



                        else if (Check(root, new Point(x - x1, y - y1)))
                        {
                            AddElement(root, new Point(x - x1, y - y1));
                            break;
                        }



                        else if (Check(root, new Point(x, y + y1)))
                        {
                            AddElement(root, new Point(x, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x2, y)))
                        {
                            AddElement(root, new Point(x - x2, y));
                            break;
                        }
                    }
                }
                break;

                case "0":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;

                        if (Check(root, new Point(x + x2, y)))
                        {
                            AddElement(root, new Point(x + x2, y));
                            break;
                        }
                        else if (Check(root, new Point(x + x1, y - y1)))
                        {
                            AddElement(root, new Point(x + x1, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x1, y + y1)))
                        {
                            AddElement(root, new Point(x + x1, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x, y - y1)))
                        {
                            AddElement(root, new Point(x, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x, y + y1)))
                        {
                            AddElement(root, new Point(x, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x1, y - y1)))
                        {
                            AddElement(root, new Point(x - x1, y - y1));
                            break;
                        }
                        else if (Check(root, new Point(x - x1, y + y1)))
                        {
                            AddElement(root, new Point(x - x1, y + y1));
                            break;
                        }
                    }
                }
                break;

                case "45":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        if (Check(root, new Point(x + x1, y + y1)))
                        {
                            AddElement(root, new Point(x + x1, y + y1));
                            break;
                        }
                        else if (Check(root, new Point(x + x2, y)))
                        {
                            AddElement(root, new Point(x + x2, y));
                            break;
                        }

                        else if (Check(root, new Point(x, y + y1)))
                        {
                            AddElement(root, new Point(x, y + y1));
                            break;
                        }
                        else if (Check(root, new Point(x + x1, y - y1)))
                        {
                            AddElement(root, new Point(x + x1, y - y1));
                            break;
                        }
                        else if (Check(root, new Point(x - x1, y + y1)))
                        {
                            AddElement(root, new Point(x - x1, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x, y - y1)))
                        {
                            AddElement(root, new Point(x, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x2, y)))
                        {
                            AddElement(root, new Point(x - x2, y));
                            break;
                        }
                    }
                }
                break;

                case "90":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        if (Check(root, new Point(x, y + y1)))
                        {
                            AddElement(root, new Point(x, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x1, y + y1)))
                        {
                            AddElement(root, new Point(x - x1, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x1, y + y1)))
                        {
                            AddElement(root, new Point(x + x1, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x2, y)))
                        {
                            AddElement(root, new Point(x - x2, y));
                            break;
                        }
                        else if (Check(root, new Point(x + x2, y)))
                        {
                            AddElement(root, new Point(x + x2, y));
                            break;
                        }

                        else if (Check(root, new Point(x - x1, y - y1)))
                        {
                            AddElement(root, new Point(x - x1, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x1, y - y1)))
                        {
                            AddElement(root, new Point(x + x1, y - y1));
                            break;
                        }
                    }
                }
                break;

                case "135":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        if (Check(root, new Point(x - x1, y + y1)))
                        {
                            AddElement(root, new Point(x - x1, y + y1));
                            break;
                        }
                        else if (Check(root, new Point(x - x2, y)))
                        {
                            AddElement(root, new Point(x - x2, y));
                            break;
                        }

                        else if (Check(root, new Point(x, y + y1)))
                        {
                            AddElement(root, new Point(x, y + y1));
                            break;
                        }
                        else if (Check(root, new Point(x - x1, y - y1)))
                        {
                            AddElement(root, new Point(x - x1, y - y1));
                            break;
                        }
                        else if (Check(root, new Point(x + x1, y + y1)))
                        {
                            AddElement(root, new Point(x + x1, y + y1));
                            break;
                        }
                        else if (Check(root, new Point(x, y - y1)))
                        {
                            AddElement(root, new Point(x, y - y1));
                            break;
                        }
                        else if (Check(root, new Point(x + x2, y)))
                        {
                            AddElement(root, new Point(x + x2, y));
                            break;
                        }
                    }
                }
                break;

                case "180":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        if (Check(root, new Point(x - x2, y)))
                        {
                            AddElement(root, new Point(x - x2, y));
                            break;
                        }

                        else if (Check(root, new Point(x - x1, y - y1)))
                        {
                            AddElement(root, new Point(x - x1, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x1, y + y1)))
                        {
                            AddElement(root, new Point(x - x1, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x, y - y1)))
                        {
                            AddElement(root, new Point(x, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x, y + y1)))
                        {
                            AddElement(root, new Point(x, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x1, y - y1)))
                        {
                            AddElement(root, new Point(x + x1, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x1, y + y1)))
                        {
                            AddElement(root, new Point(x + x1, y + y1));
                            break;
                        }
                    }
                }
                break;

                case "-135":
                {
                    for (int i = 1; i < 10; i++)
                    {
                        x1 = (i * length - ((i - 1) * min)) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        y1 = (i * length) + (root.Root.Info as INodeInfo).ActualHeight / 2 + (root.Child.Info as INodeInfo).ActualHeight / 2;
                        x2 = (i * length) + (root.Root.Info as INodeInfo).ActualWidth / 2 + (root.Child.Info as INodeInfo).ActualWidth / 2;
                        if (Check(root, new Point(x - x1, y - y1)))
                        {
                            AddElement(root, new Point(x - x1, y - y1));
                            break;
                        }

                        else if (Check(root, new Point(x - x2, y)))
                        {
                            AddElement(root, new Point(x - x2, y));
                            break;
                        }

                        else if (Check(root, new Point(x, y - y1)))
                        {
                            AddElement(root, new Point(x, y - y1));
                            break;
                        }
                        else if (Check(root, new Point(x - x1, y + y1)))
                        {
                            AddElement(root, new Point(x - x1, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x1, y - y1)))
                        {
                            AddElement(root, new Point(x + x1, y - y1));
                            break;
                        }
                        else if (Check(root, new Point(x, y + y1)))
                        {
                            AddElement(root, new Point(x, y + y1));
                            break;
                        }

                        else if (Check(root, new Point(x + x2, y)))
                        {
                            AddElement(root, new Point(x + x2, y));
                            break;
                        }
                    }
                }
                break;
                }
            }
        }