-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main1.pas
741 lines (667 loc) · 20.8 KB
/
Main1.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
//Copyright (c) 2012 by Donald R. Ziesig
//
//Donald.at.Ziesig.org
//
//This file is part of MagicTracks.
//
//MagicTracks is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//MagicTracks is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with MagicTracks. If not, see <http://www.gnu.org/licenses/>.
unit Main1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
ActnList, ComCtrls, ExtCtrls, StdCtrls, PrintersDlgs, types, Drawing1,
Preferences1, DrawingSetFrame1, Layers1;
type
{ TMainForm }
TMainForm = class(TForm)
FilePageSetup: TAction;
GuidesToLine: TAction;
GuidesToRectangularSolid: TAction;
GuidesToSphere: TAction;
FileSaveAll: TAction;
HelpShowInternals: TAction;
IdleTimer1: TIdleTimer;
MenuItem31: TMenuItem;
MenuItem32: TMenuItem;
MenuItem33: TMenuItem;
MenuItem34: TMenuItem;
MenuItem35: TMenuItem;
MenuItem36: TMenuItem;
GuidesStraightLine: TMenuItem;
MenuItem37: TMenuItem;
MenuItem38: TMenuItem;
PageSetupDialog1: TPageSetupDialog;
PrintDialog1: TPrintDialog;
PrinterSetupDialog1: TPrinterSetupDialog;
VisibleLayerPanel: TPanel;
ActiveLayerPanel: TPanel;
ToolButton19: TToolButton;
ToolsLayerDefaults: TAction;
LayersEdit: TAction;
DrawingSetFrame1: TDrawingSetFrame;
MenuItem29: TMenuItem;
MenuItem30: TMenuItem;
PositionLowerLeft: TAction;
MenuItem23: TMenuItem;
MenuItem27: TMenuItem;
MenuItem28: TMenuItem;
ToolButton14: TToolButton;
ToolsShowGrid: TAction;
MenuItem25: TMenuItem;
MenuItem26: TMenuItem;
MIZoom1: TMenuItem;
MIZoom2: TMenuItem;
MIzoom3: TMenuItem;
MIZoom4: TMenuItem;
MIZoom5: TMenuItem;
MIZoom6: TMenuItem;
MIZoom7: TMenuItem;
MIZoom8: TMenuItem;
MIZoom9: TMenuItem;
MIZoom10: TMenuItem;
MIZoom12: TMenuItem;
MIZoom15: TMenuItem;
MIZoom20: TMenuItem;
MIZoom25: TMenuItem;
MIZoom30: TMenuItem;
MIZoom40: TMenuItem;
MIZoom50: TMenuItem;
MIZoom60: TMenuItem;
MIZoom70: TMenuItem;
MIZoom80: TMenuItem;
StatusBar2: TStatusBar;
ZoomOut1: TMenuItem;
ZoomIn1: TMenuItem;
ToolButton16: TToolButton;
ToolButton17: TToolButton;
ToolButton18: TToolButton;
ViewZoomOut: TAction;
ViewZoomIn: TAction;
MenuItem24: TMenuItem;
ToolsSnapToGrid: TAction;
ToolButton13: TToolButton;
ToolButton15: TToolButton;
ToolsPreferencesCurrentDrawing: TAction;
ToolsPreferencesNewDrawing: TAction;
HelpAbout: TAction;
FileClose: TAction;
FilePrint: TAction;
FilePrintSetup: TAction;
EditPaste: TAction;
EditCut: TAction;
EditCopy: TAction;
EditUndo: TAction;
FileExit: TAction;
FileSaveAs: TAction;
FileSave: TAction;
FileOpen: TAction;
FileNew: TAction;
ActionList1: TActionList;
ImageList1: TImageList;
MainMenu1: TMainMenu;
MenuItem1: TMenuItem;
MenuItem10: TMenuItem;
MenuItem11: TMenuItem;
MenuItem12: TMenuItem;
MenuItem13: TMenuItem;
MenuItem14: TMenuItem;
MenuItem15: TMenuItem;
MenuItem16: TMenuItem;
MenuItem17: TMenuItem;
MenuItem18: TMenuItem;
MenuItem19: TMenuItem;
MenuItem2: TMenuItem;
MenuItem20: TMenuItem;
MenuItem21: TMenuItem;
MenuItem22: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
MenuItem8: TMenuItem;
MenuItem9: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
StatusBar1: TStatusBar;
TabControl1: TTabControl;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
ToolButton12: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
procedure FileCloseExecute(Sender: TObject);
procedure FileExitExecute(Sender: TObject);
procedure FileNewExecute(Sender: TObject);
procedure FileOpenExecute(Sender: TObject);
procedure FilePageSetupExecute(Sender: TObject);
procedure FilePrintExecute(Sender: TObject);
procedure FilePrintSetupExecute(Sender: TObject);
procedure FileSaveAllExecute(Sender: TObject);
procedure FileSaveAsExecute(Sender: TObject);
procedure FileSaveExecute(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure GuidesToLineExecute(Sender: TObject);
procedure GuidesToRectangularSolidExecute(Sender: TObject);
procedure GuidesToSphereExecute(Sender: TObject);
procedure HelpAboutExecute(Sender: TObject);
procedure HelpShowInternalsExecute(Sender: TObject);
procedure IdleTimer1Timer(Sender: TObject);
procedure LayersEditExecute(Sender: TObject);
procedure MIZoom1Click(Sender: TObject);
procedure PositionLowerLeftExecute(Sender: TObject);
procedure ToolsLayerDefaultsExecute(Sender: TObject);
procedure ToolsObjectsSnapToGuidesExecute(Sender: TObject);
procedure ToolsShowGridExecute(Sender: TObject);
procedure ViewZoomInExecute(Sender: TObject);
procedure ViewZoomOutExecute(Sender: TObject);
procedure TabControl1Change(Sender: TObject);
procedure ToolsPreferencesCurrentDrawingExecute(Sender: TObject);
procedure ToolsPreferencesNewDrawingExecute(Sender: TObject);
procedure ToolsSnapToGridExecute(Sender: TObject);
private
{ private declarations }
NewCount : Integer;
{
Note: Drawings as TList is a work-around for the incomplete
implementation of Object access in the Lazarus TTabControl
}
Drawings : TList;
fActiveDrawing : TDrawing;
fConfigFileName : String;
fDefaultPreferences : TPreferences;
fDefaultLayers : TLayers;
MIZooms : array[0..MaxZoom] of TMenuItem;
procedure InitFromConfig( ConfigFileName : String );
procedure InitToConfig( ConfigFileName : String );
procedure SetActiveDrawing( Value : TDrawing );
public
{ public declarations }
property ConfigFileName : String read fConfigFileName;
property ActiveDrawing : TDrawing read fActiveDrawing write SetActiveDrawing;
property DefaultPreferences : TPreferences read fDefaultPreferences;
property DefaultLayers : TLayers read fDefaultLayers;
end;
var
MainForm: TMainForm;
implementation
{$R *.lfm}
uses
About1, PreferencesForm1, LayerForm1, Internals1, Sphere1, DrawingObject1,
RectangularSolid1, ThreePoint1, StraightLine1, IniFiles, ObjectFactory1;
{ TMainForm }
procedure TMainForm.FileCloseExecute(Sender: TObject);
var
Index : Integer;
Drawing : TDrawing;
Ans : Integer;
CloseIt : Boolean;
begin
Index := TabControl1.TabIndex;
if Index >= 0 then
begin
Drawing := TDrawing(Drawings[Index]);
CloseIt := true;
{ Check for modified Drawing, get user's permission to close if changed. }
if Drawing.Modified then
begin
Ans := MessageDlg('Drawing ' + Drawing.NameOnly + ' has been modified.'#10#13+
'Close without saving (all changes will be lost)?',
mtConfirmation,[mbNo, mbYes], 0);
CloseIt := Ans = mrYes;
end;
if CloseIt then
begin
TDrawing(Drawings[Index]).Free;
Drawings.Delete(Index);
TabControl1.Tabs.Delete(Index);
Index := TabControl1.TabIndex;
if Index >= 0 then
ActiveDrawing := TDrawing(Drawings[Index])
else
ActiveDrawing := nil;
end;
end;
end;
procedure TMainForm.FileExitExecute(Sender: TObject);
begin
InitToConfig( fConfigFileName );
Close;
end;
procedure TMainForm.FileNewExecute(Sender: TObject);
var
Drawing : TDrawing;
Index : Integer;
P : TPreferences;
begin
Inc(NewCount);
Drawing := TDrawing.Create;
Drawing.SetFullPath('UNTITLED' + '-'+IntToStr(NewCount));
P := Drawing.Preferences;
P.Assign(fDefaultPreferences);
Drawing.Preferences.Assign(fDefaultPreferences);
{ DONE 1 -oDon Ziesig -cDrawing : Add Layers to from Default to new Drawing }
Drawing.Layers.Assign(fDefaultLayers);
Index := TabControl1.Tabs.Add(Drawing.Name);
Drawings.Add(TObject(Drawing));
TabControl1.TabIndex := Index;
ActiveDrawing := Drawing; // Needed for first drawing because tab NOT changed.
Drawing.Preferences.UNMODIFY;
end;
procedure TMainForm.FileOpenExecute(Sender: TObject);
var
Drawing : TDrawing;
Index : Integer;
I, C : Integer;
begin
if OpenDialog1.Execute then
begin
C := 0;
for I := 0 to pred(Drawings.Count) do
if TDrawing(Drawings[I]).FullPath = OpenDialog1.FileName then
Inc(C);
if C > 0 then
MessageDlg(OpenDialog1.FileName + #13#10 +
'is already open in one of the tabs.' + #13#10 +
'This one will be opened "READ ONLY"',mtWarning,[mbOK],0);
Drawing := TDrawing.Create;
Drawing.SetFullPath(OpenDialog1.FileName);
Drawing.GetFromFile( C > 0 );
if C > 0 then
Index := TabControl1.Tabs.Add(Drawing.NameOnly + '(RO)')
else
Index := TabControl1.Tabs.Add(Drawing.NameOnly);
Drawings.Add(TObject(Drawing));
ActiveDrawing := Drawing;
TabControl1.TabIndex := Index;
end;
end;
procedure TMainForm.FilePageSetupExecute(Sender: TObject);
begin
if PageSetupDialog1.Execute then
begin
end;
end;
procedure TMainForm.FilePrintExecute(Sender: TObject);
begin
if PrintDialog1.Execute then
begin
end;
end;
procedure TMainForm.FilePrintSetupExecute(Sender: TObject);
begin
if PrinterSetupDialog1.Execute then
begin
;
end;
end;
procedure TMainForm.FileSaveAllExecute(Sender: TObject);
var
I : Integer;
S : String;
begin
for I := 0 to pred(Drawings.Count) do
if TDrawing(Drawings[I]).Modified then
if TDrawing(Drawings[I]).CanLoadOrSave then
TDrawing(Drawings[I]).PutToFile
else
try
S := SaveDialog1.Title;
SaveDialog1.Title := TabControl1.Tabs[I];
if SaveDialog1.Execute then
begin
TDrawing(Drawings[I]).SetFullPath(SaveDialog1.FileName);
TDrawing(Drawings[I]).PutToFile;
TabControl1.Tabs[I] := TDrawing(Drawings[I]).NameOnly;
end;
finally
SaveDialog1.Title := S;
end;
end;
procedure TMainForm.FileSaveAsExecute(Sender: TObject);
var
Index : Integer;
begin
if SaveDialog1.Execute then
begin
fActiveDrawing.SetFullPath(SaveDialog1.FileName);
fActiveDrawing.PutToFile;
ActiveDrawing := fActiveDrawing;
Index := TabControl1.TabIndex;
TabControl1.Tabs[Index] := ActiveDrawing.NameOnly;
end;
end;
procedure TMainForm.FileSaveExecute(Sender: TObject);
begin
{ DONE 3 -oMe -cControls : Add menu item and button for "Save All" }
if ActiveDrawing.CanLoadOrSave then
ActiveDrawing.PutToFile
else
FileSaveAsExecute(Sender);
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
var
I : Integer;
C : Integer;
begin
C := 0;
{ Check all drawings for modification, get user's permission to exit if any changed. }
for I := 0 to pred(Drawings.Count) do
if TDrawing(Drawings[I]).Modified then
Inc(C);
if C > 0 then
CanClose := MessageDlg(IntToStr(C) + ' Drawing(s) have been modified.'#10#13 +
'Continue exiting Magic Tracks (all changes will be lost)?' ,
mtConfirmation,[mbYes, mbNo],0) = mrYes;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.CreateForm(TInternalsForm1, InternalsForm1);
// InternalsForm1 := TInternalsForm1.Create( Self ); // So we can configure later
fConfigFileName := GetAppConfigFile(False);
{ Create the configuration file directory if it doesn't exist }
ForceDirectory(ExtractFilePath(fConfigFileName));
InitFromConfig( fConfigFileName );
fDefaultPreferences := TPreferences.Create;
fDefaultPreferences.GetFromConfig( fConfigFileName );
fDefaultLayers := TLayers.Create;
fDefaultLayers.GetFromConfig( fConfigFileName );
NewCount := 0;
Drawings := TList.Create;
{ Setup the Zoom-index MenuItems }
MIZooms[ 0] := MIZoom1;
MIZooms[ 1] := MIZoom2;
MIZooms[ 2] := MIZoom3;
MIZooms[ 3] := MIZoom4;
MIZooms[ 4] := MIZoom5;
MIZooms[ 5] := MIZoom6;
MIZooms[ 6] := MIZoom7;
MIZooms[ 7] := MIZoom8;
MIZooms[ 8] := MIZoom9;
MIZooms[ 9] := MIZoom10;
MIZooms[10] := MIZoom12;
MIZooms[11] := MIZoom15;
MIZooms[12] := MIZoom20;
MIZooms[13] := MIZoom25;
MIZooms[14] := MIZoom30;
MIZooms[15] := MIZoom40;
MIZooms[16] := MIZoom50;
MIZooms[17] := MIZoom60;
MIZooms[18] := MIZoom70;
MIZooms[19] := MIZoom80;
{ NO ActiveDrawing to start }
ActiveDrawing := nil;
{ Populate the Object Factory }
ObjectFactory.RegisterClass(TStraightLine.ClassType);
end;
procedure TMainForm.FormResize(Sender: TObject);
begin
end;
procedure TMainForm.GuidesToLineExecute(Sender: TObject);
var
S : TStraightLine;
O : TDrawingObjects;
D : TDrawing;
L : TLayer;
begin
S := TStraightLine.Create( ActiveDrawing.ActiveLayer );
S.X := ActiveDrawing.Guide2X;
S.Y := ActiveDrawing.Guide2Y;
S.Z := ActiveDrawing.Guide2Z;
S.SetLineEnd( ActiveDrawing.Guide1X - ActiveDrawing.Guide2X,
ActiveDrawing.Guide1Y - ActiveDrawing.Guide2Y,
ActiveDrawing.Guide1Z - ActiveDrawing.Guide2Z );
D := ActiveDrawing;
L := D.ActiveLayer;
O := L.DrawingObjects;
O.Add( S );
DrawingSetFrame1.Invalidate;
end;
procedure TMainForm.GuidesToRectangularSolidExecute(Sender: TObject);
var
S : TRectangularSolid;
O : TDrawingObjects;
D : TDrawing;
L : TLayer;
begin
S := TRectangularSolid.Create( ActiveDrawing.ActiveLayer );
S.X := ActiveDrawing.Guide2X;
S.Y := ActiveDrawing.Guide2Y;
S.Z := ActiveDrawing.Guide2Z;
S.Length := ActiveDrawing.Guide1X - ActiveDrawing.Guide2X;
S.Width := ActiveDrawing.Guide1Y - ActiveDrawing.Guide2Y;
S.Height := ActiveDrawing.Guide1Z - ActiveDrawing.Guide2Z;
D := ActiveDrawing;
L := D.ActiveLayer;
O := L.DrawingObjects;
O.Add( S );
DrawingSetFrame1.Invalidate;
end;
procedure TMainForm.GuidesToSphereExecute(Sender: TObject);
var
S : TSphere;
DX, DY, DZ : Double;
O : TDrawingObjects;
D : TDrawing;
L : TLayer;
R : T3Point;
begin
S := TSphere.Create(ActiveDrawing.ActiveLayer);
DX := ActiveDrawing.Guide2X - ActiveDrawing.Guide1X;
S.X := (ActiveDrawing.Guide1X + ActiveDrawing.Guide2X) / 2;
DY := ActiveDrawing.Guide2Y - ActiveDrawing.Guide1Y;
S.Y := (ActiveDrawing.Guide1Y + ActiveDrawing.Guide2Y) / 2;
DZ := ActiveDrawing.Guide2Z - ActiveDrawing.Guide1Z;
S.Z := (ActiveDrawing.Guide1Z + ActiveDrawing.Guide2Z) / 2;
R := T3Point.Create( DX, DY, DZ );
S.Radii := R;
R.Free;
D := ActiveDrawing;
L := D.ActiveLayer;
O := L.DrawingObjects;
O.Add( S );
DrawingSetFrame1.Invalidate;
end;
procedure TMainForm.HelpAboutExecute(Sender: TObject);
begin
AboutForm1.ShowModal;//Modal;
end;
procedure TMainForm.HelpShowInternalsExecute(Sender: TObject);
begin
InternalsForm1.Visible := True;
InternalsForm1.Show;
end;
procedure TMainForm.IdleTimer1Timer(Sender: TObject);
var
I : Integer;
Count : Integer;
begin
Count := 0;
for I := 0 to pred(Drawings.Count) do
if TDrawing(Drawings[I]).Modified then
Inc(Count);
FileSaveAll.Enabled := Count > 0;
end;
procedure TMainForm.InitFromConfig(ConfigFileName: String);
var
F : TIniFile;
FS : TFormStyle;
Val : Integer;
I : Integer;
begin
F := TIniFile.Create( ConfigFileName );
InternalsForm1.Visible := F.ReadBool('Internals','Visible',False);
InternalsForm1.FormStyle := TFormStyle(F.ReadInteger('Internals','FormStyle',ord(fsNormal) ));
InternalsForm1.MenuItem2.Checked := InternalsForm1.FormStyle = fsStayOnTop;
Val := F.ReadInteger('Internals','Top',-100000);
if Val <> -100000 then
begin
InternalsForm1.Top := Val;
InternalsForm1.Left := F.ReadInteger('Internals','Left',0);
end;
F.Free;
end;
procedure TMainForm.InitToConfig(ConfigFileName: String);
var
F : TIniFile;
begin
F := TIniFile.Create( ConfigFileName );
F.WriteBool('Internals','Visible',InternalsForm1.Visible );
F.WriteInteger('Internals','FormStyle', ord(InternalsForm1.FormStyle) );
F.WriteInteger('Internals','Top', InternalsForm1.Top );
F.WriteInteger('Internals','Left', InternalsForm1.Left );
F.Free;
end;
procedure TMainForm.LayersEditExecute(Sender: TObject);
begin
LayerForm.Assign( ActiveDrawing.Layers);
if LayerForm.ShowModal = mrOk then
begin
ActiveDrawing.Layers.Assign(LayerForm.Layers);
ActiveDrawing.ActiveLayer := LayerForm.ActiveLayer;
end;
end;
procedure TMainForm.MIZoom1Click(Sender: TObject);
begin
ActiveDrawing.SetZoom((Sender as TMenuItem).Tag);
ActiveDrawing := ActiveDrawing;
end;
procedure TMainForm.PositionLowerLeftExecute(Sender: TObject);
begin
if ActiveDrawing <> nil then
begin
DrawingSetFrame1.PositionLowerLeft;
end;
end;
procedure TMainForm.SetActiveDrawing(Value: TDrawing);
var
IsActive : Boolean;
I : Integer;
V : TLayerKinds;
begin
fActiveDrawing := Value;
IsActive := Value <> nil;
if IsActive then
begin
StatusBar1.Panels[1].Text := Value.FullPath;
ToolsShowGrid.Checked := fActiveDrawing.Preferences.ShowGrid;
ToolsSnapToGrid.Checked := fActiveDrawing.Preferences.SnapToGrid;
VisibleLayerPanel.Caption := '';
for V in TLayerKinds do
if V in ActiveDrawing.Layers.ViewLayers then
VisibleLayerPanel.Caption := VisibleLayerPanel.Caption + LayerNames[V] + ' ';
ActiveLayerPanel.Caption := LayerNames[ActiveDrawing.Layers.ActiveLayerKind];
end
else
begin
StatusBar1.Panels[1].Text := 'NIL';
VisibleLayerPanel.Caption := '';
ActiveLayerPanel.Caption := '';
end;
FileSave.Enabled := IsActive;
FileSaveAs.Enabled := IsActive;
FileClose.Enabled := IsActive;
FilePrint.Enabled := IsActive;
ToolsPreferencesCurrentDrawing.Enabled := IsActive;
ToolsShowGrid.Enabled := IsActive;
ToolsSnapToGrid.Enabled := IsActive;
ViewZoomIn.Enabled := IsActive;
ViewZoomOut.Enabled := IsActive;
LayersEdit.Enabled := IsActive;
for I := 0 to MaxZoom do
begin
MiZooms[I].Enabled := IsActive;
MiZooms[I].Checked := False;
end;
if IsActive then
begin
MIZooms[ActiveDrawing.ZoomIndex].Checked := true;
end;
DrawingSetFrame1.Drawing := ActiveDrawing;
end;
procedure TMainForm.TabControl1Change(Sender: TObject);
var
Index : Integer;
begin
Index := TabControl1.TabIndex;
if Index >= 0 then
ActiveDrawing := TDrawing(Drawings[Index])
else
ActiveDrawing := nil;
end;
procedure TMainForm.ToolsLayerDefaultsExecute(Sender: TObject);
begin
LayerForm.Assign( fDefaultLayers );
if LayerForm.ShowModal = mrOk then
begin
LayerForm.Layers.PutToConfig( fConfigFilename );
fDefaultLayers.Assign( LayerForm.Layers );
end;
end;
procedure TMainForm.ToolsObjectsSnapToGuidesExecute(Sender: TObject);
begin
{ TODO 1 -oDon Ziesig -cUser Interface : Implement Objects Snap to Guides }
end;
procedure TMainForm.ToolsPreferencesCurrentDrawingExecute(Sender: TObject);
begin
PreferencesForm.Preferences.Assign( ActiveDrawing.Preferences );
if PreferencesForm.ShowModal = mrOk then
ActiveDrawing.Preferences.Assign( PreferencesForm.Preferences );
end;
procedure TMainForm.ToolsPreferencesNewDrawingExecute(Sender: TObject);
var
Ans : Integer;
begin
PreferencesForm.Preferences.Assign(fDefaultPreferences);
Ans := PreferencesForm.ShowModal;
if Ans = mrOk then
begin
PreferencesForm.Preferences.PutToConfig(fConfigFileName);
fDefaultPreferences.Assign(PreferencesForm.Preferences);
end;
end;
procedure TMainForm.ToolsShowGridExecute(Sender: TObject);
begin
if ActiveDrawing = nil then exit;
ActiveDrawing.Preferences.ShowGrid := ToolsShowGrid.Checked;
ActiveDrawing := ActiveDrawing;
end;
procedure TMainForm.ToolsSnapToGridExecute(Sender: TObject);
begin
ActiveDrawing.Preferences.SnapToGrid := ToolsSnapToGrid.Checked;
end;
procedure TMainForm.ViewZoomInExecute(Sender: TObject);
begin
if ActiveDrawing = nil then exit;
ActiveDrawing.DecZoom;
ActiveDrawing := ActiveDrawing;
end;
procedure TMainForm.ViewZoomOutExecute(Sender: TObject);
begin
if ActiveDrawing = nil then exit;
ActiveDrawing.IncZoom;
ActiveDrawing := ActiveDrawing;
end;
end.