Exemplo n.º 1
0
        public void InitializeDirection()
        {
            TopolotyNode inCommingNode  = FindNode(this.IncomingSections[0]);
            TopolotyNode inSectionFirst = FindNode(this.InSections[0]);

            if (inCommingNode.ConnectableDevice is Section)
            {
                this.RouteDirection_ = inCommingNode.RightNodes.Contains(inSectionFirst) ? TrainDir.Right : TrainDir.Left;
            }
            else if (inCommingNode.ConnectableDevice is RailSwitch)
            {
                List <TopolotyNode> CommingRightNode = inCommingNode.RightNodes;
                foreach (var item in CommingRightNode)
                {
                    if (item.ConnectableDevice is RailSwitch)
                    {
                        if ((item.ConnectableDevice as RailSwitch).SectionName == (inCommingNode.ConnectableDevice as RailSwitch).SectionName)
                        {
                            inCommingNode = item;
                        }
                    }
                }
                this.RouteDirection_ = inCommingNode.RightNodes.Contains(inSectionFirst) ? TrainDir.Right : TrainDir.Left;
            }
        }
Exemplo n.º 2
0
 private void SetDirection(TopolotyNode incommingnode, TopolotyNode inSectionFirst)
 {
     foreach (var node in incommingnode.RightNodes)
     {
         this.RouteDirection_ = node.ConnectableDevice == inSectionFirst.ConnectableDevice ? TrainDir.Right : TrainDir.Left;
     }
 }
Exemplo n.º 3
0
 public UInt16 GetOffset(TrainDir Direction)
 {
     if (this.SectionName == "W0105" || this.SectionName == "W0106" || this.SectionName == "W0411" || this.SectionName == "W0414")
     {
         if (this.IsPositionNormal && !this.IsPositionReverse)
         {
             return(Convert.ToUInt16(2 * this.NormalDistance));
         }
         else if (this.IsPositionReverse && !this.IsPositionNormal)
         {
             return(Convert.ToUInt16(2 * this.ReverseDistance));
         }
         else
         {
             return(0);
         }
     }
     else
     {
         if (this.IsPositionNormal && !this.IsPositionReverse)
         {
             return(Convert.ToUInt16(this.NormalDistance));
         }
         else if (!this.IsPositionNormal && this.IsPositionReverse)
         {
             return(Convert.ToUInt16(this.ReverseDistance));
         }
         else
         {
             return(0);
         }
     }
 }
Exemplo n.º 4
0
 public void SetTrainOccupy(TrainDir trainDir, UInt32 offset, bool isOccupy, UInt16 trainID)
 {
     if (this.LogicCount == 1)
     {
         SetTrainList(this.isFrontLogicOccupy_, isOccupy, trainID);
         SetTrainList(this.isLastLogicOccupy_, isOccupy, trainID);
     }
     else
     {
         if (trainDir == TrainDir.Right)
         {
             if (offset < (this.Distance / 2))
             {
                 SetTrainList(this.isFrontLogicOccupy_, isOccupy, trainID);
             }
             else
             {
                 SetTrainList(this.isLastLogicOccupy_, isOccupy, trainID);
             }
         }
         else if (trainDir == TrainDir.Left)
         {
             if (offset < (this.Distance / 2))
             {
                 SetTrainList(this.isFrontLogicOccupy_, isOccupy, trainID);
             }
             else
             {
                 SetTrainList(this.isLastLogicOccupy_, isOccupy, trainID);
             }
         }
     }
 }
Exemplo n.º 5
0
        static void Main()
        {
            App app =
                new TrainDir();

            // new TestProgram();
            app.Run();
        }
Exemplo n.º 6
0
 private void ChangeDeviceOccupy(Device position, uint offset, TrainDir trainDirection, bool isOccupy)
 {
     if (position is Section)
     {
         (position as Section).SetTrainOccupy(trainDirection, offset, isOccupy, CurrentTrain.NIDTrain);
         AddToDeviceNeedToChange(position);
     }
     else if (position is RailSwitch)
     {
         ChangeRailSwitchOccupy(position as RailSwitch, isOccupy);
     }
 }
Exemplo n.º 7
0
        private void HandlePosition(TrainDir trainDir, UInt32 offset, bool isOccupy, UInt16 trainID, Device device)
        {
            if (device is Section)
            {
                (device as Section).SetTrainOccupy(trainDir, offset, isOccupy, trainID);
                UpdateDevice(device);
            }
            else if (device is RailSwitch)
            {
                RailSwitch railswitch = device as RailSwitch;
                railswitch.SetTrainOccupy(trainID, isOccupy);
                UpdateDevice(device);

                RailSwitch railNeedToChange = FindAnotherRailswitch(railswitch);
                if (railNeedToChange != null)
                {
                    railNeedToChange.SetTrainOccupy(trainID, isOccupy);
                    UpdateDevice(railNeedToChange);
                }
            }
        }
Exemplo n.º 8
0
        public UInt16 GetOffset(TrainDir Direction, UInt16 trainID)
        {
            if (this.LogicCount == 1)
            {
                return(Convert.ToUInt16(this.Distance));
            }
            switch (Direction)
            {
            case TrainDir.Right:
                switch (GetTrainOccupy(trainID))
                {
                case TrainOccupy.NonOccupy:
                    return(Convert.ToUInt16(this.Distance));

                case TrainOccupy.RightOccupy:
                    return(Convert.ToUInt16(this.Distance / 2));

                default:
                    return(0);
                }

            case TrainDir.Left:
                switch (GetTrainOccupy(trainID))
                {
                case TrainOccupy.NonOccupy:
                    return(Convert.ToUInt16(this.Distance));

                case TrainOccupy.LeftOccupy:
                    return(Convert.ToUInt16(this.Distance / 2));

                default:
                    return(0);
                }

            default:
                return(0);
            }
        }