Esempio n. 1
0
        public TrackSegment(TrackNodeAE node, int idx, TSectionDatFile tdf)
        {
            tcIndex = new List <int>();
            if (node.TCCrossReference != null)
            {
                foreach (var tcc in node.TCCrossReference)
                {
                    tcIndex.Add(tcc.CrossRefIndex);
                }
            }
            TrVectorSection item1 = node.TrVectorNode.TrVectorSections[idx];
            TrVectorSection item2 = node.TrVectorNode.TrVectorSections[idx + 1];

            A           = new MSTSCoord();
            A.TileX     = item1.TileX;
            A.TileY     = item1.TileZ;
            A.X         = item1.X;
            A.Y         = item1.Z;
            B           = new MSTSCoord();
            SectionIdxA = node.TrVectorNode.TrVectorSections[idx].SectionIndex;
            B.TileX     = item2.TileX;
            B.TileY     = item2.TileZ;
            B.X         = item2.X;
            B.Y         = item2.Z;
            NodeIdx     = node.Index;
            SectionIdxB = (uint)idx + 1;
            isCurved    = false;
            WorldUid    = node.getWorldFileUiD();
            CheckCurve(tdf, item1.flag2);
        }
Esempio n. 2
0
        public StationAreaItem AddPointArea(MSTSCoord coord, double snapDist, MSTSBase tileBase)
        {
            PointF found = new PointF(0, 0);
            double dist = -1, closestDist = double.PositiveInfinity;
            int    i;
            int    closestI = -1;
            PointF closest;

            StationAreaItem newPoint = new StationAreaItem(TypeEditor.ROUTECONFIG, this);

            if (areaCompleted)
            {
                StationAreaItem p1;
                StationAreaItem p2;
                for (i = 0; i < stationArea.Count - 1; i++)
                {
                    p1   = stationArea[i];
                    p2   = stationArea[i + 1];
                    dist = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(),
                                                             new AESegment(p1.Coord.ConvertToPointF(), p2.Coord.ConvertToPointF()), out found);
                    if (dist >= 0 && dist < snapDist && dist < closestDist)
                    {
                        closestDist = dist;
                        closestI    = i + 1;
                        closest     = found;
                    }
                    dist = -1;
                }
                p1   = stationArea[stationArea.Count - 1];
                p2   = stationArea[0];
                dist = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(),
                                                         new AESegment(p1.Coord.ConvertToPointF(), p2.Coord.ConvertToPointF()), out closest);

                if (dist >= 0 && dist < snapDist && dist < closestDist)
                {
                    closestDist = dist;
                    closestI    = 0;
                    closest     = found;
                }
                if (closestDist < double.PositiveInfinity)
                {
                    coord = tileBase.getMstsCoord(closest);
                    newPoint.configCoord(coord);
                    newPoint.toggleSelected();
                    stationArea.Insert(closestI, newPoint);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                //  Until area complete, we only add new point at the end
                newPoint.configCoord(coord);
                newPoint.toggleSelected();
                stationArea.Add(newPoint);
            }
            return(newPoint);
        }
Esempio n. 3
0
        public void checkForNewConnector(ORRouteConfig orRouteConfig, List <TrackSegment> segments, MSTSBase tileBase)
        {
            PointF pointIntersect;
            int    realPosit = 0;
            int    ii        = 0;

            //  First, we remove all un configured connectors
            //foreach (StationAreaItem SAWidget in stationArea)
            for (int cnt = 0; cnt < stationArea.Count; cnt++)
            {
                var SAWidget = stationArea[cnt];
                if (SAWidget.IsInterface() && !SAWidget.getStationConnector().isConfigured())
                {
                    removeConnector(orRouteConfig, SAWidget);
                    cnt--;
                }
            }
            //  Next, we search for new connectors and add them
            List <AESegment> polySegment = getPolySegment();

            for (int cntPointEdge = 0; cntPointEdge < polySegment.Count; cntPointEdge++)
            {
                List <System.Drawing.PointF> pointsIntersect = new List <System.Drawing.PointF>();
                foreach (var segment in segments)
                {
                    if ((segment.NodeIdx == 35 || segment.NodeIdx == 86) && cntPointEdge > 2 &&
                        (segment.SectionIdxA == 191 || segment.SectionIdxA == 40000))
                    {
                        ii = 1;
                    }
                    pointIntersect = DrawUtility.FindIntersection(polySegment[cntPointEdge], new AESegment(segment));
                    if (!pointIntersect.IsEmpty)
                    {
                        StationAreaItem newPoint = new StationAreaItem(TypeEditor.ROUTECONFIG, this);
                        MSTSCoord       coord    = tileBase.getMstsCoord(pointIntersect);
                        newPoint.configCoord(coord);
                        //newPoint.toggleSelected();
                        realPosit++;    // +1 car on doit placer après le cntEdge courant
                        List <AESegment> newPolySegment = getPolySegment();
                        insertConnector(newPolySegment, newPoint);
                        newPoint.DefineAsInterface(segment);
                    }
                }
                realPosit++;    //  On incrémente pour suivre le cntPointEdge
            }
        }
