From 8cc48bf240d9d1b34a2066fdf4b585a350523605 Mon Sep 17 00:00:00 2001 From: kfilippenok Date: Fri, 20 Dec 2024 17:54:46 +0500 Subject: [PATCH] refactore: code reorganization --- .../TilesDownload.Exceptions.pas | 20 +------------------ ...ations.Core.pas => TilesManipulations.pas} | 18 +++++++++-------- src/tilesdownloader.lpi | 4 ++-- src/tilesdownloader.lpr | 5 ++--- 4 files changed, 15 insertions(+), 32 deletions(-) rename src/TilesManipulations/{TilesManipulations.Core.pas => TilesManipulations.pas} (98%) diff --git a/src/TilesDownload/TilesDownload.Exceptions.pas b/src/TilesDownload/TilesDownload.Exceptions.pas index e53893c..c854c7e 100644 --- a/src/TilesDownload/TilesDownload.Exceptions.pas +++ b/src/TilesDownload/TilesDownload.Exceptions.pas @@ -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); @@ -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. diff --git a/src/TilesManipulations/TilesManipulations.Core.pas b/src/TilesManipulations/TilesManipulations.pas similarity index 98% rename from src/TilesManipulations/TilesManipulations.Core.pas rename to src/TilesManipulations/TilesManipulations.pas index 6bf8a2a..dc591b3 100644 --- a/src/TilesManipulations/TilesManipulations.Core.pas +++ b/src/TilesManipulations/TilesManipulations.pas @@ -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} @@ -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); @@ -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; @@ -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; @@ -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); diff --git a/src/tilesdownloader.lpi b/src/tilesdownloader.lpi index ef535b6..0f4a388 100644 --- a/src/tilesdownloader.lpi +++ b/src/tilesdownloader.lpi @@ -106,11 +106,11 @@ - + - + diff --git a/src/tilesdownloader.lpr b/src/tilesdownloader.lpr index d3729d9..50423a2 100644 --- a/src/tilesdownloader.lpr +++ b/src/tilesdownloader.lpr @@ -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; @@ -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);