Exemple #1
0
        protected internal virtual void ElementInsert(T element)
        {
            if (element.Model == null)
            {
                element.SetModel(Model);
            }

            //Set the layer if not already set
            if (element.Layer == null && Model != null)
            {
                Layer layer = Model.Layers.CurrentLayer;
                element.SetLayer(layer);
            }

            //Set up ports in a port container
            if (element is IPortContainer)
            {
                IPortContainer portContainer = element as IPortContainer;

                foreach (Port port in portContainer.Ports.Values)
                {
                    port.SetModel(Model);
                    port.SetLayer(element.Layer);
                    if (port.Location.IsEmpty)
                    {
                        portContainer.LocatePort(port);
                    }
                }
            }
        }
Exemple #2
0
        public Port(Port prototype) : base(prototype)
        {
            SuspendEvents = true;

            Label       = null;
            StencilItem = null;

            mAlignment   = prototype.Alignment;
            mOffset      = prototype.Offset;
            mAllowMove   = prototype.AllowMove;
            mAllowRotate = prototype.AllowRotate;
            mDirection   = prototype.Direction;
            mInteraction = prototype.Interaction;
            Label        = null;
            mPortStyle   = prototype.Style;
            Cursor       = prototype.Cursor;

            mPercent     = prototype.Percent;
            mOrientation = prototype.Orientation;

            //Needed for action mvoe
            mParent = prototype.Parent;

            SuspendEvents = false;
        }
