/// <summary> /// /// </summary> /// <param name="sideItem"></param> /// <param name="signal"></param> public AESignalItem(SignalItem item, AESignalObject signal, TrackDatabaseFile TDB) { typeItem = (int)TypeItem.SIGNAL_ITEM; Item = item; Signal = signal; sigFonction = new List <MstsSignalFunction>(); foreach (var sig in Signal.SignalHeads) { sigFonction.Add(sig.sigFunction); } hasDir = false; Location.X = item.TileX * 2048 + item.X; Location.Y = item.TileZ * 2048 + item.Z; try { associateNode = TDB.TrackDB.TrackNodes[signal.trackNode]; Vector2 v2; if (associateNode.TrVectorNode != null) { associateNodeIdx = (int)associateNode.Index; var ts = associateNode.TrVectorNode.TrVectorSections[0]; v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z); } else if (associateNode.TrJunctionNode != null) { associateNodeIdx = associateNode.TrJunctionNode.Idx; var ts = associateNode.UiD; v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z); } else { throw new Exception(); } var v1 = new Vector2(Location.X, Location.Y); var v3 = v1 - v2; v3.Normalize(); v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 12f : -12f); //v2 = v1 - Vector2.Multiply(v3, 12f); Dir.X = (float)v2.X; Dir.Y = (float)v2.Y; //v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 1.5f : -1.5f);//shift signal along the dir for 2m, so signals will not be overlapped v2 = v1 - Vector2.Multiply(v3, 1.5f); Location.X = (float)v2.X; Location.Y = (float)v2.Y; hasDir = true; } catch { } }
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 }