Пример #1
0
        /// <summary>
        /// Removes any connection between this node and the specified node.
        /// </summary>
        /// <param name="other">The other node whose connection is to be removed.</param>
        /// <returns>True if a connection existed.</returns>
        public bool Disconnect(Layn other)
        {
            bool c = this.mConnections.Remove(other);
            bool p = other.mConnections.Remove(this);

            return(c || p);
        }
Пример #2
0
 /// <summary>
 /// Connects this node to the specified parent node.
 /// </summary>
 /// <param name="parent">The node to connect to this node.</param>
 /// <returns>True if the other node was connected to this node.</returns>
 public bool AddParent(Layn parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     return(parent.AddChild(this));
 }
Пример #3
0
        /// <summary>
        /// Calculates the repulsion force between any two nodes in the diagram space.
        /// </summary>
        /// <param name="x">The node that the force is acting on.</param>
        /// <param name="y">The node creating the force.</param>
        /// <returns>A Vector representing the repulsion force.</returns>
        private Layv CalcRepulsionForce(Layn x, Layn y)
        {
            int proximity = Math.Max(CalcDistance(x.Location, y.Location), 1);

            // Coulomb's Law: F = k(Qq/r^2)
            double force = -(REPULSION_CONSTANT / Math.Pow(proximity, 2));
            double angle = GetBearingAngle(x.Location, y.Location);

            return(new Layv(force, angle));
        }
Пример #4
0
        /// <summary>
        /// Calculates the attraction force between two connected nodes, using the specified spring length.
        /// </summary>
        /// <param name="x">The node that the force is acting on.</param>
        /// <param name="y">The node creating the force.</param>
        /// <param name="springLength">The length of the spring, in pixels.</param>
        /// <returns>A Vector representing the attraction force.</returns>
        private Layv CalcAttractionForce(Layn x, Layn y, double springLength)
        {
            int proximity = Math.Max(CalcDistance(x.Location, y.Location), 1);

            // Hooke's Law: F = -kx
            double force = ATTRACTION_CONSTANT * Math.Max(proximity - springLength, 0);
            double angle = GetBearingAngle(x.Location, y.Location);

            return(new Layv(force, angle));
        }
Пример #5
0
 /// <summary>
 /// Removes the specified node from the diagram. Any connected nodes will remain on the diagram.
 /// </summary>
 /// <param name="layn">The node to remove from the diagram.</param>
 /// <returns>True if the node belonged to the diagram.</returns>
 public bool RemoveNode(Layn layn)
 {
     layn.Laydg = null;
     foreach (Layn other in mNodes)
     {
         if ((other != layn) && other.Connections.Contains(layn))
         {
             other.Disconnect(layn);
         }
     }
     return(mNodes.Remove(layn));
 }
Пример #6
0
 /// <summary>
 /// Connects the specified child node to this node.
 /// </summary>
 /// <param name="child">The child node to add.</param>
 /// <returns>True if the node was connected to this node.</returns>
 public bool AddChild(Layn child)
 {
     if (child == null)
     {
         throw new ArgumentNullException("child");
     }
     if ((child != this) && !this.mConnections.Contains(child))
     {
         child.Laydg = this.Laydg;
         this.mConnections.Add(child);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #7
0
        /// <summary>
        /// Adds the specified Node to this Diagram.
        /// </summary>
        /// <param name="layn">The Node to add to the diagram.</param>
        /// <returns>True if the node was added, false if the node is already on this Diagram.</returns>
        public bool AddNode(Layn layn)
        {
            if (layn == null)
            {
                throw new ArgumentNullException("layn");
            }

            if (!mNodes.Contains(layn))
            {
                // add node, associate with diagram, then add all connected nodes
                mNodes.Add(layn);
                layn.Laydg = this;
                foreach (Layn child in layn.Connections)
                {
                    AddNode(child);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #8
0
 /// <summary>
 /// Draws a connector between this node and the specified child node using GDI+.
 /// The source and destination coordinates (relative to the Graphics surface) are also specified.
 /// </summary>
 /// <param name="graphics">GDI+ Graphics surface.</param>
 /// <param name="from">Source coodinate.</param>
 /// <param name="to">Destination coordinate.</param>
 /// <param name="other">The other node.</param>
 public virtual void DrawConnector(Graphics graphics, Point from, Point to, Layn other)
 {
     graphics.DrawLine(Pens.Gray, from, to);
 }
Пример #9
0
            public Point NextPosition;  // the node's position after the next iteration

            /// <summary>
            /// Initialises a new instance of the Diagram.NodeLayoutInfo class, using the specified parameters.
            /// </summary>
            /// <param name="layn"></param>
            /// <param name="velocity"></param>
            /// <param name="nextPosition"></param>
            public NodeLayoutInfo(Layn layn, Layv velocity, Point nextPosition)
            {
                Layn         = layn;
                Velocity     = velocity;
                NextPosition = nextPosition;
            }
Пример #10
0
 /// <summary>
 /// Determines whether the diagram contains the specified node.
 /// </summary>
 /// <param name="layn">The node to test.</param>
 /// <returns>True if the diagram contains the node.</returns>
 public bool ContainsNode(Layn layn)
 {
     return(mNodes.Contains(layn));
 }