Ejemplo n.º 1
0
 private void CollectionChangedHandler(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.NewItems != null)
     {
         ConnectorCollection.Add(new IPluginInformation(((ConnectorVisual)e.NewItems[0]).Model));
     }
 }
Ejemplo n.º 2
0
        protected override void SiteChanged()
        {
            connectors.Remove(cBottom);
            cBottom = new Connector(new Point((int)(rectangle.Left + rectangle.Width / 2), rectangle.Bottom));
            cBottom.ContainEntity = this;
            cBottom.ConnectorsIndexOfContainEntity = connectors.Count;
            cBottom.Site               = this.site;
            cBottom.OwnerID            = this.ObjectID;
            cBottom.Index              = connectors.Count;
            cBottom.Name               = "Bottom connector";
            cBottom.ConnectorDirection = ConnectorDirection.Down;
            connectors.Add(cBottom);

            connectors.Remove(cLeft);
            cLeft = new Connector(new Point(rectangle.Left, (int)(rectangle.Top + rectangle.Height / 2)));
            cLeft.ContainEntity = this;
            cLeft.ConnectorsIndexOfContainEntity = connectors.Count;
            cLeft.Site               = this.site;
            cLeft.OwnerID            = this.ObjectID;
            cLeft.Index              = connectors.Count;
            cLeft.Name               = "Left connector";
            cLeft.ConnectorDirection = ConnectorDirection.Left;
            connectors.Add(cLeft);

            connectors.Remove(cRight);
            cRight = new Connector(new Point(rectangle.Right, (int)(rectangle.Top + rectangle.Height / 2)));
            cRight.ContainEntity = this;
            cRight.ConnectorsIndexOfContainEntity = connectors.Count;
            cRight.Site               = this.site;
            cRight.OwnerID            = this.ObjectID;
            cRight.Index              = connectors.Count;
            cRight.Name               = "Right connector";
            cRight.ConnectorDirection = ConnectorDirection.Right;
            connectors.Add(cRight);

            connectors.Remove(cTop);
            cTop = new Connector(new Point((int)(rectangle.Left + rectangle.Width / 2), rectangle.Top));
            cTop.ContainEntity = this;
            cTop.ConnectorsIndexOfContainEntity = connectors.Count;
            cTop.Site               = this.site;
            cTop.OwnerID            = this.ObjectID;
            cTop.Index              = connectors.Count;
            cTop.Name               = "Top connector";
            cTop.ConnectorDirection = ConnectorDirection.Up;
            connectors.Add(cTop);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a connection between the two given points
        /// </summary>
        /// <param name="from">the starting point of the connection</param>
        /// <param name="to">the end-point of the connection</param>
        public Connection(DiagramPoint from, DiagramPoint to)
        {
            Connector connector1, connector2;

            Connectors = new ConnectorCollection();

            this.from                  = new Connector(from.Copy());
            this.from.Name             = "From";
            this.from.LocationChanged += Connector_LocationChanged;
            connector1                 = this.from;
            Connectors.Add(connector1);

            this.to                    = new Connector(to.Copy());
            this.To.Name               = "To";
            connector2                 = this.to;
            this.to.LocationChanged   += Connector_LocationChanged;
            this.To.AttachedToChanged += To_AttachedToChanged;
            Connectors.Add(connector2);
        }
 /// <summary>
 /// Attaches the given connector to this connector
 /// </summary>
 /// <param name="c"></param>
 public void AttachConnector(Connector c)
 {
     //remove from the previous, if any
     if (c.attachedTo != null)
     {
         c.attachedTo.attachedConnectors.Remove(c);
     }
     attachedConnectors.Add(c);
     c.AttachedTo = this;
 }
Ejemplo n.º 5
0
        private void Init()
        {
            m_leftConnector = new Connector(this, "Left", true);
            Connectors.Add(m_leftConnector);

            Connector t_connector = null;

            for (int i = 0; i < m_switchCount; i++)
            {
                t_connector = new Connector(this, i.ToString(), true);
                t_connector.AllowNewConnectionsTo = false;
                m_switchConnectors.Add(t_connector);
            }

            Connectors.AddRange(m_switchConnectors);
        }
Ejemplo n.º 6
0
        private void InitialPath()
        {
            Connector           connector1 = this.from, connector2 = this.to;
            int                 x = 0, y = 0;
            ConnectorCollection connectors = new ConnectorCollection();

            connectors.Add(this.from);

            #region  对上

            if (connector1.ConnectorDirection == ConnectorDirection.Down && connector2.ConnectorDirection == ConnectorDirection.Up)
            {
                if (connector1.Point.Y < connector2.Point.Y && connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y >= connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y + 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = (connector1.Point.X + connector2.Point.X) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y -= 30 + connector1.Point.Y - connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region  对左

            else if (connector1.ConnectorDirection == ConnectorDirection.Down && connector2.ConnectorDirection == ConnectorDirection.Left)
            {
                if (connector1.Point.Y < connector2.Point.Y && connector1.Point.X >= connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X - 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y < connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y + 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X - 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region  对右

            else if (connector1.ConnectorDirection == ConnectorDirection.Down && connector2.ConnectorDirection == ConnectorDirection.Right)
            {
                if (connector1.Point.Y < connector2.Point.Y && connector1.Point.X <= connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y < connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y + 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region  对下

            else if (connector1.ConnectorDirection == ConnectorDirection.Down && connector2.ConnectorDirection == ConnectorDirection.Down)
            {
                if (connector1.Point.Y < connector2.Point.Y && connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = connector2.Point.Y + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y < connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y + 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y + 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector1.Point.X + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y -= 10 + (connector1.Point.Y - connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region 右对上

            else if (connector1.ConnectorDirection == ConnectorDirection.Right && connector2.ConnectorDirection == ConnectorDirection.Up)
            {
                if (connector1.Point.Y < connector2.Point.Y && connector1.Point.X + 10 >= connector2.Point.X)
                {
                    x = connector1.Point.X + 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y < connector2.Point.Y)
                {
                    x = connector2.Point.X;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else
                {
                    x = connector1.Point.X + 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y - 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region 右对右

            else if (connector1.ConnectorDirection == ConnectorDirection.Right && connector2.ConnectorDirection == ConnectorDirection.Right)
            {
                x = Math.Max(connector1.Point.X + 10, connector2.Point.X + 20);
                y = connector1.Point.Y;
                connectors.Add(new Connector(new DiagramPoint(x, y)));

                y = connector2.Point.Y;
                connectors.Add(new Connector(new DiagramPoint(x, y)));
            }

            #endregion

            #region 右对下

            else if (connector1.ConnectorDirection == ConnectorDirection.Right && connector2.ConnectorDirection == ConnectorDirection.Down)
            {
                if (connector1.Point.Y < connector2.Point.Y)
                {
                    x = connector1.Point.X + 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y == connector2.Point.Y)
                {
                    x = connector1.Point.X + 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector1.Point.Y + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.X + 10 < connector2.Point.X)
                {
                    x = connector2.Point.X;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else
                {
                    x = connector1.Point.X + 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region 右对左

            else if (connector1.ConnectorDirection == ConnectorDirection.Right && connector2.ConnectorDirection == ConnectorDirection.Left)
            {
                if (connector1.Point.X + 10 >= connector2.Point.X)
                {
                    x = connector1.Point.X + 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X - 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else
                {
                    x = connector1.Point.X + 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region  对上

            else if (connector1.ConnectorDirection == ConnectorDirection.Up && connector2.ConnectorDirection == ConnectorDirection.Up)
            {
                x = connector1.Point.X;
                y = Math.Min(connector1.Point.Y - 10, connector2.Point.Y - 20);
                connectors.Add(new Connector(new DiagramPoint(x, y)));

                x = connector2.Point.X;
                connectors.Add(new Connector(new DiagramPoint(x, y)));
            }

            #endregion

            #region  对右

            else if (connector1.ConnectorDirection == ConnectorDirection.Up && connector2.ConnectorDirection == ConnectorDirection.Right)
            {
                if (connector1.Point.Y > connector2.Point.Y && connector1.Point.X > connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y > connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y <= connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y - 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region  对下

            else if (connector1.ConnectorDirection == ConnectorDirection.Up && connector2.ConnectorDirection == ConnectorDirection.Down)
            {
                if (connector1.Point.Y > connector2.Point.Y && connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y < connector2.Point.Y && connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y - 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = (connector1.Point.X + connector2.Point.X) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region  对左

            else if (connector1.ConnectorDirection == ConnectorDirection.Up && connector2.ConnectorDirection == ConnectorDirection.Left)
            {
                if (connector1.Point.Y > connector2.Point.Y && connector1.Point.X < connector2.Point.X)
                {
                    x = connector1.Point.X;
                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y > connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X - 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y <= connector2.Point.Y)
                {
                    x = connector1.Point.X;
                    y = connector1.Point.Y - 10;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X - 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region 左对上

            else if (connector1.ConnectorDirection == ConnectorDirection.Left && connector2.ConnectorDirection == ConnectorDirection.Up)
            {
                if (connector1.Point.Y < connector2.Point.Y && connector1.Point.X - 10 >= connector2.Point.X)
                {
                    x = connector2.Point.X;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y < connector2.Point.Y)
                {
                    x = connector1.Point.X - 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.Y > connector2.Point.Y)
                {
                    x = connector1.Point.X - 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y - 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region 左对右

            else if (connector1.ConnectorDirection == ConnectorDirection.Left && connector2.ConnectorDirection == ConnectorDirection.Right)
            {
                if (connector1.Point.X - 10 >= connector2.Point.X)
                {
                    x = (connector1.Point.X + connector2.Point.X) / 2;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else
                {
                    x = connector1.Point.X - 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = (connector1.Point.Y + connector2.Point.Y) / 2;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region 左对下

            else if (connector1.ConnectorDirection == ConnectorDirection.Left && connector2.ConnectorDirection == ConnectorDirection.Down)
            {
                if (connector1.Point.Y > connector2.Point.Y && connector1.Point.X > connector2.Point.X)
                {
                    x = connector2.Point.X;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
                else if (connector1.Point.X != connector2.Point.X)
                {
                    x = connector1.Point.X - 10;
                    y = connector1.Point.Y;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    y = connector2.Point.Y + 20;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));

                    x = connector2.Point.X;
                    connectors.Add(new Connector(new DiagramPoint(x, y)));
                }
            }

            #endregion

            #region 左对左

            else if (connector1.ConnectorDirection == ConnectorDirection.Left && connector2.ConnectorDirection == ConnectorDirection.Left)
            {
                x = Math.Min(connector1.Point.X - 10, connector2.Point.X - 20);
                y = connector1.Point.Y;
                connectors.Add(new Connector(new DiagramPoint(x, y)));

                y = connector2.Point.Y;
                connectors.Add(new Connector(new DiagramPoint(x, y)));
            }

            #endregion

            connectors.Add(this.to);
            Connectors = connectors;
        }
Ejemplo n.º 7
0
        //Connects the Hexagon arrangment Nodes.
        private void CreateConnection()
        {
            int                 increment           = 0;
            int                 altenate            = 0;
            NodeCollection      nodecollection      = diagram.Nodes as NodeCollection;
            ConnectorCollection connectorcollection = diagram.Connectors as ConnectorCollection;

            for (int j = 1; j < 101; j++)
            {
                for (int i = 0; i < 100; i++)
                {
                    if ((i + increment + 1) % 100 != 0)
                    {
                        ConnectorViewModel cv1 = new ConnectorViewModel()
                        {
                            SourceNode = nodecollection.ToList()[i + increment],
                            TargetNode = nodecollection.ToList()[i + 1 + increment],
                        };
                        connectorcollection.Add(cv1);
                    }
                    if (j == 1 && i == 0)
                    {
                        ConnectorViewModel cv1 = new ConnectorViewModel()
                        {
                            SourceNode = nodecollection.ToList()[i],
                            TargetNode = nodecollection.ToList()[i + 101],
                        };
                        connectorcollection.Add(cv1);
                    }
                    if (j != 1)
                    {
                        if (i == 0)
                        {
                            if (!((increment + 100) > 9900))
                            {
                                ConnectorViewModel cv1 = new ConnectorViewModel()
                                {
                                    SourceNode = nodecollection.ToList()[i + increment],
                                    TargetNode = nodecollection.ToList()[i + 1 + (increment + 100)],
                                };
                                connectorcollection.Add(cv1);
                            }
                        }
                        else
                        {
                            altenate += 1;
                            if (altenate == 2 || altenate == 5)
                            {
                                if (altenate == 2)
                                {
                                    ConnectorViewModel cv1 = new ConnectorViewModel()
                                    {
                                        SourceNode = nodecollection.ToList()[i + increment],
                                        TargetNode = nodecollection.ToList()[i + 1 + (increment - 100)],
                                    };
                                    connectorcollection.Add(cv1);
                                }
                                else
                                {
                                    ConnectorViewModel cv1 = new ConnectorViewModel()
                                    {
                                        SourceNode = nodecollection.ToList()[i + increment],
                                        TargetNode = nodecollection.ToList()[i - 1 + (increment - 100)],
                                    };
                                    connectorcollection.Add(cv1);
                                }
                            }
                            if (altenate == 5)
                            {
                                altenate  = 0;
                                altenate += 1;
                            }
                        }
                    }
                }
                increment += 100;
                altenate   = 0;
            }
        }
Ejemplo n.º 8
0
        public void DeserializeNetwork(string filePath)
        {
            NewFile();

            // Create an reader
            using (var reader = new XmlTextReader(filePath))
            {
                reader.MoveToContent();

                var enumString = reader.GetAttribute("GraphFlowDirection");

                if (enumString != null)
                {
                    ImportFlowDirection =
                        (GraphFlowDirections)Enum.Parse(typeof(GraphFlowDirections), enumString, true);
                }


                reader.ReadToDescendant("Nodes");

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:

                        if (reader.Name != null)
                        {
                            var type = Type.GetType(reader.Name);

                            if (type == null)
                            {
                                try     // try to find type in entry assembly
                                {
                                    var assembly = Assembly.GetEntryAssembly();
                                    type = assembly.GetTypes().First(t => t.FullName == reader.Name);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex);
                                }

                                try     // try to find type in ExternalNodeTypes
                                {
                                    type = ExternalNodeTypes.ToArray().First(t => t.FullName == reader.Name);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex);
                                }
                            }


                            if (type != null)
                            {
                                if (type.IsSubclassOf(typeof(Node)))
                                {
                                    var node = (Node)Activator.CreateInstance(type, this);
                                    node.DeserializeNetwork(reader);
                                    NodeCollection.Add(node);
                                }
                                else if (type == typeof(Connector))
                                {
                                    Node startNode = null;
                                    Node endNode   = null;

                                    var value = reader.GetAttribute("StartNode");
                                    if (value != null)
                                    {
                                        startNode =
                                            NodeCollection.FirstOrDefault(node => node.Guid == new Guid(value));
                                    }

                                    value = reader.GetAttribute("EndNode");
                                    if (value != null)
                                    {
                                        endNode = NodeCollection.FirstOrDefault(node => node.Guid == new Guid(value));
                                    }

                                    value = reader.GetAttribute("StartIndex");
                                    var startIndex = Convert.ToInt32(value);

                                    value = reader.GetAttribute("EndIndex");
                                    var endIndex = Convert.ToInt32(value);


                                    if (startNode != null && endNode != null)
                                    {
                                        var startPort = startNode.OutputPorts[startIndex];
                                        var endPort   = endNode.InputPorts[endIndex];

                                        if (startPort != null && endPort != null)
                                        {
                                            var connector = new Connector(this, startPort, endPort);
                                            ConnectorCollection.Add(connector);
                                        }
                                    }
                                }
                            }
                        }

                        break;

                    case XmlNodeType.Text:

                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:

                        break;

                    case XmlNodeType.Comment:

                        break;

                    case XmlNodeType.EndElement:

                        break;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /*
         * public void DoDynamicAnimation(object sender, MouseButtonEventArgs args)
         * {
         *  for (var i = 0; i < 36; ++i)
         *  {
         *      // var e = new Button { Width = 50, Height = 16, Content="Test" };
         *
         *      //var e = new Ellipse { Width = 16, Height = 16, Fill = SystemColors.HighlightBrush };
         *      //var e = new Ellipse { Width = 6, Height = 6, Fill=Brushes.HotPink };
         *
         *      var e = new SliderNode(this) {Left = Mouse.GetPosition(this).X, Top = Mouse.GetPosition(this).Y};
         *
         *      // var e = new TextBlock { Text = "Test" };
         *      // var e = new Slider { Width = 100 };
         *
         *      // var e = new ProgressBar { Width = 100 , Height =10, Value=i };
         *
         *      // var e = =new DataGrid{Width=100, Height=100};
         *      // var e = new TextBox { Text = "Hallo" };
         *      // var e = new Label { Content = "Halllo" };
         *      // var e = new RadioButton { Content="dfsdf" };
         *
         *      //Canvas.SetLeft(e, Mouse.GetPosition(this).X);
         *      //Canvas.SetTop(e, Mouse.GetPosition(this).Y);
         *
         *      var tg = new TransformGroup();
         *      var translation = new TranslateTransform(30, 0);
         *      var translationName = "myTranslation" + translation.GetHashCode();
         *      RegisterName(translationName, translation);
         *      tg.Children.Add(translation);
         *      tg.Children.Add(new RotateTransform(i*10));
         *      e.RenderTransform = tg;
         *
         *      NodeCollection.Add(e);
         *      Children.Add(e);
         *
         *      var anim = new DoubleAnimation(3, 250, new Duration(new TimeSpan(0, 0, 0, 2, 0)))
         *      {
         *          EasingFunction = new PowerEase {EasingMode = EasingMode.EaseOut}
         *      };
         *
         *      var s = new Storyboard();
         *      Storyboard.SetTargetName(s, translationName);
         *      Storyboard.SetTargetProperty(s, new PropertyPath(TranslateTransform.YProperty));
         *      var storyboardName = "s" + s.GetHashCode();
         *      Resources.Add(storyboardName, s);
         *
         *      s.Children.Add(anim);
         *
         *      s.Completed +=
         *          (sndr, evtArgs) =>
         *          {
         *              //panel.Children.Remove(e);
         *              Resources.Remove(storyboardName);
         *              UnregisterName(translationName);
         *          };
         *      s.Begin();
         *  }
         * }
         */


        public void VplControl_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Delete:

                foreach (var node in SelectedNodes)
                {
                    node.Delete();
                }

                SelectedNodes.Clear();
                break;

            case Key.C:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    tempCollection = new TrulyObservableCollection <Node>();


                    foreach (var node in SelectedNodes)
                    {
                        tempCollection.Add(node);
                    }
                }
            }
            break;

            case Key.V:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    if (tempCollection == null)
                    {
                        return;
                    }
                    if (tempCollection.Count == 0)
                    {
                        return;
                    }

                    var bBox = Node.GetBoundingBoxOfNodes(tempCollection.ToList());

                    var copyPoint  = new Point(bBox.Left + bBox.Size.Width / 2, bBox.Top + bBox.Size.Height / 2);
                    var pastePoint = Mouse.GetPosition(this);

                    var delta = Point.Subtract(pastePoint, copyPoint);

                    SelectedNodes.Clear();

                    var alreadyClonedConnectors = new List <Connector>();
                    var copyConnections         = new List <CopyConnection>();

                    // copy nodes from clipboard to canvas
                    foreach (var node in tempCollection)
                    {
                        var newNode = node.Clone();

                        newNode.Left += delta.X;
                        newNode.Top  += delta.Y;

                        newNode.Left = Convert.ToInt32(newNode.Left);
                        newNode.Top  = Convert.ToInt32(newNode.Top);

                        NodeCollection.Add(newNode);

                        copyConnections.Add(new CopyConnection {
                                NewNode = newNode, OldNode = node
                            });
                    }

                    foreach (var cc in copyConnections)
                    {
                        var counter = 0;

                        foreach (var conn in cc.OldNode.InputPorts)
                        {
                            foreach (var connector in conn.ConnectedConnectors)
                            {
                                if (!alreadyClonedConnectors.Contains(connector))
                                {
                                    Connector newConnector = null;

                                    // start and end node are contained in selection
                                    if (tempCollection.Contains(connector.StartPort.ParentNode))
                                    {
                                        var cc2 =
                                            copyConnections.FirstOrDefault(
                                                i => Equals(i.OldNode, connector.StartPort.ParentNode));

                                        if (cc2 != null)
                                        {
                                            newConnector = new Connector(this, cc2.NewNode.OutputPorts[0],
                                                                         cc.NewNode.InputPorts[counter]);
                                        }
                                    }
                                    // only end node is contained in selection
                                    else
                                    {
                                        newConnector = new Connector(this, connector.StartPort,
                                                                     cc.NewNode.InputPorts[counter]);
                                    }

                                    if (newConnector != null)
                                    {
                                        alreadyClonedConnectors.Add(connector);
                                        ConnectorCollection.Add(newConnector);
                                    }
                                }
                            }
                            counter++;
                        }
                    }
                }
            }
            break;

            case Key.G:
            {
                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    GroupNodes();
                }
            }
            break;

            case Key.S:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    SaveFile();
                }
            }
            break;

            case Key.O:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    OpenFile();
                }
            }
            break;

            case Key.A:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    SelectedNodes.Clear();

                    foreach (var node in NodeCollection)
                    {
                        node.IsSelected = true;
                        SelectedNodes.Add(node);
                    }
                }
            }
            break;
            }
        }