-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgrid_unit.pas
More file actions
6076 lines (4354 loc) · 293 KB
/
grid_unit.pas
File metadata and controls
6076 lines (4354 loc) · 293 KB
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
(*
================================================================================
This file is part of OpenTemplot2024, a computer program for the design of model railway track.
Copyright (C) 2024 Martin Wynne. email: martin@85a.uk
This program is free software: you may redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation, either version 3 of the Licence, or
(at your option) any later version.
This program 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 Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program. See the file: licence.txt
Or if not, refer to the web site: https://www.gnu.org/licenses/
================================================================================
This file was saved from Delphi5
This file was derived from Templot2 version 244d
*)
unit grid_unit;
{$MODE Delphi}
{$ALIGN OFF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls;
type
Tgrid_form = class(TForm)
blue_corner_panel: TPanel;
size_updown: TUpDown;
colour_panel: TPanel;
colour_patch: TImage;
close_panel: TPanel;
close_button: TButton;
ring_copies_groupbox: TGroupBox;
make_copy_button: TButton;
delete_copy_button: TButton;
clear_button: TButton;
pen_groupbox: TGroupBox;
move_pen_button: TButton;
draw_line_button: TButton;
set_groupbox: TGroupBox;
ring_size_button: TButton;
dia_label: TLabel;
measuring_panel: TPanel;
x_label: TLabel;
y_label: TLabel;
diag_label: TLabel;
cross_hairs_button: TButton;
ring_location_button: TButton;
colour_button: TButton;
six_foot_button: TButton;
jump_groupbox: TGroupBox;
jump_to_notch_button: TButton;
jump_to_centre_button: TButton;
jump_to_mouse_button: TButton;
mouse_actions_groupbox: TGroupBox;
mouse_button: TButton;
adjust_ring_dia_button: TButton;
help_button: TButton;
dummy_vehicle_copies_groupbox: TGroupBox;
dummy_vehicle_make_copy_button: TButton;
dummy_vehicle_delete_copy_button: TButton;
dummy_vehicle_clear_copies_button: TButton;
roll_dummy_vehicle_button: TButton;
show_ring_groupbox: TGroupBox;
show_rings_radio_button: TRadioButton;
hide_rings_radio_button: TRadioButton;
dummy_vehicle_groupbox: TGroupBox;
show_dummy_vehicles_radio_button: TRadioButton;
hide_dummy_vehicles_radio_button: TRadioButton;
road_groupbox: TGroupBox;
main_road_dummy_vehicle_radio_button: TRadioButton;
turnout_road_dummy_vehicle_radio_button: TRadioButton;
dummy_vehicle_dimensions_button: TButton;
dummy_vehicle_clearance_button: TButton;
attach_ring_checkbox: TCheckBox;
adjust_adjacent_centres_ms_button: TButton;
adjust_adjacent_centres_ts_button: TButton;
help_shape: TShape;
Shape1: TShape;
reset_centre_line_button: TButton;
vehicle_envelope_button: TButton;
clear_first_envelope_button: TButton;
ring_copy_colour_button: TButton;
clear_last_envelope_button: TButton;
clear_all_envelopes_button: TButton;
Label1: TLabel;
blank_ends_checkbox: TCheckBox;
make_target_button: TButton;
GroupBox1: TGroupBox;
make_circle_shapes_button: TButton;
make_target_clip_button: TButton;
make_clip_button: TButton;
procedure size_updownClick(Sender: TObject; Button: TUDBtnType);
procedure colour_panelClick(Sender: TObject);
procedure close_buttonClick(Sender: TObject);
procedure help_buttonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ring_size_buttonClick(Sender: TObject);
procedure colour_buttonClick(Sender: TObject);
procedure make_target_buttonClick(Sender: TObject);
procedure make_circle_shapes_buttonClick(Sender: TObject);
procedure clear_buttonClick(Sender: TObject);
procedure delete_copy_buttonClick(Sender: TObject);
procedure make_copy_buttonClick(Sender: TObject);
procedure move_pen_buttonClick(Sender: TObject);
procedure draw_line_buttonClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure show_rings_radio_buttonClick(Sender: TObject);
procedure hide_rings_radio_buttonClick(Sender: TObject);
procedure mouse_buttonClick(Sender: TObject);
procedure jump_to_centre_buttonClick(Sender: TObject);
procedure ring_copy_colour_buttonClick(Sender: TObject);
procedure cross_hairs_buttonClick(Sender: TObject);
procedure ring_location_buttonClick(Sender: TObject);
procedure jump_to_notch_buttonClick(Sender: TObject);
procedure six_foot_buttonClick(Sender: TObject);
procedure jump_to_mouse_buttonClick(Sender: TObject);
procedure adjust_ring_dia_buttonClick(Sender: TObject);
procedure dummy_vehicle_dimensions_buttonClick(Sender: TObject);
procedure turnout_road_dummy_vehicle_radio_buttonClick(Sender:TObject);
procedure main_road_dummy_vehicle_radio_buttonClick(Sender: TObject);
procedure hide_dummy_vehicles_radio_buttonClick(Sender: TObject);
procedure show_dummy_vehicles_radio_buttonClick(Sender: TObject);
procedure roll_dummy_vehicle_buttonClick(Sender: TObject);
procedure dummy_vehicle_clear_copies_buttonClick(Sender: TObject);
procedure dummy_vehicle_delete_copy_buttonClick(Sender: TObject);
procedure dummy_vehicle_make_copy_buttonClick(Sender: TObject);
procedure dummy_vehicle_clearance_buttonClick(Sender: TObject);
procedure attach_ring_checkboxClick(Sender: TObject);
procedure adjust_adjacent_centres_ts_buttonClick(Sender: TObject);
procedure adjust_adjacent_centres_ms_buttonClick(Sender: TObject);
procedure reset_centre_line_buttonClick(Sender: TObject);
procedure vehicle_envelope_buttonClick(Sender: TObject);
procedure clear_first_envelope_buttonClick(Sender: TObject);
procedure clear_last_envelope_buttonClick(Sender: TObject);
procedure clear_all_envelopes_buttonClick(Sender: TObject);
procedure make_target_clip_buttonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
grid_form: Tgrid_form;
procedure arc_ellipse(canv:TCanvas; X1,Y1,X2,Y2:integer);
//---------------------
const
ring_help_str:string=' Spacing-Ring Tool'
+'||The spacing-ring is used as a design aid to check the spacing and clearances between adjacent tracks, model structures and baseboard constraints.'
+'||It can also be used to make reference marks on the trackpad, as a general measuring tool, and as a drawing pen.'
+'||It can be positioned anywhere on the trackpad by mouse action (click the MOUSE ACTIONS > MOVE RING button) or by entering X,Y co-ordinates directly.'
+' Its diameter can be adjusted by mouse action (click the MOUSE ACTIONS > RING SIZE button) or by entering the diameter directly.'
+'||Multiple copies of the ring can be created and left in position on the trackpad as fixed markers.'
+'||Any infringement of the ring (and optionally any copies) by the control template causes a warning lamp to flash on the trackpad INFORMATION panel.'
+' This is useful when adjusting the template to remain clear of obstructions, and when using the ring to measure clearances.'
+'|| 1. Checking Track Spacings and Clearances'
+'||To set the size of the ring, click the SET RING > SIZE... button and enter the required inner diameter of the spacing-ring in mm, or click the MOUSE ACTIONS > RING SIZE button to set the diameter by mouse action.'
+' The outer diameter of the ring is always automatically set to correspond to a ring-width equal to the current rail-width.'
+'||This then means that you normally use the INNER diameter of the ring to check against the OUTER-EDGE of the rail, and the OUTER diameter of the ring'
+' to check against the INNER or GAUGE-FACE edge of the rail.'
+'||While using the mouse actions to adjust the template (with SKELETON DRAW - the normal setting), only the gauge-face rail edges are shown,'
+' which means that only the outer ring diameter is then relevant.'
+'||If you select the pre-set dimension by clicking the SET RING > P-S button (or enter a slash "/") the ring size will be set to give a track centre-to-centre dimension of 11ft 2in scale for your current gauge and scale.'
+' This dimension corresponds to the standard minimum 6ft way between running lines for standard-gauge track.'
+'||You should use the spacing-ring to check that no two tracks come closer than this pre-set dimension to maintain the proper clearance for passing trains, and if there is a curving radius'
+' of less than about 750ft scale (3000 mm or 10ft radius in 4mm scale), the clearance should be increased.'
+'||The pre-set dimension represents the MINIMUM spacing for running lines - there is no harm in using wider spacings if conditions permit. Also, railway regulations require increased spacing (9ft or 10ft way)'
+' for loops and sidings alongside running lines for the safety of staff on the ground, and to give room for signal posts, etc.'
+'||( If you are designing for a track gauge other than standard-gauge the pre-set should not be used - enter the ring dimension as required. For Irish 5ft 3in gauge, for example, enter the 6ft way'
+' dimension directly, e.g. enter 24mm for 6ft way with exact scale Irish 21mm gauge in 4mm/ft scale.)'
+'|| 2. Marking and Measuring'
+'||You can leave a copy of the ring in position as a reference point. Click the RING COPIES > MAKE button. This is useful when you need to mark several clearance points while making adjustments.'
+' You can have up to 32 such copies if you wish, and each one can be a different size. While you are moving the ring its current position on the trackpad is shown in title bar at the top of the screen.'
+'||If the inner ring size is set to a small dimension or zero (click the SHRINK RING button to make it 6" scale diameter), the spacing-ring and any copies of it become small targets which are useful as general markers.'
+' The cross-hair lines are each 18" scale long.'
+'||The spacing-ring can also be used as a gauge to check any other dimensions on the drawing as required - just remember that the size you set is the inner diameter of the ring.'
+' For example, if you need to fit a locomotive which is 200mm long into an engine spur, set the ring to 200mm and check the clear length of the spur.'
+' This method is sometimes easier than using the ruler tool (UTILS > RULER menu item) to check dimensions. A fixed diameter can be set and the ring can then be positioned with a single mouse action,'
+' whereas the ruler needs to have each end positioned independently.'
+'||Or you can measure dimensions directly with the ring or the mouse. The readout panel displays the dimensions from the most recent copy of the ring to the current position.'
+' When the ring is being moved the dimensions are to the centre of the ring and the readout panel is yellow; at other times the readout panel is white and dimensions are to the mouse pointer,'
+' which can be changed to the cross-hairs symbol for accuracy by clicking the CROSS-HAIRS button.'
+'||To measure the distance between two positions on the drawing, simply move the centre of the ring to the first position and click the RING COPIES / MAKE button.'
+' Then move the ring or the mouse to the second position and read off the dimensions from the first one. The DIAGONAL dimension is the straight-line diagonal dimension between the two positions.'
+'|| 3. Handy Hints :'
+'||For simple point-to-point measurements it is often easier to use the mouse readout functions on the Jotter. (UTILS > JOTTER ~ X-Y READOUT menu item. Right-click on the jotter for the help notes.)'
+'||Moving the ring with the mouse action generates continuous trackpad redraws. When using the ring for marking and measuring you can get a faster response by using the mouse pointer directly. Try this:'
+'|Press the F12 key to cancel the mouse action.'
+'|Click the CROSS-HAIRS button (or press CTRL-full stop key).'
+'|Move the cross-hairs mouse pointer to the required ring position. But don''t click the mouse on it otherwise you will cancel the cross-hairs symbol.'
+'|Select the JUMP RING TO > MOUSE button (not with the mouse of course, press the U key on the keyboard, shown underlined on the button).'
+'|You can now click the RING COPIES > MAKE button (or press the K key) to start measuring from the ring to the mouse pointer.'
+'||Make a note of the underlined accelerator keys on the other buttons. Then you can resize the form much smaller to avoid obstructing the drawing and still be able to use the buttons.'
+'||The JUMP RING TO > NOTCH button jumps the ring to the current position of the pegging notch. By first using the NOTCH UNDER PEG functions, you can position the ring on the fixing peg of the control template, or any background template.'
+'||Likewise the GEOMETRY > NOTCH OPTIONS > NOTCH ON SPACING RING menu item moves the pegging notch to the ring position, and you can then use the SHIFT ONTO NOTCH functions to position the control template at the ring position.'
+'||To temporarily hide the ring and any copies, click the RINGS > HIDE option button. They will re-appear when you click the RINGS > SHOW option button, or select the UTILS > DUMMY VEHICLE • SPACING-RING menu item.'
+'||You can choose different colours for the ring and any copies by clicking the COLOUR... buttons. But avoid choosing red if possible, otherwise at some zoom settings the ring might be confused with the fixing peg.'
+'||When accuracy is needed, always zoom in so that the ring fills a good proportion of the visible pad. At lower zoom settings, rounding effects for the screen may appear to make the two ring diameters non-concentric.'
+'||Like the pegging notch, the spacing-ring and its copies "belong" to the trackpad, not the control template, so you can''t save these items in the data files as they stand.'
+' To save a ring for future use, it can be converted to a collection of 4 background shapes (2 rings and 2 cross-hair lines) and included in your background shapes list along with any other shapes which you have defined. Click the'
+' MAKE BACKGROUND SHAPES FROM RING > CIRCLE SHAPES button to do this. Or click the TARGET MARK / BRICK CLIP button to create a background target mark shape at the ring location.'
+' Background target mark shapes are treated as brick connector clips when exporting 3-D files.'
+'||Once in the background shapes list, the shapes forming the ring image can be modified as required in the same way as any other shape. You could delete the outer ring, for example, or change it to a square without changing any dimensions.'
+' (Note that you won''t actually see the underlying shapes until you move the ring, and then only if background shapes have been switched on in the TRACKPAD menu.)'
+'||The spacing ring can also be used as a means of drawing other background features. If you click the DRAWING PEN > MOVE TO RING button, an imaginary "drawing pen" is moved to the current position of the spacing ring. After moving'
+' the ring, if you then click the DRAW TO RING button, the "pen" will draw a line to the new position of the ring. By repeatedly moving the ring and clicking DRAW TO RING, an irregular outline can be produced.'
+' Each drawn line becomes a separate shape in the background shapes list, and can be deleted or modified as required. Background line shapes are treated as splints when exporting 3-D files.'
+'||( An easier way to draw simple free-hand shapes is to use the normal mouse drawing function - select the BACKGROUND > DRAW WITH MOUSE menu item.)'
+'||Ring copies can also be used to define the dimensions of other background shapes as pre-sets. This is useful if you need a shape which is a specified distance from the rails, or from another shape.'
+' Click the help buttons in the background shapes list for more information (BACKGROUND > SHAPES menu item).'
+'||Remember to save the shapes before quitting Templot (they are not included in the storage box data files).';
var
ex,by,sx,sy,fx,fy,ffx,ffy,gx,gy:extended;
xmax,ymax:integer;
show_spacing_rings:boolean=False;
show_ruler_tool:boolean=False;
draw_export_rectangle_flag:boolean=False; // 0.93.a
procedure draw_background_templates(canv:TCanvas; group_code:integer; highlight_index:integer; highlight_on:boolean; highlight_colour:TColor); // all the background templates.
procedure do_background(mode:integer); // draw the complete background.
procedure copy_draw_to_pad; // copy the draw-bitmap to the pad.
procedure wipe_draw_bmp(add_sketchboard_items:boolean); // wipe the draw-bitmap.
procedure wipe_pad; // wipe the actual pad form.
procedure draw_bg_shapes(canv:TCanvas;index,colour:integer); // draw any background shapes.
procedure draw_notch(canv:TCanvas); // draw the pegging notch. (might get redrawn by the control template).
procedure draw_rings(canv:TCanvas; copies,dummy_vehicle:boolean); //206b draw the spacing-ring or copies.
procedure draw_dummy_vehicle_copies(on_canvas:TCanvas); // 0.98.a
function hover_mousedown(click_x, click_y, limit:extended):integer; // highlight a bgnd keep if any at this clicked location.
function get_show_margins_info(calc_for_none:boolean):boolean; // 0.93.a
//_________________________________________________________________________________________
implementation
{$BOOLEVAL ON}
uses
control_room, pad_unit, bgnd_unit, bgkeeps_unit, math_unit, math, preview_unit,
colour_unit, help_sheet, shove_timber, keep_select, print_settings_unit,
export_unit, entry_sheet, alert_unit,
action_unit, { OT2024 file_viewer,} dxf_unit, brick_unit;
{$R *.lfm}
//_________________________________________________________________________________________
{ calc scaling, etc. ..
y scaling factor for screen = same as x:
640 * 480 dots = 1.33333 : 1 for which the
screen area is 187 mm * 141 mm = 1.326 : 1 (Iiyama 17" monitor at 1024 x 768 resolution).
y factor is negative - (calcs origin at bottom left).
ex = end x dim (pixels) to left grid margin (printed page top)
by = bottom y dim (pixels) to grid bottom margin (printed page left).
gx = end zoom offset x (pixels)
gy = bottom zoom offset y (pixels)
draw_mode = 0 means initial draw - calc scaling.
1 means zoom free, so adjust the scaling to show whole turnout (per turnoutx).
2 means zoom locked, so we don't even change the existing scale. (but adjust zoom might have changed screenx).
}
//__________________________________________________________________________________
var
now_keep:Tbgnd_keep;
move_to, line_to, infill3, infill4: TPoint;
p1, p2, p3, p4: TPoint;
p:array[0..27] of TPoint; // 221a for chair outlines
pen_now_at:Tpex;
zzz:integer=0;
procedure show_scalebar(canv:TCanvas);forward;
procedure draw_ruler(canv:TCanvas);forward;
procedure copy_drop_to_canvas(canv:TCanvas);forward; // copy the drop-bitmap to the specified canvas.
procedure wipe_fill_drop;forward; // draw as much as will remain fixed on the backdrop.
procedure draw_all_on_canvas(canv:TCanvas);forward; // normal draw, use the specified canvas for everything.
procedure finish_on_canvas(canv:TCanvas);forward; // draw any items not on the backdrop on the specified canvas.
procedure draw_export_rectangle(canv:TCanvas);forward; // 0.93.a
procedure draw_dummy_vehicle_outline_envelope_as_polygon(on_canvas:TCanvas);forward; // 215c
function skip_show_brick_template(n:integer):boolean;forward; // 234a
//___________________________________________________________________________________
function get_show_margins_info(calc_for_none:boolean):boolean; // 0.93.a
var
temp:extended;
begin
RESULT:=False; // init
case show_margins of // 0.93.a
0: begin // if no margins, do calcs as for printer if wanted but return False
if calc_for_none=True then page_info(True,True,False,0);
EXIT;
end;
1: if page_info(True,True,False,0)=False then EXIT; // get current printer info and calc page limits etc.
2: begin
try
pdf_width_dpi:=StrToInt(export_form.pdf_dpi_edit.Text);
pdf_height_dpi:=pdf_width_dpi; // both the same
pdf_height_mm:=StrToFloat(export_form.pdf_long_mm_edit.Text);
pdf_width_mm:=StrToFloat(export_form.pdf_short_mm_edit.Text);
except
EXIT;
end;//try
if export_form.pdf_side_run_radio.Checked=True // swap dimensions for landscape
then begin
temp:=pdf_height_mm;
pdf_height_mm:=pdf_width_mm;
pdf_width_mm:=temp;
end;
if export_form.pdf_size_inside_trim_margins_checkbox.Checked=True // 205e increase document size to allow for trim margin default sizes (fixed for PDF)
then begin
pdf_width_mm:=pdf_width_mm+9.0; // left margin 7mm, right margin 2mm
pdf_height_mm:=pdf_height_mm+10.5; // top margin 6mm, bottom margin 4.5mm
end;
pdf_width_dots:=Round(pdf_width_mm*pdf_width_dpi/25.4);
pdf_height_dots:=Round(pdf_height_mm*pdf_height_dpi/25.4);
if page_info(True,True,True,0)=False then EXIT; // get current PDF info and calc page limits etc.
end;
else EXIT;
end;//case
RESULT:=True;
end;
//______________________________________________________________________________
procedure draw_page_outlines(canv:TCanvas);
var
n,m,pl,pw,ml:extended;
staggered:boolean;
top_offset,left_offset:extended;
page_count_long:integer;
page_count_wide:integer;
porg_rec:integer;
/////////////////////////////////////////////////////////////////
procedure draw_margin_line;
begin
move_to.X:=limits_i(-1,xmax+2,move_to.X); // force within pad limits...
move_to.Y:=limits_i(-1,ymax+2,move_to.Y);
line_to.X:=limits_i(-1,xmax+2,line_to.X);
line_to.Y:=limits_i(-1,ymax+2,line_to.Y);
with canv do begin
MoveTo(move_to.X, move_to.Y);
LineTo(line_to.X, line_to.Y);
end;//with
end;
//////////////////////////////////////////////////////////////////
begin
if get_show_margins_info(False)=False then EXIT; // no outlines wanted
with canv do begin
Brush.Color:=paper_colour;
Brush.Style:=bsSolid;
TextOut(0,0,''); // !!! Delphi bug? This seems to be necessary before dotted lines and hatched masks will draw properly.
// show the printed page margins (if not more than outlines_limit pages long on screen, or adjust page origin is in progress) ...
if (page_length>minfp) and (out_factor>minfp) // div 0 checks.
then begin
if ( (show_margins>0) and (paper_bunching=False) { out 0.93.a and ((screenx*100*out_factor/page_length)<outlines_limit)} )
or (porg_mod=1)
or (out_factor_mod=1)
then begin
Pen.Width:=1;
Pen.Mode:=pmCopy; // use Pen.Color.
Pen.Style:=psDot; // dotted trim margin lines.
Pen.Color:=page_colour;
pl:=page_length*sx/out_factor; // effective printer page length between trim margins.
pw:=page_width*sy/out_factor; // (sy negative) printer page width between trim margins (in 1/100 mm actual unscaled).
if staggered_pages=True then ml:=(sheet_down_c+1)*pl+pl/2 // total margin length.
else ml:=(sheet_down_c+1)*pl;
top_offset:=print_pages_top_origin*fx;
left_offset:=print_pages_left_origin*fy; // (fy negative).
if banner_paper=True then top_offset:=top_offset-25*fx; // 25 mm extra top space for banner paper.
page_count_wide:=0; // init.
m:=by-gy+left_offset; // draw first horz. line.
staggered:=False;
repeat
if staggered_pages=True
then begin
if page_count_wide=0
then begin
move_to.X:=Round(ex-gx+top_offset); // first line.
line_to.X:=move_to.X+Round(ml-pl/2); // shorter margin length.
end
else begin
move_to.X:=Round(ex-gx+top_offset-pl/2); // subsequent lines.
line_to.X:=move_to.X+Round(ml); // full margin length.
end;
end
else begin
move_to.X:=Round(ex-gx+top_offset); // no stagger.
line_to.X:=move_to.X+Round(ml); // full margin length.
end;
move_to.Y:=Round(m);
line_to.Y:=move_to.Y; // horizontal line.
if move_to.Y<>Round(by-gy) then draw_margin_line; // don't overwrite the grid bottom datum line.
// now add vertical lines...
if staggered=True then n:=top_offset-pl/2
else n:=top_offset; // alternate columns staggered.
page_count_long:=0; // init.
While (n<(xmax+gx)) and (pl>0) do begin // draw staggered vertical page lines up to next horizontal.
if (banner_paper=False) or (page_count_long=0) or (page_count_long=(sheet_down_c+1)) // no intermediate vertical page margins for banner printing.
then begin
move_to.X:=Round(ex-gx+n);
line_to.X:=move_to.X;
move_to.Y:=Round(m);
line_to.Y:=Round(m+pw+1);
if move_to.X<>Round(ex-gx) then draw_margin_line; // don't overwrite the grid left datum line.
end;
n:=n+pl;
INC(page_count_long);
if page_count_long>(sheet_down_c+1) then BREAK; // index+2 = count+1 to add right margin line (33 sheets = 34 margin lines)
end;//while
m:=m+pw;
INC(page_count_wide);
if staggered_pages=True
then staggered:= not staggered // alternate columns staggered.
else staggered:=False;
until (m<pw) or (page_count_wide>(sheet_across_c)); // index+2 = count+1 to add top margin line (26 sheets = 27 margin lines)
if staggered_pages=True
then begin
move_to.X:=Round(ex-gx+top_offset-pl/2); // add top margin line (26 sheets = 27 margin lines).
line_to.X:=move_to.X+Round(ml-pl/2); // final margin is shorter by half a page.
end
else begin
move_to.X:=Round(ex-gx+top_offset); // no stagger.
line_to.X:=move_to.X+Round(ml); // full margin length.
end;
move_to.Y:=Round(m);
line_to.Y:=move_to.Y; // horizontal line.
draw_margin_line;
if (pad_form.show_printable_area_menu_entry.Checked=True) and (out_factor=1.0)
then begin
move_to.X:=Round(ex-gx+(print_pages_top_origin-page_margin_top_mm)*fx);
move_to.Y:=Round(by-gy+(print_pages_left_origin-page_margin_left_mm)*fy);
line_to.X:=move_to.X+Round(print_length*sx);
line_to.Y:=move_to.Y+Round(print_width*sy);
Pen.Width:=1;
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
Pen.Color:=page_colour;
Brush.Color:=page_colour;
Brush.Style:=bsClear;
if check_limits(move_to, line_to)=True then Rectangle(move_to.X, move_to.Y, line_to.X, line_to.Y);
end;
end;//if show page outlines
// draw rectangle mark at the page origin...
if (show_margins>0) or (porg_mod=1) or (out_factor_mod=1)
then begin
porg_rec:=Round(page_length*sx/4); // 1/2 page length overall size.
if porg_rec>4 then porg_rec:=4; // max size of mark (arbitrary).
move_to.X:=Round(ex-gx+print_pages_top_origin*fx)-porg_rec;
line_to.X:=move_to.X+porg_rec*2;
move_to.Y:=Round(by-gy+print_pages_left_origin*fy)-porg_rec;
line_to.Y:=move_to.Y+porg_rec*2;
Pen.Width:=1;
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
Pen.Color:=page_colour;
Brush.Style:=bsSolid;
Brush.Color:=page_colour;
if check_limits(move_to, line_to)=True then Rectangle(move_to.X, move_to.Y, line_to.X, line_to.Y);
end;
end;
end;//with
end;
//_________________________________________________________________________________________
procedure shift_keep_moveto(n:integer; canv:TCanvas);
var
i:integer;
begin
if (n<0) or (n>(keeps_list.Count-1)) then EXIT; // ???
if Ttemplate(keeps_list.Objects[n]).group_selected=False // not selected for mouse shift/rotate.
then EXIT;
move_to.X:=move_to.X+Round(xshift_keeps*fx); // for mouse action shift all keeps...
move_to.Y:=move_to.Y+Round(yshift_keeps*fy);
infill3.X:=infill3.X+Round(xshift_keeps*fx); // timber infill...
infill3.Y:=infill3.Y+Round(yshift_keeps*fy);
infill4.X:=infill4.X+Round(xshift_keeps*fx);
infill4.Y:=infill4.Y+Round(yshift_keeps*fy);
for i:=0 to 27 do begin // chair outlines...
p[i].X:=p[i].X+Round(xshift_keeps*fx);
p[i].Y:=p[i].Y+Round(yshift_keeps*fy);
end;//next
canv.Pen.Color:=selection_colour; // draw selected keeps in this colour.
end;
//_________________________________________________________________________________
procedure shift_keep_lineto(n:integer);
begin
if (n<0) or (n>(keeps_list.Count-1)) then EXIT; // ???
if Ttemplate(keeps_list.Objects[n]).group_selected=False // not selected for mouse shift/rotate.
then EXIT;
line_to.X:=line_to.X+Round(xshift_keeps*fx); // these increments are zero at other times.
line_to.Y:=line_to.Y+Round(yshift_keeps*fy); // n.b. approximation using screen co-ordinates during mouse action.
end;
//___________________________________________________________________________________
function keep_transform(krot:extended; pin:TPoint):TPoint;
// perform rotations/transformations about notch using on screen co-ords for twist keeps.
// enter with rotation angle krot.
// and input point pin.
// result point returned.
var
x,y:extended;
notch_centre_x, notch_centre_y:extended;
begin
notch_centre_x:=notchx*fx+ex-gx; // notch centre in screen co-ords.
notch_centre_y:=notchy*fy+by-gy;
x:=pin.x-notch_centre_x; // shift to origin
y:=pin.y-notch_centre_y;
RESULT.x:=Round(x*COS(krot)-y*SIN(krot)+notch_centre_x); // rotate and shift back onto notch.
RESULT.y:=Round(x*SIN(krot)+y*COS(krot)+notch_centre_y);
end;
//______________________________________________________________________________________
procedure twist_keep_moveto(n:integer; canv:TCanvas);
var
i:integer;
begin
if (n<0) or (n>(keeps_list.Count-1)) then EXIT; // ???
if Ttemplate(keeps_list.Objects[n]).group_selected=False // not selected for mouse shift/rotate.
then EXIT;
move_to:=keep_transform(kform_keeps,move_to); // for mouse action twist all keeps...
infill3:=keep_transform(kform_keeps,infill3); // timber infill.
infill4:=keep_transform(kform_keeps,infill4);
for i:=0 to 27 do begin // chair outlines...
p[i]:=keep_transform(kform_keeps,p[i]);
end;//next
canv.Pen.Color:=selection_colour; // draw selected keeps in this colour.
end;
//_________________________________________________________________________________
procedure twist_keep_lineto(n:integer);
begin
if (n<0) or (n>(keeps_list.Count-1)) then EXIT; // ???
if Ttemplate(keeps_list.Objects[n]).group_selected=False // not selected for mouse shift/rotate.
then EXIT;
line_to:=keep_transform(kform_keeps,line_to); // for mouse action twist all keeps.
end;
//___________________________________________________________________________________
procedure mark_end(n:integer; canv:TCanvas; aq1, aq1end, aq2, aq2end:integer; pen_solid:boolean); // make the background rail end mark.
begin
try
with now_keep do begin
if (bgnd_endmarks_yn[aq1,aq1end]=True) and (bgnd_endmarks_yn[aq2,aq2end]=True)
then begin
p1:=bgnd_endmarks[aq1,aq1end];
p2:=bgnd_endmarks[aq2,aq2end];
with canv do begin
Pen.Width:=1;
Brush.Color:=paper_colour; // gaps in dotted lines.
Brush.Style:=bsSolid;
if pen_solid=True then Pen.Style:=psSolid // 0.93.a mods for platforms
else Pen.Style:=psDot;
move_to.X:=Round(p1.X*sx+ex-gx); move_to.Y:=Round(P1.Y*sy+by-gy);
line_to.X:=Round(p2.X*sx+ex-gx); line_to.Y:=Round(p2.Y*sy+by-gy);
if shift_keeps_mod=1
then begin
shift_keep_moveto(n,canv); // mouse action shift keeps, sets pen colour if selected.
shift_keep_lineto(n);
end;
if twist_keeps_mod=1
then begin
twist_keep_moveto(n,canv); // mouse action twist keeps.
twist_keep_lineto(n);
end;
if check_limits(move_to, line_to)=True then begin MoveTo(move_to.X, move_to.Y); LineTo(line_to.X, line_to.Y); end;
end;//with
end;
end;//with
except
EXIT; // abandon this mark if calcs fail.
end;//try
end;
//_______________________________________________________________________________________
procedure arc_ellipse(canv:TCanvas; X1,Y1,X2,Y2:integer);
// draw ellipse as 2 arcs. This is a bug fix.
// allows ellipse with centre clear.
// Delphi bug - Brush.Style bsClear doesn't work properly when drawing directly on the form canvas.
// 0.95.a now also used for control template peg
begin
with canv do begin
Arc(X1,Y1, X2,Y2, X1,Y1, X2,Y2); // draw 2 180 deg arcs.
Arc(X1,Y1, X2,Y2, X2,Y2, X1,Y1);
end;//with
end;
//____________________________________________________________________________________
procedure draw_zooming_ring(canv:TCanvas);
// 205a changed to octogon to avoid being confused with spacing ring
var
target_x, target_y, target_rad:integer;
oct_w,oct_l:extended; // 205a
target_w,target_l:integer; // 205a
begin
if pad_form.show_zoom_target_menu_entry.Checked=True
then begin
with canv do begin
Pen.Width:=2; // 0.93.a , was 1
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
Pen.Color:=clYellow; // changed 0.93.a
oct_w:=(xmax-ex)/40; // 205a half octagon width (octogon 1/20th of pad width)
oct_l:=oct_w*TAN(Pi/8); // 205a half of octogon side length
target_w:=Round(oct_w);
target_l:=Round(oct_l);
target_x:=Round((ex+xmax)/2);
target_y:=Round(by/2);
// draw octogon... 205a
MoveTo(target_x-target_w,target_y+target_l);
LineTo(target_x-target_l,target_y+target_w);
LineTo(target_x+target_l,target_y+target_w);
LineTo(target_x+target_w,target_y+target_l);
LineTo(target_x+target_w,target_y-target_l);
LineTo(target_x+target_l,target_y-target_w);
LineTo(target_x-target_l,target_y-target_w);
LineTo(target_x-target_w,target_y-target_l);
LineTo(target_x-target_w,target_y+target_l);
Pen.Width:=1; // restored for next
// add cross lines... 205a
MoveTo(target_x,target_y+target_w);
LineTo(target_x,target_y-target_w);
MoveTo(target_x-target_w,target_y);
LineTo(target_x+target_w,target_y);
end;//with
end;
end;
//________________________________________________________________________________________
procedure draw_dotted_line(canv:TCanvas; move_to,line_to:TPoint);
// this is a workaround. 7-2-00. Assigning now_shape clobbers access to Pen.Style in the same routine for some unfathomable reason.
begin
with canv do begin
Brush.Color:=paper_colour; // gaps in dotted lines
Brush.Style:=bsSolid;
TextOut(0,0,''); // This seems to be necessary before dotted lines will draw properly.
Pen.Style:=psDot;
Pen.Width:=1; // dots work only for single-width lines.
if check_limits(move_to, line_to)=True then begin MoveTo(move_to.X, move_to.Y); LineTo(line_to.X, line_to.Y); end;
end;//with
end;
//_________________________________________________________________________________________
procedure draw_export_rectangle(canv:TCanvas); // 0.93.a
var
x1,y1,x2,y2:extended;
begin
if draw_export_rectangle_flag=False then EXIT;
with canv do begin
Pen.Width:=2;
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
Pen.Color:=pad_form.Font.Color; // arbitrary
Brush.Color:=paper_colour;
Brush.Style:=bsClear;
x1:=(output_rectangle_x1*100+re_org_x)*sx;
y1:=(output_rectangle_y1*100+re_org_y)*sy;
x2:=(output_rectangle_x2*100+re_org_x)*sx;
y2:=(output_rectangle_y2*100+re_org_y)*sy;
move_to.X:=Round(ex-gx+x1);
move_to.Y:=Round(by-gy+y1);
line_to.X:=Round(ex-gx+x2);
line_to.Y:=Round(by-gy+y2);
if check_limits(move_to, line_to)=True
then Rectangle(move_to.X, move_to.Y, line_to.X, line_to.Y);
Pen.Width:=1; // for all other lines on pad.
end;//with canvas
end;
//______________________________________________________________________________
procedure draw_bg_shapes(canv:TCanvas;index,colour:integer); // draw any background shapes.
// if index=-1 then draw all.
var
font_height, font_size:extended;
i,first_index,max_index:integer;
x1,y1,x2,y2:extended;
arm,diamond:extended;
dummy_i:integer;
raster_rect,bunched_raster_rect:TRect; // 237a
brick_boundary_pen_width:integer;
n:integer;
infill_points:array[0..11] of TPoint; // for target mark claws outline.. 12 points
infill_points_pex:array[0..11] of Tpex;
inner_points:array[0..3] of TPoint; // for target mark inner claws outline 4 points
pbar,pclaws:TPoint;
clip_length,clip_rot:extended;
claw_guide1,claw_guide2:Tpex; // 241c
tommy_guide1,tommy_guide2:Tpex;
was_colour:TColor;
splint_points:array[0..3] of TPoint;
splint_points_pex:array[0..3] of Tpex;
xlo,ylo,xhi,yhi,spk,spw:extended;
rect_centx,rect_centy:extended; // 234b
unbunched_move_to,unbunched_line_to:TPoint; // 237a
unbunched_width,unbunched_height:integer; // 237a
bunch_end:integer; // 237a
omit_shape:boolean; // 237a
bunched_bitmap:TBitmap; // 237a
////////////////////////////////////////////////////////////////
procedure rotate_4p(rot,x1,y1:extended; var p1,p2,p3,p4:Tpex); // rotate 4 points
begin
dotransform(rot,x1,y1,p1,p1);
dotransform(rot,x1,y1,p2,p2);
dotransform(rot,x1,y1,p3,p3);
dotransform(rot,x1,y1,p4,p4);
end;
////////////////////////////////////////////////////////////////
procedure draw_4lines(p1,p2,p3,p4:Tpex); // 234a to screen dims
var
save_pencol:integer;
begin
with canv do begin
save_pencol:=Pen.Color;
Pen.Color:=clBlack;
MoveTo(Round(ex-gx+(p1.x*100+re_org_x)*sx),Round(by-gy+(p1.y*100+re_org_y)*sy));
LineTo(Round(ex-gx+(p2.x*100+re_org_x)*sx),Round(by-gy+(p2.y*100+re_org_y)*sy));
LineTo(Round(ex-gx+(p3.x*100+re_org_x)*sx),Round(by-gy+(p3.y*100+re_org_y)*sy));
LineTo(Round(ex-gx+(p4.x*100+re_org_x)*sx),Round(by-gy+(p4.y*100+re_org_y)*sy));
LineTo(Round(ex-gx+(p1.x*100+re_org_x)*sx),Round(by-gy+(p1.y*100+re_org_y)*sy));
Pen.Color:=save_pencol;
end;//with
end;
////////////////////////////////////////////////////////////////
procedure seven_seg(text_scaling,x1,y1:extended; str:string); // draw numbers 7-seg style on brick label 234a
// segments numbered: datum bottom left vertical segments 1"x3.5" horz segments 2"x1"
// 7
// 2 3
// 6
// 1 4
// 5
var
n:integer;
num_char:Char;
orgx,orgy:extended;
p1,p2,p3,p4:Tpex;
blscale:extended;
//============================================
procedure seg(segment:integer); // 234a layer=28 (as splints)
begin
case segment of
1: begin
p1.x:=orgx; p1.y:=orgy;
p2.x:=orgx+blscale; p2.y:=p1.y;
p3.x:=p2.x; p3.y:=orgy+3.5*blscale;
p4.x:=p1.x; p4.y:=p3.y;
end;
2: begin
p1.x:=orgx; p1.y:=orgy+3.5*blscale;
p2.x:=orgx+blscale; p2.y:=p1.y;
p3.x:=p2.x; p3.y:=orgy+7*blscale;
p4.x:=p1.x; p4.y:=p3.y;
end;
3: begin
p1.x:=orgx+3*blscale; p1.y:=orgy+3.5*blscale;
p2.x:=orgx+4*blscale; p2.y:=p1.y;
p3.x:=p2.x; p3.y:=orgy+7*blscale;
p4.x:=p1.x; p4.y:=p3.y;
end;
4: begin
p1.x:=orgx+3*blscale; p1.y:=orgy;
p2.x:=orgx+4*blscale; p2.y:=p1.y;
p3.x:=p2.x; p3.y:=orgy+3.5*blscale;
p4.x:=p1.x; p4.y:=p3.y;
end;
5: begin
p1.x:=orgx+blscale; p1.y:=orgy;
p2.x:=orgx+3*blscale; p2.y:=p1.y;
p3.x:=p2.x; p3.y:=orgy+blscale;
p4.x:=p1.x; p4.y:=p3.y;
end;
6: begin
p1.x:=orgx+blscale; p1.y:=orgy+3*blscale;