Beispiel #1
0
        //Following The Test Code

        #region Private Methods

        /// <summary>
        /// A function to conveniently populate the view-model with test data.
        /// </summary>
        private void PopulateWithTestData()
        {
            //
            // Create a network, the root of the view-model.
            //
            this.Network = new NetworkViewModel();

            //
            // Create some nodes and add them to the view-model.
            //
            AbstractNodeViewModel testInXamlEditor = CreateNode <PrintStringNodeViewModel>(new Point(350, 280), false);
            AbstractNodeViewModel node1            = CreateNode <ConstantIntegerNodeViewModel>(new Point(100, 60), false);
            AbstractNodeViewModel node2            = CreateNode <ConstantIntegerNodeViewModel>(new Point(100, 90), false);
            AbstractNodeViewModel node3            = CreateNode <AddIntegerNodeViewModel>(new Point(350, 80), false);

            AbstractNodeViewModel node4 = CreateNode <ConstantFloatNodeViewModel>(new Point(100, 150), false);
            AbstractNodeViewModel node5 = CreateNode <ConstantFloatNodeViewModel>(new Point(100, 190), false);
            AbstractNodeViewModel node6 = CreateNode <AddFloatNodeViewModel>(new Point(350, 120), false);

            //
            // Create a connection between the nodes.
            //
            ConnectionViewModel connection = new ConnectionViewModel();

            connection.SourceConnector = node1.OutputConnectors[0];
            connection.DestConnector   = node3.InputConnectors[0];

            //
            // Add the connection to the view-model.
            //
            this.Network.Connections.Add(connection);
        }
