Changeset 31 for trunk


Ignore:
Timestamp:
Apr 18, 2015, 11:43:05 PM (10 years ago)
Author:
chronos
Message:
  • Added: Track points now belong to TTrack class. TTrackPoint and TTrackLine have Track as Parent instead of TMetroLine. This change is needed to gradually separate TTrack, TTrackLink and TTrackPoint to separate unit and allow consistent implementations of TTrackLinks and direct object references between TTrackPoints insted of searching in list using IndexOf.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r30 r31  
    2020  TTrackPoint = class;
    2121  TLineStation = class;
     22  TTrackPoints = class;
     23  TTrack = class;
    2224
    2325  { TMapStation }
     
    6466
    6567  TTrackPoint = class
    66     Line: TMetroLine;
    6768    LineStation: TLineStation;
    6869    Position: TPoint;
     
    7071    PositionDesigned: TPoint;
    7172    Pending: Boolean;
     73    NeighPoints: TTrackPoints;
     74    Track: TTrack;
    7275    function GetDown: TTrackPoint;
    7376    function GetUp: TTrackPoint;
     
    7679    // Move to TTrackLink later
    7780    function GetDistance: Integer;
    78   end;
     81    constructor Create;
     82    destructor Destroy; override;
     83  end;
     84
     85  { TTrackPoints }
    7986
    8087  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;
    8596    PointDown: TTrackPoint;
    8697    PointUp: TTrackPoint;
    8798    Line: TMetroLine;
    8899    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;
    89114  end;
    90115
     
    92117
    93118  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;
    96121  end;
    97122
     
    122147    LineStations: TLineStations;
    123148    Trains: TMetroTrains;
    124     TrackPoints: TTrackPoints;
     149    Track: TTrack;
    125150    procedure ConnectStation(Station: TMapStation; LineStationDown, LineStationUp: TLineStation);
    126151    procedure DisconnectStation(ALineStation: TLineStation);
     
    246271    function GetExistStationShapes: TStationShapeSet;
    247272    function GetStationOnPos(Pos: TPoint): TMapStation;
    248     function GetTrackOnPos(Pos: TPoint): TTrack;
     273    function GetTrackOnPos(Pos: TPoint): TTrackLink;
    249274    function GetTrainOnPos(Pos: TPoint): TMetroTrain;
    250275    procedure DrawLine(Canvas: TCanvas; Pos: TPoint);
     
    325350  SZeroZoomNotAlowed = 'Zero zoom not allowed';
    326351
     352{ TTrackPoints }
     353
     354function TTrackPoints.AddNew: TTrackPoint;
     355begin
     356  Result := TTrackPoint.Create;
     357  Result.Track := Track;
     358end;
     359
     360{ TTrack }
     361
     362constructor TTrack.Create;
     363begin
     364  Points := TTrackPoints.Create;
     365  Points.Track := Self;
     366  Links := TTrackLinks.Create;
     367end;
     368
     369destructor TTrack.Destroy;
     370begin
     371  Points.Free;
     372  Links.Free;
     373  inherited Destroy;
     374end;
     375
     376{ TTrackLink }
     377
     378constructor TTrackLink.Create;
     379begin
     380  Points := TTrackPoints.Create;
     381  Points.OwnsObjects := False;
     382end;
     383
     384destructor TTrackLink.Destroy;
     385begin
     386  Points.Free;
     387  inherited Destroy;
     388end;
     389
    327390{ TRiver }
    328391
     
    407470{ TTracks }
    408471
    409 function TTracks.SearchPointUp(TrackPoint: TTrackPoint; Skip: TTrack): TTrack;
     472function TTracks.SearchPointUp(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink;
    410473var
    411474  I: Integer;
    412475begin
    413476  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])
    416479    else Result := nil;
    417480end;
    418481
    419 function TTracks.SearchPointDown(TrackPoint: TTrackPoint; Skip: TTrack): TTrack;
     482function TTracks.SearchPointDown(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink;
    420483var
    421484  I: Integer;
    422485begin
    423486  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])
    426489    else Result := nil;
    427490end;
     
    459522  I: Integer;
    460523begin
    461   I := Line.TrackPoints.IndexOf(Self) - 1;
    462   while (I >= 0) and not Assigned(TTrackPoint(Line.TrackPoints[I]).LineStation) do
     524  I := Track.Points.IndexOf(Self) - 1;
     525  while (I >= 0) and not Assigned(TTrackPoint(Track.Points[I]).LineStation) do
    463526    Dec(I);
    464   if I >= 0 then Result := TTrackPoint(Line.TrackPoints[I])
     527  if I >= 0 then Result := TTrackPoint(Track.Points[I])
    465528    else Result := nil;
    466529end;
     
    470533  I: Integer;
    471534begin
    472   I := Line.TrackPoints.IndexOf(Self) + 1;
    473   while (I < Line.TrackPoints.Count) and not Assigned(TTrackPoint(Line.TrackPoints[I]).LineStation) do
     535  I := Track.Points.IndexOf(Self) + 1;
     536  while (I < Track.Points.Count) and not Assigned(TTrackPoint(Track.Points[I]).LineStation) do
    474537    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])
    476539    else Result := nil;
    477540end;
     
    482545begin
    483546  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]);
    486549end;
    487550
     
    491554begin
    492555  Result := nil;
    493   if Assigned(Line) then begin
    494     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]);
    496559  end;
    497560end;
     
    501564  Index: Integer;
    502565begin
    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);
     569end;
     570
     571constructor TTrackPoint.Create;
     572begin
     573  NeighPoints := TTrackPoints.Create;
     574  NeighPoints.OwnsObjects := False;
     575end;
     576
     577destructor TTrackPoint.Destroy;
     578begin
     579  NeighPoints.Free;
     580  inherited Destroy;
    506581end;
    507582
     
    639714begin
    640715  if LineStations.Count >= 2 then begin
    641     Index := TrackPoints.IndexOf(TLineStation(LineStations.First).TrackPoint);
     716    Index := Track.Points.IndexOf(TLineStation(LineStations.First).TrackPoint);
    642717    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;
    667740  end;
    668741end;
     
    688761  Station.Lines.Add(Self);
    689762
    690   NewTrackPoint := TTrackPoint.Create;
     763  NewTrackPoint := Track.Points.AddNew;
    691764  NewTrackPoint.LineStation := NewLineStation;
    692765  NewTrackPoint.Position := Station.Position;
    693766  NewTrackPoint.PositionDesigned := NewTrackPoint.Position;
    694   NewTrackPoint.Line := TrackPoints.Line;
    695767  Index := 0;
    696   if Assigned(LineStationDown) then Index := TrackPoints.IndexOf(LineStationDown.TrackPoint) + 1
    697     else if Assigned(LineStationUp) then Index := TrackPoints.IndexOf(LineStationUp.TrackPoint);
    698   TrackPoints.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);
    699771  NewLineStation.TrackPoint := NewTrackPoint;
    700772
     
    710782      Train.Line := Self;
    711783      Train.TargetStation := TLineStation(LineStations[0]);
    712       Train.BaseTrackPoint := TTrackPoint(TrackPoints.First);
     784      Train.BaseTrackPoint := TTrackPoint(Track.Points.First);
    713785      Trains.Add(Train);
    714786    end;
     
    729801  // Determine track point range to be removed
    730802  TP1 := ALineStation.TrackPoint.GetDown;
    731   if not Assigned(TP1) then TP1 := TTrackPoint(TrackPoints.First);
     803  if not Assigned(TP1) then TP1 := TTrackPoint(Track.Points.First);
    732804  TP2 := ALineStation.TrackPoint.GetUp;
    733   if not Assigned(TP2) then TP2 := TTrackPoint(TrackPoints.Last);
     805  if not Assigned(TP2) then TP2 := TTrackPoint(Track.Points.Last);
    734806
    735807  // Remove track points from trains
     
    737809  with TMetroTrain(Trains[I]) do begin
    738810    IsOnTrack := False;
    739     for J := TrackPoints.IndexOf(TP1) to TrackPoints.IndexOf(TP2) do
    740     if TTrackPoint(TrackPoints[J]) = BaseTrackPoint then begin
     811    for J := Track.Points.IndexOf(TP1) to Track.Points.IndexOf(TP2) do
     812    if TTrackPoint(Track.Points[J]) = BaseTrackPoint then begin
    741813      IsOnTrack := True;
    742814      Break;
     
    753825
    754826  // Delete old trackpoints
    755   Index := TrackPoints.IndexOf(ALineStation.TrackPoint) - 1;
    756   while (Index >= 0) and (not Assigned(TTrackPoint(TrackPoints[Index]).LineStation)) do begin
    757     TrackPoints.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);
    758830    Dec(Index);
    759831  end;
    760832  Index := Index + 1;
    761   TrackPoints.Delete(Index);
    762   while (Index < TrackPoints.Count) and (not Assigned(TTrackPoint(TrackPoints[Index]).LineStation)) do
    763     TrackPoints.Delete(Index);
    764 
    765   if ((Index - 1) >= 0) and (Index < TrackPoints.Count) then
    766     RouteTrack(TTrackPoint(TrackPoints[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]));
    767839
    768840  ALineStation.MapStation.Lines.Remove(Self);
     
    796868begin
    797869  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;
    804875  Delta := Point(P2.X - P1.X, P2.Y - P1.Y);
    805876  if Abs(Delta.X) > Abs(Delta.Y) then begin
     
    810881    NewTrackPoint.PositionDesigned := NewTrackPoint.Position;
    811882  end;
    812   TrackPoints.Insert(Index1 + 1, NewTrackPoint);
     883  Track.Points.Insert(Index1 + 1, NewTrackPoint);
    813884end;
    814885
     
    819890  I: Integer;
    820891begin
    821   Index1 := TrackPoints.IndexOf(TP1);
    822   Index2 := TrackPoints.IndexOf(TP2);
     892  Index1 := Track.Points.IndexOf(TP1);
     893  Index2 := Track.Points.IndexOf(TP2);
    823894  if (Index1 = -1) then
    824895    raise Exception.Create('TrackPoint1 not found');
     
    831902  end;
    832903  for I := 1 to Index2 - Index1 - 1 do
    833     TrackPoints.Delete(Index1 + 1);
     904    Track.Points.Delete(Index1 + 1);
    834905end;
    835906
     
    839910begin
    840911  Result := 0;
    841   for I := 0 to TrackPoints.Count - 1 do
     912  for I := 0 to Track.Points.Count - 1 do
    842913  if I > 0 then
    843     Result := Result + Distance(TTrackPoint(TrackPoints[I]).Position, TTrackPoint(TrackPoints[I - 1]).Position);
     914    Result := Result + Distance(TTrackPoint(Track.Points[I]).Position, TTrackPoint(Track.Points[I - 1]).Position);
    844915end;
    845916
     
    850921  Trains := TMetroTrains.Create;
    851922  Trains.OwnsObjects := False;
    852   TrackPoints := TTrackPoints.Create;
    853   TrackPoints.Line := Self;
     923  Track := TTrack.Create;
     924  Track.Line := Self;
    854925end;
    855926
    856927destructor TMetroLine.Destroy;
    857928begin
    858   TrackPoints.Free;
    859929  Trains.Free;
    860930  LineStations.Free;
     931  Track.Free;
    861932  inherited Destroy;
    862933end;
     
    890961  Result := 0;
    891962  if Assigned(BaseTrackPoint) and Assigned(TargetStation) then begin
    892   Current := Line.TrackPoints.IndexOf(BaseTrackPoint);
    893   Target := Line.TrackPoints.IndexOf(TargetStation.TrackPoint);
     963  Current := Line.Track.Points.IndexOf(BaseTrackPoint);
     964  Target := Line.Track.Points.IndexOf(TargetStation.TrackPoint);
    894965  if Current < Target then begin
    895966    for I := Current to Target - 1 do
    896       Result := Result + TTrackPoint(Line.TrackPoints[I]).GetDistance;
     967      Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance;
    897968    Result := Result - Trunc(RelPos);
    898969  end else
    899970  if Current > Target then begin
    900971    for I := Current - 1 downto Target do
    901       Result := Result + TTrackPoint(Line.TrackPoints[I]).GetDistance;
     972      Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance;
    902973    Result := Result + Trunc(RelPos);
    903974  end else Result := Trunc(RelPos);
     
    9691040  TPAngleGroup: TTrackPointsAngleGroup;
    9701041  GroupItem: TTrackPointsAngle;
    971   NewTrack: TTrack;
     1042  NewTrack: TTrackLink;
    9721043  HAngle: Double;
    973   PairTrack: TTrack;
     1044  PairTrack: TTrackLink;
    9741045  NewPoint: TPoint;
    9751046begin
     
    9821053    LS := Line.LineStations.SearchMapStation(Self);
    9831054    TP := LS.TrackPoint;
    984     Index := Line.TrackPoints.IndexOf(TP);
     1055    Index := Line.Track.Points.IndexOf(TP);
    9851056    if Index > 0 then begin
    986       NewTrack := TTrack.Create;
    987       NewTrack.PointDown := TTrackPoint(Line.TrackPoints[Index - 1]);
    988       NewTrack.PointUp := TTrackPoint(Line.TrackPoints[Index]);
     1057      NewTrack := TTrackLink.Create;
     1058      NewTrack.PointDown := TTrackPoint(Line.Track.Points[Index - 1]);
     1059      NewTrack.PointUp := TTrackPoint(Line.Track.Points[Index]);
    9891060      Tracks.Add(NewTrack);
    9901061    end;
    991     if Index < (Line.TrackPoints.Count - 1) then begin
    992       NewTrack := TTrack.Create;
    993       NewTrack.PointDown := TTrackPoint(Line.TrackPoints[Index + 1]);
    994       NewTrack.PointUp := TTrackPoint(Line.TrackPoints[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]);
    9951066      Tracks.Add(NewTrack);
    9961067    end;
     
    10001071  TPAngleGroup := TTrackPointsAngleGroup.Create;
    10011072  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);
    10041075    GroupItem := TPAngleGroup.SearchAngle(Angle);
    10051076    if not Assigned(GroupItem) then begin
     
    10081079      TPAngleGroup.Add(GroupItem);
    10091080    end;
    1010     GroupItem.Tracks.Add(TTrack(Tracks[I]))
     1081    GroupItem.Tracks.Add(TTrackLink(Tracks[I]))
    10111082  end;
    10121083
     
    10151086  with TTrackPointsAngle(TPAngleGroup[I]) do begin
    10161087    for J := 0 to Tracks.Count - 1 do
    1017       with TTrack(Tracks[J]) do begin
     1088      with TTrackLink(Tracks[J]) do begin
    10181089        // Get orthogonal angle
    10191090        HAngle := Angle + Pi / 2;
     
    11571228end;
    11581229
    1159 function TEngine.GetTrackOnPos(Pos: TPoint): TTrack;
     1230function TEngine.GetTrackOnPos(Pos: TPoint): TTrackLink;
    11601231var
    11611232  I: Integer;
     
    11641235  MinD: Integer;
    11651236begin
    1166   Result := TTrack.Create;
     1237  Result := TTrackLink.Create;
    11671238  Result.PointDown := nil;
    11681239  Result.PointUp := nil;
     
    11711242  while (I < Lines.Count) do
    11721243  with TMetroLine(Lines[I]) do begin
    1173     for T := 1 to TrackPoints.Count - 1 do begin
    1174       D := PointToLineDistance(Pos, TTrackPoint(TrackPoints[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);
    11751246      if (D < MinD) and (D < TrackClickDistance) then begin
    11761247        MinD := D;
    1177         Result.PointDown := TTrackPoint(TrackPoints[T - 1]);
    1178         Result.PointUp := TTrackPoint(TrackPoints[T]);
     1248        Result.PointDown := TTrackPoint(Track.Points[T - 1]);
     1249        Result.PointUp := TTrackPoint(Track.Points[T]);
    11791250      end;
    11801251    end;
     
    15221593begin
    15231594  I := 0;
    1524   while (I < Lines.Count) and (TMetroLine(Lines[I]).TrackPoints.Count > 0) do Inc(I);
     1595  while (I < Lines.Count) and (TMetroLine(Lines[I]).Track.Points.Count > 0) do Inc(I);
    15251596  if I < Lines.Count then Result := TMetroLine(Lines[I])
    15261597    else Result := nil;
     
    15381609  for I := 0 to Lines.Count - 1 do
    15391610  with TMetroLine(Lines[I]) do
    1540     for J := 0 to TrackPoints.Count - 1 do
    1541     TTrackPoint(TrackPoints[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;
    15421613
    15431614  // Calculate new position shifts
     
    15481619  for L := 0 to Lines.Count - 1 do
    15491620  with TMetroLine(Lines[L]) do begin
    1550     if TrackPoints.Count > 0 then
    1551       TTrackPoint(TrackPoints[0]).Position := AddPoint(TTrackPoint(TrackPoints[0]).PositionDesigned,
    1552         TTrackPoint(TrackPoints[0]).PositionShift);
    1553     for I := 1 to TrackPoints.Count - 1 do
    1554     with TTrackPoint(TrackPoints[I]) do begin
    1555       Link1 := SubPoint(AddPoint(TTrackPoint(TrackPoints[I]).PositionDesigned, TTrackPoint(TrackPoints[I]).PositionShift),
    1556         AddPoint(TTrackPoint(TrackPoints[I - 1]).PositionDesigned, TTrackPoint(TrackPoints[I - 1]).PositionShift));
    1557       if (I + 1) < TrackPoints.Count then
    1558         Link2 := SubPoint(AddPoint(TTrackPoint(TrackPoints[I + 1]).PositionDesigned, TTrackPoint(TrackPoints[I + 1]).PositionShift),
    1559           AddPoint(TTrackPoint(TrackPoints[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))
    15601631        else Link2 := Link1;
    15611632
    15621633      if ArcTanPoint(Link1) = ArcTanPoint(Link2) then begin
    15631634        // Parallel lines
    1564         TTrackPoint(TrackPoints[I]).Position := AddPoint(TTrackPoint(TrackPoints[I]).PositionDesigned,
    1565           TTrackPoint(TrackPoints[I]).PositionShift);
     1635        TTrackPoint(Track.Points[I]).Position := AddPoint(TTrackPoint(Track.Points[I]).PositionDesigned,
     1636          TTrackPoint(Track.Points[I]).PositionShift);
    15661637      end else begin
    15671638        // Intersected lines
    1568         NewPoint := LineIntersect(AddPoint(TTrackPoint(TrackPoints[I - 1]).PositionDesigned, TTrackPoint(TrackPoints[I - 1]).PositionShift),
    1569           AddPoint(TTrackPoint(TrackPoints[I]).PositionDesigned, TTrackPoint(TrackPoints[I]).PositionShift),
    1570           AddPoint(TTrackPoint(TrackPoints[I]).PositionDesigned, TTrackPoint(TrackPoints[I]).PositionShift),
    1571           AddPoint(TTrackPoint(TrackPoints[I + 1]).PositionDesigned, TTrackPoint(TrackPoints[I + 1]).PositionShift));
    1572         TTrackPoint(TrackPoints[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;
    15731644      end;
    15741645    end;
     
    17271798      FocusedStation := GetStationOnPos(View.PointDestToSrc(Position));
    17281799      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;
    17311802      if Assigned(Line) and not Assigned(LastFocusedStation) and Assigned(FocusedStation) then begin
    17321803        if Assigned(TrackStationDown) and (TrackStationDown.LineStation.MapStation = FocusedStation) then begin
     
    17661837var
    17671838  I: Integer;
    1768   FocusedTrack: TTrack;
     1839  FocusedTrack: TTrackLink;
    17691840begin
    17701841  if Button = mbLeft then begin
     
    17791850      FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Position));
    17801851      if Assigned(FocusedTrack.PointDown) then begin
    1781         SelectedTrain.Line := FocusedTrack.PointDown.Line;
     1852        SelectedTrain.Line := FocusedTrack.PointDown.Track.Line;
    17821853        SelectedTrain.Line.Trains.Add(SelectedTrain);
    17831854        SelectedTrain.BaseTrackPoint := FocusedTrack.PointDown;
    17841855      end else
    17851856      if Assigned(FocusedTrack.PointDown) then begin
    1786         SelectedTrain.Line := FocusedTrack.PointUp.Line;
     1857        SelectedTrain.Line := FocusedTrack.PointUp.Track.Line;
    17871858        SelectedTrain.Line.Trains.Add(SelectedTrain);
    17881859        SelectedTrain.BaseTrackPoint := FocusedTrack.PointUp;
     
    18001871
    18011872    // Remove single line station on line
    1802     if Assigned(TrackStationDown) and (TrackStationDown.Line.LineStations.Count = 1) then begin
    1803       TrackStationDown.Line.DisconnectStation(TLineStation(TrackStationDown.Line.LineStations.First));
    1804     end;
    1805     if Assigned(TrackStationUp) and (TrackStationUp.Line.LineStations.Count = 1) then begin
    1806       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));
    18071878    end;
    18081879  end else
     
    18221893  I: Integer;
    18231894  NewLine: TMetroLine;
    1824   Track: TTrack;
     1895  Track: TTrackLink;
    18251896  NewIndex: Integer;
    18261897begin
     
    18461917    Track := GetTrackOnPos(View.PointDestToSrc(Position));
    18471918    if Assigned(Track) and Assigned(Track.PointDown) and Assigned(Track.PointUp) then begin
    1848       SelectedLine := Track.PointDown.Line;
     1919      SelectedLine := Track.PointDown.Track.Line;
    18491920
    18501921      TrackStationDown := Track.PointDown;
    1851       NewIndex := TrackStationDown.Line.TrackPoints.IndexOf(TrackStationDown);
     1922      NewIndex := TrackStationDown.Track.Points.IndexOf(TrackStationDown);
    18521923      while Assigned(TrackStationDown) and (not Assigned(TrackStationDown.LineStation)) do begin
    18531924        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])
    18551926          else TrackStationDown := nil;
    18561927      end;
    18571928      TrackStationUp := Track.PointUp;
    1858       NewIndex := TrackStationUp.Line.TrackPoints.IndexOf(TrackStationDown);
     1929      NewIndex := TrackStationUp.Track.Points.IndexOf(TrackStationDown);
    18591930      while Assigned(TrackStationUp) and (not Assigned(TrackStationUp.LineStation)) do begin
    18601931        NewIndex := NewIndex + 1;
    1861         if NewIndex < TrackStationUp.Line.TrackPoints.Count then
    1862           TrackStationUp := TTrackPoint(TrackStationUp.Line.TrackPoints[NewIndex])
     1932        if NewIndex < TrackStationUp.Track.Points.Count then
     1933          TrackStationUp := TTrackPoint(TrackStationUp.Track.Points[NewIndex])
    18631934          else TrackStationUp := nil;
    18641935      end;
     
    18751946      if Assigned(NewLine) then begin
    18761947        NewLine.ConnectStation(Station, nil, nil);
    1877         TrackStationDown := TTrackPoint(NewLine.TrackPoints.Last);
     1948        TrackStationDown := TTrackPoint(NewLine.Track.Points.Last);
    18781949        TrackStationUp := nil;
    18791950        LastFocusedStation := Station;
     
    20032074    Canvas.Pen.Style := psSolid;
    20042075    Canvas.Pen.Width := MetroLineThickness;
    2005     if TrackPoints.Count > 0 then Canvas.MoveTo(TTrackPoint(TrackPoints[0]).Position);
    2006     for S := 1 to TrackPoints.Count - 1 do begin
    2007       Canvas.LineTo(TTrackPoint(TrackPoints[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);
    20082079{      if (S = TrackPoints.Count - 1) then begin
    20092080        Canvas.Pen.EndCap := pecSquare;
     
    20392110  // Draw design time lines
    20402111  if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin
    2041     Canvas.Pen.Color := TrackStationDown.Line.Color;
     2112    Canvas.Pen.Color := TrackStationDown.Track.Line.Color;
    20422113    Canvas.MoveTo(TrackStationDown.LineStation.TrackPoint.Position);
    20432114    DrawLine(Canvas, View.PointDestToSrc(LastMousePos));
    20442115  end;
    20452116  if Assigned(TrackStationUp) and Assigned(TrackStationUp.LineStation) then begin
    2046     Canvas.Pen.Color := TrackStationUp.Line.Color;
     2117    Canvas.Pen.Color := TrackStationUp.Track.Line.Color;
    20472118    Canvas.MoveTo(TrackStationUp.LineStation.TrackPoint.Position);
    20482119    DrawLine(Canvas, View.PointDestToSrc(LastMousePos));
     
    21112182
    21122183  // Line selection
     2184  TargetCanvas.Pen.Width := 4;
    21132185  for I := 0 to High(LineColors) do begin
    21142186    if Assigned(Lines.SearchByColor(LineColors[I])) then begin
     
    21402212  // Status interface
    21412213  Text := IntToStr(ServedPassengerCount);
    2142   TargetCanvas.Draw(TargetCanvas.Width - 140, 20, ImagePassenger.Picture.Bitmap);
     2214  TargetCanvas.Draw(TargetCanvas.Width - 100, TargetCanvas.Height - 60, ImagePassenger.Picture.Bitmap);
    21432215  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);
    21452217
    21462218  DrawClock(TargetCanvas);
Note: See TracChangeset for help on using the changeset viewer.