Example #1
0
        public void DeleteModel(XmlElement modelData)
        {
            ModelBase model = GetModelForElement(modelData);

            if (model is NoteModel)
            {
                Notes.Remove(model as NoteModel);
            }
            else if (model is ConnectorModel)
            {
                ConnectorModel connector = model as ConnectorModel;
                Connectors.Remove(connector);
                connector.NotifyConnectedPortsOfDeletion();
            }
            else if (model is NodeModel)
            {
                Nodes.Remove(model as NodeModel);
            }
            else
            {
                // If it gets here we obviously need to handle it.
                throw new InvalidOperationException(string.Format(
                                                        "Unhandled type: {0}", model.GetType().ToString()));
            }
        }
Example #2
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();
            }
        }
Example #3
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;
            }
        }