internal void BeginConnection(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]; // 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) { // Define the new active connector var c = new ConnectorViewModel(portModel.Connectors[0].Start); this.SetActiveConnector(c); // 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 (_model.Connectors.Contains(connector)) { List<ModelBase> models = new List<ModelBase>(); models.Add(connector); _model.RecordAndDeleteModels(models); connector.NotifyConnectedPortsOfDeletion(); } } else { try { // Create a connector view model to begin drawing var connector = new ConnectorViewModel(portModel); this.SetActiveConnector(connector); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } }
internal void BeginConnection(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]; // 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) { // Define the new active connector var c = new ConnectorViewModel(portModel.Connectors[0].Start); this.SetActiveConnector(c); // 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 (_model.Connectors.Contains(connector)) { List <ModelBase> models = new List <ModelBase>(); models.Add(connector); _model.RecordAndDeleteModels(models); connector.NotifyConnectedPortsOfDeletion(); } } else { try { // Create a connector view model to begin drawing var connector = new ConnectorViewModel(portModel); this.SetActiveConnector(connector); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } }
internal void BeginShiftReconnections(Guid nodeId, int portIndex, PortType portType) { if (portType == PortType.Input) { return; } NodeModel node = Model.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel portModel = node.OutPorts[portIndex]; if (portModel.Connectors.Count <= 0) { return; } // Try to obtain connectors for selected nodes var selected = portModel.Connectors.Where(x => x.End.Owner.IsSelected).Select(y => y.End); // If there are no selected nodes, obtain all the associated connectors if (selected.Count() <= 0) { selected = portModel.Connectors.Select(y => y.End); } var connectorsAr = new ConnectorViewModel[selected.Count()]; for (int i = 0; i < selected.Count(); i++) { var c = new ConnectorViewModel(this, selected.ElementAt(i)); connectorsAr[i] = c; } this.SetActiveConnectors(connectorsAr); return; }
void Connectors_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { var viewModel = new ConnectorViewModel(this, item as ConnectorModel); _connectors.Add(viewModel); } break; case NotifyCollectionChangedAction.Reset: _connectors.Clear(); break; case NotifyCollectionChangedAction.Remove: foreach (var item in e.OldItems) { _connectors.Remove(_connectors.First(x => x.ConnectorModel == item)); } break; } }
internal void BeginConnection(Guid nodeId, int portIndex, PortType portType) { bool isInPort = portType == PortType.Input; NodeModel node = Model.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) { // Define the new active connector var c = new ConnectorViewModel[] { new ConnectorViewModel(this, portModel.Connectors[0].Start) }; this.SetActiveConnectors(c); firstStartPort = portModel.Connectors[0].Start; } else { try { // Create an array containing a connector view model to begin drawing var connectors = new ConnectorViewModel[] { new ConnectorViewModel(this, portModel) }; this.SetActiveConnectors(connectors); firstStartPort = isInPort ? null : node.OutPorts[portIndex]; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } }
void Connectors_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { var viewModel = new ConnectorViewModel(this, item as ConnectorModel); _connectors.Add(viewModel); } break; case NotifyCollectionChangedAction.Reset: _connectors.Clear(); break; case NotifyCollectionChangedAction.Remove: foreach (var item in e.OldItems) { _connectors.Remove(_connectors.First(x => x.ConnectorModel == item)); } break; } }
void Connectors_ConnectorAdded(ConnectorModel c) { var viewModel = new ConnectorViewModel(this, c); if (_connectors.All(x => x.ConnectorModel != c)) _connectors.Add(viewModel); }
private void SetActiveConnector(ConnectorViewModel connector) { if (null != connector) { System.Diagnostics.Debug.Assert(null == activeConnector); this.WorkspaceElements.Add(connector); this.activeConnector = connector; } else { System.Diagnostics.Debug.Assert(null != activeConnector); this.WorkspaceElements.Remove(activeConnector); this.activeConnector = null; } this.RaisePropertyChanged("ActiveConnector"); }
void Connectors_ConnectorAdded(ConnectorModel c) { var viewModel = new ConnectorViewModel(this, c); if (_connectors.All(x => x.ConnectorModel != c)) _connectors.Add(viewModel); }
internal void BeginConnection(Guid nodeId, int portIndex, PortType portType) { bool isInPort = portType == PortType.Input; NodeModel node = Model.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) { // Define the new active connector var c = new ConnectorViewModel(this, portModel.Connectors[0].Start); this.SetActiveConnector(c); } else { try { // Create a connector view model to begin drawing var connector = new ConnectorViewModel(this, portModel); this.SetActiveConnector(connector); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } }
void Connectors_ConnectorAdded(ConnectorModel c) { var viewModel = new ConnectorViewModel(this, c); _connectors.Add(viewModel); }