示例#1
0
 public void Update(CustomNode node)
 {
     AddNode(node.Pair);
     foreach (CustomNode n in node.Childs)
     {
         Update(n);
     }
     //if (!Nodes.Contains(node))
     //    Nodes.Add(node);
 }
示例#2
0
 public double FindAngle(CustomNode node)
 {
     //if (node.Pair == null)
     //    node.Pair = node.InitialPair;
     if (node.Pair.Root != null)
     {
         Point  p1  = new Point(node.Pair.Root.OffsetX, node.Pair.Root.OffsetY);
         Point  p2  = new Point(node.Pair.Child.OffsetX, node.Pair.Child.OffsetY);
         double dx  = p2.X - p1.X;
         double dy  = p2.Y - p1.Y;
         double ang = Math.Atan2(dy, dx) * 180 / Math.PI;
         return(ang);
     }
     else
     {
         return(0);
     }
 }
示例#3
0
        public async void RemoveNode(CustomNode root)
        {
            if (root.Childs != null)
            {
                foreach (CustomNode node in root.Childs)
                {
                    RemoveNode(node);
                }
            }

            if (!AllowUpdate & root.Pair.Root != null)
            {
                Animate(root, (root.Info as INodeInfo).ActualWidth, 0, "Width");
                Animate(root, (root.Info as INodeInfo).ActualHeight, 0, "Height");
                if (root.Pair.Root.OffsetX < root.OffsetX)
                {
                    Animate(root, root.OffsetX, root.OffsetX - 100, "OffsetX");
                }
                if (root.Pair.Root.OffsetX > root.OffsetX)
                {
                    Animate(root, root.OffsetX, root.OffsetX + 100, "OffsetX");
                }
                if (root.Pair.Root.OffsetY < root.OffsetY)
                {
                    Animate(root, root.OffsetY, root.OffsetY - 100, "OffsetY");
                }
                if (root.Pair.Root.OffsetY > root.OffsetY)
                {
                    Animate(root, root.OffsetY, root.OffsetY + 100, "OffsetY");
                }
                await Task.Delay(TimeSpan.FromMilliseconds(200));

                if (root.Pair.Link != null)
                {
                    Lines.Remove(root.Pair.Link);
                }
                Nodes.Remove(root);
            }
            else
            {
                root.OffsetX = 700;
                root.OffsetY = 350;
            }
        }
示例#4
0
        public Storyboard RepeatAnimate(CustomNode n, double from, double to, string property, bool complete, bool autoreverse)
        {
            Storyboard storyboard = new Storyboard();

            // if (complete)
            //     storyboard.Completed += storyboard_Completed;
            // DoubleAnimation doubleAnimation = new DoubleAnimation();
            // doubleAnimation.From = from;
            // doubleAnimation.To = to;
            // if (autoreverse)
            //     doubleAnimation.AutoReverse = true;
            // doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(200));
            // doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
            // doubleAnimation.EnableDependentAnimation = true;
            // storyboard.Children.Add(doubleAnimation);
            //// Storyboard.SetTarget(doubleAnimation,n);
            // Storyboard.SetTargetProperty(doubleAnimation, property);
            // storyboard.Begin();
            return(storyboard);
        }
示例#5
0
        public CustomNode RootNode()
        {
            CustomNode n = new CustomNode();

            n.AllowDelete = false;
            n.InitialPair = new Nodepair(null, n, null);
            n.Childs      = new ObservableCollection <CustomNode>();
            n.OffsetX     = 700;
            n.OffsetY     = 350;
            //n.Constraints = n.Constraints ^ NodeConstraints.Draggable;
            //n.ContentTemplate = App.Current.Resources["RNodeTemplate"] as DataTemplate;
            var resourceDictionary = new ResourceDictionary()
            {
                Source = new Uri("ms-appx:///Template/ProcessNodeEditorTemplate.xaml", UriKind.Absolute)
            };

            n.ContentTemplate = resourceDictionary["RNodeTemplate"] as DataTemplate;
            NodePort port  = new NodePort();
            NodePort port1 = new NodePort();

            port.Visibility   = Visibility.Collapsed;
            port1.Visibility  = Visibility.Collapsed;
            port.NodeOffsetX  = 0;
            port.NodeOffsetY  = 20;
            port1.NodeOffsetX = 90;
            port1.NodeOffsetY = 20;
            n.NodePorts       = new ObservableCollection <INodePort>()
            {
                port,
                port1
            };
            n.NodeAnnotations = new ObservableCollection <IAnnotation>()
            {
                new CustomLabel()
                {
                    Content = "Root Node"
                }
            };
            Nodes.Add(n);
            return(n);
        }