Beispiel #2
0
        /// <summary>
        /// Delete the node from the view-model.
        /// Also deletes any connections to or from the node.
        /// </summary>
        public void DeleteNode(AbstractNodeViewModel node)
        {
            //
            // Remove all connections attached to the node.
            //
            this.Network.Connections.RemoveRange(node.AttachedConnections);

            //
            // Remove the node from the network.
            //
            this.Network.Nodes.Remove(node);
        }
        /// <summary>
        /// Determine the area covered by the specified list of nodes.
        /// </summary>
        private Rect DetermineAreaOfNodes(IList nodes)
        {
            AbstractNodeViewModel firstNode = (AbstractNodeViewModel)nodes[0];
            Rect actualContentRect          = new Rect(firstNode.X, firstNode.Y, firstNode.Size.Width, firstNode.Size.Height);

            for (int i = 1; i < nodes.Count; ++i)
            {
                AbstractNodeViewModel node = (AbstractNodeViewModel)nodes[i];
                Rect nodeRect = new Rect(node.X, node.Y, node.Size.Width, node.Size.Height);
                actualContentRect = Rect.Union(actualContentRect, nodeRect);
            }
            return(actualContentRect);
        }
 public void DetectEndOfNode(AbstractNodeViewModel node)
 {
     /// Check OutputConnectors Count
     foreach (var output in node.OutputConnectors)
     {
         if (output.AttachedConnections.Count != 0)
         {
             return;                                       /// not end
         }
     }
     if (EndOfNodes.IndexOf(node) < 0)
     {
         EndOfNodes.Add(node);
     }
 }
        /// <summary>
        /// Recursive Solve single node calculation
        /// </summary>
        /// <param name="node"></param>
        /// <returns>Is success solved</returns>
        private bool UnitSolve(AbstractNodeViewModel node, ConnectorViewModel invokerConnector = null)
        {
            {
                bool isSuccessed = true;

                if (node.InputConnectors.Count != 0)
                {
                    foreach (var connector in node.InputConnectors)
                    {
                        // Exist input connectors, so check whether this attached to any node
                        if (connector.AttachedConnections.Count != 0)
                        {
                            // Attached input

                            // Attached num check
                            if (connector.AttachedConnections.Count > 1)
                            {
                                // Usually not reached point
                                throw new NotImplementedException("now input connection must has single attached.");
                            }
                            //So call the self recursively in terms of get this node's destination of the node
                            foreach (var connection in connector.AttachedConnections)
                            {
                                AbstractNodeViewModel outputNode = null;
                                if (connection.DestConnector.Type == ConnectorType.Output)
                                {
                                    outputNode = connection.DestConnector.ParentNode;
                                }
                                else
                                {
                                    outputNode = connection.SourceConnector.ParentNode;
                                }

                                isSuccessed = UnitSolve(outputNode, connector);
                            }
                        }
                    }
                }

                /// If could not solved of just before node, cancel solve
                //if (!isSuccessed) return false;
            }

            /// Execute Calculation
            node.Calculate();

            /// Check node is be able to solve of static
            //if(node.SolverType != NodeCalculationType.Dynamic)
            //{
            //    return false;
            //}

            /// Propagate data to invoker
            foreach (var connector in node.OutputConnectors)
            {
                foreach (var connection in connector.AttachedConnections)
                {
                    ConnectorViewModel outputConnector = null;
                    ConnectorViewModel inputConnector  = null;
                    if (connection.DestConnector.Type == ConnectorType.Output)
                    {
                        outputConnector = connection.DestConnector;
                        inputConnector  = connection.SourceConnector;
                    }
                    else
                    {
                        outputConnector = connection.SourceConnector;
                        inputConnector  = connection.DestConnector;
                    }
                    if (inputConnector == invokerConnector && connection.DestConnector.DataType == invokerConnector.DataType)
                    {
                        invokerConnector.NoRaiseEntity = outputConnector.Entity;
                    }
                }
            }

            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Create a node and add it to the view-model.
        /// </summary>
        public AbstractNodeViewModel CreateNode <NodeType>(Point nodeLocation, bool centerNode)
            where NodeType : AbstractNodeViewModel
        {
            Type Type = typeof(NodeType);
            AbstractNodeViewModel node = null;

            try
            {
                node = (AbstractNodeViewModel)Activator.CreateInstance(Type);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(node);
            }
            node.X = nodeLocation.X;
            node.Y = nodeLocation.Y;

            //node.InputConnectors.Add(new ConnectorViewModel("In1",typeof(int)));
            //node.InputConnectors.Add(new ConnectorViewModel("In2", typeof(int)));
            //node.OutputConnectors.Add(new ConnectorViewModel("Out1", typeof(int)));
            //node.OutputConnectors.Add(new ConnectorViewModel("Out2", typeof(int)));
            //node.OutputConnectors.Add(new ConnectorViewModel("Out1", typeof(int)));
            //node.OutputConnectors.Add(new ConnectorViewModel("Out2", typeof(int)));

            if (centerNode)
            {
                //
                // We want to center the node.
                //
                // For this to happen we need to wait until the UI has determined the
                // size based on the node's data-template.
                //
                // So we define an anonymous method to handle the SizeChanged event for a node.
                //
                // Note: If you don't declare sizeChangedEventHandler before initializing it you will get
                //       an error when you try and unsubscribe the event from within the event handler.
                //
                EventHandler <EventArgs> sizeChangedEventHandler = null;
                sizeChangedEventHandler =
                    delegate(object sender, EventArgs e)
                {
                    //
                    // This event handler will be called after the size of the node has been determined.
                    // So we can now use the size of the node to modify its position.
                    //
                    node.X -= node.Size.Width / 2;
                    node.Y -= node.Size.Height / 2;

                    //
                    // Don't forget to unhook the event, after the initial centering of the node
                    // we don't need to be notified again of any size changes.
                    //
                    node.SizeChanged -= sizeChangedEventHandler;
                };

                //
                // Now we hook the SizeChanged event so the anonymous method is called later
                // when the size of the node has actually been determined.
                //
                node.SizeChanged += sizeChangedEventHandler;
            }

            //
            // Add the event of update entity
            //
            foreach (var connector in node.InputConnectors)
            {
                connector.PropertyChanged += Node_EntityChanged;
            }
            foreach (var connector in node.OutputConnectors)
            {
                connector.PropertyChanged += Node_EntityChanged;
            }
            //
            // Add the node to the view-model.
            //
            this.Network.Nodes.Add(node);

            return(node);
        }
Beispiel #7
0
 private void DecideLastedNode(AbstractNodeViewModel node)
 {
 }