示例#1
0
        //================================================================================================//
        //
        // Constructor for empty entries
        //

        public TrackCircuitSection(int INode, Signals thisSignals)
        {
            signalRef = thisSignals;

            Index         = INode;
            OriginalIndex = -1;
            CircuitType   = TrackCircuitType.Empty;

            for (int iDir = 0; iDir < 2; iDir++)
            {
                EndIsTrailingJunction[iDir] = false;
                EndSignals[iDir]            = null;
                OffsetLength[iDir]          = 0;
            }

            for (int iDir = 0; iDir < 2; iDir++)
            {
                for (int pin = 0; pin < 2; pin++)
                {
                    Pins[iDir, pin]                 = new TrPin();
                    Pins[iDir, pin].Direction       = -1;
                    Pins[iDir, pin].Link            = -1;
                    ActivePins[iDir, pin]           = new TrPin();
                    ActivePins[iDir, pin].Direction = -1;
                    ActivePins[iDir, pin].Link      = -1;
                }
            }

            CircuitItems = new TrackCircuitItems();
            CircuitState = new TrackCircuitState();
        }
示例#2
0
        public List <int> SignalsPassingRoutes;                   // list of signals reading passed junction //
        //================================================================================================//
        //
        // Constructor
        //


        public TrackCircuitSection(TrackNode thisNode, int orgINode,
                                   TSectionDatFile tsectiondat, Signals thisSignals)
        {
            //
            // Copy general info
            //

            signalRef = thisSignals;

            Index         = orgINode;
            OriginalIndex = orgINode;

            if (thisNode.TrEndNode)
            {
                CircuitType = TrackCircuitType.EndOfTrack;
            }
            else if (thisNode.TrJunctionNode != null)
            {
                CircuitType = TrackCircuitType.Junction;
            }
            else
            {
                CircuitType = TrackCircuitType.Normal;
            }


            //
            // Preset pins, then copy pin info
            //

            for (int direction = 0; direction < 2; direction++)
            {
                for (int pin = 0; pin < 2; pin++)
                {
                    Pins[direction, pin]                 = new TrPin();
                    Pins[direction, pin].Direction       = -1;
                    Pins[direction, pin].Link            = -1;
                    ActivePins[direction, pin]           = new TrPin();
                    ActivePins[direction, pin].Direction = -1;
                    ActivePins[direction, pin].Link      = -1;
                }
            }

            int PinNo = 0;

            for (int pin = 0; pin < Math.Min(thisNode.Inpins, Pins.GetLength(1)); pin++)
            {
                Pins[0, pin] = thisNode.TrPins[PinNo].Copy();
                PinNo++;
            }
            if (PinNo < thisNode.Inpins)
            {
                PinNo = (int)thisNode.Inpins;
            }
            for (int pin = 0; pin < Math.Min(thisNode.Outpins, Pins.GetLength(1)); pin++)
            {
                Pins[1, pin] = thisNode.TrPins[PinNo].Copy();
                PinNo++;
            }


            //
            // preset no end signals
            // preset no trailing junction
            //

            for (int direction = 0; direction < 2; direction++)
            {
                EndSignals[direction]            = null;
                EndIsTrailingJunction[direction] = false;
            }

            //
            // Preset length and offset
            // If section index not in tsectiondat, set length to 0.
            //

            float totalLength = 0.0f;

            if (thisNode.TrVectorNode != null && thisNode.TrVectorNode.TrVectorSections != null)
            {
                foreach (TrVectorSection thisSection in thisNode.TrVectorNode.TrVectorSections)
                {
                    float thisLength = 0.0f;

                    if (tsectiondat.TrackSections.ContainsKey(thisSection.SectionIndex))
                    {
                        TrackSection TS = tsectiondat.TrackSections[thisSection.SectionIndex];

                        if (TS.SectionCurve != null)
                        {
                            thisLength =
                                MathHelper.ToRadians(Math.Abs(TS.SectionCurve.Angle)) *
                                TS.SectionCurve.Radius;
                        }
                        else
                        {
                            thisLength = TS.SectionSize.Length;
                        }
                    }

                    totalLength += thisLength;
                }
            }

            Length = totalLength;

            for (int direction = 0; direction < 2; direction++)
            {
                OffsetLength[direction] = 0;
            }

            //
            // set signal list for junctions
            //

            if (CircuitType == TrackCircuitType.Junction)
            {
                SignalsPassingRoutes = new List <int>();
            }
            else
            {
                SignalsPassingRoutes = null;
            }

            // for Junction nodes, obtain default route
            // set switch to default route
            // copy overlap (if set)

            if (CircuitType == TrackCircuitType.Junction)
            {
                uint trackShapeIndex = thisNode.TrJunctionNode.ShapeIndex;
                try
                {
                    TrackShape trackShape = tsectiondat.TrackShapes[trackShapeIndex];
                    JunctionDefaultRoute = (int)trackShape.MainRoute;

                    Overlap = trackShape.ClearanceDistance;
                }
                catch (Exception)
                {
                    JunctionDefaultRoute = 0;
                    Overlap = 0;
                }

                JunctionLastRoute = JunctionDefaultRoute;
                //signalRef.setSwitch(OriginalIndex, JunctionLastRoute, this);
            }

            //
            // Create circuit items
            //

            CircuitItems = new TrackCircuitItems();
            CircuitState = new TrackCircuitState();
        }