コード例 #1
0
        /// <summary>
        /// Run through the track and for each node find the direction on the node
        /// </summary>
        void FindNodeOrientations()
        {
            // Node orientations are determined based on the track leading to the node
            // This makes it easier to extend the path (in case the last node is not known)
            // Only for the start node this is not possible. But hey, that is anyway up to the user.

            // start of path
            TrainpathNode currentMainNode = FirstNode;

            while (currentMainNode.NextMainNode != null)
            {
                // If there is a siding starting here, go through it until it ends.
                TrainpathNode currentSidingNode = currentMainNode;
                while (currentSidingNode.NextSidingNode != null)
                {
                    TrainpathNode nextSidingNode = currentSidingNode.NextSidingNode;
                    nextSidingNode.DetermineOrientation(currentSidingNode, currentSidingNode.NextSidingTvnIndex);
                    currentSidingNode = nextSidingNode;
                }

                // In case a main node has two nodes leading to it (siding and main), then
                // the main track will override.
                TrainpathNode nextMainNode = currentMainNode.NextMainNode;
                nextMainNode.DetermineOrientation(currentMainNode, currentMainNode.NextMainTvnIndex);
                currentMainNode = nextMainNode;
            }

            if (currentMainNode is TrainpathVectorNode)
            {   // Only vector nodes can be a real end!
                HasEnd = true;
                currentMainNode.NodeType = TrainpathNodeType.End;
            }
            else
            {
                HasEnd = false;
            }

            //Determine direction of first point. By using second point, the direction will be reversed
            FirstNode.DetermineOrientation(FirstNode.NextMainNode, FirstNode.NextMainTvnIndex);
            FirstNode.ReverseOrientation();
        }