void EndShiftReconnections(Guid nodeId, int portIndex, PortType portType) { if (portType == PortType.Input) { return; //only handle multiple connections when the port selected is an output port } if (activeStartPorts == null || activeStartPorts.Count() <= 0) { return; } var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel selectedPort = node.OutPorts[portIndex]; var firstModel = GetConnectorsToAddAndDelete(selectedPort, activeStartPorts[0]); for (int i = 1; i < activeStartPorts.Count(); i++) { var models = GetConnectorsToAddAndDelete(selectedPort, activeStartPorts[i]); foreach (var m in models) { firstModel.Add(m.Key, m.Value); } } WorkspaceModel.RecordModelsForUndo(firstModel, CurrentWorkspace.UndoRecorder); activeStartPorts = null; return; }
void EndAndStartCtrlConnection(Guid nodeId, int portIndex, PortType portType) { if (portType == PortType.Output) { return; // Only handle ctrl connections if selected port is an input port } if (firstStartPort == null || activeStartPorts == null || activeStartPorts.Count() <= 0) { return; } var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel portModel = node.InPorts[portIndex]; var models = GetConnectorsToAddAndDelete(portModel, activeStartPorts[0]); WorkspaceModel.RecordModelsForUndo(models, CurrentWorkspace.UndoRecorder); activeStartPorts = new PortModel[] { firstStartPort }; }
void BeginConnection(Guid nodeId, int portIndex, PortType portType) { bool isInPort = portType == PortType.Input; 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) { activeStartPort = 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.RecordAndDeleteModels(models); connector.Delete(); } } else { activeStartPort = portModel; } }
void EndConnection(Guid nodeId, int portIndex, PortType portType) { // Check if the node from which the connector starts is valid and has not been deleted if (activeStartPorts == null || activeStartPorts.Count() <= 0 || activeStartPorts[0].Owner == null) { return; } var startNode = CurrentWorkspace.GetModelInternal(activeStartPorts[0].Owner.GUID); if (startNode == null) { return; } var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } bool isInPort = portType == PortType.Input; PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex]; var models = GetConnectorsToAddAndDelete(portModel, activeStartPorts[0]); WorkspaceModel.RecordModelsForUndo(models, CurrentWorkspace.UndoRecorder); activeStartPorts = null; firstStartPort = null; }
void SelectModelImpl(SelectModelCommand command) { // Empty ModelGuid means clear selection. if (command.ModelGuid == Guid.Empty) { DynamoSelection.Instance.ClearSelection(); return; } ModelBase model = CurrentWorkspace.GetModelInternal(command.ModelGuid); if (false == model.IsSelected) { if (!command.Modifiers.HasFlag(ModifierKeys.Shift)) { DynamoSelection.Instance.ClearSelection(); } if (!DynamoSelection.Instance.Selection.Contains(model)) { DynamoSelection.Instance.Selection.Add(model); } } else { if (command.Modifiers.HasFlag(ModifierKeys.Shift)) { DynamoSelection.Instance.Selection.Remove(model); } } }
void SelectModelImpl(SelectModelCommand command) { // Empty ModelGuid means clear selection. if (command.ModelGuid == Guid.Empty) { DynamoSelection.Instance.ClearSelection(); return; } foreach (var guid in command.ModelGuids) { ModelBase model = CurrentWorkspace.GetModelInternal(guid); if (!model.IsSelected) { if (!command.Modifiers.HasFlag(ModifierKeys.Shift) && command.ModelGuids.Count() == 1) { DynamoSelection.Instance.ClearSelection(); } DynamoSelection.Instance.Selection.AddUnique(model); } else { if (command.Modifiers.HasFlag(ModifierKeys.Shift)) { DynamoSelection.Instance.Selection.Remove(model); } } } }
private void BeginDuplicateConnection(Guid nodeId, int portIndex, PortType portType) { // If the port clicked is an output port, begin connection as per normal if (portType == PortType.Output) { BeginConnection(nodeId, portIndex, portType); return; } // Otherwise, if the port is an input port, check if the port already has a connection. // If it does, duplicate the existing connection. var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } var portModel = node.InPorts[portIndex]; if (portModel.Connectors.Count == 0) { // If the port doesn't have any existing connections, begin connection as per normal BeginConnection(nodeId, portIndex, portType); return; } // Duplicate the existing connection activeStartPorts = new PortModel[] { portModel.Connectors[0].Start }; firstStartPort = portModel.Connectors[0].Start; }
void UngroupModelImpl(UngroupModelCommand command) { if (command.ModelGuid == Guid.Empty) { return; } var modelsToUngroup = command.ModelGuids.Select(guid => CurrentWorkspace.GetModelInternal(guid)).ToList(); UngroupModel(modelsToUngroup); }
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; }
void AddToGroupImpl(AddModelToGroupCommand command) { var modelsToUngroup = new List <ModelBase>(); if (command.ModelGuid != Guid.Empty) { modelsToUngroup.Add(CurrentWorkspace.GetModelInternal(command.ModelGuid)); } AddToGroup(modelsToUngroup); }
void UngroupModelImpl(UngroupModelCommand command) { var modelsToUngroup = new List <ModelBase>(); if (command.ModelGuid != Guid.Empty) { modelsToUngroup.Add(CurrentWorkspace.GetModelInternal(command.ModelGuid)); } UngroupModel(modelsToUngroup); }
void AddToGroupImpl(AddModelToGroupCommand command) { if (command.ModelGuid == Guid.Empty) { return; } var modelsToGroup = command.ModelGuids.Select(guid => CurrentWorkspace.GetModelInternal(guid)).ToList(); AddToGroup(modelsToGroup); }
/// <summary> /// This method assumes that there exists an undo-redo action group already /// that can be used to record creation and deletion of models. /// </summary> /// <param name="command"></param> private void CreateAndConnectNodeImplWithUndoGroup(CreateAndConnectNodeCommand command) { var newNode = CreateNodeFromNameOrType(command.ModelGuid, command.NewNodeName); if (newNode == null) { return; } newNode.X = command.X; newNode.Y = command.Y; var existingNode = CurrentWorkspace.GetModelInternal(command.ModelGuids.ElementAt(1)) as NodeModel; if (existingNode == null) { return; } AddNodeToCurrentWorkspace(newNode, false, command.AddNewNodeToSelection); CurrentWorkspace.UndoRecorder.RecordCreationForUndo(newNode); PortModel inPortModel, outPortModel; if (command.CreateAsDownstreamNode) { // Connect output port of Existing Node to input port of New node outPortModel = existingNode.OutPorts[command.OutputPortIndex]; inPortModel = newNode.InPorts[command.InputPortIndex]; } else { // Connect output port of New Node to input port of existing node outPortModel = newNode.OutPorts[command.OutputPortIndex]; inPortModel = existingNode.InPorts[command.InputPortIndex]; } var models = GetConnectorsToAddAndDelete(inPortModel, outPortModel); foreach (var modelPair in models) { switch (modelPair.Value) { case UndoRedoRecorder.UserAction.Creation: CurrentWorkspace.UndoRecorder.RecordCreationForUndo(modelPair.Key); break; case UndoRedoRecorder.UserAction.Deletion: CurrentWorkspace.UndoRecorder.RecordDeletionForUndo(modelPair.Key); break; } } }
void DeleteModelImpl(DeleteModelCommand command) { var modelsToDelete = new List <ModelBase>(); if (command.ModelGuid == Guid.Empty) { // When nothing is specified then it means all selected models. modelsToDelete.AddRange(DynamoSelection.Instance.Selection.OfType <ModelBase>()); } else { modelsToDelete.AddRange(command.ModelGuids.Select(guid => CurrentWorkspace.GetModelInternal(guid))); } DeleteModelInternal(modelsToDelete); }
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 EndConnection(Guid nodeId, int portIndex, PortType portType) { bool isInPort = portType == PortType.Input; var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex]; var models = GetConnectorsToAddAndDelete(portModel, activeStartPort); WorkspaceModel.RecordModelsForUndo(models, CurrentWorkspace.UndoRecorder); activeStartPort = null; }
void DeleteModelImpl(DeleteModelCommand command) { List <ModelBase> modelsToDelete = new List <ModelBase>(); if (command.ModelGuid != Guid.Empty) { modelsToDelete.Add(CurrentWorkspace.GetModelInternal(command.ModelGuid)); } else { // When nothing is specified then it means all selected models. foreach (ISelectable selectable in DynamoSelection.Instance.Selection) { if (selectable is ModelBase) { modelsToDelete.Add(selectable as ModelBase); } } } DeleteModelInternal(modelsToDelete); }
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; }
private void AddToGroupImpl(AddModelToGroupCommand command) { if (command.ModelGuid == Guid.Empty) { return; } var modelsToGroup = command.ModelGuids.Select(guid => CurrentWorkspace.GetModelInternal(guid)).ToList(); if (modelsToGroup.OfType <NodeModel>().Any()) { var nodeModels = modelsToGroup.OfType <NodeModel>(); var pinnedNotes = CurrentWorkspace.Notes .Where(x => x.PinnedNode != null && nodeModels.Contains(x.PinnedNode)); if (pinnedNotes.Any()) { modelsToGroup.AddRange(pinnedNotes); } } AddToGroup(modelsToGroup); }