Esempio n. 4
0
        public TrackSegment(TrackNodeAE nodeA, TrackNodeAE nodeB, TSectionDatFile tdf, int i)
        {
            tcIndex = new List <int>();

            int direction = DrawUtility.getDirection(nodeA, nodeB);

            A           = nodeA.getMSTSCoord(direction);
            B           = nodeB.getMSTSCoord(direction);
            NodeIdx     = nodeA.Index;
            SectionIdxB = (uint)i;
            if (nodeA.TrJunctionNode != null)
            {
                direction   = DrawUtility.getDirection(nodeB, nodeA);
                SectionIdxA = nodeB.getSectionIndex(direction);
                if (nodeB.TCCrossReference != null)
                {
                    foreach (var tcc in nodeB.TCCrossReference)
                    {
                        tcIndex.Add(tcc.CrossRefIndex);
                    }
                }
            }
            else
            {
                SectionIdxA = nodeA.getSectionIndex(direction);
                if (nodeA.TCCrossReference != null)
                {
                    foreach (var tcc in nodeA.TCCrossReference)
                    {
                        tcIndex.Add(tcc.CrossRefIndex);
                    }
                }
            }
            isCurved = false;
            WorldUid = nodeA.getWorldFileUiD();
            CheckCurve(tdf, direction);
            linkToOther = true;
        }
Esempio n. 5
0
        public float setCenter(PointF p1, PointF p3, PointF p2)
        {
            float t   = p2.X * p2.X + p2.Y * p2.Y;
            float bc  = (p1.X * p1.X + p1.Y * p1.Y - t) / 2.0f;
            float cd  = (t - p3.X * p3.X - p3.Y * p3.Y) / 2.0f;
            float det = (p1.X - p2.X) * (p2.Y - p3.Y) - (p2.X - p3.X) * (p1.Y - p2.Y);

            if (Math.Abs(det) > 1.0e-6) // Determinant was found. Otherwise, radius will be left as zero.
            {
                det = 1f / det;
                float x = ((bc * (p2.Y - p3.Y)) - (cd * (p1.Y - p2.Y))) * det;
                float y = (((p1.X - p2.X) * cd) - ((p2.X - p3.X) * bc)) * det;
                radiusComputed = (float)Math.Sqrt((x - p1.X) * (x - p1.X) + (y - p1.Y) * (y - p1.Y));

                PointF current = new PointF(x, y);
                Centre = new MSTSCoord();
                Centre.Convert(current);
            }
            else
            {
                radiusComputed = 0;
            }
            return(radiusComputed);
        }
Esempio n. 6
0
 public override void Update(MSTSCoord coord, TrackSegment segment)
 {
     base.configCoord(coord);
 }
Esempio n. 7
0
 public override void configCoord(MSTSCoord coord)
 {
     base.configCoord(coord);
 }
Esempio n. 8
0
 public override void configCoord(MSTSCoord coord)
 {
     base.configCoord(coord);
     typeWidget  = (int)TypeWidget.STATION_WIDGET;
     nameVisible = false;
 }
Esempio n. 9
0
 public virtual void Update(MSTSCoord coord, TrackSegment segment)
 {
 }
Esempio n. 10
0
 public virtual void configCoord(MSTSCoord coord)
 {
     Coord      = coord;
     Location.X = coord.TileX * 2048f + coord.X;
     Location.Y = coord.TileY * 2048f + coord.Y;
 }
Esempio n. 11
0
 public override void configCoord(MSTSCoord coord)
 {
     base.configCoord(coord);
     typeItem    = (int)TypeItem.ACTIVITY_ITEM;
     nameVisible = false;
 }
