Skip to content

Commit

Permalink
refactore: code reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
kfilippenok committed Dec 20, 2024
1 parent d2879ad commit 8cc48bf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
20 changes: 1 addition & 19 deletions src/TilesDownload/TilesDownload.Exceptions.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
interface

uses
Classes, SysUtils, TilesDownload.Types;
Classes, SysUtils;

type

EMissingOptions = class(Exception)
constructor Create(AOptions: TOptions); overload;
end;

EUnknownIdentProvider = class(Exception);

ETileDownload = class(Exception);
Expand All @@ -39,19 +35,5 @@ ETDSave = class(ETileDownload);

implementation

constructor EMissingOptions.Create(AOptions: TOptions);
var LMsg: String;
LOption: TOptionKind;
begin
LMsg := 'Options: ';
for LOption in AOptions do
begin
LMsg := LMsg + Format('-%s ', [getOptionName(LOption)]);
end;
LMsg := LMsg + 'are missing';

inherited Create(LMsg);
end;

end.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License. }

unit TilesManipulations.Core;
unit TilesManipulations;

{$mode ObjFPC}{$H+}{$MODESWITCH ADVANCEDRECORDS}

Expand Down Expand Up @@ -153,7 +153,7 @@ TLayer = class
FProvider: IProvider;
FBGRABitmap: TBGRABitmap;
public
constructor Create(AProvider: IProvider; AFilter: IFilter); virtual; reintroduce;
constructor Create(AProvider: IProvider); virtual; reintroduce;
destructor Destroy; override;
public
procedure Load(const AZoom: Integer; const AX, AY: Integer);
Expand All @@ -169,7 +169,7 @@ TLayer = class

TLayers = class(_TLayers)
public
function Add(AProvider: IProvider; AFilter: IFilter): Integer; virtual; reintroduce;
function Add(AProvider: IProvider): Integer; virtual; reintroduce;
procedure Load(const AZoom: Integer; const AX, AY: Integer); virtual;
end;

Expand Down Expand Up @@ -498,12 +498,12 @@ function TProviders.Add(AKey: String; AName, AURL: String): Integer;

{ TLayer }

constructor TLayer.Create(AProvider: IProvider; AFilter: IFilter);
constructor TLayer.Create(AProvider: IProvider);
begin
inherited Create;

FProvider := AProvider;
FFilter := AFilter;
FFilter := nil;
end;

destructor TLayer.Destroy;
Expand All @@ -515,14 +515,16 @@ destructor TLayer.Destroy;

procedure TLayer.Load(const AZoom: Integer; const AX, AY: Integer);
begin
BGRABitmap := Provider.GiveTile(AZoom, AX, AY);
FBGRABitmap := Provider.GiveTile(AZoom, AX, AY);
if Assigned(Filter) then
Filter.Transform(FBGRABitmap);
end;

{ TLayers }

function TLayers.Add(AProvider: IProvider; AFilter: IFilter): Integer;
function TLayers.Add(AProvider: IProvider): Integer;
begin
Result := inherited Add(Tlayer.Create(AProvider, AFilter));
Result := inherited Add(Tlayer.Create(AProvider));
end;

procedure TLayers.Load(const AZoom: Integer; const AX, AY: Integer);
Expand Down
4 changes: 2 additions & 2 deletions src/tilesdownloader.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="TilesManipulations/TilesManipulations.Core.pas"/>
<Filename Value="TilesDownloader/TilesDownloader.Options.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="TilesDownloader/TilesDownloader.Options.pas"/>
<Filename Value="TilesManipulations/TilesManipulations.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
Expand Down
5 changes: 2 additions & 3 deletions src/tilesdownloader.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
{$IFDEF WINDOWS}
Interfaces, // For BGRABitmap
{$ENDIF}
SysUtils, Classes, CustApp,
TilesManipulations.Core;
SysUtils, Classes, CustApp, TilesManipulations;

var
//OptionParameter: array[TOptionKind] of String;
Expand Down Expand Up @@ -62,7 +61,7 @@ ATilesDownloader = class(TCustomApplication)
TilesManipulator: TTilesManipulator;
begin
TilesManipulator := TTilesManipulator.Create;
TilesManipulator.Layers.Add(Providers['osm-standard'], TFilterGrayscale.Create);
TilesManipulator.Layers.Add(Providers['osm-standard']);
//TilesManipulator.Layers.Load(0, 0, 0);
//TilesManipulator.Download(1, 1);

Expand Down

0 comments on commit 8cc48bf

Please sign in to comment.