-
Notifications
You must be signed in to change notification settings - Fork 0
/
DigIt_form_main.pas
2880 lines (2441 loc) · 79.5 KB
/
DigIt_form_main.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*******************************************************************************
** DigIt **
** **
** (s) 2024 Massimo Magnano **
** **
********************************************************************************
** Main Form **
*******************************************************************************)
unit DigIt_Form_Main;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtDlgs, ExtCtrls, Menus, ComCtrls,
ActnList, Spin, ShellCtrls, EditBtn,
Digit_Bridge_Intf, Digit_Bridge_Impl,
FPImage, BGRAImageManipulation, BGRABitmap, BGRABitmapTypes, BGRASpeedButton, BCPanel, BCLabel, BCListBox,
BGRAImageList, BCExpandPanels, Laz2_XMLCfg, SpinEx, BGRAPapers, DigIt_Types, DigIt_Utils, DigIt_Counters, LCLType;
resourcestring
rsContinue = 'Continue from last Work Session?';
rsNoFilesDownloaded = 'NO Files Downloaded ';
rsTakeAgain = 'Replace the last %d taked files with a new Take?';
rsNoMoreFiles = 'There are no more files to process, should I clear the Work Queue?';
rsMiddlePage = 'The page is within the already processed range'#13#10'Should I put it in the middle?';
rsProcessingImages = 'Processing Images';
rsProcessing = 'Processing %d / %s';
rsProcessed = 'Processed %d / %s';
rsClearQueue = 'Clear the Work Queue?';
rsExcCreateCounter = 'Failed to Create the Counter';
rsNotImpl = 'Not yet implemented';
rsSaveProject = 'Save Current Project?';
rsConvertPDF = 'Converting Images to PDF...';
rsClearCrops = 'Clear Crop Areas ?';
rsCropFull = 'Full Area';
rsCropCust = 'Custom';
rsCropToDo = '%d files to do';
rsCounterPrev = 'Value Previous: %d';
type
TSourceFile = packed record
fCrop: Boolean;
fName: String;
end;
TSourceFileArray = array of TSourceFile;
TCapturedFile = packed record
fAge: LongInt;
fName: String;
iIndex: Integer;
end;
TCapturedFileArray = array of TCapturedFile;
{ TDigIt_Main }
TDigIt_Main = class(TForm)
actCropGoBack: TAction;
actCropAll: TAction;
actCrop: TAction;
actClearQueue: TAction;
actCropGoNext: TAction;
actTakeBuildDuplex: TAction;
actTakeRe: TAction;
actTimerTake: TAction;
actProjectSaveAs: TAction;
actPreview: TAction;
actRotateRight: TAction;
actRotateLeft: TAction;
ActionListC: TActionList;
actOptions: TAction;
actProjectOpen: TAction;
actProjectSave: TAction;
actProjectNew: TAction;
actCropNext: TAction;
actTake: TAction;
ActionListMain: TActionList;
BCLabel1: TBCLabel;
BCLabel10: TBCLabel;
BCLabel11: TBCLabel;
BCLabel12: TBCLabel;
BCLabel13: TBCLabel;
BCLabel14: TBCLabel;
BCLabel2: TBCLabel;
BCLabel3: TBCLabel;
BCLabel4: TBCLabel;
BCLabel5: TBCLabel;
BCLabel6: TBCLabel;
BCLabel7: TBCLabel;
BCLabel8: TBCLabel;
imgListCaptured: TImageList;
itemTake: TMenuItem;
itemTakeAgain: TMenuItem;
itemBuildDuplex: TMenuItem;
panelTop: TPanel;
panelCounterList: TBCPanel;
btCounter_Add: TBGRASpeedButton;
btCounter_Del: TBGRASpeedButton;
btPFlipH: TSpeedButton;
btPRotateLeft: TSpeedButton;
btPRotateRight: TSpeedButton;
btPFlipV: TSpeedButton;
btPRotate180: TSpeedButton;
cbCounterList: TComboBox;
imgListImgActions: TImageList;
Label10: TLabel;
Label9: TLabel;
menuDestinations: TPopupMenu;
itemCropModeFull: TMenuItem;
itemCropModeCustom: TMenuItem;
panelPageRotate: TBCPanel;
btBox_Add: TBGRASpeedButton;
btBox_Del: TBGRASpeedButton;
btCFlipHLeft: TSpeedButton;
btCFlipHRight: TSpeedButton;
btCFlipVDown: TSpeedButton;
btCFlipVUp: TSpeedButton;
btCropCounter_Add: TBGRASpeedButton;
btCropCounter_Del: TBGRASpeedButton;
btCropDuplicate: TSpeedButton;
btCropDuplicateOp: TSpeedButton;
btCRotateLeft: TSpeedButton;
btCRotateRight: TSpeedButton;
btPageSizes: TSpeedButton;
btPageSizesToCrops: TSpeedButton;
btPaperSizes: TSpeedButton;
btZBack: TSpeedButton;
btZDown: TSpeedButton;
btZFront: TSpeedButton;
btZUp: TSpeedButton;
cbBoxList: TComboBox;
cbCropCounterList: TComboBox;
edCounterName: TEdit;
edCounterValue: TSpinEdit;
edCounterValueStringDigits: TSpinEdit;
edCounterValueStringPost: TEdit;
edCounterValueStringPre: TEdit;
edCropAspectPersonal: TEditButton;
edCropHeight: TFloatSpinEdit;
edCropLeft: TFloatSpinEdit;
edCropName: TEdit;
edCropTop: TFloatSpinEdit;
edCropUnit_Type: TComboBox;
edCropWidth: TFloatSpinEdit;
edPageHeight: TFloatSpinEdit;
edPageWidth: TFloatSpinEdit;
edPage_UnitType: TComboBox;
imgListMenu: TImageList;
imgListThumb: TBGRAImageList;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label7: TLabel;
Label8: TLabel;
imgManipulation: TBGRAImageManipulation;
imgListMain: TImageList;
lbCounterExample: TLabel;
lbPrevious: TLabel;
lvCaptured: TListView;
menuTimerTakeConfig: TMenuItem;
menuTimerTakeStop: TMenuItem;
menuOptions: TMenuItem;
OpenProject: TOpenDialog;
panelCounter: TBCPanel;
panelCropArea: TBCPanel;
menuPaperSizes: TPopupMenu;
menuSources: TPopupMenu;
panelPageSize: TBCPanel;
menuTimerTake: TPopupMenu;
menuCropMode: TPopupMenu;
menuTake: TPopupMenu;
rgCropAspect: TRadioGroup;
rollCounters: TBCExpandPanel;
rollCrops: TBCExpandPanel;
rollPages: TBCExpandPanel;
SaveProject: TSaveDialog;
Separator1: TMenuItem;
menuProjectOpen: TMenuItem;
menuProjectSave: TMenuItem;
menuProjectNew: TMenuItem;
OpenCropList: TOpenDialog;
OpenPicture: TOpenPictureDialog;
MenuMain: TPopupMenu;
SavePDF: TSaveDialog;
SavePicture: TSavePictureDialog;
SelectDirectory: TSelectDirectoryDialog;
tbCaptured: TToolBar;
tbCapturedRotateLeft: TToolButton;
tbCapturedPDF: TToolButton;
tbCapturedRotateRight: TToolButton;
tbCropAll: TToolButton;
tbCropMode: TToolButton;
tbCropNext: TToolButton;
tbCropPrev: TToolButton;
tbCropSummary: TToolButton;
tbDestination: TToolButton;
tbMain: TToolBar;
tbMenu: TToolButton;
tbPreview: TToolButton;
tbSepCrop: TToolButton;
tbSepMenu: TToolButton;
tbSepTake: TToolButton;
tbSource: TToolButton;
tbTake: TToolButton;
tbTakeAgain: TToolButton;
tbTimerTake: TToolButton;
tbCrop: TToolBar;
tbSepClear: TToolButton;
tbClearQueue: TToolButton;
ToolButton1: TToolButton;
procedure actOptionsExecute(Sender: TObject);
procedure actProjectNewExecute(Sender: TObject);
procedure actProjectOpenExecute(Sender: TObject);
procedure actProjectSaveAsExecute(Sender: TObject);
procedure actProjectSaveExecute(Sender: TObject);
procedure actRotateLeftExecute(Sender: TObject);
procedure actRotateRightExecute(Sender: TObject);
procedure actPreviewExecute(Sender: TObject);
procedure actTakeReExecute(Sender: TObject);
procedure actTakeExecute(Sender: TObject);
procedure actTimerTakeExecute(Sender: TObject);
procedure actCropNextExecute(Sender: TObject);
procedure actCropGoNextExecute(Sender: TObject);
procedure actCropGoBackExecute(Sender: TObject);
procedure actCropAllExecute(Sender: TObject);
procedure actClearQueueExecute(Sender: TObject);
procedure btCFlipHLeftClick(Sender: TObject);
procedure btCFlipHRightClick(Sender: TObject);
procedure btCFlipVDownClick(Sender: TObject);
procedure btCFlipVUpClick(Sender: TObject);
procedure btCropDuplicateClick(Sender: TObject);
procedure btCRotateLeftClick(Sender: TObject);
procedure btCRotateRightClick(Sender: TObject);
procedure btPageSizesClick(Sender: TObject);
procedure btPageSizesToCropsClick(Sender: TObject);
procedure btPaperSizesClick(Sender: TObject);
procedure btZBackClick(Sender: TObject);
procedure btZDownClick(Sender: TObject);
procedure btZFrontClick(Sender: TObject);
procedure btZUpClick(Sender: TObject);
procedure cbCounterListChange(Sender: TObject);
procedure btCounter_AddClick(Sender: TObject);
procedure btCounter_DelClick(Sender: TObject);
procedure cbCropCounterListChange(Sender: TObject);
procedure btCropCounter_AddClick(Sender: TObject);
procedure btCropCounter_DelClick(Sender: TObject);
procedure edPageHeightChange(Sender: TObject);
procedure edPageWidthChange(Sender: TObject);
procedure edPage_UnitTypeChange(Sender: TObject);
procedure itemCropModeClick(Sender: TObject);
procedure lvCapturedDblClick(Sender: TObject);
procedure lvCapturedShowHint(Sender: TObject; HintInfo: PHintInfo);
procedure edCounterNameEditingDone(Sender: TObject);
procedure edCounterValueChange(Sender: TObject);
procedure edCounterValueStringDigitsChange(Sender: TObject);
procedure edCounterValueStringPreEditingDone(Sender: TObject);
procedure edCounterValueStringPostEditingDone(Sender: TObject);
procedure edCropNameEditingDone(Sender: TObject);
procedure edCropUnit_TypeChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure edNameChange(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure btBox_AddClick(Sender: TObject);
procedure btBox_DelClick(Sender: TObject);
procedure cbBoxListChange(Sender: TObject);
procedure edCropHeightChange(Sender: TObject);
procedure edCropLeftChange(Sender: TObject);
procedure edCropTopChange(Sender: TObject);
procedure edCropWidthChange(Sender: TObject);
procedure rgCropAspectSelectionChanged(Sender: TObject);
procedure btCropApplyAspectRatioClick(Sender: TObject);
procedure AddedCrop(Sender: TBGRAImageManipulation; CropArea: TCropArea);
procedure DeletedCrop(Sender: TBGRAImageManipulation; CropArea: TCropArea);
procedure ChangedCrop(Sender: TBGRAImageManipulation; CropArea: TCropArea);
procedure SelectedChangedCrop(Sender: TBGRAImageManipulation; CropArea: TCropArea);
procedure tbWorkSaveClick(Sender: TObject);
procedure TestClick(Sender: TObject);
procedure TestRClick(Sender: TObject);
procedure tbCapturedPDFClick(Sender: TObject);
private
{ private declarations }
lastNewBoxNum: Word;
changingAspect,
Closing,
XML_Loading,
inFillCounterUI,
inFillBoxUI,
inFillPagesUI,
imgListThumb_Changed,
UserCancel: Boolean;
Counters: TDigIt_CounterList;
XMLWork,
XMLProject: TXMLConfig;
rSource: PSourceInfo;
rSourceName: String;
rSourceParams: IDigIt_Params;
{ #note -oMaxM : Not enabled for now until I figure out how to pass the image data and make the thumbnails }
(* rDestination: PDestinationInfo;
rDestinationParams: IDigIt_Params;
*)
rDestinationName: String;
CropMode: TDigItCropMode;
SaveExt,
SavePath,
rProject_File,
LoadedFile: String;
testI,
lastCropped,
lastLenTaked, //Used in Take Again
iSourceFiles,
iCapturedFiles: Integer;
SourceFiles: TSourceFileArray;
CapturedFiles: TCapturedFileArray; { #todo 10 -oMaxM : Use this array and not ListItems }
function GetCurrentCropArea: TCropArea;
function Counters_GetCurrent: TDigIt_Counter;
procedure Counters_Dec;
procedure Counters_Inc;
procedure UI_FillBox(ABox :TCropArea);
procedure UI_FillCounter(ACounter :TDigIt_Counter);
procedure UI_FillCounters;
procedure UI_FillPageSizes;
procedure UI_ToolBar;
procedure UI_ToolBarMods;
procedure UI_MenuItemsChecks(newSourceI, newDestinationI: Integer);
procedure UI_ThumbnailUpdate(AIndex: Integer; AFileName: String); overload;
procedure UI_ThumbnailUpdate(AIndex: Integer; ABitmap: TBGRABitmap); overload;
procedure DestinationMenuClick(Sender: TObject);
procedure SourceMenuClick(Sender: TObject);
procedure SaveCallBack(Bitmap :TBGRABitmap; CropArea: TCropArea; AUserData:Integer);
procedure UpdateBoxList;
procedure UpdateCropAreaCountersList(ACounter :TDigIt_Counter);
procedure CounterSelect(AIndex:Integer);
function LoadImage(AImageFile: String): Boolean;
procedure XML_LoadWork;
procedure XML_SaveWork;
procedure XML_LoadCapturedFiles;
procedure XML_SaveCapturedFile;
procedure XML_LoadProject(AFileName:String);
procedure XML_SaveProject(AFileName:String);
procedure XML_LoadPageSettings;
procedure XML_SavePageSettings;
procedure Default_Work;
function Source_Select(newSourceIndex: Integer): Boolean;
function Destination_Select(newDestinationIndex: Integer): Boolean;
procedure setProject_File(AValue: String);
procedure setCropMode(ANewCropMode: TDigItCropMode);
// function WaitForAFile(AFileName: String; ATimeOut: Integer): Boolean;
function SourceFiles_Add(AArray: IDigIt_ROArray): Integer; overload;
function SourceFiles_Add(AFileName: String): Integer; overload;
function CropFile_Full(AFileName: String): Boolean; overload;
procedure CropFile_Full(AStartIndex: Integer); overload;
procedure ProgressImagesShow(TotalMin, TotalMax: Integer);
procedure Pages_InsertMiddle(ASourceFileIndex: Integer);
property Project_File:String read rProject_File write setProject_File;
public
procedure ItemSizesClick(Sender: TObject);
procedure PageSizesClick(Sender: TObject);
property Source: PSourceInfo read rSource;
property SourceName: String read rSourceName;
property SourceParams: IDigIt_Params read rSourceParams;
(*
property Destination: PDestinationInfo read rDestination;
property DestinationParams: IDigIt_Params read rDestinationParams;
*)
property DestinationName: String read rDestinationName;
end;
var
DigIt_Main: TDigIt_Main;
implementation
{$R *.lfm}
uses
{$ifopt D+}
lazlogger,
{$endif}
LCLIntf, LCLProc, fppdf,
Digit_Destinations, DigIt_Form_Progress, DigIt_Form_Templates, DigIt_Form_BuildDuplex;
{ TDigIt_Main }
procedure TDigIt_Main.edCounterNameEditingDone(Sender: TObject);
var
curCounter :TDigIt_Counter;
begin
curCounter :=Counters_GetCurrent;
if (curCounter<>nil) then
begin
curCounter.Name :=edCounterName.Text;
UpdateCropAreaCountersList(curCounter);
end;
end;
procedure TDigIt_Main.edCounterValueChange(Sender: TObject);
var
curCounter :TDigIt_Counter;
begin
if inFillCounterUI then exit;
curCounter :=Counters_GetCurrent;
if (curCounter<>nil) then
begin
curCounter.Value_Next :=edCounterValue.Value;
lbCounterExample.Caption:=curCounter.GetValue(True);
end;
end;
procedure TDigIt_Main.edCounterValueStringDigitsChange(Sender: TObject);
var
curCounter :TDigIt_Counter;
begin
if inFillCounterUI then exit;
curCounter :=Counters_GetCurrent;
if (curCounter<>nil) then
begin
curCounter.Value_StringDigits :=edCounterValueStringDigits.Value;
lbCounterExample.Caption:=curCounter.GetValue(True);
end;
end;
procedure TDigIt_Main.edCounterValueStringPreEditingDone(Sender: TObject);
var
curCounter :TDigIt_Counter;
begin
curCounter :=Counters_GetCurrent;
if (curCounter<>nil) then
begin
curCounter.Value_StringPre :=edCounterValueStringPre.Text;
lbCounterExample.Caption:=curCounter.GetValue(True);
end;
end;
procedure TDigIt_Main.edCounterValueStringPostEditingDone(Sender: TObject);
var
curCounter :TDigIt_Counter;
begin
curCounter :=Counters_GetCurrent;
if (curCounter<>nil) then
begin
curCounter.Value_StringPost :=edCounterValueStringPost.Text;
lbCounterExample.Caption:=curCounter.GetValue(True);
end;
end;
procedure TDigIt_Main.edCropNameEditingDone(Sender: TObject);
var
CropArea :TCropArea;
begin
CropArea :=GetCurrentCropArea;
if CropArea<>nil
then CropArea.Name :=edCropName.Text;
end;
procedure TDigIt_Main.edCropUnit_TypeChange(Sender: TObject);
var
CropArea :TCropArea;
begin
CropArea :=GetCurrentCropArea;
if CropArea<>nil then
begin
CropArea.AreaUnit:=TResolutionUnit(edCropUnit_Type.ItemIndex);
UI_FillBox(CropArea);
end;
end;
procedure TDigIt_Main.FormCreate(Sender: TObject);
var
i :Integer;
begin
XMLWork:=nil;
XMLProject:=nil;
Project_File:='';
LoadedFile:='';
Counters :=TDigIt_CounterList.Create('Counters');
Closing :=False;
XML_Loading:= False;
changingAspect :=False;
inFillCounterUI :=False;
inFillBoxUI :=False;
inFillPagesUI :=False;
imgListThumb_Changed:= False;
lastNewBoxNum :=0;
TStringList(cbBoxList.Items).OwnsObjects:=False;
TStringList(cbCounterList.Items).OwnsObjects:=False;
rSource:= nil;
rSourceName:= '';;
rSourceParams:= nil;
SourceFiles:= nil;
iSourceFiles:= -1;
iCapturedFiles:= -1;
lastCropped:= -1;
lastLenTaked:= 0;
BuildSourcesMenu(Self, menuSources, @SourceMenuClick);
// rDestination:= nil;
// rDestinationParams:= nil;
rDestinationName:= '';
BuildDestinationsMenu(Self, menuDestinations, @DestinationMenuClick);
CropMode:= diCropNull; //setCropMode works only if there are changes
{$ifopt D+}
{$endif}
end;
procedure TDigIt_Main.FormDestroy(Sender: TObject);
begin
XML_SaveWork;
if (XMLProject<>nil) then XMLProject.Free;
Counters.Free;
theBridge.Free;
SourceFiles:= nil;
end;
procedure TDigIt_Main.FormShow(Sender: TObject);
var
i:Integer;
begin
UI_ToolBarMods;
if FileExists(Path_Config+Config_XMLWork)
{$ifopt D-}
and (MessageDlg('DigIt', rsContinue, mtConfirmation, [mbYes, mbNo], 0)=mrYes)
{$endif}
then begin
XML_LoadWork;
(* {$ifopt D-}
actPreview.Execute;
{$endif} *)
end
else begin
Default_Work;
UI_MenuItemsChecks(-1, -1);
end;
//Crop Areas are done when adding it
UI_FillCounters;
UI_FillCounter(Counters_GetCurrent);
UI_ToolBar;
end;
procedure TDigIt_Main.actPreviewExecute(Sender: TObject);
var
curData: Pointer;
curDataType: TDigItDataType;
res: Integer;
curImageFile: PChar;
begin
try
curData:= nil;
res:= rSource^.Inst.Take(takeActPreview, curDataType, curData);
if (res > 0) and (curData <> nil) then
begin
if (curDataType = diDataType_FileName) then
begin
if (res = 1)
then curImageFile:= PChar(curData)
else if (res > 1)
then if not(IDigIt_ROArray(curData).Get(0, curImageFile))
then curImageFile:= '';
if (curImageFile <> '') then
begin
LoadImage(curImageFile);
StrDispose(curImageFile);
XML_SaveWork;
end;
end;
end
else MessageDlg(rsNoFilesDownloaded, mtError, [mbOk], 0);
UI_ToolBar;
finally
end;
end;
procedure TDigIt_Main.actTakeReExecute(Sender: TObject);
var
lenSources: Integer;
begin
if (SourceFiles <> nil) and
(MessageDlg('DigIt', Format(rsTakeAgain, [lastLenTaked]),
mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
begin
lenSources:= Length(SourceFiles);
if ((lenSources - lastLenTaked) > 0)
then SetLength(SourceFiles, lenSources-lastLenTaked)
else SourceFiles:= nil;
lastLenTaked:= 0;
actTake.Execute;
end;
end;
procedure TDigIt_Main.actTakeExecute(Sender: TObject);
var
curData: Pointer;
curDataType: TDigItDataType;
res, i,
oldLength: Integer;
curImageFile: PChar;
curArray: IDigIt_ROArray;
begin
try
UserCancel:= False;
curData:= nil;
res:= 0;
if (Sender = actTake)
then res:= rSource^.Inst.Take(takeActTake, curDataType, curData)
else
if (Sender = actTakeBuildDuplex)
then res:= WizardBuildDuplexExecute(curDataType, curData);
if (res > 0) and (curData <> nil) then
begin
if (curDataType = diDataType_FileName) then
begin
if (res = 1)
then curImageFile:= PChar(curData)
else if (res > 1) then curArray:= IDigIt_ROArray(curData);
Case CropMode of
diCropFull: begin
ProgressImagesShow(1, res);
if (res = 1 )
then begin
CropFile_Full(curImageFile);
StrDispose(curImageFile);
end
else begin
//Add files to the array instead of processing them directly,
//so if the user closes the application before the end when he reopens it we restart
SourceFiles_Add(curArray);
{ #todo 5 -oMaxM : Check User Cancel the Operation }
CropFile_Full(0);
end;
SourceFiles:= nil; iSourceFiles:= -1;
rSource^.Inst.Clear;
UI_ToolBar;
end;
diCropCustom: begin
//Add files to the queue array
oldLength:= Length(SourceFiles);
if (res = 1 )
then begin
SourceFiles_Add(curImageFile);
StrDispose(curImageFile);
end
else SourceFiles_Add(curArray);
//The queue was empty, Start from the first file
if (oldLength = 0) and (Length(SourceFiles) > 0) then
begin
iSourceFiles:= 0;
LoadImage(SourceFiles[0].fName);
end;
UI_ToolBar;
(*
//Crop directly the first File,
// I don't use iSourceFiles because the user could be here having done Next and then Prev
if (oldLength = 0) and (Length(SourceFiles) > 0) then
begin
if LoadImage(SourceFiles[0]) then actCropNext.Execute;
end;
*)
end;
end;
Application.ProcessMessages;
XML_SaveWork;
end;
UI_FillCounter(nil);
end
else MessageDlg(rsNoFilesDownloaded, mtError, [mbOk], 0);
finally
DigIt_Progress.Hide;
FreeAndNil(WizardBuildDuplex);
UserCancel:= False;
end;
end;
procedure TDigIt_Main.actTimerTakeExecute(Sender: TObject);
begin
//
end;
procedure TDigIt_Main.actCropNextExecute(Sender: TObject);
var
lenSources: Integer;
function CheckEndOfFiles: Boolean;
begin
Result:= (iSourceFiles >= lenSources);
if Result and (lenSources > 1) then
begin
//User Confirmation
if (MessageDlg('DigIt', rsNoMoreFiles, mtConfirmation,
[mbYes, mbNo], 0) = mrYes)
then begin
iSourceFiles:= -1;
SourceFiles:= nil;
rSource^.Inst.Clear;
end;
end;
end;
begin
try
lenSources:= Length(SourceFiles);
if (iSourceFiles = -1) then iSourceFiles:= 0;
if (iSourceFiles = lenSources)
then begin
//We've already cut the last one, Re Crop the Last File, dec the Counters first
Counters_Dec;
imgManipulation.getAllBitmaps(@SaveCallBack, 1, True);
end
else begin
if SourceFiles[iSourceFiles].fCrop
then imgManipulation.getAllBitmaps(@SaveCallBack, 1, True) //Re Crop, Counters is already decremented by GoBack
else begin //(lastCropped < iSourceFiles)
if (lastCropped > iSourceFiles) then
begin
if (MessageDlg('DigIt', rsMiddlePage, mtConfirmation, [mbYes, mbCancel], 0) = mrCancel)
then exit
else begin Pages_InsertMiddle(iSourceFiles); exit; end;
end;
imgManipulation.getAllBitmaps(@SaveCallBack, 0, True);
SourceFiles[iSourceFiles].fCrop:= True;
if (iSourceFiles > lastCropped) then lastCropped:= iSourceFiles;
end;
inc(iSourceFiles);
end;
if not(CheckEndOfFiles)
then if (iSourceFiles > -1) and (iSourceFiles < Length(SourceFiles))
then if not(LoadImage(SourceFiles[iSourceFiles].fName))
then begin
{ #todo -oMaxM : do something if LoadImage Fails? }
end;
lvCaptured.Selected:= lvCaptured.Items[iCapturedFiles];
UI_FillCounter(nil);
UI_ToolBar;
XML_SaveWork;
finally
end;
end;
procedure TDigIt_Main.actCropGoNextExecute(Sender: TObject);
var
new_iSourceFiles: Integer;
begin
try
new_iSourceFiles:= iSourceFiles;
if (new_iSourceFiles >= 0) and (new_iSourceFiles < Length(SourceFiles)-1) then
begin
inc(new_iSourceFiles);
if LoadImage(SourceFiles[new_iSourceFiles].fName) then
begin
if SourceFiles[new_iSourceFiles].fCrop then Counters_Inc;
iSourceFiles:= new_iSourceFiles;
lvCaptured.Selected:= lvCaptured.Items[iCapturedFiles];
UI_FillCounter(nil);
UI_ToolBar;
XML_SaveWork;
end;
end;
finally
end;
end;
procedure TDigIt_Main.actCropGoBackExecute(Sender: TObject);
var
new_iSourceFiles: Integer;
begin
try
new_iSourceFiles:= iSourceFiles;
if (new_iSourceFiles > 0) then
begin
//We've already cut the last one, start with the penultimate one
if (new_iSourceFiles >= Length(SourceFiles)) then
begin
new_iSourceFiles:= Length(SourceFiles)-1;
Counters_Dec;
end;
dec(new_iSourceFiles);
if LoadImage(SourceFiles[new_iSourceFiles].fName) then
begin
if SourceFiles[new_iSourceFiles].fCrop then Counters_Dec;
iSourceFiles:= new_iSourceFiles;
lvCaptured.Selected:= lvCaptured.Items[iCapturedFiles];
UI_FillCounter(nil);
UI_ToolBar;
XML_SaveWork;
end;
end;
finally
end;
end;
procedure TDigIt_Main.actCropAllExecute(Sender: TObject);
var
i: Integer;
c: Integer;
cStr: String;
Finished: Boolean;
function CheckEndOfFiles: Boolean;
begin
Result:= (iSourceFiles >= Length(SourceFiles));
if Result then
begin
//User Confirmation
if (MessageDlg('DigIt', rsNoMoreFiles, mtConfirmation, [mbYes, mbNo], 0) = mrYes)
then begin
iSourceFiles:= -1;
SourceFiles:= nil;
rSource^.Inst.Clear;
end;
end;
end;
begin
try
UserCancel:= False;
Finished:= False;
c:= Length(SourceFiles);
cStr:= IntToStr(c);
ProgressImagesShow(iSourceFiles, c);
repeat
DigIt_Progress.progressTotal.Position:= iSourceFiles;
DigIt_Progress.capTotal.Caption:= Format(rsProcessing, [iSourceFiles, cStr]);
Application.ProcessMessages;
imgManipulation.getAllBitmaps(@SaveCallBack, 0, True);
SourceFiles[iSourceFiles].fCrop:= True;
inc(iSourceFiles);
Finished:= CheckEndOfFiles;
if not(Finished)
then if not(LoadImage(SourceFiles[iSourceFiles].fName))
then begin
{ #todo -oMaxM : do something if LoadImage Fails? }
UserCancel:= True;
end;
lvCaptured.Selected:= lvCaptured.Items[iCapturedFiles];
UI_FillCounter(nil);
UI_ToolBar;
XML_SaveWork;
DigIt_Progress.progressTotal.Position:= iSourceFiles+1;
DigIt_Progress.capTotal.Caption:= Format(rsProcessed, [iSourceFiles-1, cStr]);
Application.ProcessMessages;
Until Finished or UserCancel;
finally
DigIt_Progress.Hide;
UserCancel:= False;
end;
end;
procedure TDigIt_Main.actClearQueueExecute(Sender: TObject);
begin
if (MessageDlg('DigIt', rsClearQueue, mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
begin
iSourceFiles:= -1;
lastCropped:= -1;
lastLenTaked:= 0;
SourceFiles:= nil;
rSource^.Inst.Clear;
UI_ToolBar;
XML_SaveWork;
end;
end;
procedure TDigIt_Main.btCRotateLeftClick(Sender: TObject);
var
CropArea :TCropArea;
begin
CropArea :=GetCurrentCropArea;
if CropArea<>nil then
begin
if btCropDuplicateOp.Down then
begin
CropArea :=TCropArea.Create(imgManipulation, CropArea, True);
imgManipulation.SelectedCropArea :=CropArea;
end;
CropArea.RotateLeft;
end;
end;
procedure TDigIt_Main.btCFlipVDownClick(Sender: TObject);
var
CropArea :TCropArea;
begin
CropArea :=GetCurrentCropArea;
if CropArea<>nil then
begin
if btCropDuplicateOp.Down then
begin
CropArea :=TCropArea.Create(imgManipulation, CropArea, True);
imgManipulation.SelectedCropArea :=CropArea;
end;
CropArea.FlipVDown;
end;
end;
procedure TDigIt_Main.btCFlipHLeftClick(Sender: TObject);
var
CropArea :TCropArea;
begin
CropArea :=GetCurrentCropArea;
if CropArea<>nil then
begin
if btCropDuplicateOp.Down then
begin
CropArea :=TCropArea.Create(imgManipulation, CropArea, True);
imgManipulation.SelectedCropArea :=CropArea;
end;