Ejemplo n.º 1
0
        /// <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();
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        /// <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();
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
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 };
                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
            }
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
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.SaveAndDeleteModels(connectorsForDeletion);
            for (int i = 0; i < numOfConnectors; i++) //delete the connectors
            {
                selectedPort.Connectors[0].Delete();
            }
            return;
        }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
 private void RegisterConnector(ConnectorModel connector)
 {
     connector.Deleted += () => OnConnectorDeleted(connector);
 }
Ejemplo n.º 14
0
 protected virtual void OnConnectorAdded(ConnectorModel obj)
 {
     RegisterConnector(obj);
     var handler = ConnectorAdded;
     if (handler != null) handler(obj);
 }
Ejemplo n.º 15
0
 /// <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);
 }
Ejemplo n.º 16
0
 /// <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();
 }
Ejemplo n.º 18
0
        /// <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();
        }
Ejemplo n.º 19
0
        /// <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);
        }
Ejemplo n.º 20
0
 void Connectors_ConnectorDeleted(ConnectorModel c)
 {
     var connector = _connectors.FirstOrDefault(x => x.ConnectorModel == c);
     if (connector != null)
         _connectors.Remove(connector);
 }
Ejemplo n.º 21
0
        public void Connect(ConnectorModel connector)
        {
            connectors.Add(connector);

            //throw the event for a connection
            OnPortConnected(EventArgs.Empty);

            IsConnected = true;
        }
Ejemplo n.º 22
0
 void Connectors_ConnectorAdded(ConnectorModel c)
 {
     var viewModel = new ConnectorViewModel(this, c);
     if (_connectors.All(x => x.ConnectorModel != c))
         _connectors.Add(viewModel);
 }
Ejemplo n.º 23
0
 /// <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);
 }
Ejemplo n.º 24
0
        /// <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();
        }
Ejemplo n.º 25
0
 protected virtual void OnConnectorDeleted(ConnectorModel obj)
 {
     var handler = ConnectorDeleted;
     if (handler != null) handler(obj);
 }
Ejemplo n.º 26
0
 private void RegisterConnector(ConnectorModel connector)
 {
     connector.Deleted += () => OnConnectorDeleted(connector);
 }
Ejemplo n.º 27
0
 internal void OnConnectorDeleted(ConnectorModel connector)
 {
     if (ConnectorDeleted != null)
     {
         ConnectorDeleted(connector);
     }
 }
Ejemplo n.º 28
0
        /// <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);
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Called when a port is connected.
 /// </summary>
 /// <param name="connector"></param>
 protected virtual void OnPortConnected(ConnectorModel connector)
 {
     if (PortConnected != null)
         PortConnected(this, connector);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Called when a connector is added.
 /// </summary>
 /// <param name="connector"></param>
 private void OnConnectorAdded(ConnectorModel connector)
 {
     if (ConnectorAdded != null)
     {
         ConnectorAdded(connector);
     }
 }
Ejemplo n.º 31
0
        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();
        }
Ejemplo n.º 32
0
        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();
        }
Ejemplo n.º 33
0
        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();
        }
Ejemplo n.º 34
0
        protected virtual void OnConnectorDeleted(ConnectorModel obj)
        {
            if (hasNodeInSyncWithDefinition)
            {
                undoRecorder.RecordModelAsOffTrack(obj.GUID);
            }

            var handler = ConnectorDeleted;
            if (handler != null) handler(obj);
        }
Ejemplo n.º 35
0
 protected virtual void PortConnectedHandler(PortModel arg1, ConnectorModel arg2)
 {
     // Do nothing for a standard node.
 }
Ejemplo n.º 36
0
        /// <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();*/
        }