Exemple #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;
        }
 public void RemoveConnection(PortModel connectionEnd)
 {
     //do a null check to make sure the port actually has a connector here
     //before attemtping to remove it
     if (connectionEnd.connectors.Count > 0 && connectionEnd.connectors[0] != null)
     {
         //TODO THIS ONLY MAKES SENSE FOR INPUT NODES... and data connectors, not execution connectors
         Connectors.Remove(connectionEnd.connectors[0]);
         connectionEnd.Disconnect(connectionEnd.connectors[0]);
     }
 }
Exemple #3
0
        internal void EndConnection(Guid nodeId, int portIndex, PortType portType)
        {
            int  index    = portIndex;
            bool isInPort = portType == PortType.INPUT;

            NodeModel      node              = _model.GetModelInternal(nodeId) as NodeModel;
            PortModel      portModel         = isInPort ? node.InPorts[index] : node.OutPorts[index];
            ConnectorModel connectorToRemove = null;

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

            // Create the new connector model
            var start = this.activeConnector.ActiveStartPort;
            var end   = portModel;

            // 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 = start, second = end;

            if (portModel.PortType != PortType.INPUT)
            {
                firstPort = end;
                second    = start;
            }

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

            if (newConnectorModel != null) // Add to the current workspace
            {
                _model.Connectors.Add(newConnectorModel);
            }

            // 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);
            _model.RecordModelsForUndo(models);
            this.SetActiveConnector(null);
        }