Changeset 31
- Timestamp:
- Apr 18, 2015, 11:43:05 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r30 r31 20 20 TTrackPoint = class; 21 21 TLineStation = class; 22 TTrackPoints = class; 23 TTrack = class; 22 24 23 25 { TMapStation } … … 64 66 65 67 TTrackPoint = class 66 Line: TMetroLine;67 68 LineStation: TLineStation; 68 69 Position: TPoint; … … 70 71 PositionDesigned: TPoint; 71 72 Pending: Boolean; 73 NeighPoints: TTrackPoints; 74 Track: TTrack; 72 75 function GetDown: TTrackPoint; 73 76 function GetUp: TTrackPoint; … … 76 79 // Move to TTrackLink later 77 80 function GetDistance: Integer; 78 end; 81 constructor Create; 82 destructor Destroy; override; 83 end; 84 85 { TTrackPoints } 79 86 80 87 TTrackPoints = class(TObjectList) 81 Line: TMetroLine; 82 end; 83 84 TTrack = class 88 Track: TTrack; 89 function AddNew: TTrackPoint; 90 end; 91 92 { TTrackLink } 93 94 TTrackLink = class 95 Points: TTrackPoints; 85 96 PointDown: TTrackPoint; 86 97 PointUp: TTrackPoint; 87 98 Line: TMetroLine; 88 99 Shift: TPoint; 100 Track: TTrack; 101 constructor Create; 102 destructor Destroy; override; 103 end; 104 105 TTrackLinks = class(TObjectList) 106 end; 107 108 TTrack = class 109 Points: TTrackPoints; 110 Links: TTrackLinks; 111 Line: TMetroLine; 112 constructor Create; 113 destructor Destroy; override; 89 114 end; 90 115 … … 92 117 93 118 TTracks = class(TObjectList) 94 function SearchPointUp(TrackPoint: TTrackPoint; Skip: TTrack ): TTrack;95 function SearchPointDown(TrackPoint: TTrackPoint; Skip: TTrack ): TTrack;119 function SearchPointUp(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink; 120 function SearchPointDown(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink; 96 121 end; 97 122 … … 122 147 LineStations: TLineStations; 123 148 Trains: TMetroTrains; 124 Track Points: TTrackPoints;149 Track: TTrack; 125 150 procedure ConnectStation(Station: TMapStation; LineStationDown, LineStationUp: TLineStation); 126 151 procedure DisconnectStation(ALineStation: TLineStation); … … 246 271 function GetExistStationShapes: TStationShapeSet; 247 272 function GetStationOnPos(Pos: TPoint): TMapStation; 248 function GetTrackOnPos(Pos: TPoint): TTrack ;273 function GetTrackOnPos(Pos: TPoint): TTrackLink; 249 274 function GetTrainOnPos(Pos: TPoint): TMetroTrain; 250 275 procedure DrawLine(Canvas: TCanvas; Pos: TPoint); … … 325 350 SZeroZoomNotAlowed = 'Zero zoom not allowed'; 326 351 352 { TTrackPoints } 353 354 function TTrackPoints.AddNew: TTrackPoint; 355 begin 356 Result := TTrackPoint.Create; 357 Result.Track := Track; 358 end; 359 360 { TTrack } 361 362 constructor TTrack.Create; 363 begin 364 Points := TTrackPoints.Create; 365 Points.Track := Self; 366 Links := TTrackLinks.Create; 367 end; 368 369 destructor TTrack.Destroy; 370 begin 371 Points.Free; 372 Links.Free; 373 inherited Destroy; 374 end; 375 376 { TTrackLink } 377 378 constructor TTrackLink.Create; 379 begin 380 Points := TTrackPoints.Create; 381 Points.OwnsObjects := False; 382 end; 383 384 destructor TTrackLink.Destroy; 385 begin 386 Points.Free; 387 inherited Destroy; 388 end; 389 327 390 { TRiver } 328 391 … … 407 470 { TTracks } 408 471 409 function TTracks.SearchPointUp(TrackPoint: TTrackPoint; Skip: TTrack ): TTrack;472 function TTracks.SearchPointUp(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink; 410 473 var 411 474 I: Integer; 412 475 begin 413 476 I := 0; 414 while (I < Count) and (TTrack (Items[I]).PointUp <> TrackPoint) and (TTrack(Items[I]) <> Skip) do Inc(I);415 if I < Count then Result := TTrack (Items[I])477 while (I < Count) and (TTrackLink(Items[I]).PointUp <> TrackPoint) and (TTrackLink(Items[I]) <> Skip) do Inc(I); 478 if I < Count then Result := TTrackLink(Items[I]) 416 479 else Result := nil; 417 480 end; 418 481 419 function TTracks.SearchPointDown(TrackPoint: TTrackPoint; Skip: TTrack ): TTrack;482 function TTracks.SearchPointDown(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink; 420 483 var 421 484 I: Integer; 422 485 begin 423 486 I := 0; 424 while (I < Count) and (TTrack (Items[I]).PointDown <> TrackPoint) and (TTrack(Items[I]) <> Skip) do Inc(I);425 if I < Count then Result := TTrack (Items[I])487 while (I < Count) and (TTrackLink(Items[I]).PointDown <> TrackPoint) and (TTrackLink(Items[I]) <> Skip) do Inc(I); 488 if I < Count then Result := TTrackLink(Items[I]) 426 489 else Result := nil; 427 490 end; … … 459 522 I: Integer; 460 523 begin 461 I := Line.TrackPoints.IndexOf(Self) - 1;462 while (I >= 0) and not Assigned(TTrackPoint( Line.TrackPoints[I]).LineStation) do524 I := Track.Points.IndexOf(Self) - 1; 525 while (I >= 0) and not Assigned(TTrackPoint(Track.Points[I]).LineStation) do 463 526 Dec(I); 464 if I >= 0 then Result := TTrackPoint( Line.TrackPoints[I])527 if I >= 0 then Result := TTrackPoint(Track.Points[I]) 465 528 else Result := nil; 466 529 end; … … 470 533 I: Integer; 471 534 begin 472 I := Line.TrackPoints.IndexOf(Self) + 1;473 while (I < Line.TrackPoints.Count) and not Assigned(TTrackPoint(Line.TrackPoints[I]).LineStation) do535 I := Track.Points.IndexOf(Self) + 1; 536 while (I < Track.Points.Count) and not Assigned(TTrackPoint(Track.Points[I]).LineStation) do 474 537 Inc(I); 475 if I < Line.TrackPoints.Count then Result := TTrackPoint(Line.TrackPoints[I])538 if I < Track.Points.Count then Result := TTrackPoint(Track.Points[I]) 476 539 else Result := nil; 477 540 end; … … 482 545 begin 483 546 Result := nil; 484 NewIndex := Line.TrackPoints.IndexOf(Self) - 1;485 if NewIndex >= 0 then Result := TTrackPoint( Line.TrackPoints[NewIndex]);547 NewIndex := Track.Points.IndexOf(Self) - 1; 548 if NewIndex >= 0 then Result := TTrackPoint(Track.Points[NewIndex]); 486 549 end; 487 550 … … 491 554 begin 492 555 Result := nil; 493 if Assigned( Line) then begin494 NewIndex := Line.TrackPoints.IndexOf(Self) + 1;495 if NewIndex < Line.TrackPoints.Count then Result := TTrackPoint(Line.TrackPoints[NewIndex]);556 if Assigned(Track) then begin 557 NewIndex := Track.Points.IndexOf(Self) + 1; 558 if NewIndex < Track.Points.Count then Result := TTrackPoint(Track.Points[NewIndex]); 496 559 end; 497 560 end; … … 501 564 Index: Integer; 502 565 begin 503 Index := Line.TrackPoints.IndexOf(Self); 504 Result := Distance(TTrackPoint(Line.TrackPoints[Index + 1]).Position, 505 TTrackPoint(Line.TrackPoints[Index]).Position); 566 Index := Track.Points.IndexOf(Self); 567 Result := Distance(TTrackPoint(Track.Points[Index + 1]).Position, 568 TTrackPoint(Track.Points[Index]).Position); 569 end; 570 571 constructor TTrackPoint.Create; 572 begin 573 NeighPoints := TTrackPoints.Create; 574 NeighPoints.OwnsObjects := False; 575 end; 576 577 destructor TTrackPoint.Destroy; 578 begin 579 NeighPoints.Free; 580 inherited Destroy; 506 581 end; 507 582 … … 639 714 begin 640 715 if LineStations.Count >= 2 then begin 641 Index := Track Points.IndexOf(TLineStation(LineStations.First).TrackPoint);716 Index := Track.Points.IndexOf(TLineStation(LineStations.First).TrackPoint); 642 717 if Index = 0 then begin 643 NewTrackPoint := TTrackPoint.Create; 644 NewTrackPoint.Line := Self; 645 TrackPoints.Insert(0, NewTrackPoint); 646 end; 647 Index := TrackPoints.IndexOf(TLineStation(LineStations.Last).TrackPoint); 648 if Index = TrackPoints.Count - 1 then begin 649 NewTrackPoint := TTrackPoint.Create; 650 NewTrackPoint.Line := Self; 651 TrackPoints.Insert(TrackPoints.Count, NewTrackPoint); 652 end; 653 654 Angle := arctan2((TTrackPoint(TrackPoints[2]).Position.Y - TTrackPoint(TrackPoints[1]).Position.Y), 655 (TTrackPoint(TrackPoints[2]).Position.X - TTrackPoint(TrackPoints[1]).Position.X)); 656 EndPoint := Point(Round(TTrackPoint(TrackPoints[1]).Position.X - EndStationLength * Cos(Angle)), 657 Round(TTrackPoint(TrackPoints[1]).Position.Y - EndStationLength * Sin(Angle))); 658 TTrackPoint(TrackPoints.First).Position := EndPoint; 659 TTrackPoint(TrackPoints.First).PositionDesigned := EndPoint; 660 661 Angle := arctan2((TTrackPoint(TrackPoints[TrackPoints.Count - 2]).Position.Y - TTrackPoint(TrackPoints[TrackPoints.Count - 3]).Position.Y), 662 (TTrackPoint(TrackPoints[TrackPoints.Count - 2]).Position.X - TTrackPoint(TrackPoints[TrackPoints.Count - 3]).Position.X)); 663 EndPoint := Point(Round(TTrackPoint(TrackPoints[TrackPoints.Count - 2]).Position.X + EndStationLength * Cos(Angle)), 664 Round(TTrackPoint(TrackPoints[TrackPoints.Count - 2]).Position.Y + EndStationLength * Sin(Angle))); 665 TTrackPoint(TrackPoints.Last).Position := EndPoint; 666 TTrackPoint(TrackPoints.Last).PositionDesigned := EndPoint; 718 NewTrackPoint := Track.Points.AddNew; 719 Track.Points.Insert(0, NewTrackPoint); 720 end; 721 Index := Track.Points.IndexOf(TLineStation(LineStations.Last).TrackPoint); 722 if Index = Track.Points.Count - 1 then begin 723 NewTrackPoint := Track.Points.AddNew; 724 Track.Points.Insert(Track.Points.Count, NewTrackPoint); 725 end; 726 727 Angle := arctan2((TTrackPoint(Track.Points[2]).Position.Y - TTrackPoint(Track.Points[1]).Position.Y), 728 (TTrackPoint(Track.Points[2]).Position.X - TTrackPoint(Track.Points[1]).Position.X)); 729 EndPoint := Point(Round(TTrackPoint(Track.Points[1]).Position.X - EndStationLength * Cos(Angle)), 730 Round(TTrackPoint(Track.Points[1]).Position.Y - EndStationLength * Sin(Angle))); 731 TTrackPoint(Track.Points.First).Position := EndPoint; 732 TTrackPoint(Track.Points.First).PositionDesigned := EndPoint; 733 734 Angle := arctan2((TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.Y - TTrackPoint(Track.Points[Track.Points.Count - 3]).Position.Y), 735 (TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.X - TTrackPoint(Track.Points[Track.Points.Count - 3]).Position.X)); 736 EndPoint := Point(Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.X + EndStationLength * Cos(Angle)), 737 Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).Position.Y + EndStationLength * Sin(Angle))); 738 TTrackPoint(Track.Points.Last).Position := EndPoint; 739 TTrackPoint(Track.Points.Last).PositionDesigned := EndPoint; 667 740 end; 668 741 end; … … 688 761 Station.Lines.Add(Self); 689 762 690 NewTrackPoint := T TrackPoint.Create;763 NewTrackPoint := Track.Points.AddNew; 691 764 NewTrackPoint.LineStation := NewLineStation; 692 765 NewTrackPoint.Position := Station.Position; 693 766 NewTrackPoint.PositionDesigned := NewTrackPoint.Position; 694 NewTrackPoint.Line := TrackPoints.Line;695 767 Index := 0; 696 if Assigned(LineStationDown) then Index := Track Points.IndexOf(LineStationDown.TrackPoint) + 1697 else if Assigned(LineStationUp) then Index := Track Points.IndexOf(LineStationUp.TrackPoint);698 Track Points.Insert(Index, NewTrackPoint);768 if Assigned(LineStationDown) then Index := Track.Points.IndexOf(LineStationDown.TrackPoint) + 1 769 else if Assigned(LineStationUp) then Index := Track.Points.IndexOf(LineStationUp.TrackPoint); 770 Track.Points.Insert(Index, NewTrackPoint); 699 771 NewLineStation.TrackPoint := NewTrackPoint; 700 772 … … 710 782 Train.Line := Self; 711 783 Train.TargetStation := TLineStation(LineStations[0]); 712 Train.BaseTrackPoint := TTrackPoint(Track Points.First);784 Train.BaseTrackPoint := TTrackPoint(Track.Points.First); 713 785 Trains.Add(Train); 714 786 end; … … 729 801 // Determine track point range to be removed 730 802 TP1 := ALineStation.TrackPoint.GetDown; 731 if not Assigned(TP1) then TP1 := TTrackPoint(Track Points.First);803 if not Assigned(TP1) then TP1 := TTrackPoint(Track.Points.First); 732 804 TP2 := ALineStation.TrackPoint.GetUp; 733 if not Assigned(TP2) then TP2 := TTrackPoint(Track Points.Last);805 if not Assigned(TP2) then TP2 := TTrackPoint(Track.Points.Last); 734 806 735 807 // Remove track points from trains … … 737 809 with TMetroTrain(Trains[I]) do begin 738 810 IsOnTrack := False; 739 for J := Track Points.IndexOf(TP1) to TrackPoints.IndexOf(TP2) do740 if TTrackPoint(Track Points[J]) = BaseTrackPoint then begin811 for J := Track.Points.IndexOf(TP1) to Track.Points.IndexOf(TP2) do 812 if TTrackPoint(Track.Points[J]) = BaseTrackPoint then begin 741 813 IsOnTrack := True; 742 814 Break; … … 753 825 754 826 // Delete old trackpoints 755 Index := Track Points.IndexOf(ALineStation.TrackPoint) - 1;756 while (Index >= 0) and (not Assigned(TTrackPoint(Track Points[Index]).LineStation)) do begin757 Track Points.Delete(Index);827 Index := Track.Points.IndexOf(ALineStation.TrackPoint) - 1; 828 while (Index >= 0) and (not Assigned(TTrackPoint(Track.Points[Index]).LineStation)) do begin 829 Track.Points.Delete(Index); 758 830 Dec(Index); 759 831 end; 760 832 Index := Index + 1; 761 Track Points.Delete(Index);762 while (Index < Track Points.Count) and (not Assigned(TTrackPoint(TrackPoints[Index]).LineStation)) do763 Track Points.Delete(Index);764 765 if ((Index - 1) >= 0) and (Index < Track Points.Count) then766 RouteTrack(TTrackPoint(Track Points[Index - 1]), TTrackPoint(TrackPoints[Index]));833 Track.Points.Delete(Index); 834 while (Index < Track.Points.Count) and (not Assigned(TTrackPoint(Track.Points[Index]).LineStation)) do 835 Track.Points.Delete(Index); 836 837 if ((Index - 1) >= 0) and (Index < Track.Points.Count) then 838 RouteTrack(TTrackPoint(Track.Points[Index - 1]), TTrackPoint(Track.Points[Index])); 767 839 768 840 ALineStation.MapStation.Lines.Remove(Self); … … 796 868 begin 797 869 RemoveTrackBetween(TP1, TP2); 798 Index1 := TrackPoints.IndexOf(TP1); 799 Index2 := TrackPoints.IndexOf(TP2); 800 P1 := TTrackPoint(TrackPoints[Index1]).Position; 801 P2 := TTrackPoint(TrackPoints[Index2]).Position; 802 NewTrackPoint := TTrackPoint.Create; 803 NewTrackPoint.Line := Self; 870 Index1 := Track.Points.IndexOf(TP1); 871 Index2 := Track.Points.IndexOf(TP2); 872 P1 := TTrackPoint(Track.Points[Index1]).Position; 873 P2 := TTrackPoint(Track.Points[Index2]).Position; 874 NewTrackPoint := Track.Points.AddNew; 804 875 Delta := Point(P2.X - P1.X, P2.Y - P1.Y); 805 876 if Abs(Delta.X) > Abs(Delta.Y) then begin … … 810 881 NewTrackPoint.PositionDesigned := NewTrackPoint.Position; 811 882 end; 812 Track Points.Insert(Index1 + 1, NewTrackPoint);883 Track.Points.Insert(Index1 + 1, NewTrackPoint); 813 884 end; 814 885 … … 819 890 I: Integer; 820 891 begin 821 Index1 := Track Points.IndexOf(TP1);822 Index2 := Track Points.IndexOf(TP2);892 Index1 := Track.Points.IndexOf(TP1); 893 Index2 := Track.Points.IndexOf(TP2); 823 894 if (Index1 = -1) then 824 895 raise Exception.Create('TrackPoint1 not found'); … … 831 902 end; 832 903 for I := 1 to Index2 - Index1 - 1 do 833 Track Points.Delete(Index1 + 1);904 Track.Points.Delete(Index1 + 1); 834 905 end; 835 906 … … 839 910 begin 840 911 Result := 0; 841 for I := 0 to Track Points.Count - 1 do912 for I := 0 to Track.Points.Count - 1 do 842 913 if I > 0 then 843 Result := Result + Distance(TTrackPoint(Track Points[I]).Position, TTrackPoint(TrackPoints[I - 1]).Position);914 Result := Result + Distance(TTrackPoint(Track.Points[I]).Position, TTrackPoint(Track.Points[I - 1]).Position); 844 915 end; 845 916 … … 850 921 Trains := TMetroTrains.Create; 851 922 Trains.OwnsObjects := False; 852 Track Points := TTrackPoints.Create;853 Track Points.Line := Self;923 Track := TTrack.Create; 924 Track.Line := Self; 854 925 end; 855 926 856 927 destructor TMetroLine.Destroy; 857 928 begin 858 TrackPoints.Free;859 929 Trains.Free; 860 930 LineStations.Free; 931 Track.Free; 861 932 inherited Destroy; 862 933 end; … … 890 961 Result := 0; 891 962 if Assigned(BaseTrackPoint) and Assigned(TargetStation) then begin 892 Current := Line.Track Points.IndexOf(BaseTrackPoint);893 Target := Line.Track Points.IndexOf(TargetStation.TrackPoint);963 Current := Line.Track.Points.IndexOf(BaseTrackPoint); 964 Target := Line.Track.Points.IndexOf(TargetStation.TrackPoint); 894 965 if Current < Target then begin 895 966 for I := Current to Target - 1 do 896 Result := Result + TTrackPoint(Line.Track Points[I]).GetDistance;967 Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance; 897 968 Result := Result - Trunc(RelPos); 898 969 end else 899 970 if Current > Target then begin 900 971 for I := Current - 1 downto Target do 901 Result := Result + TTrackPoint(Line.Track Points[I]).GetDistance;972 Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance; 902 973 Result := Result + Trunc(RelPos); 903 974 end else Result := Trunc(RelPos); … … 969 1040 TPAngleGroup: TTrackPointsAngleGroup; 970 1041 GroupItem: TTrackPointsAngle; 971 NewTrack: TTrack ;1042 NewTrack: TTrackLink; 972 1043 HAngle: Double; 973 PairTrack: TTrack ;1044 PairTrack: TTrackLink; 974 1045 NewPoint: TPoint; 975 1046 begin … … 982 1053 LS := Line.LineStations.SearchMapStation(Self); 983 1054 TP := LS.TrackPoint; 984 Index := Line.Track Points.IndexOf(TP);1055 Index := Line.Track.Points.IndexOf(TP); 985 1056 if Index > 0 then begin 986 NewTrack := TTrack .Create;987 NewTrack.PointDown := TTrackPoint(Line.Track Points[Index - 1]);988 NewTrack.PointUp := TTrackPoint(Line.Track Points[Index]);1057 NewTrack := TTrackLink.Create; 1058 NewTrack.PointDown := TTrackPoint(Line.Track.Points[Index - 1]); 1059 NewTrack.PointUp := TTrackPoint(Line.Track.Points[Index]); 989 1060 Tracks.Add(NewTrack); 990 1061 end; 991 if Index < (Line.Track Points.Count - 1) then begin992 NewTrack := TTrack .Create;993 NewTrack.PointDown := TTrackPoint(Line.Track Points[Index + 1]);994 NewTrack.PointUp := TTrackPoint(Line.Track Points[Index]);1062 if Index < (Line.Track.Points.Count - 1) then begin 1063 NewTrack := TTrackLink.Create; 1064 NewTrack.PointDown := TTrackPoint(Line.Track.Points[Index + 1]); 1065 NewTrack.PointUp := TTrackPoint(Line.Track.Points[Index]); 995 1066 Tracks.Add(NewTrack); 996 1067 end; … … 1000 1071 TPAngleGroup := TTrackPointsAngleGroup.Create; 1001 1072 for I := 0 to Tracks.Count - 1 do begin 1002 Angle := ArcTan2(TTrack (Tracks[I]).PointDown.PositionDesigned.Y - Position.Y,1003 TTrack (Tracks[I]).PointDown.PositionDesigned.X - Position.X);1073 Angle := ArcTan2(TTrackLink(Tracks[I]).PointDown.PositionDesigned.Y - Position.Y, 1074 TTrackLink(Tracks[I]).PointDown.PositionDesigned.X - Position.X); 1004 1075 GroupItem := TPAngleGroup.SearchAngle(Angle); 1005 1076 if not Assigned(GroupItem) then begin … … 1008 1079 TPAngleGroup.Add(GroupItem); 1009 1080 end; 1010 GroupItem.Tracks.Add(TTrack (Tracks[I]))1081 GroupItem.Tracks.Add(TTrackLink(Tracks[I])) 1011 1082 end; 1012 1083 … … 1015 1086 with TTrackPointsAngle(TPAngleGroup[I]) do begin 1016 1087 for J := 0 to Tracks.Count - 1 do 1017 with TTrack (Tracks[J]) do begin1088 with TTrackLink(Tracks[J]) do begin 1018 1089 // Get orthogonal angle 1019 1090 HAngle := Angle + Pi / 2; … … 1157 1228 end; 1158 1229 1159 function TEngine.GetTrackOnPos(Pos: TPoint): TTrack ;1230 function TEngine.GetTrackOnPos(Pos: TPoint): TTrackLink; 1160 1231 var 1161 1232 I: Integer; … … 1164 1235 MinD: Integer; 1165 1236 begin 1166 Result := TTrack .Create;1237 Result := TTrackLink.Create; 1167 1238 Result.PointDown := nil; 1168 1239 Result.PointUp := nil; … … 1171 1242 while (I < Lines.Count) do 1172 1243 with TMetroLine(Lines[I]) do begin 1173 for T := 1 to Track Points.Count - 1 do begin1174 D := PointToLineDistance(Pos, TTrackPoint(Track Points[T - 1]).Position, TTrackPoint(TrackPoints[T]).Position);1244 for T := 1 to Track.Points.Count - 1 do begin 1245 D := PointToLineDistance(Pos, TTrackPoint(Track.Points[T - 1]).Position, TTrackPoint(Track.Points[T]).Position); 1175 1246 if (D < MinD) and (D < TrackClickDistance) then begin 1176 1247 MinD := D; 1177 Result.PointDown := TTrackPoint(Track Points[T - 1]);1178 Result.PointUp := TTrackPoint(Track Points[T]);1248 Result.PointDown := TTrackPoint(Track.Points[T - 1]); 1249 Result.PointUp := TTrackPoint(Track.Points[T]); 1179 1250 end; 1180 1251 end; … … 1522 1593 begin 1523 1594 I := 0; 1524 while (I < Lines.Count) and (TMetroLine(Lines[I]).Track Points.Count > 0) do Inc(I);1595 while (I < Lines.Count) and (TMetroLine(Lines[I]).Track.Points.Count > 0) do Inc(I); 1525 1596 if I < Lines.Count then Result := TMetroLine(Lines[I]) 1526 1597 else Result := nil; … … 1538 1609 for I := 0 to Lines.Count - 1 do 1539 1610 with TMetroLine(Lines[I]) do 1540 for J := 0 to Track Points.Count - 1 do1541 TTrackPoint(Track Points[J]).Position := TTrackPoint(TrackPoints[J]).PositionDesigned;1611 for J := 0 to Track.Points.Count - 1 do 1612 TTrackPoint(Track.Points[J]).Position := TTrackPoint(Track.Points[J]).PositionDesigned; 1542 1613 1543 1614 // Calculate new position shifts … … 1548 1619 for L := 0 to Lines.Count - 1 do 1549 1620 with TMetroLine(Lines[L]) do begin 1550 if Track Points.Count > 0 then1551 TTrackPoint(Track Points[0]).Position := AddPoint(TTrackPoint(TrackPoints[0]).PositionDesigned,1552 TTrackPoint(Track Points[0]).PositionShift);1553 for I := 1 to Track Points.Count - 1 do1554 with TTrackPoint(Track Points[I]) do begin1555 Link1 := SubPoint(AddPoint(TTrackPoint(Track Points[I]).PositionDesigned, TTrackPoint(TrackPoints[I]).PositionShift),1556 AddPoint(TTrackPoint(Track Points[I - 1]).PositionDesigned, TTrackPoint(TrackPoints[I - 1]).PositionShift));1557 if (I + 1) < Track Points.Count then1558 Link2 := SubPoint(AddPoint(TTrackPoint(Track Points[I + 1]).PositionDesigned, TTrackPoint(TrackPoints[I + 1]).PositionShift),1559 AddPoint(TTrackPoint(Track Points[I]).PositionDesigned, TTrackPoint(TrackPoints[I]).PositionShift))1621 if Track.Points.Count > 0 then 1622 TTrackPoint(Track.Points[0]).Position := AddPoint(TTrackPoint(Track.Points[0]).PositionDesigned, 1623 TTrackPoint(Track.Points[0]).PositionShift); 1624 for I := 1 to Track.Points.Count - 1 do 1625 with TTrackPoint(Track.Points[I]) do begin 1626 Link1 := SubPoint(AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).PositionShift), 1627 AddPoint(TTrackPoint(Track.Points[I - 1]).PositionDesigned, TTrackPoint(Track.Points[I - 1]).PositionShift)); 1628 if (I + 1) < Track.Points.Count then 1629 Link2 := SubPoint(AddPoint(TTrackPoint(Track.Points[I + 1]).PositionDesigned, TTrackPoint(Track.Points[I + 1]).PositionShift), 1630 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).PositionShift)) 1560 1631 else Link2 := Link1; 1561 1632 1562 1633 if ArcTanPoint(Link1) = ArcTanPoint(Link2) then begin 1563 1634 // Parallel lines 1564 TTrackPoint(Track Points[I]).Position := AddPoint(TTrackPoint(TrackPoints[I]).PositionDesigned,1565 TTrackPoint(Track Points[I]).PositionShift);1635 TTrackPoint(Track.Points[I]).Position := AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, 1636 TTrackPoint(Track.Points[I]).PositionShift); 1566 1637 end else begin 1567 1638 // Intersected lines 1568 NewPoint := LineIntersect(AddPoint(TTrackPoint(Track Points[I - 1]).PositionDesigned, TTrackPoint(TrackPoints[I - 1]).PositionShift),1569 AddPoint(TTrackPoint(Track Points[I]).PositionDesigned, TTrackPoint(TrackPoints[I]).PositionShift),1570 AddPoint(TTrackPoint(Track Points[I]).PositionDesigned, TTrackPoint(TrackPoints[I]).PositionShift),1571 AddPoint(TTrackPoint(Track Points[I + 1]).PositionDesigned, TTrackPoint(TrackPoints[I + 1]).PositionShift));1572 TTrackPoint(Track Points[I]).Position := NewPoint;1639 NewPoint := LineIntersect(AddPoint(TTrackPoint(Track.Points[I - 1]).PositionDesigned, TTrackPoint(Track.Points[I - 1]).PositionShift), 1640 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).PositionShift), 1641 AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned, TTrackPoint(Track.Points[I]).PositionShift), 1642 AddPoint(TTrackPoint(Track.Points[I + 1]).PositionDesigned, TTrackPoint(Track.Points[I + 1]).PositionShift)); 1643 TTrackPoint(Track.Points[I]).Position := NewPoint; 1573 1644 end; 1574 1645 end; … … 1727 1798 FocusedStation := GetStationOnPos(View.PointDestToSrc(Position)); 1728 1799 Line := nil; 1729 if Assigned(TrackStationDown) then Line := TrackStationDown. Line;1730 if Assigned(TrackStationUp) then Line := TrackStationUp. Line;1800 if Assigned(TrackStationDown) then Line := TrackStationDown.Track.Line; 1801 if Assigned(TrackStationUp) then Line := TrackStationUp.Track.Line; 1731 1802 if Assigned(Line) and not Assigned(LastFocusedStation) and Assigned(FocusedStation) then begin 1732 1803 if Assigned(TrackStationDown) and (TrackStationDown.LineStation.MapStation = FocusedStation) then begin … … 1766 1837 var 1767 1838 I: Integer; 1768 FocusedTrack: TTrack ;1839 FocusedTrack: TTrackLink; 1769 1840 begin 1770 1841 if Button = mbLeft then begin … … 1779 1850 FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Position)); 1780 1851 if Assigned(FocusedTrack.PointDown) then begin 1781 SelectedTrain.Line := FocusedTrack.PointDown. Line;1852 SelectedTrain.Line := FocusedTrack.PointDown.Track.Line; 1782 1853 SelectedTrain.Line.Trains.Add(SelectedTrain); 1783 1854 SelectedTrain.BaseTrackPoint := FocusedTrack.PointDown; 1784 1855 end else 1785 1856 if Assigned(FocusedTrack.PointDown) then begin 1786 SelectedTrain.Line := FocusedTrack.PointUp. Line;1857 SelectedTrain.Line := FocusedTrack.PointUp.Track.Line; 1787 1858 SelectedTrain.Line.Trains.Add(SelectedTrain); 1788 1859 SelectedTrain.BaseTrackPoint := FocusedTrack.PointUp; … … 1800 1871 1801 1872 // Remove single line station on line 1802 if Assigned(TrackStationDown) and (TrackStationDown. Line.LineStations.Count = 1) then begin1803 TrackStationDown. Line.DisconnectStation(TLineStation(TrackStationDown.Line.LineStations.First));1804 end; 1805 if Assigned(TrackStationUp) and (TrackStationUp. Line.LineStations.Count = 1) then begin1806 TrackStationUp. Line.DisconnectStation(TLineStation(TrackStationUp.Line.LineStations.First));1873 if Assigned(TrackStationDown) and (TrackStationDown.Track.Line.LineStations.Count = 1) then begin 1874 TrackStationDown.Track.Line.DisconnectStation(TLineStation(TrackStationDown.Track.Line.LineStations.First)); 1875 end; 1876 if Assigned(TrackStationUp) and (TrackStationUp.Track.Line.LineStations.Count = 1) then begin 1877 TrackStationUp.Track.Line.DisconnectStation(TLineStation(TrackStationUp.Track.Line.LineStations.First)); 1807 1878 end; 1808 1879 end else … … 1822 1893 I: Integer; 1823 1894 NewLine: TMetroLine; 1824 Track: TTrack ;1895 Track: TTrackLink; 1825 1896 NewIndex: Integer; 1826 1897 begin … … 1846 1917 Track := GetTrackOnPos(View.PointDestToSrc(Position)); 1847 1918 if Assigned(Track) and Assigned(Track.PointDown) and Assigned(Track.PointUp) then begin 1848 SelectedLine := Track.PointDown. Line;1919 SelectedLine := Track.PointDown.Track.Line; 1849 1920 1850 1921 TrackStationDown := Track.PointDown; 1851 NewIndex := TrackStationDown. Line.TrackPoints.IndexOf(TrackStationDown);1922 NewIndex := TrackStationDown.Track.Points.IndexOf(TrackStationDown); 1852 1923 while Assigned(TrackStationDown) and (not Assigned(TrackStationDown.LineStation)) do begin 1853 1924 NewIndex := NewIndex - 1; 1854 if NewIndex >= 0 then TrackStationDown := TTrackPoint(TrackStationDown. Line.TrackPoints[NewIndex])1925 if NewIndex >= 0 then TrackStationDown := TTrackPoint(TrackStationDown.Track.Points[NewIndex]) 1855 1926 else TrackStationDown := nil; 1856 1927 end; 1857 1928 TrackStationUp := Track.PointUp; 1858 NewIndex := TrackStationUp. Line.TrackPoints.IndexOf(TrackStationDown);1929 NewIndex := TrackStationUp.Track.Points.IndexOf(TrackStationDown); 1859 1930 while Assigned(TrackStationUp) and (not Assigned(TrackStationUp.LineStation)) do begin 1860 1931 NewIndex := NewIndex + 1; 1861 if NewIndex < TrackStationUp. Line.TrackPoints.Count then1862 TrackStationUp := TTrackPoint(TrackStationUp. Line.TrackPoints[NewIndex])1932 if NewIndex < TrackStationUp.Track.Points.Count then 1933 TrackStationUp := TTrackPoint(TrackStationUp.Track.Points[NewIndex]) 1863 1934 else TrackStationUp := nil; 1864 1935 end; … … 1875 1946 if Assigned(NewLine) then begin 1876 1947 NewLine.ConnectStation(Station, nil, nil); 1877 TrackStationDown := TTrackPoint(NewLine.Track Points.Last);1948 TrackStationDown := TTrackPoint(NewLine.Track.Points.Last); 1878 1949 TrackStationUp := nil; 1879 1950 LastFocusedStation := Station; … … 2003 2074 Canvas.Pen.Style := psSolid; 2004 2075 Canvas.Pen.Width := MetroLineThickness; 2005 if Track Points.Count > 0 then Canvas.MoveTo(TTrackPoint(TrackPoints[0]).Position);2006 for S := 1 to Track Points.Count - 1 do begin2007 Canvas.LineTo(TTrackPoint(Track Points[S]).Position);2076 if Track.Points.Count > 0 then Canvas.MoveTo(TTrackPoint(Track.Points[0]).Position); 2077 for S := 1 to Track.Points.Count - 1 do begin 2078 Canvas.LineTo(TTrackPoint(Track.Points[S]).Position); 2008 2079 { if (S = TrackPoints.Count - 1) then begin 2009 2080 Canvas.Pen.EndCap := pecSquare; … … 2039 2110 // Draw design time lines 2040 2111 if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin 2041 Canvas.Pen.Color := TrackStationDown. Line.Color;2112 Canvas.Pen.Color := TrackStationDown.Track.Line.Color; 2042 2113 Canvas.MoveTo(TrackStationDown.LineStation.TrackPoint.Position); 2043 2114 DrawLine(Canvas, View.PointDestToSrc(LastMousePos)); 2044 2115 end; 2045 2116 if Assigned(TrackStationUp) and Assigned(TrackStationUp.LineStation) then begin 2046 Canvas.Pen.Color := TrackStationUp. Line.Color;2117 Canvas.Pen.Color := TrackStationUp.Track.Line.Color; 2047 2118 Canvas.MoveTo(TrackStationUp.LineStation.TrackPoint.Position); 2048 2119 DrawLine(Canvas, View.PointDestToSrc(LastMousePos)); … … 2111 2182 2112 2183 // Line selection 2184 TargetCanvas.Pen.Width := 4; 2113 2185 for I := 0 to High(LineColors) do begin 2114 2186 if Assigned(Lines.SearchByColor(LineColors[I])) then begin … … 2140 2212 // Status interface 2141 2213 Text := IntToStr(ServedPassengerCount); 2142 TargetCanvas.Draw(TargetCanvas.Width - 1 40, 20, ImagePassenger.Picture.Bitmap);2214 TargetCanvas.Draw(TargetCanvas.Width - 100, TargetCanvas.Height - 60, ImagePassenger.Picture.Bitmap); 2143 2215 TargetCanvas.Brush.Style := bsClear; 2144 TargetCanvas.TextOut(TargetCanvas.Width - 146 - TargetCanvas.TextWidth(Text), 25, Text);2216 TargetCanvas.TextOut(TargetCanvas.Width - 50 - TargetCanvas.TextWidth(Text), TargetCanvas.Height - 55, Text); 2145 2217 2146 2218 DrawClock(TargetCanvas);
Note:
See TracChangeset
for help on using the changeset viewer.