コード例 #1
0
        /// <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;


        }
コード例 #2
0
 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);
 }