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); }
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; }
public void CheckCurve(TSectionDatFile tdf, int flag2) { TrackSection ts = tdf.TrackSections.Get((uint)SectionIdxA); if (ts != null) { if (ts.SectionCurve != null) { Vector2 vectorA; Vector2 vectorB; if (ts.SectionCurve.Radius < 15f) { return; } vectorA = A.ConvertVector2(); vectorB = B.ConvertVector2(); double lenCorde = Vector2.Distance(vectorA, vectorB); if (lenCorde < 2) { return; } double lenFleche = ((ts.SectionCurve.Radius * ts.SectionCurve.Radius) - (lenCorde * lenCorde) / 4f); lenFleche = Math.Abs(lenFleche); lenFleche = (float)Math.Sqrt(lenFleche); lenFleche = (float)ts.SectionCurve.Radius - lenFleche; if (double.IsNaN(lenFleche)) { return; } curve = new AESectionCurve(ts.SectionCurve); Vector3 v = new Vector3((float)(vectorB.X - vectorA.X), 0, (float)(vectorB.Y - vectorA.Y)); Vector3 v2 = Vector3.Cross(Vector3.Up, v); v2.Normalize(); v = v / 2; v.X += (float)vectorA.X; v.Z += (float)vectorA.Y; if (ts.SectionCurve.Angle < 0) { v = (v2 * lenFleche) + v; curve.direction = 1; } else { v = (v2 * -lenFleche) + v; curve.direction = -1; } PointF pointV = new System.Drawing.PointF((float)v.X, (float)v.Z); curve.C = new MSTSCoord(); curve.C.Convert(pointV); isCurved = true; PointF pA = new PointF((float)vectorA.X, (float)vectorA.Y); PointF pB = new PointF((float)vectorB.X, (float)vectorB.Y); float r; float errorRadius = 0; if ((r = curve.setCenter(pA, pB, pointV)) != curve.Radius) { //File.AppendAllText(@"F:\temp\AE.txt", // "Radius original: " + curve.Radius + " ,calculé: " + r + "\n"); errorRadius = curve.Radius; // A surveiller! } else { curve.setStartAngle(pA, pB, pointV); } } else { isCurved = false; } } }
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(); }
public AIPath(TDBFile TDB, TSectionDatFile tsectiondat, string filePath) #endif { PathFile patFile = new PathFile(filePath); pathName = patFile.Name; TrackDB = TDB.TrackDB; TSectionDat = tsectiondat; #if ACTIVITY_EDITOR orRouteConfig = orRouteConf; #endif bool fatalerror = false; if (patFile.TrPathNodes.Count <= 0) { fatalerror = true; Nodes = null; return; } foreach (TrPathNode tpn in patFile.TrPathNodes) { Nodes.Add(new AIPathNode(tpn, patFile.TrackPDPs[(int)tpn.fromPDP], TrackDB, isTimetableMode)); } FirstNode = Nodes[0]; //LastVisitedNode = FirstNode; // Connect the various nodes to each other for (int i = 0; i < Nodes.Count; i++) { AIPathNode node = Nodes[i]; node.Index = i; TrPathNode tpn = patFile.TrPathNodes[i]; // find TVNindex to next main node. if (tpn.HasNextMainNode) { node.NextMainNode = Nodes[(int)tpn.nextMainNode]; node.NextMainTVNIndex = node.FindTVNIndex(node.NextMainNode, TDB, tsectiondat); if (node.JunctionIndex >= 0) { node.IsFacingPoint = TestFacingPoint(node.JunctionIndex, node.NextMainTVNIndex); } if (node.NextMainTVNIndex < 0) { node.NextMainNode = null; Trace.TraceWarning("Cannot find main track for node {1} in path {0}", filePath, i); fatalerror = true; } } // find TVNindex to next siding node if (tpn.HasNextSidingNode) { node.NextSidingNode = Nodes[(int)tpn.nextSidingNode]; node.NextSidingTVNIndex = node.FindTVNIndex(node.NextSidingNode, TDB, tsectiondat); if (node.JunctionIndex >= 0) { node.IsFacingPoint = TestFacingPoint(node.JunctionIndex, node.NextSidingTVNIndex); } if (node.NextSidingTVNIndex < 0) { node.NextSidingNode = null; Trace.TraceWarning("Cannot find siding track for node {1} in path {0}", filePath, i); fatalerror = true; } } if (node.NextMainNode != null && node.NextSidingNode != null) { node.Type = AIPathNodeType.SidingStart; } } FindSidingEnds(); if (fatalerror) { Nodes = null; // invalid path - do not return any nodes } }