/// <summary> /// Deletes all connectors attached to this PortModel. /// </summary> public void DestroyConnectors() { if (Owner == null) { return; } while (Connectors.Any()) { ConnectorModel connector = Connectors[0]; connector.Delete(); } }
public void CreateModel(XmlElement modelData) { XmlElementHelper helper = new XmlElementHelper(modelData); string typeName = helper.ReadString("type", String.Empty); if (string.IsNullOrEmpty(typeName)) { // If there wasn't a "type" attribute, then we fall-back onto // the name of the XmlElement itself, which is usually the type // name. typeName = modelData.Name; if (string.IsNullOrEmpty(typeName)) { string guid = helper.ReadString("guid"); throw new InvalidOperationException( string.Format("No type information: {0}", guid)); } } #if USE_DSENGINE if (typeName.Equals("Dynamo.Nodes.DSFunction") || typeName.Equals("Dynamo.Nodes.DSVarArgFunction")) { // For DSFunction and DSVarArgFunction node types, the type name // is actually embedded within "name" attribute (for an example, // "UV.ByCoordinates@double,double"). // typeName = modelData.Attributes["name"].Value; } #endif if (typeName.StartsWith("Dynamo.Models.ConnectorModel")) { ConnectorModel connector = ConnectorModel.Make(); connector.Deserialize(modelData, SaveContext.Undo); Connectors.Add(connector); } else if (typeName.StartsWith("Dynamo.Models.NoteModel")) { NoteModel noteModel = new NoteModel(0.0, 0.0); noteModel.Deserialize(modelData, SaveContext.Undo); Notes.Add(noteModel); } else // Other node types. { NodeModel nodeModel = DynamoModel.CreateNodeInstance(typeName); nodeModel.WorkSpace = this; nodeModel.Deserialize(modelData, SaveContext.Undo); Nodes.Add(nodeModel); } }
/// <summary> /// Deletes all connectors attached to this PortModel. /// </summary> public void DestroyConnectors() { if (Owner == null) { return; } while (Connectors.Any()) { ConnectorModel connector = Connectors[0]; Owner.WorkSpace.Connectors.Remove(connector); connector.NotifyConnectedPortsOfDeletion(); } }
static Dictionary <ModelBase, UndoRedoRecorder.UserAction> GetConnectorsToAddAndDelete( PortModel endPort, PortModel startPort) { ConnectorModel connectorToRemove = null; // Remove connector if one already exists if (endPort.Connectors.Count > 0 && endPort.PortType == PortType.Input) { connectorToRemove = endPort.Connectors[0]; connectorToRemove.Delete(); } // 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, secondPort; if (endPort.PortType != PortType.Input) { firstPort = endPort; secondPort = startPort; } else { // Create the new connector model firstPort = startPort; secondPort = endPort; } ConnectorModel newConnectorModel = ConnectorModel.Make( firstPort.Owner, secondPort.Owner, firstPort.Index, secondPort.Index); // 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); } if (newConnectorModel != null) { models.Add(newConnectorModel, UndoRedoRecorder.UserAction.Creation); } return(models); }
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; }
public void Disconnect(ConnectorModel connector) { if (!connectors.Contains(connector)) { return; } //throw the event for a connection OnPortDisconnected(EventArgs.Empty); connectors.Remove(connector); //don't set back to white if //there are still connectors on this port if (connectors.Count == 0) { IsConnected = false; } Owner.ValidateConnections(); }
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 } }
public void CreateModel(XmlElement modelData) { XmlElementHelper helper = new XmlElementHelper(modelData); string typeName = helper.ReadString("type", String.Empty); if (string.IsNullOrEmpty(typeName)) { // If there wasn't a "type" attribute, then we fall-back onto // the name of the XmlElement itself, which is usually the type // name. typeName = modelData.Name; if (string.IsNullOrEmpty(typeName)) { string guid = helper.ReadString("guid"); throw new InvalidOperationException( string.Format("No type information: {0}", guid)); } } if (typeName.StartsWith("Dynamo.Nodes")) { NodeModel nodeModel = DynamoModel.CreateNodeInstance(typeName); nodeModel.WorkSpace = this; nodeModel.Deserialize(modelData, SaveContext.Undo); Nodes.Add(nodeModel); } else if (typeName.StartsWith("Dynamo.Models.ConnectorModel")) { ConnectorModel connector = ConnectorModel.Make(); connector.Deserialize(modelData, SaveContext.Undo); Connectors.Add(connector); } else if (typeName.StartsWith("Dynamo.Models.NoteModel")) { NoteModel noteModel = new NoteModel(0.0, 0.0); noteModel.Deserialize(modelData, SaveContext.Undo); Notes.Add(noteModel); } }
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; }
void BeginConnection(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]; // 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)) { List <ModelBase> models = new List <ModelBase>() { connector }; CurrentWorkspace.RecordAndDeleteModels(models); connector.NotifyConnectedPortsOfDeletion(); } } else { activeStartPort = portModel; } }
public void Disconnect(ConnectorModel connector) { if (!connectors.Contains(connector)) { return; } //throw the event for a connection OnPortDisconnected(EventArgs.Empty); //also trigger the model's connector deletion dynSettings.Controller.DynamoModel.OnConnectorDeleted(connector); connectors.Remove(connector); //don't set back to white if //there are still connectors on this port if (connectors.Count == 0) { IsConnected = false; } Owner.ValidateConnections(); }
public void Disconnect(ConnectorModel connector, bool silent = false) { if (!connectors.Contains(connector)) { return; } //throw the event for a disconnection if (!silent) { OnPortDisconnected(); } connectors.Remove(connector); //don't set back to white if //there are still connectors on this port if (connectors.Count == 0) { IsConnected = false; } Owner.ValidateConnections(); }
private void RegisterConnector(ConnectorModel connector) { connector.Deleted += () => OnConnectorDeleted(connector); }
protected virtual void OnConnectorAdded(ConnectorModel obj) { RegisterConnector(obj); var handler = ConnectorAdded; if (handler != null) handler(obj); }
/// <summary> /// Checks whether the given connection is inside the node to code set or outside it. /// This determines if it should be redrawn(if it is external) or if it should be /// deleted (if it is internal) /// </summary> private static bool IsInternalNodeToCodeConnection(IEnumerable<NodeModel> nodes, ConnectorModel connector) { return nodes.Contains(connector.Start.Owner) && nodes.Contains(connector.End.Owner); }
/// <summary> /// Checks whether the given connection is inside the node to code set or outside it. /// This determines if it should be redrawn(if it is external) or if it should be /// deleted (if it is internal) /// </summary> private bool IsInternalNodeToCodeConnection(ConnectorModel connector) { return(DynamoSelection.Instance.Selection.Contains(connector.Start.Owner) && DynamoSelection.Instance.Selection.Contains(connector.End.Owner)); }
protected override void PortConnectedHandler(PortModel arg1, ConnectorModel arg2) { UpdateUpstream(); }
/// <summary> /// Construct a view and respond to property changes on the model. /// </summary> /// <param name="model"></param> public ConnectorViewModel(ConnectorModel model) { _model = model; _model.PropertyChanged += Model_PropertyChanged; _model.Start.Owner.PropertyChanged += StartOwner_PropertyChanged; _model.End.Owner.PropertyChanged += EndOwner_PropertyChanged; dynSettings.Controller.DynamoViewModel.PropertyChanged += DynamoViewModel_PropertyChanged; Redraw(); }
/// <summary> /// Handler for the model's ConnectorDeleted event. /// </summary> /// <param name="connector"></param> void DynamoModel_ConnectorDeleted(ConnectorModel connector) { //we are given the connector that was deleted //if it's end node still exists, clear the package for //the node and trigger an update. if (connector.End != null) connector.End.Owner.ClearRenderPackages(); //tell the watches that they require re-binding. OnVisualizationUpdateComplete(this, EventArgs.Empty); }
void Connectors_ConnectorDeleted(ConnectorModel c) { var connector = _connectors.FirstOrDefault(x => x.ConnectorModel == c); if (connector != null) _connectors.Remove(connector); }
public void Connect(ConnectorModel connector) { connectors.Add(connector); //throw the event for a connection OnPortConnected(EventArgs.Empty); IsConnected = true; }
void Connectors_ConnectorAdded(ConnectorModel c) { var viewModel = new ConnectorViewModel(this, c); if (_connectors.All(x => x.ConnectorModel != c)) _connectors.Add(viewModel); }
/// <summary> /// Checks whether the given connection is inside the node to code set or outside it. /// This determines if it should be redrawn(if it is external) or if it should be /// deleted (if it is internal) /// </summary> private bool IsInternalNodeToCodeConnection(ConnectorModel connector) { return DynamoSelection.Instance.Selection.Contains(connector.Start.Owner) && DynamoSelection.Instance.Selection.Contains(connector.End.Owner); }
/// <summary> /// Construct a view and respond to property changes on the model. /// </summary> /// <param name="model"></param> public ConnectorViewModel(WorkspaceViewModel workspace, ConnectorModel model) { this.workspaceViewModel = workspace; _model = model; _model.PropertyChanged += Model_PropertyChanged; _model.Start.Owner.PropertyChanged += StartOwner_PropertyChanged; _model.End.Owner.PropertyChanged += EndOwner_PropertyChanged; workspaceViewModel.DynamoViewModel.PropertyChanged += DynamoViewModel_PropertyChanged; Redraw(); }
protected virtual void OnConnectorDeleted(ConnectorModel obj) { var handler = ConnectorDeleted; if (handler != null) handler(obj); }
internal void OnConnectorDeleted(ConnectorModel connector) { if (ConnectorDeleted != null) { ConnectorDeleted(connector); } }
/// <summary> /// Handler for the model's ConnectorDeleted event. Clears the visualization for /// the node at the 'end' of the connector. /// </summary> /// <param name="connector"></param> void DynamoModel_ConnectorDeleted(ConnectorModel connector) { if (Visualizations.ContainsKey(connector.End.Owner.GUID.ToString())) { Visualizations.Remove(connector.End.Owner.GUID.ToString()); //tell the watches that they require re-binding. //OnVisualizationUpdateComplete(this, new VisualizationEventArgs(AggregateRenderDescriptions())); OnVisualizationUpdateComplete(this, EventArgs.Empty); } }
/// <summary> /// Called when a port is connected. /// </summary> /// <param name="connector"></param> protected virtual void OnPortConnected(ConnectorModel connector) { if (PortConnected != null) PortConnected(this, connector); }
/// <summary> /// Called when a connector is added. /// </summary> /// <param name="connector"></param> private void OnConnectorAdded(ConnectorModel connector) { if (ConnectorAdded != null) { ConnectorAdded(connector); } }
private void PortConnected(PortModel port, ConnectorModel connector) { ValidateConnections(); if (port.PortType != PortType.Input) return; var data = InPorts.IndexOf(port); var startPort = connector.Start; var outData = startPort.Owner.OutPorts.IndexOf(startPort); ConnectInput(data, outData, startPort.Owner); startPort.Owner.ConnectOutput(outData, data, this); OnConnectorAdded(connector); OnNodeModified(); }
public void Disconnect(ConnectorModel connector, bool silent = false) { if (!connectors.Contains(connector)) return; //throw the event for a disconnection if (!silent) { OnPortDisconnected(); } connectors.Remove(connector); //don't set back to white if //there are still connectors on this port if (connectors.Count == 0) { IsConnected = false; } Owner.ValidateConnections(); }
public void Disconnect(ConnectorModel connector) { if (!connectors.Contains(connector)) return; //throw the event for a connection OnPortDisconnected(EventArgs.Empty); //also trigger the model's connector deletion owner.Workspace.DynamoModel.OnConnectorDeleted(connector); connectors.Remove(connector); //don't set back to white if //there are still connectors on this port if (connectors.Count == 0) { IsConnected = false; } Owner.ValidateConnections(); }
protected virtual void OnConnectorDeleted(ConnectorModel obj) { if (hasNodeInSyncWithDefinition) { undoRecorder.RecordModelAsOffTrack(obj.GUID); } var handler = ConnectorDeleted; if (handler != null) handler(obj); }
protected virtual void PortConnectedHandler(PortModel arg1, ConnectorModel arg2) { // Do nothing for a standard node. }
/// <summary> /// Handler for the model's ConnectorDeleted event. /// </summary> /// <param name="connector"></param> private void DynamoModel_ConnectorDeleted(ConnectorModel connector) { // TODO: Ian should remove this when the CBN reconnection bug is solved. /*if (connector.Start.Owner.GetType() == typeof(CodeBlockNodeModel)) { return; } //we are given the connector that was deleted //if it's end node still exists, clear the package for //the node and trigger an update. if (connector.End != null) connector.End.Owner.ClearRenderPackages(); //tell the watches that they require re-binding. QueueRenderTask();*/ }