Esempio n. 12
0
        public void LoadItemsFromMSTS()
        {
#if SHOW_STOPWATCH
            Stopwatch stopWatch = new Stopwatch();
            TimeSpan  ts;
            string    elapsedTime;
            if (File.Exists(@"C:\temp\stopwatch.txt"))
            {
                File.Delete(@"C:\temp\stopwatch.txt");
            }
#endif


            if (TDB == null ||
                TDB.TrackDB == null ||
                TDB.TrackDB.TrItemTable == null)
            {
                return;
            }
            foreach (GlobalItem item in orRouteConfig.AllItems)
            {
                if (item.GetType() == typeof(AEBufferItem))
                {
                    mstsItems.buffers.Add((AEBufferItem)item);
                }
            }
            Program.actEditor.DisplayStatusMessage("Start loading Track Nodes ...");
#if SHOW_STOPWATCH
            stopWatch.Start();
#endif
            nodes = TDB.TrackDB.TrackNodes;
            for (int nodeIdx = 0; nodeIdx < nodes.Length; nodeIdx++)
            {
                if (nodes[nodeIdx] != null)
                {
                    TrackNode currNode = nodes[nodeIdx];

                    AEBufferItem foundBuffer;
                    if (currNode.TrEndNode)
                    {
                        //Program.actEditor.DisplayStatusMessage("Init data for display...  Load End Nodes: " + currNode.Index);
                        try
                        {
                            foundBuffer = (AEBufferItem)orRouteConfig.AllItems.First(x => x.associateNodeIdx == currNode.Index);
                            foundBuffer.updateNode(currNode);
                        }
                        catch (InvalidOperationException)
                        {
                            foundBuffer = new AEBufferItem((TrackNode)currNode);
                            mstsItems.buffers.Add(foundBuffer);
                        }
#if SHOW_STOPWATCH
                        ts = stopWatch.Elapsed;
                        stopWatch.Reset();

                        // Format and display the TimeSpan value.
                        elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                    ts.Hours, ts.Minutes, ts.Seconds,
                                                    ts.Milliseconds);
                        File.AppendAllText(@"C:\temp\stopwatch.txt", "One END node: " + elapsedTime + "\n");
                        stopWatch.Start();
#endif
                    }
                    else if (currNode.TrVectorNode != null && currNode.TrVectorNode.TrVectorSections != null)
                    {
                        //Program.actEditor.DisplayStatusMessage("Init data for display...  Load Vector Nodes: " + currNode.Index);
                        if (currNode.TrVectorNode.TrVectorSections.Length > 1)
                        {
                            AddSegments(currNode);
                            TrVectorSection section = currNode.TrVectorNode.TrVectorSections[currNode.TrVectorNode.TrVectorSections.Length - 1];
                            MSTSCoord       A       = new MSTSCoord(section);

                            TrPin pin = currNode.TrPins[1];
                            {
                                TrackNode connectedNode = nodes[pin.Link];
                                int       direction     = DrawUtility.getDirection(currNode, connectedNode);
                                if (A == connectedNode.getMSTSCoord(direction))
                                {
                                    continue;
                                }
                                AESegment    aeSegment = new AESegment(A, connectedNode.getMSTSCoord(direction));
                                TrackSegment lineSeg   = new TrackSegment(aeSegment, currNode, currNode.TrVectorNode.TrVectorSections.Length - 1, direction, TSectionDat);
                                addTrItems(lineSeg, currNode);
                                mstsItems.AddSegment(lineSeg);
                            }
#if SHOW_STOPWATCH
                            ts = stopWatch.Elapsed;
                            stopWatch.Reset();

                            // Format and display the TimeSpan value.
                            elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                        ts.Hours, ts.Minutes, ts.Seconds,
                                                        ts.Milliseconds);
                            File.AppendAllText(@"C:\temp\stopwatch.txt", "One mult TRACK node: " + elapsedTime + "\n");
                            stopWatch.Start();
#endif
                        }
                        else
                        {
                            TrVectorSection s;
                            s = currNode.TrVectorNode.TrVectorSections[0];
                            areaRoute.manageTiles(s.TileX, s.TileZ);
                            foreach (TrPin pin in currNode.TrPins)
                            {
                                TrackNode connectedNode = nodes[pin.Link];
                                int       direction     = DrawUtility.getDirection(currNode, connectedNode);
                                if (MSTSCoord.near(currNode.getMSTSCoord(direction), connectedNode.getMSTSCoord(direction)))
                                {
                                    continue;
                                }
                                AESegment    aeSegment = new AESegment(currNode.getMSTSCoord(direction), connectedNode.getMSTSCoord(direction));
                                TrackSegment lineSeg   = new TrackSegment(aeSegment, currNode, 0, direction, TSectionDat);
                                addTrItems(lineSeg, currNode);
                                mstsItems.AddSegment(lineSeg);
                            }
#if SHOW_STOPWATCH
                            ts = stopWatch.Elapsed;
                            stopWatch.Reset();

                            // Format and display the TimeSpan value.
                            elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                        ts.Hours, ts.Minutes, ts.Seconds,
                                                        ts.Milliseconds);
                            File.AppendAllText(@"C:\temp\stopwatch.txt", "One simple TRACK node: " + elapsedTime + "\n");
                            stopWatch.Start();
#endif
                        }
                    }

                    else if (currNode.TrJunctionNode != null)
                    {
                        //Program.actEditor.DisplayStatusMessage("Init data for display...  Load Junction Nodes: " + currNode.Index);
                        mstsItems.switches.Add(new AEJunctionItem(currNode));
                        areaRoute.manageTiles(currNode.UiD.TileX, currNode.UiD.TileZ);
#if SHOW_STOPWATCH
                        ts = stopWatch.Elapsed;
                        stopWatch.Reset();

                        // Format and display the TimeSpan value.
                        elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                    ts.Hours, ts.Minutes, ts.Seconds,
                                                    ts.Milliseconds);
                        File.AppendAllText(@"C:\temp\stopwatch.txt", "One JN node: " + elapsedTime + "\n");
                        stopWatch.Start();