示例#6
0
        public bool ChildCheck(CustomNode node)
        {
            bool IsFound = false;

            if (node.Childs != null)
            {
                foreach (CustomNode n in node.Childs)
                {
                    if (n == CheckingNode)
                    {
                        IsFound = true;
                    }
                    else
                    {
                        IsFound = ChildCheck(n);
                    }
                    if (IsFound)
                    {
                        break;
                    }
                }
            }
            return(IsFound);
        }
示例#7
0
        void CNode_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            CustomNode node = this.DataContext as CustomNode;
            string     Type = node.Type;

            if (Type != null && !Type.Equals(""))
            {
                TextBlock box = (sender as CustomLabel).ViewTemplate.LoadContent() as TextBlock;
                string    str = (sender as CustomLabel).Content.ToString();
                string[]  stringSeparators = new string[] { "\n" };
                string[]  splitted         = str.Split(stringSeparators, StringSplitOptions.None);
                string    i     = splitted.OrderByDescending(s => s.Length).First();
                int       n     = str.Length - str.Replace("\n", "").Length + 1;
                int       len   = i.Length;
                int       count = splitted.Length;
                double    size  = len * 8 + 30;
                double    ht    = count * 11 + 30 + (count - 1) * 7;
                node.UnitHeight = ht > 30 ? ht : 30;
                node.UnitWidth  = size > 50 ? size : 50;

                if (Type != null && Type.Equals("root"))
                {
                    if (node.NodePorts != null && node.NodePorts.Count() > 1)
                    {
                        (node.NodePorts.ElementAt(0) as NodePort).NodeOffsetX = 0;
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetX = UnitWidth;
                        (node.NodePorts.ElementAt(0) as NodePort).NodeOffsetY = UnitHeight / 2;
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetY = UnitHeight / 2;
                    }
                }
                else if (Type != null && Type.Equals("right"))
                {
                    if (node.NodePorts != null && node.NodePorts.Count() > 0)
                    {
                        (node.NodePorts.ElementAt(0) as NodePort).NodeOffsetX = UnitWidth;
                        (node.NodePorts.ElementAt(0) as NodePort).NodeOffsetY = UnitHeight / 2;
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetY = UnitHeight / 2;
                    }
                }
                else if (Type != null && Type.Equals("left"))
                {
                    if (node.NodePorts != null && node.NodePorts.Count() > 0)
                    {
                        (node.NodePorts.ElementAt(0) as NodePort).NodeOffsetY = UnitHeight / 2;
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetY = UnitHeight / 2;
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetX = UnitWidth;
                    }
                }
                else if (Type != null && Type.Equals("subright"))
                {
                    if (node.NodePorts != null && node.NodePorts.Count() > 1)
                    {
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetX = UnitWidth;
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetY = UnitHeight - 0.5;
                        (node.NodePorts.ElementAt(0) as NodePort).NodeOffsetY = UnitHeight - 0.5;
                        (node.NodePorts.ElementAt(1) as NodePort).UpdateLayout();
                    }
                }
                else if (Type != null && Type.Equals("subleft"))
                {
                    if (node.NodePorts != null && node.NodePorts.Count() > 1)
                    {
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetX = UnitWidth;
                        (node.NodePorts.ElementAt(0) as NodePort).NodeOffsetY = UnitHeight - 0.5;
                        (node.NodePorts.ElementAt(1) as NodePort).NodeOffsetY = UnitHeight - 0.5;
                        (node.NodePorts.ElementAt(0) as NodePort).UpdateLayout();
                    }
                }
                if (Type != null && Type.StartsWith("sub"))
                {
                    LineGeometry line = new LineGeometry();
                    if (line != null)
                    {
                        line.StartPoint = new Point(0, UnitHeight);
                        line.EndPoint   = new Point(UnitWidth, UnitHeight);
                    }
                    (node.Content as NodeCustom).path = line;
                }
                node._havetoUpdateLayout = true;
                this.InvalidateMeasure();
                this.UpdateLayout();
            }
        }
示例#8
0
 public Nodepair(CustomNode Root, CustomNode Child, CustomConnector Link)
 {
     this.Root  = Root;
     this.Child = Child;
     this.Link  = Link;
 }
示例#9
0
 private void Animate(CustomNode root, double from, double to, string name)
 {
     //root.From = from;
     //root.Pname = name;
     //root.To = to;
 }