コード例 #1
0
        void BeginShiftReconnections(Guid nodeId, int portIndex, PortType portType)
        {
            if (portType == PortType.Input)
            {
                return;                             //only handle multiple connections when the port selected is an output port
            }
            var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel;

            if (node == null)
            {
                return;
            }

            PortModel selectedPort = node.OutPorts[portIndex];

            var connectorsForDeletion = new List <ModelBase>();
            int numOfConnectors       = selectedPort.Connectors.Count;

            if (numOfConnectors == 0)
            {
                return;
            }

            activeStartPorts = new PortModel[numOfConnectors];

            for (int i = 0; i < numOfConnectors; i++)
            {
                ConnectorModel connector = selectedPort.Connectors[i];
                connectorsForDeletion.Add(connector);
                activeStartPorts[i] = connector.End;
            }
            CurrentWorkspace.SaveModelsForUndo(connectorsForDeletion);
            for (int i = 0; i < numOfConnectors; i++) //delete the connectors
            {
                selectedPort.Connectors[0].Delete();
            }
            return;
        }
コード例 #2
0
        void BeginConnection(Guid nodeId, int portIndex, PortType portType)
        {
            bool isInPort = portType == PortType.Input;

            activeStartPorts = null;

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

            if (node == null)
            {
                return;
            }
            PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex];

            // Test if port already has a connection, if so grab it and begin connecting
            // to somewhere else (we don't allow the grabbing of the start connector).
            if (portModel.Connectors.Count > 0 && portModel.Connectors[0].Start != portModel)
            {
                activeStartPorts = new PortModel[] { portModel.Connectors[0].Start };
                // Disconnect the connector model from its start and end ports
                // and remove it from the connectors collection. This will also
                // remove the view model.
                ConnectorModel connector = portModel.Connectors[0];
                if (CurrentWorkspace.Connectors.Contains(connector))
                {
                    var models = new List <ModelBase> {
                        connector
                    };
                    CurrentWorkspace.SaveModelsForUndo(models);
                    connector.Delete();
                }
            }
            else
            {
                activeStartPorts = new PortModel[] { portModel };
            }
        }