private 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 selectedConnectors = new List <ConnectorModel>(); selectedConnectors = selectedPort.Connectors.Where(x => x.End.Owner.IsSelected).ToList(); // If no connectors are selected, process all of the associated nodes if (selectedConnectors.Count() <= 0) { selectedConnectors = selectedPort.Connectors.ToList(); } int numOfConnectors = selectedConnectors.Count(); if (numOfConnectors == 0) { return; } activeStartPorts = new PortModel[numOfConnectors]; for (int i = 0; i < numOfConnectors; i++) { ConnectorModel connector = selectedConnectors[i]; activeStartPorts[i] = connector.End; } CurrentWorkspace.SaveAndDeleteModels(selectedConnectors.ToList <ModelBase>()); for (int i = 0; i < numOfConnectors; i++) //delete the connectors { selectedConnectors[i].Delete(); } return; }
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 }; firstStartPort = 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.SaveAndDeleteModels(models); connector.Delete(); } } else { activeStartPorts = new PortModel[] { portModel }; firstStartPort = isInPort ? null : portModel; // Only assign firstStartPort if the port selected is an output port } }
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.SaveAndDeleteModels(connectorsForDeletion); for (int i = 0; i < numOfConnectors; i++) //delete the connectors { selectedPort.Connectors[0].Delete(); } return; }