Example #1
0
        public static void AddCrossing(eTrack track1, eTrack track2, double length, double pos1, double pos2)
        {
            string id1 = DataContainer.IDGenerator("Connection");
            string id2 = DataContainer.IDGenerator("Connection");
            string id3 = DataContainer.IDGenerator("Connection");
            string id4 = DataContainer.IDGenerator("Connection");

            tConnectionData switchtotrack1 = new tConnectionData()
            {
                id = id1, @ref = id2
            };
            tSwitchConnectionData track1toswitch = new tSwitchConnectionData()
            {
                id = id2, @ref = id1
            };
            tConnectionData switchtotrack2 = new tConnectionData()
            {
                id = id3, @ref = id4
            };
            tSwitchConnectionData track2toswitch = new tSwitchConnectionData()
            {
                id = id4, @ref = id3
            };

            eTrack track = new eTrack()
            {
                id = DataContainer.IDGenerator("track")
            };

            track.trackTopology.trackBegin.pos  = 0;
            track.trackTopology.trackEnd.pos    = (decimal)length;
            track.trackTopology.trackBegin.Item = switchtotrack1;
            track.trackTopology.trackEnd.Item   = switchtotrack2;
            DataContainer.model.infrastructure.tracks.Add(track);

            eSwitch switch1 = new eSwitch()
            {
                pos = (decimal)pos1, id = DataContainer.IDGenerator("Switch")
            };

            switch1.connection.Add(track1toswitch);
            track1.trackTopology.connections.Add(switch1);
            eSwitch switch2 = new eSwitch()
            {
                pos = (decimal)pos2, id = DataContainer.IDGenerator("Switch")
            };

            switch1.connection.Add(track2toswitch);
            track2.trackTopology.connections.Add(switch2);
        }
Example #2
0
        public static void ConnectEnd(eTrack track1, eTrack track2)
        {
            string id1 = DataContainer.IDGenerator("connection");
            string id2 = DataContainer.IDGenerator("connection");

            tConnectionData connection1 = new tConnectionData()
            {
                id = id1, @ref = id2
            };
            tConnectionData connection2 = new tConnectionData()
            {
                id = id2, @ref = id1
            };

            track1.trackTopology.trackEnd.Item   = connection1;
            track2.trackTopology.trackBegin.Item = connection2;
        }
Example #3
0
        private static eSwitch FindConnections(eSwitch tempswitch)
        {
            Point  switchlocation = new Point(tempswitch.geoCoord.coord[0], tempswitch.geoCoord.coord[1]);
            eTrack hostline       = null;
            eTrack track2         = null;
            bool   trackend       = false;

            while (track2 == null)
            {
                eTrack besttrack = null;
                double bestdist  = 999999999999;

                foreach (eTrack track in DataContainer.model.infrastructure.tracks)
                {
                    double dist = GetDistance(switchlocation, new Point(track.trackTopology.trackBegin.geoCoord.coord[0], track.trackTopology.trackBegin.geoCoord.coord[1]));
                    if (dist < bestdist)
                    {
                        bestdist = dist; besttrack = track; trackend = false;
                    }
                    dist = GetDistance(switchlocation, new Point(track.trackTopology.trackEnd.geoCoord.coord[0], track.trackTopology.trackEnd.geoCoord.coord[1]));
                    if (dist < bestdist)
                    {
                        bestdist = dist; besttrack = track; trackend = true;
                    }
                }
                track2 = besttrack;
            }
            while (hostline == null)
            {
                eTrack besttrack = null;
                double bestdist  = 99999999999;

                foreach (eTrack track in DataContainer.model.infrastructure.tracks)
                {
                    if (track == track2)
                    {
                        continue;
                    }
                    List <Point> pointlist = NodeList(track);
                    for (int i = 0; i < pointlist.Count - 1; i++)
                    {
                        double dist = GetDistance(pointlist[i], pointlist[i + 1], switchlocation);
                        if (dist < bestdist)
                        {
                            bestdist = dist; besttrack = track;
                        }
                    }
                }
                hostline = besttrack;
            }

            tConnectionData conn1 = new tConnectionData();

            DataContainer.IDGenerator(conn1);
            tSwitchConnectionData conn2 = new tSwitchConnectionData();

            DataContainer.IDGenerator(conn2);
            conn1.@ref = conn2.id; conn2.@ref = conn1.id;
            if (trackend == true)
            {
                track2.trackTopology.trackEnd.Item = conn1;
            }
            else
            {
                track2.trackTopology.trackBegin.Item = conn1;
            }
            tempswitch.connection.Add(conn2);
            hostline.trackTopology.connections.Add(tempswitch);
            string[] orientation = GetOrientation(hostline, track2, tempswitch);
            tempswitch.connection[0].orientation = orientation[0];
            tempswitch.connection[0].course      = orientation[1];

            return(tempswitch);
        }