Example #1
0
        /// <summary>
        /// Converts a tree styled rigging graph to a model graph.
        /// </summary>
        /// <param name="rig">The rigging graph to conver.</param>
        /// <param name="port">Method for generating portals.</param>
        /// <param name="junc">Method for generating junctions.</param>
        /// <param name="term">Method for generating terminals.</param>
        public void BuildSet(Func <Port> port, Func <int, Junction> junc, Func <Terminal> term)
        {
            List <GraphNode> current_model, next_model = Roots.ToList <GraphNode>();
            GraphNode        model_node;
            bool             isHead = true;

            do
            {
                // Switch next to current, and get new next
                current_model = next_model;
                next_model    = new List <GraphNode>();

                // Got through each node of current
                for (int i = 0; i < current_model.Count; i++)
                {
                    // Get current node
                    model_node = current_model[i];

                    // Build set piece on node and add un-built children to next tier
                    if (isHead)
                    {
                        ((RootNode)model_node).Port = port();
                        if (model_node.Neighbors[0].Station == null)
                        {
                            next_model.Add(model_node.Neighbors[0]);
                        }
                    }
                    else
                    {
                        if (model_node.Neighbors.Length > 1)
                        {
                            ((BranchNode)model_node).Junction = junc(model_node.Neighbors.Length);
                            for (int j = 0; j < model_node.Neighbors.Length; j++)
                            {
                                if (model_node.Neighbors[j].Station == null)
                                {
                                    next_model.Add(model_node.Neighbors[j]);
                                }
                            }
                        }
                        else
                        {
                            ((LeafNode)model_node).Terminal = term();
                        }
                    }
                }

                // Flip bool for speach head case
                if (isHead)
                {
                    isHead = false;
                }
            } while (next_model.Count > 0);
        }