Exemple #3
0
        /// <summary>
        /// Determines if this link is entering the given node.
        /// </summary>
        /// <param name="graphNode">Node to test</param>
        /// <returns>true if edge is entering the given node</returns>
        public bool IsNodeEntering(IGraphNode graphNode)
        {
            Port headPort = this.HeadPort;

            if (headPort != null)
            {
                foreach (Connection connection in this.Connections)
                {
                    Port foreignPort = connection.GetForeignPort(this);
                    if (foreignPort != null)
                    {
                        IPortContainer foreignObj = foreignPort.Container;
                        if (foreignObj != null)
                        {
                            IGraphNode foreignGraphNode = foreignObj as IGraphNode;
                            if (foreignGraphNode != null && foreignGraphNode == graphNode)
                            {
                                Port localPort = connection.GetLocalPort(this);
                                if (localPort != null)
                                {
                                    if (localPort == headPort)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #4
0
        public override bool AcceptConnection(Port sourcePort, Port targetPort)
        {
            bool accept = false;

            // First, determine which port belongs to the foreign port container.

            Port foreignPort = null;

            if (this.Ports.Contains(sourcePort) || this.CenterPort == sourcePort)
            {
                foreignPort = targetPort;
            }
            else if (this.Ports.Contains(targetPort) || this.CenterPort == targetPort)
            {
                foreignPort = sourcePort;
            }

            if (foreignPort == null)
            {
                return(false);                 // This should never happen
            }

            // Now get the foreign port container and check to see if it is
            // a Link object. If so, then check to see if the foreign port
            // is the link's tail port or head port. If it's the tail port,
            // then always allow the connection, because a member symbol can
            // have any number of edges leaving it. If it's the head port,
            // then only allow the connection if the member symbol has no
            // other edges entering it yet.

            IPortContainer foreignContainer = foreignPort.Container;

            if (foreignContainer != null)
            {
                Link link = foreignContainer as Link;
                if (link != null)
                {
                    if (foreignPort == link.TailPort)
                    {
                        accept = true;
                    }
                    else
                    {
                        IGraphNode curNode = this as IGraphNode;

                        if (curNode != null)
                        {
                            ICollection edgesEntering = curNode.EdgesEntering;
                            if (edgesEntering.Count == 0)
                            {
                                accept = true;
                            }
                        }
                    }
                }
            }

            return(accept);
        }
Exemple #5
0
        /// <summary>
        /// Tests to see if a connection to the given port is allowed.
        /// </summary>
        /// <param name="port">Port to test</param>
        /// <returns>
        /// true if a connection is allowed between this port and the specified port;
        /// otherwise false
        /// </returns>
        /// <remarks>
        /// <para>
        /// This method calls the port container's
        /// <see cref="Syncfusion.Windows.Forms.Diagram.IPortContainer.AcceptConnection"/>
        /// method, passing as parameters this port and the parameter to this
        /// method.
        /// </para>
        /// </remarks>
        public bool AcceptConnection(Port port)
        {
            bool           accept    = false;
            IPortContainer container = this.Container;

            if (container != null)
            {
                return(container.AcceptConnection(this, port));
            }
            return(accept);
        }
Exemple #6
0
 /// <summary>
 /// Takes a port container as a parameter and returns the either
 /// the SourcePort or TargetPort, depending on which one does
 /// not belong to the given container.
 /// </summary>
 /// <param name="container">Port container to test</param>
 /// <returns>Port not belonging to the given port container</returns>
 /// <remarks>
 /// <para>
 /// If the SourcePort belongs to the given port container, then the
 /// TargetPort is returned. If the TargetPort belongs to the
 /// given port container, then the SourcePort is returned.
 /// </para>
 /// <seealso cref="Syncfusion.Windows.Forms.Diagram.Connection.SourcePort"/>
 /// <seealso cref="Syncfusion.Windows.Forms.Diagram.Connection.TargetPort"/>
 /// </remarks>
 public Port GetForeignPort(IPortContainer container)
 {
     if (this.sourcePort.Container == container)
     {
         return(this.targetPort);
     }
     else if (this.targetPort.Container == container)
     {
         return(this.sourcePort);
     }
     return(null);
 }
Exemple #7
0
        /// <summary>
        /// Notifies the connection that one of the port containers has moved.
        /// </summary>
        /// <param name="container">Container that moved</param>
        /// <remarks>
        /// This method calls the
        /// <see cref="Syncfusion.Windows.Forms.Diagram.IPortContainer.OnConnectionMove"/>
        /// method on the foreign port container. The foreign port container is the
        /// port container that is not the one passed in as a parameter.
        /// </remarks>
        public void SymbolMoved(IPortContainer container)
        {
            Port           receiverPort = this.GetForeignPort(container);
            IPortContainer receiver;

            if (receiverPort != null)
            {
                receiver = receiverPort.Container;

                if (receiver != null)
                {
                    receiver.OnConnectionMove(this);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Retrieve the value of a property given its name.
        /// </summary>
        /// <param name="propertyName">Name of property to retrieve</param>
        /// <returns>Value of the named property or null if it doesn't exist</returns>
        public virtual object GetPropertyValue(string propertyName)
        {
            object         value         = null;
            IPortContainer portContainer = this.Container;

            IPropertyContainer parentProps = null;

            if (this.parent != null)
            {
                parentProps = this.parent.GetPropertyContainer(this);
            }

            if (this.propertyValues.Contains(propertyName))
            {
                value = this.propertyValues[propertyName];
            }

            if (value == null && parentProps != null)
            {
                value = parentProps.GetPropertyValue(propertyName);
            }

            if (propertyName == "Visible" && parentProps != null)
            {
                // Visibility may depend on whether the AutoHidePorts property
                // is set to true in the symbol symbol

                bool visible = true;

                if (value != null && value.GetType() == typeof(bool))
                {
                    visible = (bool)value;
                }

                if (visible && portContainer != null && portContainer.AutoHidePorts)
                {
                    object revealPorts = parentProps.GetPropertyValue("RevealPorts");
                    if (revealPorts != null && revealPorts.GetType() == typeof(bool))
                    {
                        value = (bool)revealPorts;
                    }
                }
            }

            return(value);
        }
Exemple #9
0
        public Port(Port prototype) : base(prototype)
        {
            Label       = null;
            StencilItem = null;

            _offset      = prototype.Offset;
            _allowMove   = prototype.AllowMove;
            _allowRotate = prototype.AllowRotate;
            _direction   = prototype.Direction;
            _interaction = prototype.Interaction;
            Label        = null;
            _portStyle   = prototype.Style;
            Cursor       = prototype.Cursor;

            _percent     = prototype.Percent;
            _orientation = prototype.Orientation;

            //Needed for action move
            _parent   = prototype.Parent;
            Alignment = prototype.Alignment;
        }
Exemple #10
0
		protected internal virtual void SetParent(IPortContainer parent)
		{
			mParent = parent;
		}
Exemple #11
0
		public Port(Port prototype): base(prototype)
		{
			SuspendEvents = true;

			Label = null;
			StencilItem = null;

			mAlignment = prototype.Alignment;				
			mOffset = prototype.Offset;
			mAllowMove = prototype.AllowMove;
			mAllowRotate = prototype.AllowRotate;
			mDirection = prototype.Direction;
			mInteraction = prototype.Interaction;
			Label = null;
			mPortStyle = prototype.Style;
			Cursor = prototype.Cursor;

			mPercent = prototype.Percent;
			mOrientation = prototype.Orientation;
			
			//Needed for action mvoe
			mParent = prototype.Parent;

			SuspendEvents = false;
		}
Exemple #12
0
        //Occurs when an element is added to the elements collection
        private void Element_Insert(object sender, ElementsEventArgs e)
        {
            Element element = e.Value;

            if (element is Group)
            {
                throw new GroupException("A group cannot be added to another group.");
            }

            //Set the layer if not already set
            //Deserialized elements have layer information set
            if (element.Layer == null && Layer != null)
            {
                Layer layer = Layer;
                element.SetLayer(layer);

                //Add to the default level
                string key = layer.Elements.CreateKey();
                layer.Elements.SetModifiable(true);
                layer.Elements.Add(key, element);
                layer.Elements.SetModifiable(false);

                //Set the layer key
                element.SetLayerKey(key);

                //Set the element z order
                element.mZOrder = layer.Elements.Count;

                if (element is IUserInteractive)
                {
                    IUserInteractive interactive = (IUserInteractive)element;
                    if ((interactive.Interaction & UserInteraction.BringToFront) == UserInteraction.BringToFront)
                    {
                        layer.Elements.BringToFront(element);
                    }
                }
            }

            //Set the container
            element.SetContainer(this);

            //Set handlers
            element.ElementInvalid += new EventHandler(Element_ElementInvalid);

            //Draw the path if a line
            if (element is Line)
            {
                Line line = (Line)element;

                //If a connector and is not auto routed then calculate points
                if (element is Connector)
                {
                    Connector connector = (Connector)element;
                    if (connector.Points == null)
                    {
                        connector.CalculateRoute();
                    }
                }

                line.DrawPath();
            }

            //Set any containers for child elements
            if (element is IPortContainer)
            {
                IPortContainer container = (IPortContainer)element;

                foreach (Port port in container.Ports.Values)
                {
                    port.SetContainer(this);
                }
            }

            CreateRenderList();
            OnElementInvalid();

            //Raise the ElementInserted event
            OnElementInserted(element);
        }
Exemple #13
0
 /// <summary>
 /// Constructs a Port given a port container.
 /// </summary>
 /// <param name="container">Port container that owns the port</param>
 public Port(IPortContainer container)
 {
     this.Container      = container;
     this.propertyValues = new Hashtable();
     SetDefaultPropertyValues();
 }
Exemple #14
0
 protected internal virtual void SetParent(IPortContainer parent)
 {
     _parent = parent;
 }
Exemple #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="container"></param>
 public CenterPort(IPortContainer container) : base(container)
 {
 }
Exemple #16
0
        public override void Execute()
        {
            if (Elements == null)
            {
                return;
            }

            MouseElements mouseElements = MouseElements;

            foreach (Element element in Elements)
            {
                if (element.Visible)
                {
                    if (element.ActionElement == null)
                    {
                        throw new ComponentException("Element action may not be null.");
                    }
                    if (element is Shape)
                    {
                        Shape shape       = (Shape)element;
                        Shape actionShape = (Shape)element.ActionElement;

                        //Round values if appropriate
                        if (Controller.RoundPixels)
                        {
                            shape.Location = Point.Round(shape.Location);
                            shape.Size     = System.Drawing.Size.Round(shape.Size);
                        }

                        //Move and scale. Shape size property does not check equality
                        if (!actionShape.Location.Equals(shape.Location))
                        {
                            actionShape.Location = shape.Location;                                               //new PointF(shape.X,shape.Y);
                        }
                        if (!actionShape.Size.Equals(shape.Size))
                        {
                            actionShape.Size = shape.Size;
                        }

                        //Update children of a complex shape
                        if (shape is ComplexShape)
                        {
                            ComplexShape complex = (ComplexShape)shape;

                            foreach (Solid solid in complex.Children.Values)
                            {
                                Solid actionSolid = (Solid)solid.ActionElement;
                                actionSolid.SetPath(solid.GetPath());
                                actionSolid.SetRectangle(solid.Location);
                                actionSolid.SetTransformRectangle(solid.Location);
                            }
                        }
                    }

                    //Update rotation
                    if (element is ITransformable)
                    {
                        ITransformable transform       = element as ITransformable;
                        ITransformable actionTransform = element.ActionElement as ITransformable;

                        if (actionTransform.Rotation != transform.Rotation)
                        {
                            actionTransform.Rotation = transform.Rotation;
                        }
                    }

                    if (element is Port)
                    {
                        Port port       = (Port)element;
                        Port actionPort = (Port)element.ActionElement;

                        //Move and scale. Port size property does not check equality
                        if (!actionPort.Location.Equals(port.Location))
                        {
                            actionPort.Location = port.Location;                                             //new PointF(port.X,port.Y);
                        }
                        //Update the port percentage
                        IPortContainer ports = (IPortContainer)actionPort.Parent;
                        ports.GetPortPercentage(actionPort, actionPort.Location);
                    }

                    //Update the locations of the line origins
                    if (element is Link)
                    {
                        Link clone = (Link)element;

                        //Undock any origins
                        if (mouseElements.MouseStartOrigin != null && mouseElements.MouseStartOrigin.Docked && mouseElements.MouseStartOrigin.AllowMove)
                        {
                            Origin origin = mouseElements.MouseStartOrigin;
                            if (origin == origin.Parent.Start)
                            {
                                origin.Location = origin.Parent.FirstPoint;
                            }
                            if (origin == origin.Parent.End)
                            {
                                origin.Location = origin.Parent.LastPoint;
                            }
                        }

                        if (element is ComplexLine)
                        {
                            ComplexLine complexLine   = (ComplexLine)element;
                            ComplexLine actionLine    = (ComplexLine)element.ActionElement;
                            Segment     segment       = null;
                            Segment     actionSegment = null;

                            for (int i = 0; i < complexLine.Segments.Count; i++)
                            {
                                segment       = complexLine.Segments[i];
                                actionSegment = actionLine.Segments[i];
                                if (!actionSegment.Start.Docked)
                                {
                                    actionSegment.Start.Location = segment.Start.Location;
                                }
                            }

                            //Update end of last segment
                            if (segment != null && actionSegment != null && !actionSegment.End.Docked)
                            {
                                actionSegment.End.Location = segment.End.Location;
                            }

                            actionLine.DrawPath();
                            actionLine.LocatePorts();
                        }
                        else if (element is Curve)
                        {
                            Curve curve       = (Curve)element;
                            Curve actionCurve = (Curve)element.ActionElement;

                            if (!actionCurve.Start.Docked)
                            {
                                actionCurve.Start.Location = curve.Start.Location;
                            }
                            if (!actionCurve.End.Docked)
                            {
                                actionCurve.End.Location = curve.End.Location;
                            }

                            actionCurve.ControlPoints = curve.ControlPoints;
                            actionCurve.DrawPath();
                            actionCurve.LocatePorts();
                        }
                        else if (element is Connector)
                        {
                            //Update connector oblong handle
                            if (mouseElements.MouseHandle.Type == HandleType.UpDown || mouseElements.MouseHandle.Type == HandleType.LeftRight)
                            {
                                Connector connectorLine = element as Connector;
                                Connector actionLine    = element.ActionElement as Connector;

                                //Get the two points of the segment
                                ConnectorHandle handle = mouseElements.MouseHandle as ConnectorHandle;
                                if (handle != null)
                                {
                                    actionLine.Points[handle.Index - 1] = (PointF)connectorLine.Points[handle.Index - 1];
                                    actionLine.Points[handle.Index]     = (PointF)connectorLine.Points[handle.Index];
                                    actionLine.RefinePoints();
                                    actionLine.DrawPath();
                                    actionLine.LocatePorts();
                                    actionLine.CreateHandles();
                                }
                            }
                            //Update start or end of connector
                            else if (mouseElements.MouseHandle.Type == HandleType.Origin)
                            {
                                Connector connectorLine = element as Connector;
                                Connector actionLine    = element.ActionElement as Connector;

                                actionLine.SetPoints(connectorLine.Points);
                                actionLine.RefinePoints();

                                //Set origins
                                if (!actionLine.Start.Docked)
                                {
                                    actionLine.Start.Location = connectorLine.FirstPoint;
                                }
                                if (!actionLine.End.Docked)
                                {
                                    actionLine.End.Location = connectorLine.LastPoint;
                                }

                                actionLine.GetPortPercentages();
                                actionLine.DrawPath();
                                actionLine.LocatePorts();
                            }
                            //Move all points if connector is not connected
                            else if (mouseElements.MouseHandle.Type == HandleType.Move)
                            {
                                Connector connectorLine = element as Connector;
                                Connector actionLine    = element.ActionElement as Connector;

                                if (actionLine.AllowMove && !actionLine.Start.Docked && !actionLine.End.Docked)
                                {
                                    actionLine.Points.Clear();

                                    foreach (PointF point in connectorLine.Points)
                                    {
                                        actionLine.Points.Add(point);
                                    }

                                    actionLine.DrawPath();
                                    actionLine.LocatePorts();
                                }
                            }
                        }
                        else
                        {
                            Link line       = (Link)element;
                            Link actionLine = (Link)element.ActionElement;

                            //Round values if appropriate
                            if (Controller.RoundPixels)
                            {
                                line.Start.Location = Point.Round(line.Start.Location);
                                line.End.Location   = Point.Round(line.End.Location);
                            }

                            if (!actionLine.Start.Docked)
                            {
                                actionLine.Start.Location = line.Start.Location;
                            }
                            if (!actionLine.End.Docked)
                            {
                                actionLine.End.Location = line.End.Location;
                            }

                            actionLine.DrawPath();
                            actionLine.LocatePorts();
                        }
                    }

                    if (element is Port)
                    {
                        Port actionPort = element as Port;
                        Port port       = actionPort.ActionElement as Port;

                        port.Location = actionPort.Location;
                    }
                }
            }

            //Update the line docking
            if (mouseElements != null && mouseElements.MouseStartOrigin != null && mouseElements.MouseStartOrigin.AllowMove && mouseElements.MouseMoveElement != null && mouseElements.IsDockable() && Controller.CanDock(InteractiveMode, mouseElements))
            {
                Link line = mouseElements.MouseStartElement as Link;

                //Dock start to shape
                if (mouseElements.MouseStartOrigin == line.Start && mouseElements.MouseMoveElement is Shape)
                {
                    line.Start.Shape = mouseElements.MouseMoveElement as Shape;
                }
                //Dock end to shape
                if (mouseElements.MouseStartOrigin == line.End && mouseElements.MouseMoveElement is Shape)
                {
                    line.End.Shape = mouseElements.MouseMoveElement as Shape;
                }
                //Dock start to port
                if (mouseElements.MouseStartOrigin == line.Start && mouseElements.MouseMoveElement is Port)
                {
                    line.Start.Port = mouseElements.MouseMoveElement as Port;
                }
                //Dock end to port
                if (mouseElements.MouseStartOrigin == line.End && mouseElements.MouseMoveElement is Port)
                {
                    line.End.Port = mouseElements.MouseMoveElement as Port;
                }
            }

            Executed = true;
        }