#endif
                    }
                }
            }
#if SPA_ADD
            var maxsize = maxX - minX > maxX - minX ? maxX - minX : maxX - minX;
            maxsize = (int)maxsize / 100 * 100;
            if (maxsize < 2000)
            {
                maxsize = 2000;
            }
            ZoomFactor = (decimal)maxsize;
#endif
            #region AddItem


            Program.actEditor.DisplayStatusMessage("Init data for display...  Load MSTS Items...");
            foreach (var item in TDB.TrackDB.TrItemTable)
            {
                if (item.ItemType == TrItem.trItemType.trSIGNAL && Signals != null)
                {
                    if (item is SignalItem)
                    {
#if SHOW_STOPWATCH
                        Program.actEditor.DisplayStatusMessage("Init data for display...  Load Items... Signal");
#endif
                        SignalItem si = item as SignalItem;

                        if (si.SigObj >= 0 && si.SigObj < Signals.SignalObjects.Length)
                        {
                            AESignalObject s = Signals.SignalObjects[si.SigObj];
                            if (s.isSignal) // && s.isSignalNormal())
                            {
                                mstsItems.AddSignal(new AESignalItem(si, s, TDB));
                            }
                        }
                    }
                }
            }

#if SHOW_STOPWATCH
            ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                        ts.Hours, ts.Minutes, ts.Seconds,
                                        ts.Milliseconds);
            File.AppendAllText(@"C:\temp\stopwatch.txt", "Signals: " + elapsedTime + "\n");
            stopWatch.Stop();
#endif
            #endregion
        }
Esempio n. 13
0
        public StationAreaItem AddPointArea(StationItem itemToUpdate, MSTSCoord coord)
        {
            PointF tf = new PointF(0f, 0f);

            return(itemToUpdate.AddPointArea(coord, Viewer.snapSize, Viewer.Simulator.mstsDataConfig.TileBase));
        }
Esempio n. 14
0
        public GlobalItem UpdateItem(GlobalItem item, MSTSCoord coord, bool controlKey, bool forceConnector)
        {
            PointF          closest          = new PointF(0f, 0f);
            StationItem     parent           = null;
            StationAreaItem item3            = null;
            PointF          tf2              = new PointF(0f, 0f);
            double          snapSize         = Viewer.snapSize;
            double          num2             = -1.0;
            double          positiveInfinity = double.PositiveInfinity;
            PointF          tf3              = coord.ConvertToPointF();

            if (item.GetType() == typeof(StationAreaItem))
            {
                item3  = (StationAreaItem)item;
                parent = item3.parent;
                if (parent == null)
                {
                    return(null);
                }
            }
            else
            {
                if (typeof(StationItem) == item.GetType())
                {
                    parent = (StationItem)item;
                    foreach (StationAreaItem item4 in parent.stationArea)
                    {
                        StationAreaItem item5 = parent.getNextArea(item4);
                        num2 = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(), new AESegment(item4.Location, item5.Location), out closest);
                        if ((num2 < snapSize) && (num2 < positiveInfinity))
                        {
                            positiveInfinity = num2;
                            item3            = item4;
                        }
                    }
                    parent.Update(coord);
                    return(parent);
                }
                if (!item.IsLineSnap())
                {
                    item.Update(coord);
                    return(item);
                }
            }
            TrackSegment segment          = null;
            int          associateNodeIdx = 0;

            foreach (TrackSegment segment2 in aeItems.getSegments())
            {
                segment2.unsetSnap();
                num2 = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(), segment2, out closest);
                if ((num2 < snapSize) && (num2 < positiveInfinity))
                {
                    positiveInfinity = num2;
                    segment          = segment2;
                    segment.setSnap();
                    tf2 = closest;
                    associateNodeIdx = segment.associateNodeIdx;
                }
            }
            if (segment != null)
            {
                segment.setSnap();
            }
            if ((!item.IsLineSnap() || (segment != null)) || controlKey)
            {
                item3.Update(coord);
            }
            return(parent);
        }