示例#1
0
        private void Connect(PortModel p)
        {
            //test if the port that you are connecting too is not the start port or the end port
            //of the current connector
            if (p.Equals(Start) || p.Equals(End))
            {
                return;
            }

            //if the selected connector is also an output connector, return false
            //output ports can't be connected to eachother
            if (p.PortType == PortType.Output)
            {
                return;
            }

            //test if the port that you are connecting to is an input and
            //already has other connectors
            if (p.PortType == PortType.Input && p.Connectors.Count > 0)
            {
                p.Disconnect(p.Connectors[0]);
            }

            //turn the line solid
            End = p;

            if (End != null)
            {
                p.Connect(this);
            }

            return;
        }
示例#2
0
        void EndConnection(Guid nodeId, int portIndex, PortType portType)
        {
            bool isInPort = portType == PortType.INPUT;

            NodeModel node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel;

            if (node == null)
            {
                return;
            }

            PortModel      portModel         = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex];
            ConnectorModel connectorToRemove = null;

            // Remove connector if one already exists
            if (portModel.Connectors.Count > 0 && portModel.PortType == PortType.INPUT)
            {
                connectorToRemove = portModel.Connectors[0];
                CurrentWorkspace.Connectors.Remove(connectorToRemove);
                portModel.Disconnect(connectorToRemove);
                var startPort = connectorToRemove.Start;
                startPort.Disconnect(connectorToRemove);
            }

            // We could either connect from an input port to an output port, or
            // another way around (in which case we swap first and second ports).
            PortModel firstPort, second;

            if (portModel.PortType != PortType.INPUT)
            {
                firstPort = portModel;
                second    = activeStartPort;
            }
            else
            {
                // Create the new connector model
                firstPort = activeStartPort;
                second    = portModel;
            }

            ConnectorModel newConnectorModel = CurrentWorkspace.AddConnection(firstPort.Owner,
                                                                              second.Owner, firstPort.Index, second.Index, PortType.INPUT);

            // Record the creation of connector in the undo recorder.
            var models = new Dictionary <ModelBase, UndoRedoRecorder.UserAction>();

            if (connectorToRemove != null)
            {
                models.Add(connectorToRemove, UndoRedoRecorder.UserAction.Deletion);
            }
            models.Add(newConnectorModel, UndoRedoRecorder.UserAction.Creation);
            CurrentWorkspace.RecordModelsForUndo(models);
            activeStartPort = null;
        }
示例#3
0
 public void NotifyConnectedPortsOfDeletion()
 {
     if (pStart != null && pStart.Connectors.Contains(this))
     {
         pStart.Disconnect(this);
     }
     if (pEnd != null && pEnd.Connectors.Contains(this))
     {
         pEnd.Disconnect(this);
     }
 }
示例#4
0
        public void Disconnect(PortModel p)
        {
            if (p.Equals(pStart))
            {
                pStart = null;
            }

            if (p.Equals(pEnd))
            {
                pEnd = null;
            }

            p.Disconnect(this);
        }
示例#5
0
        public bool Connect(PortModel p)
        {
            //test if the port that you are connecting too is not the start port or the end port
            //of the current connector
            if (p.Equals(pStart) || p.Equals(pEnd))
            {
                return false;
            }

            //if the selected connector is also an output connector, return false
            //output ports can't be connected to eachother
            if (p.PortType == PortType.OUTPUT)
            {
                return false;
            }

            //test if the port that you are connecting to is an input and 
            //already has other connectors
            if (p.PortType == PortType.INPUT && p.Connectors.Count > 0)
            {
                p.Disconnect(p.Connectors[0]);
            }

            //turn the line solid
            pEnd = p;

            if (pEnd != null)
            {
                p.Connect(this);
            }

            return true;
        }
示例#6
0
        public void Disconnect(PortModel p)
        {
            if (p.Equals(pStart))
            {
                pStart = null;
            }

            if (p.Equals(pEnd))
            {
                pEnd = null;
            }

            p.Disconnect(this);

        }