Esempio n. 1
0
        /// <summary>
        /// Try to find the index of the vector node connecting this path node to the (given) nextNode.
        /// </summary>
        /// <returns>The index of the vector node connection, or -1</returns>
        public override int FindTvnIndex(TrainpathNode nextNode)
        {
            TrainpathVectorNode nextAsVectorNode = nextNode as TrainpathVectorNode;

            if (nextAsVectorNode != null)
            {   // from junction to vector node.
                if (this.ConnectsToTrack(nextAsVectorNode.TvnIndex))
                {
                    return(nextAsVectorNode.TvnIndex);
                }
                else
                {   //node is perhaps not broken, but connecting track is
                    return(-1);
                }
            }

            //both this node and the next node are junctions: find the vector node connecting them.
            //Probably this can be faster, by just finding the TrPins from this and next junction and find the common one.
            int nextJunctionIndex = (nextNode as TrainpathJunctionNode).JunctionIndex;

            for (int i = 0; i < TrackDB.TrackNodes.Count(); i++)
            {
                TrackNode tn = TrackDB.TrackNodes[i];
                if (tn == null || tn.TrVectorNode == null)
                {
                    continue;
                }
                if ((tn.JunctionIndexAtStart() == this.JunctionIndex && tn.JunctionIndexAtEnd() == nextJunctionIndex) ||
                    (tn.JunctionIndexAtEnd() == this.JunctionIndex && tn.JunctionIndexAtStart() == nextJunctionIndex))
                {
                    return(i);
                }
            }
            return(-1);
        }
Esempio n. 2
0
        /// <summary>
        /// From the current pathnode and the linking tracknode, fin the junctionIndex of the next junction (or possibly end-point)
        /// </summary>
        /// <param name="linkingTrackNodeIndex">The index of the tracknode leaving the node</param>
        /// <returns>The index of the junction index at the end of the track (as seen from the node)</returns>
        public override int GetNextJunctionIndex(int linkingTrackNodeIndex)
        {
            TrackNode linkingTrackNode = TrackDB.TrackNodes[linkingTrackNodeIndex];

            return(ForwardOriented
                ? linkingTrackNode.JunctionIndexAtEnd()
                : linkingTrackNode.JunctionIndexAtStart());
        }
Esempio n. 3
0
        /// <summary>
        /// From the current pathnode and the linking tracknode, find the junctionIndex of the previous junction (or possibly end-point)
        /// </summary>
        /// <param name="linkingTrackNodeIndex">The index of the tracknode leaving the node</param>
        /// <returns>The index of the junction index at the beginning of the track (as seen from the node)</returns>
        public int GetPrevJunctionIndex(int linkingTrackNodeIndex)
        {
            TrackNode linkingTrackNode             = TrackDB.TrackNodes[linkingTrackNodeIndex];
            bool      towardsNodeIsForwardOriented =
                (this.NodeType == TrainpathNodeType.Reverse)
                ? !ForwardOriented
                : ForwardOriented;

            return(towardsNodeIsForwardOriented
                ? linkingTrackNode.JunctionIndexAtStart()
                : linkingTrackNode.JunctionIndexAtEnd());
        }
Esempio n. 4
0
        /// <summary>
        /// Get the index of the junction node at the other side of the linking track vector node.
        /// This uses only the track database, no trainpath nodes.
        /// </summary>
        /// <param name="junctionIndex">Index of this junction node</param>
        /// <param name="linkingTrackNodeIndex">index of the vector node linking the two junction nodes</param>
        /// <returns>The index of the junction node at the other end, or 0 in case of trouble</returns>
        public static int GetNextJunctionIndex(int junctionIndex, int linkingTrackNodeIndex)
        {
            if (linkingTrackNodeIndex <= 0)
            {
                return(0);                            // link is not well-defined
            }
            TrackNode linkingTrackNode = trackNodes[linkingTrackNodeIndex];

            if (linkingTrackNode == null)
            {
                return(0);
            }

            if (junctionIndex == linkingTrackNode.JunctionIndexAtStart())
            {
                return(linkingTrackNode.JunctionIndexAtEnd());
            }
            else
            {
                return(linkingTrackNode.JunctionIndexAtStart());
            }
        }