- Timestamp:
- May 10, 2015, 1:41:11 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BigMetro.lpi
r29 r36 80 80 <HasResources Value="True"/> 81 81 <ResourceBaseClass Value="Form"/> 82 <UnitName Value="UFormMain"/>83 82 </Unit1> 84 83 <Unit2> 85 84 <Filename Value="UEngine.pas"/> 86 85 <IsPartOfProject Value="True"/> 87 <UnitName Value="UEngine"/>88 86 </Unit2> 89 87 <Unit3> 90 88 <Filename Value="UGeometric.pas"/> 91 89 <IsPartOfProject Value="True"/> 92 <UnitName Value="UGeometric"/>93 90 </Unit3> 94 91 <Unit4> 95 92 <Filename Value="UTrack.pas"/> 96 93 <IsPartOfProject Value="True"/> 97 <UnitName Value="UTrack"/>98 94 </Unit4> 99 95 <Unit5> 100 96 <Filename Value="UMetaCanvas.pas"/> 101 97 <IsPartOfProject Value="True"/> 102 <UnitName Value="UMetaCanvas"/>103 98 </Unit5> 104 99 </Units> -
trunk/UEngine.pas
r35 r36 22 22 TTrackPoints = class; 23 23 TTrack = class; 24 TTrackLink = class; 24 25 TTrackLinks = class; 25 26 … … 69 70 LineStation: TLineStation; 70 71 Position: TPoint; 71 PositionShift: TPoint;72 //PositionShift: TPoint; 72 73 PositionDesigned: TPoint; 73 74 Pending: Boolean; … … 75 76 NeighPoints: TTrackPoints; 76 77 NeighLinks: TTrackLinks; 78 LinkUp: TTrackLink; 79 LinkDown: TTrackLink; 77 80 procedure Connect(TrackPoint: TTrackPoint); 78 81 procedure Disconnect(TrackPoint: TTrackPoint); … … 81 84 function GetNeighDown: TTrackPoint; 82 85 function GetNeighUp: TTrackPoint; 86 function GetLinkDown: TTrackLink; 87 function GetLinkUp: TTrackLink; 83 88 // Move to TTrackLink later 84 89 function GetDistance: Integer; … … 133 138 TTrackPointsAngle = class 134 139 Angle: Double; 135 Track s: TTracks;140 TrackLinks: TTrackLinks; 136 141 constructor Create; 137 142 destructor Destroy; override; … … 536 541 constructor TTrackPointsAngle.Create; 537 542 begin 538 Track s := TTracks.Create;539 Track s.OwnsObjects := False;543 TrackLinks := TTrackLinks.Create; 544 TrackLinks.OwnsObjects := False; 540 545 end; 541 546 542 547 destructor TTrackPointsAngle.Destroy; 543 548 begin 544 Track s.Free;549 TrackLinks.Free; 545 550 inherited Destroy; 546 551 end; … … 624 629 if NewIndex < Track.Points.Count then Result := TTrackPoint(Track.Points[NewIndex]); 625 630 end; 631 end; 632 633 function TTrackPoint.GetLinkDown: TTrackLink; 634 begin 635 if Assigned(LinkDown) then Result := LinkDown 636 else begin 637 LinkDown := TTrackLink.Create; 638 LinkDown.Points.Add(GetNeighDown); 639 LinkDown.Points.Add(Self); 640 Result := LinkDown; 641 GetNeighDown.LinkUp := LinkDown; 642 end; 643 end; 644 645 function TTrackPoint.GetLinkUp: TTrackLink; 646 begin 647 if Assigned(LinkUp) then Result := LinkUp 648 else begin 649 LinkUp := TTrackLink.Create; 650 LinkUp.Points.Add(Self); 651 LinkUp.Points.Add(GetNeighUp); 652 Result := LinkUp; 653 GetNeighUp.LinkDown := LinkUp; 654 end; 626 655 end; 627 656 … … 794 823 end; 795 824 796 Angle := arctan2((TTrackPoint(Track.Points[2]).Position.Y - TTrackPoint(Track.Points[1]).Position.Y), 797 (TTrackPoint(Track.Points[2]).Position.X - TTrackPoint(Track.Points[1]).Position.X)); 798 EndPoint := Point(Round(TTrackPoint(Track.Points[1]).Position.X - EndStationLength * Cos(Angle)), 799 Round(TTrackPoint(Track.Points[1]).Position.Y - EndStationLength * Sin(Angle))); 825 Angle := ArcTan2((TTrackPoint(Track.Points[2]).PositionDesigned.Y - TTrackPoint(Track.Points[1]).PositionDesigned.Y), 826 (TTrackPoint(Track.Points[2]).PositionDesigned.X - TTrackPoint(Track.Points[1]).PositionDesigned.X)); 827 EndPoint := Point(Round(TTrackPoint(Track.Points[1]).PositionDesigned.X - EndStationLength * Cos(Angle)), 828 Round(TTrackPoint(Track.Points[1]).PositionDesigned.Y - EndStationLength * Sin(Angle))); 829 TTrackPoint(Track.Points.First).PositionDesigned := EndPoint; 800 830 TTrackPoint(Track.Points.First).Position := EndPoint; 801 TTrackPoint(Track.Points.First).PositionDesigned := EndPoint; 802 803 Angle := arctan2((TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.Y - TTrackPoint(Track.Points[Track.Points.Count - 3]).Position.Y),804 (TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.X - TTrackPoint(Track.Points[Track.Points.Count - 3]).Position.X));805 EndPoint := Point(Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.X + EndStationLength * Cos(Angle)),806 Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.Y + EndStationLength * Sin(Angle)));831 832 Angle := ArcTan2((TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.Y - TTrackPoint(Track.Points[Track.Points.Count - 3]).PositionDesigned.Y), 833 (TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.X - TTrackPoint(Track.Points[Track.Points.Count - 3]).PositionDesigned.X)); 834 EndPoint := Point(Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.X + EndStationLength * Cos(Angle)), 835 Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.Y + EndStationLength * Sin(Angle))); 836 TTrackPoint(Track.Points.Last).PositionDesigned := EndPoint; 807 837 TTrackPoint(Track.Points.Last).Position := EndPoint; 808 TTrackPoint(Track.Points.Last).PositionDesigned := EndPoint;809 838 end; 810 839 end; … … 939 968 Index1 := Points.IndexOf(TP1); 940 969 Index2 := Points.IndexOf(TP2); 941 P1 := TTrackPoint(Points[Index1]).Position ;942 P2 := TTrackPoint(Points[Index2]).Position ;970 P1 := TTrackPoint(Points[Index1]).PositionDesigned; 971 P2 := TTrackPoint(Points[Index2]).PositionDesigned; 943 972 NewTrackPoint := Points.AddNew; 944 973 Delta := Point(P2.X - P1.X, P2.Y - P1.Y); 945 974 if Abs(Delta.X) > Abs(Delta.Y) then begin 946 NewTrackPoint.Position := Point(P2.X - Sign(Delta.X) * Abs(Delta.Y), P1.Y);947 NewTrackPoint.Position Designed := NewTrackPoint.Position;975 NewTrackPoint.PositionDesigned := Point(P2.X - Sign(Delta.X) * Abs(Delta.Y), P1.Y); 976 NewTrackPoint.Position := NewTrackPoint.PositionDesigned; 948 977 end else begin 949 NewTrackPoint.Position := Point(P1.X, P2.Y - Sign(Delta.Y) * Abs(Delta.X));950 NewTrackPoint.Position Designed := NewTrackPoint.Position;978 NewTrackPoint.PositionDesigned := Point(P1.X, P2.Y - Sign(Delta.Y) * Abs(Delta.X)); 979 NewTrackPoint.Position := NewTrackPoint.PositionDesigned; 951 980 end; 952 981 Points.Insert(Index1 + 1, NewTrackPoint); … … 1099 1128 procedure TMapStation.ShiftTrackPoints; 1100 1129 var 1101 Track s: TTracks;1130 TrackLinks: TTrackLinks; 1102 1131 I: Integer; 1103 1132 J: Integer; … … 1106 1135 LS: TLineStation; 1107 1136 Line: TMetroLine; 1108 Angle: Double;1137 Angle: Float; 1109 1138 TPAngleGroup: TTrackPointsAngleGroup; 1110 1139 GroupItem: TTrackPointsAngle; 1111 NewTrack : TTrackLink;1140 NewTrackLink: TTrackLink; 1112 1141 HAngle: Double; 1113 PairTrack: TTrackLink; 1114 NewPoint: TPoint; 1115 begin 1116 Tracks := TTracks.Create; 1117 1118 // Collect all near track points as track 1142 P1, P2: TPoint; 1143 NewShift: TPoint; 1144 begin 1145 TrackLinks := TTrackLinks.Create; 1146 TrackLinks.OwnsObjects := False; 1147 1148 // Collect all near track points as track links 1119 1149 SortLines; 1120 1150 for I := 0 to Lines.Count - 1 do begin … … 1124 1154 Index := Line.Track.Points.IndexOf(TP); 1125 1155 if Index > 0 then begin 1126 NewTrack := TTrackLink.Create; 1127 NewTrack.Points.Count := 2; 1128 NewTrack.Points[0] := TTrackPoint(Line.Track.Points[Index - 1]); 1129 NewTrack.Points[1] := TTrackPoint(Line.Track.Points[Index]); 1130 Tracks.Add(NewTrack); 1156 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkDown; 1157 TrackLinks.Add(NewTrackLink); 1131 1158 end; 1132 1159 if Index < (Line.Track.Points.Count - 1) then begin 1133 NewTrack := TTrackLink.Create; 1134 NewTrack.Points.Count := 2; 1135 NewTrack.Points[0] := TTrackPoint(Line.Track.Points[Index + 1]); 1136 NewTrack.Points[1] := TTrackPoint(Line.Track.Points[Index]); 1137 Tracks.Add(NewTrack); 1138 end; 1139 end; 1140 1141 // Make groups of tracks with same angle 1160 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkUp; 1161 TrackLinks.Add(NewTrackLink); 1162 end; 1163 if Line.IsCircular and (Self = TLineStation(Line.LineStations.First).MapStation) and 1164 (Self = TLineStation(Line.LineStations.Last).MapStation) then begin 1165 LS := TLineStation(Line.LineStations.Last); 1166 TP := LS.TrackPoint; 1167 Index := Line.Track.Points.IndexOf(TP); 1168 if Index > 0 then begin 1169 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkDown; 1170 TrackLinks.Add(NewTrackLink); 1171 end; 1172 if Index < (Line.Track.Points.Count - 1) then begin 1173 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkUp; 1174 TrackLinks.Add(NewTrackLink); 1175 end; 1176 end; 1177 end; 1178 1179 // Make groups of TrackLinks with same angle 1142 1180 TPAngleGroup := TTrackPointsAngleGroup.Create; 1143 for I := 0 to Tracks.Count - 1 do begin 1144 Angle := ArcTan2(TTrackPoint(TTrackLink(Tracks[I]).Points[0]).PositionDesigned.Y - Position.Y, 1145 TTrackPoint(TTrackLink(Tracks[I]).Points[0]).PositionDesigned.X - Position.X); 1181 for I := 0 to TrackLinks.Count - 1 do begin 1182 P1 := TTrackPoint(TTrackLink(TrackLinks[I]).Points[0]).PositionDesigned; 1183 P2 := TTrackPoint(TTrackLink(TrackLinks[I]).Points[1]).PositionDesigned; 1184 if ComparePoint(P1, Position) and not ComparePoint(P2, Position) then begin 1185 Angle := ArcTan2(P2.Y - Position.Y, P2.X - Position.X); 1186 end else 1187 if ComparePoint(P2, Position) and not ComparePoint(P1, Position) then begin 1188 Angle := ArcTan2(P1.Y - Position.Y, P1.X - Position.X); 1189 end else Angle := 0;// else raise Exception.Create('TrackLink angle rrror'); 1190 1146 1191 GroupItem := TPAngleGroup.SearchAngle(Angle); 1147 1192 if not Assigned(GroupItem) then begin … … 1150 1195 TPAngleGroup.Add(GroupItem); 1151 1196 end; 1152 GroupItem.Track s.Add(TTrackLink(Tracks[I]))1153 end; 1154 1155 // Shift tracks according number of lines in group1197 GroupItem.TrackLinks.Add(TTrackLink(TrackLinks[I])) 1198 end; 1199 1200 // Shift TrackLinks according number of lines in group 1156 1201 for I := 0 to TPAngleGroup.Count - 1 do 1157 1202 with TTrackPointsAngle(TPAngleGroup[I]) do begin 1158 for J := 0 to Track s.Count - 1 do1159 with TTrackLink(Track s[J]) do begin1203 for J := 0 to TrackLinks.Count - 1 do 1204 with TTrackLink(TrackLinks[J]) do begin 1160 1205 // Get orthogonal angle 1161 1206 HAngle := Angle + Pi / 2; 1162 if HAngle > Pi then HAngle := H angle - Pi;1163 Shift.X := Trunc(MetroLineThickness * Cos(HAngle) * (J - (Tracks.Count - 1) / 2));1164 Shift.Y := Trunc(MetroLineThickness * Sin(HAngle) * (J - (Tracks.Count - 1) / 2));1165 TTrackPoint(Points[0]).PositionShift := Shift;1166 TTrackPoint(Points[1]).PositionShift :=Shift;1207 if HAngle > Pi then HAngle := HAngle - Pi; 1208 NewShift.X := Trunc(MetroLineThickness * Cos(HAngle) * (J - (TrackLinks.Count - 1) / 2)); 1209 NewShift.Y := Trunc(MetroLineThickness * Sin(HAngle) * (J - (TrackLinks.Count - 1) / 2)); 1210 //NewShift.X := TrackLinks.Count; 1211 Shift := NewShift; 1167 1212 end; 1168 1213 end; 1169 1214 1170 1215 TPAngleGroup.Free; 1171 Track s.Free;1216 TrackLinks.Free; 1172 1217 end; 1173 1218 … … 1747 1792 for L := 0 to Lines.Count - 1 do 1748 1793 with TMetroLine(Lines[L]) do begin 1749 if Track.Points.Count > 0 then1794 if Track.Points.Count > 1 then begin 1750 1795 TTrackPoint(Track.Points[0]).Position := AddPoint(TTrackPoint(Track.Points[0]).PositionDesigned, 1751 TTrackPoint(Track.Points[0]).PositionShift); 1796 TTrackPoint(Track.Points[0]).LinkUp.Shift); 1797 end; 1752 1798 for I := 1 to Track.Points.Count - 1 do 1753 with TTrackPoint(Track.Points[I]) do begin 1754 Link1 := SubPoint(AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).PositionShift), 1755 AddPoint(TTrackPoint(Track.Points[I - 1]).PositionDesigned, TTrackPoint(Track.Points[I - 1]).PositionShift)); 1799 with TTrackPoint(Track.Points[I]) do 1800 if Assigned(TTrackPoint(Track.Points[I]).LinkDown) and Assigned(TTrackPoint(Track.Points[I]).LinkUp) then begin 1801 Link1 := SubPoint(AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).LinkDown.Shift), 1802 AddPoint(TTrackPoint(Track.Points[I - 1]).PositionDesigned, TTrackPoint(Track.Points[I]).LinkDown.Shift)); 1756 1803 if (I + 1) < Track.Points.Count then 1757 Link2 := SubPoint(AddPoint(TTrackPoint(Track.Points[I + 1]).PositionDesigned, TTrackPoint(Track.Points[I + 1]).PositionShift),1758 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]). PositionShift))1804 Link2 := SubPoint(AddPoint(TTrackPoint(Track.Points[I + 1]).PositionDesigned, TTrackPoint(Track.Points[I]).LinkUp.Shift), 1805 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).LinkUp.Shift)) 1759 1806 else Link2 := Link1; 1760 1807 1761 1808 if ArcTanPoint(Link1) = ArcTanPoint(Link2) then begin 1762 1809 // Parallel lines 1763 TTrackPoint(Track.Points[I]).Position := AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, 1764 TTrackPoint(Track.Points[I]).PositionShift); 1810 NewPoint := AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, 1811 TTrackPoint(Track.Points[I]).LinkDown.Shift); 1812 TTrackPoint(Track.Points[I]).Position := NewPoint; 1765 1813 end else begin 1766 1814 // Intersected lines 1767 NewPoint := LineIntersect(AddPoint(TTrackPoint(Track.Points[I - 1]).PositionDesigned, TTrackPoint(Track.Points[I - 1]).PositionShift), 1768 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).PositionShift), 1769 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).PositionShift), 1770 AddPoint(TTrackPoint(Track.Points[I + 1]).PositionDesigned, TTrackPoint(Track.Points[I + 1]).PositionShift)); 1815 NewPoint := LineIntersect(AddPoint(TTrackPoint(Track.Points[I - 1]).PositionDesigned, 1816 TTrackPoint(Track.Points[I]).LinkDown.Shift), 1817 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).LinkDown.Shift), 1818 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).LinkUp.Shift), 1819 AddPoint(TTrackPoint(Track.Points[I + 1]).PositionDesigned, TTrackPoint(Track.Points[I]).LinkUp.Shift)); 1771 1820 TTrackPoint(Track.Points[I]).Position := NewPoint; 1772 1821 end; … … 1774 1823 end; 1775 1824 1825 // Remove all temporal links 1826 for I := 0 to Lines.Count - 1 do 1827 with TMetroLine(Lines[I]) do 1828 for J := 0 to Track.Points.Count - 1 do 1829 if Assigned(TTrackPoint(Track.Points[J]).LinkUp) then begin 1830 TTrackPoint(Track.Points[J]).LinkUp.Free; 1831 TTrackPoint(Track.Points[J]).LinkUp := nil; 1832 TTrackPoint(Track.Points[J + 1]).LinkDown := nil; 1833 end; 1776 1834 end; 1777 1835 … … 2242 2300 end;} 2243 2301 end; 2302 (* Canvas.Pen.Color := Color; 2303 Canvas.Pen.Style := psSolid; 2304 Canvas.Pen.Width := MetroLineThickness div 2; 2305 if Track.Points.Count > 0 then Canvas.MoveTo(TTrackPoint(Track.Points[0]).PositionDesigned); 2306 for S := 1 to Track.Points.Count - 1 do begin 2307 Canvas.LineTo(TTrackPoint(Track.Points[S]).PositionDesigned); 2308 { if (S = TrackPoints.Count - 1) then begin 2309 Canvas.Pen.EndCap := pecSquare; 2310 Angle := arctan2((TTrackPoint(TrackPoints[S]).Position.Y - TTrackPoint(TrackPoints[S - 1]).Position.Y), 2311 (TTrackPoint(TrackPoints[S]).Position.X - TTrackPoint(TrackPoints[S - 1]).Position.X)); 2312 EndPoint := Point(Round(TTrackPoint(TrackPoints[S]).Position.X + EndStationLength * Cos(Angle)), 2313 Round(TTrackPoint(TrackPoints[S]).Position.Y + EndStationLength * Sin(Angle))); 2314 Canvas.LineTo(EndPoint); 2315 Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3), 2316 Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3))); 2317 Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3), 2318 Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3))); 2319 Canvas.Pen.EndCap := pecRound; 2320 end;} 2321 end; 2244 2322 { 2245 2323 if (TrackPoints.Count > 1) then begin … … 2257 2335 Canvas.Pen.EndCap := pecRound; 2258 2336 end; } 2259 end;2260 2337 *) 2338 end; 2261 2339 // Draw design time lines 2262 2340 if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin
Note:
See TracChangeset
for help on using the changeset viewer.