Example #1
0
        /// <summary>
        /// Called when the user has finished dragging out the new connection.
        /// </summary>
        public void ConnectionDragCompleted(ConnectionViewModel newConnection, ConnectorViewModel connectorDraggedOut, ConnectorViewModel connectorDraggedOver)
        {
            if (connectorDraggedOver == null)
            {
                //
                // The connection was unsuccessful.
                // Maybe the user dragged it out and dropped it in empty space.
                //
                this.Network.Connections.Remove(newConnection);
                return;
            }

            //
            // Only allow connections from output connector to input connector (ie each
            // connector must have a different type).
            // Also only allocation from one node to another, never one node back to the same node.
            //
            bool connectionOk = connectorDraggedOut.ParentNode != connectorDraggedOver.ParentNode &&
                                connectorDraggedOut.Type != connectorDraggedOver.Type &&
                                connectorDraggedOver.AttachedConnections.Count == 0;


            if (!connectionOk)
            {
                //
                // Connections between connectors that have the same type,
                // eg input -> input or output -> output, are not allowed,
                // Remove the connection.
                //
                this.Network.Connections.Remove(newConnection);
                return;
            }

            //
            // The user has dragged the connection on top of another valid connector.
            //

            //
            // Remove any existing connection between the same two connectors.
            //
            var existingConnection = FindConnection(connectorDraggedOut, connectorDraggedOver);

            if (existingConnection != null)
            {
                this.Network.Connections.Remove(existingConnection);
            }

            //
            // Finalize the connection by attaching it to the connector
            // that the user dragged the mouse over.
            //
            if (newConnection.DestConnector == null)
            {
                newConnection.DestConnector = connectorDraggedOver;
            }
            else
            {
                newConnection.SourceConnector = connectorDraggedOver;
            }

            if (newConnection.DestConnector != null && newConnection.SourceConnector != null)
            {
                LibnoiseNode sourceNode        = newConnection.SourceConnector.ParentNode.Module;
                LibnoiseNode destinationNode   = newConnection.DestConnector.ParentNode.Module;
                ModuleBase   sourceModule      = newConnection.SourceConnector.ParentNode.Module.LibnoiseModule;
                ModuleBase   destinationModule = newConnection.DestConnector.ParentNode.Module.LibnoiseModule;

                // get destination type, connector name, assign to correct module
                if (newConnection.DestConnector.Name.Equals("Input"))
                {
                    destinationModule.Modules[0] = sourceModule;
                    destinationNode.Inputs[0]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Left"))
                {
                    destinationModule.Modules[0] = sourceModule;
                    destinationNode.Inputs[0]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Right"))
                {
                    destinationModule.Modules[1] = sourceModule;
                    destinationNode.Inputs[1]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Operator"))
                {
                    destinationModule.Modules[2] = sourceModule;
                    destinationNode.Inputs[2]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Primary"))
                {
                    destinationModule.Modules[0] = sourceModule;
                    destinationNode.Inputs[0]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Secondary"))
                {
                    destinationModule.Modules[1] = sourceModule;
                    destinationNode.Inputs[1]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Controller"))
                {
                    destinationModule.Modules[2] = sourceModule;
                    destinationNode.Inputs[2]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("X"))
                {
                    destinationModule.Modules[1] = sourceModule;
                    destinationNode.Inputs[1]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Y"))
                {
                    destinationModule.Modules[2] = sourceModule;
                    destinationNode.Inputs[2]    = sourceNode;
                }
                else if (newConnection.DestConnector.Name.Equals("Z"))
                {
                    destinationModule.Modules[3] = sourceModule;
                    destinationNode.Inputs[3]    = sourceNode;
                }
            }
        }
Example #2
0
 public NodeViewModel(LibnoiseNode module)
 {
     this.Module = module;
     this.name   = ModuleType;
 }