-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexport_draw_unit.pas
More file actions
3536 lines (2570 loc) · 182 KB
/
export_draw_unit.pas
File metadata and controls
3536 lines (2570 loc) · 182 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 244e
*)
unit export_draw_unit;
{$mode delphi}
{$ALIGN OFF}
interface
uses
Classes, SysUtils, Graphics, Dialogs;
//______________________________________________________________________________
var
unit_dummy:integer; // keep compiler happy
procedure export_draw(on_canvas:TCanvas; canvas_width,canvas_height,output_code:integer); // draw control template or entire pad on on_canvas
procedure export_bgnd_shapes(on_canvas:TCanvas; canvas_height:integer; grid_left,grid_top:extended; output_code:integer); // export all background shapes.
procedure export_bgnd(on_canvas:TCanvas; canvas_height:integer; grid_left,grid_top:extended; output_code:integer); // export background templates.
//______________________________________________________________________________
implementation
uses
control_room, pad_unit, math_unit, export_unit, print_settings_unit, preview_unit, print_unit, bgnd_unit, bgkeeps_unit, keep_select;
var
track_bgnd_width_in:extended=288; // 24ft default
//______________________________________________________________________________
function calc_intensity(colour:integer):integer;
var
red,green,blue,av:integer; // colour components (0-255).
begin
RESULT:=colour; // default init
if colour=clWhite then EXIT;
if (export_black_white=True) or (colour=virtual_black_colour)
then begin
RESULT:=clBlack;
EXIT;
end;
if export_grey_shade=True // average to a grey..
then begin
try
red:=(colour AND $000000FF);
green:=(colour AND $0000FF00) div $100;
blue:=(colour AND $00FF0000) div $10000;
av:=(red+green+blue) div 3;
red:=av;
green:=av;
blue:=av;
RESULT:=(blue*$10000)+(green*$100)+red;
except
RESULT:=clGray;
end;//try
end;
end;
//____________________________________________________________________________________
procedure print_colours_setup; // set grey shades and/or print intensity.
begin
if export_black_white=True
then begin
print_railedge_colour:=clBlack;
printcurail_colour:=clBlack;
printbgrail_colour:=clBlack;
printtimber_colour:=clBlack;
printrail_infill_colour_cu:=clWhite; // !!! used for solid infill.
printrail_infill_colour_bg:=clWhite; // !!! used for solid infill.
printtimber_infill_colour:=clBlack; // for hatched infill
printgrid_colour:=clBlack;
printmargin_colour:=clBlack;
printguide_colour:=clBlack;
printjoint_colour:=clBlack;
printalign_colour:=clBlack;
print_labels_font.Color:=clBlack;
print_timber_numbers_font.Color:=clBlack;
printshape_colour:=clBlack;
printbg_single_colour:=clBlack;
printplat_edge_colour:=clBlack; // platform edges
printplat_infill_colour:=clBlack; // platform infill - hatched?
sb_track_bgnd_colour:=clWhite; // 206a
sb_diagram_colour:=clWhite; // 209c
end
else begin
// calc grey shades if wanted...
print_railedge_colour:=calc_intensity(save_prc);
printcurail_colour:=print_railedge_colour;
printbgrail_colour:=print_railedge_colour;
printtimber_colour:=calc_intensity(save_ptc);
printrail_infill_colour_cu:=calc_intensity(save_priccu);
printrail_infill_colour_bg:=calc_intensity(save_pricbg);
printtimber_infill_colour:=calc_intensity(save_ptic);
printgrid_colour:=calc_intensity(save_grc);
printmargin_colour:=calc_intensity(save_pmc);
printguide_colour:=calc_intensity(save_pgc);
printjoint_colour:=calc_intensity(save_pjc);
printalign_colour:=calc_intensity(save_pac);
print_labels_font.Color:=calc_intensity(save_fc);
print_timber_numbers_font.Color:=calc_intensity(save_tnfc);
print_corner_page_numbers_font.Color:=calc_intensity(save_cpnfc); // 0.93.a added
printshape_colour:=calc_intensity(save_psc);
printbg_single_colour:=calc_intensity(save_pbg);
printplat_edge_colour:=calc_intensity(save_priplatedge); // platform edges
printplat_infill_colour:=calc_intensity(save_priplatfill); // platform infill
sb_track_bgnd_colour:=calc_intensity(save_sb_track_bgnd); // 206a
sb_diagram_colour:=calc_intensity(save_sb_diagram_col); // 209c
end;
end;
//__________________________________________________________________________________________
procedure print_line_thickness_setup;
var
av_dpi:extended;
///////////////////////////////////////////////
function calc_thick(mm_thick:extended; adjust:boolean):integer; // calc line thickness in dots.
var
line_dots:extended;
begin
line_dots:=mm_thick*av_dpi/25.4;
if (adjust=True) and (pad_form.adjust_line_thickness_menu_entry.Checked=True) then line_dots:=line_dots*out_factor;
RESULT:=Round(line_dots);
if RESULT<1 then RESULT:=1;
end;
///////////////////////////////////////////////
begin
av_dpi:=(nom_width_dpi+nom_length_dpi)/2;
printgrid_wide:=calc_thick( printgrid_thick,False); // don't reduce line thickness for scaled output - the paper size is still the same.
printmargin_wide:=calc_thick(printmargin_thick,False); // ditto.
printshape_wide:=calc_thick( printshape_thick,True);
printpicborder_wide:=calc_thick(printpicborder_thick,True);
printrail_wide:=calc_thick( printrail_thick,True);
printtimber_wide:=calc_thick( printtimber_thick,True);
printcl_wide:=calc_thick( printcl_thick,True); // 0.79.a
printmark_wide:=calc_thick( printmark_thick,True);
end;
//______________________________________________________________________________
procedure swap_line_to(on_canvas:TCanvas; canvas_height,Xin,Yin:integer);
// swap X and Y for drawing on sketchboard instead of printer...
//var
// bitmap_height:integer;
begin
//bitmap_height:=dtp_track_bitmap.Height;
//dtp_track_bitmap.Canvas.LineTo(Yin,bitmap_height-Xin);
on_canvas.LineTo(Yin,canvas_height-Xin);
end;
//____________________________
procedure swap_move_to(on_canvas:TCanvas; canvas_height,Xin,Yin:integer);
//var
// bitmap_height:integer;
begin
//bitmap_height:=dtp_track_bitmap.Height;
//dtp_track_bitmap.Canvas.MoveTo(Yin,bitmap_height-Xin);
on_canvas.MoveTo(Yin,canvas_height-Xin);
end;
//____________________________
procedure swap_text_out(on_canvas:TCanvas; canvas_height,Xin,Yin:integer; str:string);
//var
// bitmap_height:integer;
begin
//bitmap_height:=dtp_track_bitmap.Height;
//dtp_track_bitmap.Canvas.TextOut(Yin,bitmap_height-Xin,str);
on_canvas.TextOut(Yin,canvas_height-Xin,str);
end;
//____________________________
procedure swap_rectangle(on_canvas:TCanvas; canvas_height,X1in,Y1in,X2in,Y2in:integer);
//var
// bitmap_height:integer;
begin
//bitmap_height:=dtp_track_bitmap.Height;
//dtp_track_bitmap.Canvas.Rectangle(Y1in, bitmap_height-X2in, Y2in, bitmap_height-X1in);
on_canvas.Rectangle(Y1in, canvas_height-X2in, Y2in, canvas_height-X1in);
end;
//____________________________
procedure swap_polygon(on_canvas:TCanvas; canvas_height:integer; corners: array of TPoint);
var
//bitmap_height:integer;
n:integer;
Xin,Yin:integer;
begin
//bitmap_height:=dtp_track_bitmap.Height;
for n:=Low(corners) to High(corners) do begin
Xin:=corners[n].X; Yin:=corners[n].Y;
corners[n].X:=Yin; corners[n].Y:=canvas_height-Xin;
end;//next corner
on_canvas.Polygon(corners);
end;
//______________________________
procedure swap_ellipse(on_canvas:TCanvas; canvas_height,X1in,Y1in,X2in,Y2in:integer);
//var
// bitmap_height:integer;
begin
//bitmap_height:=dtp_track_bitmap.Height;
//dtp_track_bitmap.Canvas.Ellipse(Y1in, bitmap_height-X2in, Y2in, bitmap_height-X1in);
on_canvas.Ellipse(Y1in, canvas_height-X2in, Y2in, canvas_height-X1in);
end;
//____________________________
//__________________________________________________________________________________________
procedure do_text_out(on_canvas:TCanvas; canvas_height,textoutX,textoutY:integer; str:string);
// blank text backgrounds, swapped X,Y for sketchboard
var
text_rect:TRect;
//bitmap_height:integer;
begin
//bitmap_height:=dtp_track_bitmap.Height;
with on_canvas do begin
text_rect.Left:=textoutY;
text_rect.Top:=canvas_height-textoutX;
text_rect.Right:=text_rect.Left+TextWidth(str);
text_rect.Bottom:=text_rect.Top+TextHeight(str);
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
FillRect(text_rect);
end;//with
swap_text_out(on_canvas,canvas_height,textoutX,textoutY,str);
end;
//______________________________________________________________________________
procedure do_export_draw(on_canvas:TCanvas; canvas_width,canvas_height,output_code:integer); // draw control template or entire pad on a bitmap or metafile.
// output_code 1=sketchboard bitmap, 2=sketchboard metafile, 3=create image file, 4=create EMF file
var
infill_points:array[0..3] of TPoint; // array of corners for infilled timbers.
gridx, gridy, now_gridx, now_gridy:extended;
grid_label:extended;
grid_now_dots:integer;
aq, rail, now, dots_index, mark_code:integer;
p1,p2,p3,p4:Tpoint;
radcen_arm:extended;
move_to, line_to: TPoint;
l_dims_valid:boolean;
w_dims_valid:boolean;
x_dots, y_dots:integer;
bangrid_dots:integer;
pen_width:integer;
ptr_1st,ptr_2nd:^Tmark; // pointers to a Tmark record
markmax:integer;
fontsize:extended;
num_str, tbnum_str:string;
grid_str:string; // grid units
grid_label_str:string;
img_bgnd_colour:TColor; // 206a
//////////////////////////////////////////////////////////////////
procedure draw_marks(grid_left,grid_top:extended; rail_joints:boolean);
// if rail_joints=True draw only the rail joints, otherwise omit them.
var
i:integer;
begin
markmax:=intarray_max(marks_list_ptr); // max index for the present list.
if mark_index>markmax then mark_index:=markmax; // ??? shouldn't be.
tbnum_str:=timb_numbers_str; // the full string of timber numbering for the control template.
with on_canvas do begin
for i:=0 to (mark_index-1) do begin // (mark_index is always the next free slot)
ptr_1st:=Pointer(intarray_get(marks_list_ptr,i)); // pointer to the next Tmark record.
if ptr_1st=nil then BREAK;
mark_code:=ptr_1st^.code; // check this mark wanted.
if mark_code=0 then CONTINUE; // ignore mark entries with code zero (might be the second or third of a multi-mark entry, e.g. for timber infill).
if print_settings_form.output_rail_joints_checkbox.Checked=False // 223d
then begin
case mark_code of
6: CONTINUE; // rail joints not wanted.
end;//case
end;
// overwrite rail joints on rails..
if rail_joints=(mark_code<>6) then CONTINUE; // do only the rail joints if rail_joints=True and ignore them otherwise.
if print_settings_form.output_timbering_checkbox.Checked=False
then begin
case mark_code of
3,4,5,14,33,44,54,55,93,95,99,203,233,293: CONTINUE; // no timbering wanted.
end;//case
end;
if print_settings_form.output_timber_centres_checkbox.Checked=False // 223d
then begin
case mark_code of
4,14,44,54: CONTINUE; // timber centre-lines not wanted.
end;//case
end;
if print_settings_form.output_guide_marks_checkbox.Checked=False // 223d
then begin
case mark_code of
1: CONTINUE; // guide marks not wanted.
end;//case
end;
if print_settings_form.output_switch_drive_checkbox.Checked=False // 223d
then begin
case mark_code of
101: CONTINUE; // switch drive not wanted.
end;//case
end;
if print_settings_form.output_chairs_checkbox.Checked=False
then begin
case mark_code of
480..499: CONTINUE; // no chair outlines wanted 221a
end;//case
end;
if print_settings_form.output_radial_ends_checkbox.Checked=False
then begin
case mark_code of
2,7: CONTINUE; // no radial ends wanted 206a
end;//case
end;
if ((mark_code=203) or (mark_code=233) or (mark_code=293)) and (i<(mark_index-1)) // timber infill
then begin
ptr_2nd:=Pointer(intarray_get(marks_list_ptr,i+1)); // pointer to the second infill Tmark record.
if ptr_2nd=nil then BREAK;
p1:=ptr_1st^.p1; // x1,y1 in 1/100ths mm
p2:=ptr_1st^.p2; // x2,y2 in 1/100ths mm
p3:=ptr_2nd^.p1; // x3,y3 in 1/100ths mm
p4:=ptr_2nd^.p2; // x4,y4 in 1/100ths mm
end
else ptr_2nd:=nil; // keep compiler happy.
if (mark_code>0) and (mark_code<200) and (mark_code<>8) and (mark_code<>9) and (mark_code<>10) // ignore peg, rad centres, timber selector and peg arms, plain track start, label.
then begin
if ((mark_code=5) or (mark_code=55) or (mark_code=95)) and (out_factor<>1.0) then CONTINUE; // reduced ends are meaningless if not full-size.
p1:=ptr_1st^.p1; // x1,y1 in 1/100ths mm
if mark_code<>99
then begin
p2:=ptr_1st^.p2; // x2,y2 in 1/100ths mm
Brush.Color:=clWhite; // 0.93.a gaps in dotted lines.
Brush.Style:=bsClear;
TextOut(0,0,'');
if export_black_white=True
then Pen.Color:=clBlack
else case mark_code of
1,101: Pen.Color:=printguide_colour; // guide marks. switch drive
2: Pen.Color:=printalign_colour; // rad end marks.
3,33,93: Pen.Color:=printtimber_colour; // timber outlines.
6: Pen.Color:=printjoint_colour; // rail joint marks.
7: Pen.Color:=printalign_colour; // transition/slewing ends.
else Pen.Color:=calc_intensity(clBlack); // thin dotted lines in black only.
end;//case
Pen.Mode:=pmCopy;
Pen.Width:=1;
Pen.Style:=psSolid; // default init.
case mark_code of
1,101: Pen.Width:=printmark_wide; // guide marks. switch drive
2: Pen.Width:=printmark_wide; // rad end marks.
3,33,93: Pen.Width:=printtimber_wide; // timber outlines.
4,44: Pen.Style:=psDash; // timber centre-lines.
5,55,95: Pen.Style:=psDot; // timber reduced ends.
6: Pen.Width:=printmark_wide; // rail joint marks.
7: Pen.Width:=printmark_wide; // transition ends.
14,54: Pen.Width:=printrail_wide; // timber centre-lines with rail centre-lines (for rivet locations?).
else begin
Pen.Width:=1;
Pen.Style:=psSolid;
end;
end;//case
// overides...
// out 0.73.a 12-8-01 (now done in thickness setup) if out_factor<1 then Pen.Width:=Round(Pen.Width*out_factor); // scale down the line width.
if Pen.Width<1 then Pen.Width:=1;
if Pen.Style<>psSolid then Pen.Width:=1; // delphi bug? (patterns only work for lines 1 dot wide.)
// pdf if impact>0 then Pen.Width:=1; // overide for impact printer or plotter.
move_to.X:=Round((p1.Y+ypd-grid_left)*scaw_out)+page_left_dots;
move_to.Y:=Round((p1.X-grid_top)*scal_out)+page_top_dots;
line_to.X:=Round((p2.Y+ypd-grid_left)*scaw_out)+page_left_dots;
line_to.Y:=Round((p2.X-grid_top)*scal_out)+page_top_dots;
if check_limits(move_to, line_to)=True then begin swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y); swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y); end;
end;
// (no timber numbering here for exports)
end
else begin // other codes...
if ( (mark_code=-2) or (mark_code=-3) )
and (print_settings_form.output_radial_centres_checkbox.Checked=True)
// draw curving rad centres...
then begin
Pen.Width:=printmark_wide; // guide marks.
if Pen.Width<1 then Pen.Width:=1;
Pen.Style:=psSolid;
Pen.Mode:=pmCopy;
Pen.Color:=calc_intensity(clBlack);
p1:=ptr_1st^.p1; // x1,y1 in 1/100ths mm
radcen_arm:=400*scale; // 4ft scale arbitrary (scale is for control template).
move_to.X:=Round((p1.Y+radcen_arm+ypd-grid_left)*scaw_out)+page_left_dots; // mark centre widthwise.
move_to.Y:=Round((p1.X-grid_top)*scal_out)+page_top_dots;
line_to.X:=Round((p1.Y-radcen_arm+ypd-grid_left)*scaw_out)+page_left_dots;
line_to.Y:=Round((p1.X-grid_top)*scal_out)+page_top_dots;
if check_limits(move_to, line_to)=True then begin swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y); swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y); end;
move_to.X:=Round((p1.Y+ypd-grid_left)*scaw_out)+page_left_dots; // mark centre lengthwise
move_to.Y:=Round((p1.X+radcen_arm-grid_top)*scal_out)+page_top_dots;
line_to.X:=Round((p1.Y+ypd-grid_left)*scaw_out)+page_left_dots;
line_to.Y:=Round((p1.X-radcen_arm-grid_top)*scal_out)+page_top_dots;
if check_limits(move_to, line_to)=True then begin swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y); swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y); end;
end;
if ((mark_code=203) or (mark_code=233) or (mark_code=293)) and (ptr_2nd<>nil) // timber infill...
then begin
infill_points[0].X:=Round((p1.Y+ypd-grid_left)*scaw_out)+page_left_dots;
infill_points[0].Y:=Round((p1.X-grid_top)*scal_out)+page_top_dots;
infill_points[1].X:=Round((p2.Y+ypd-grid_left)*scaw_out)+page_left_dots;
infill_points[1].Y:=Round((p2.X-grid_top)*scal_out)+page_top_dots;
infill_points[2].X:=Round((p3.Y+ypd-grid_left)*scaw_out)+page_left_dots;
infill_points[2].Y:=Round((p3.X-grid_top)*scal_out)+page_top_dots;
infill_points[3].X:=Round((p4.Y+ypd-grid_left)*scaw_out)+page_left_dots;
infill_points[3].Y:=Round((p4.X-grid_top)*scal_out)+page_top_dots;
if (check_limits(infill_points[0],infill_points[1])=True) and (check_limits(infill_points[2],infill_points[3])=True)
then begin
Pen.Width:=1;
Pen.Style:=psSolid;
Pen.Mode:=pmCopy;
Pen.Color:=clWhite; // so no overdrawing of timber outlines.
if export_black_white=True
then Brush.Color:=clBlack
else Brush.Color:=printtimber_infill_colour;
case print_timb_infill_style of
0: CONTINUE;
1: Brush.Style:=bsFDiagonal; // hatched. Forward diagonal for the foreground (control template).
2: Brush.Style:=bsDiagCross;
3: if export_black_white=True
then CONTINUE // 209c now no fill was Brush.Style:=bsFDiagonal
else Brush.Style:=bsSolid;
4: begin // blank.
Brush.Style:=bsSolid;
Brush.Color:=clWhite; // overide.
end;
else CONTINUE;
end;//case
swap_polygon(on_canvas,canvas_height,infill_points);
end;
end;
end;
end;//next mark i
end;//with on_canvas
end;
//////////////////////////////////////////////////////////////////
function get_w_dots(q,n:integer):integer;
begin
with sheet[0,0] do begin // (grid_left)
RESULT:=Round((outoflist(q,n,1)+ypd-grid_left)*scaw_out)+page_left_dots;
end;//with
w_dims_valid:=check_draw_dim_w(RESULT);
end;
//////////////////////////////////////////////////////////////////
function get_l_dots(q,n:integer):integer;
begin
with sheet[0,0] do begin // (grid_top)
RESULT:=Round((outoflist(q,n,0)-grid_top)*scal_out)+page_top_dots;
end;//with
l_dims_valid:=check_draw_dim_l(RESULT);
end;
//////////////////////////////////////////////////////////////////
procedure draw_outline_railedge(aq,pencol:integer);
var
now:integer;
begin
if ( (plain_track=False) or (aq=0) or (aq=8) or (aq=3) or (aq=11) or ((aq>15) and (aq<24)) ) and (aqyn[aq]=True)
then begin
with on_canvas do begin
Pen.Color:=pencol;
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
move_to.X:=get_w_dots(aq,0); move_to.Y:=get_l_dots(aq,0);
for now:=1 to nlmax_array[aq] do begin
line_to.X:=get_w_dots(aq,now); line_to.Y:=get_l_dots(aq,now);
if check_limits(move_to, line_to)=True
then begin
swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y);
swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y);
end;
move_to:=line_to;
end;//for
end;//with on_canvas
end;
end;
////////////////////////////
procedure draw_fill_rail(outer_add:integer); // draw a complete filled rail.
const
dots_max_c=xy_pts_c*2; // 6000 max xy_pts_c=3000
var
dots:array[0..dots_max_c] of TPoint; // array of points for filled polygon mode.
// 3000 points for each side of rail. if incx is 18" scale (SQRT 9ft scale in 4mm = SQRT(36) =6 mm),
// template max is 4500' scale length.
// ( = 18000 mm or 59ft approx in 4 mm scale).
// ( = 66 A4 sheets long if straight turnout - but normally less for curved turnout).
// N.B. huge standard Pascal array is used instead of our integer arrays,
// because needed for the Polygon function.
// total memory = 6000*8 bytes = 48KB
now, start, now_max:integer;
edge_started:boolean;
mid_dots_index:integer;
edge_colour, blanking_colour:integer;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure modify_rail_end(start_index,stop_index,edge,blank:integer);
begin
if (start_index>=0) and (start_index<=dots_index) and (stop_index>=0) and (stop_index<=dots_index)
then begin
move_to:=dots[start_index];
line_to:=dots[stop_index];
if check_limits(move_to, line_to)=True
then begin
with on_canvas do begin
Pen.Color:=blank; // first blank across..
swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y);
swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y);
Pen.Color:=edge; // then restore the corner points..
swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y);
swap_line_to(on_canvas,canvas_height,move_to.X, move_to.Y);
swap_move_to(on_canvas,canvas_height,line_to.X, line_to.Y);
swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y);
end;//with
end;
end;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
begin
with on_canvas do begin
if (rail=16) or (rail=20) // 0.93.a platforms
then Pen.Color:=printplat_edge_colour
else Pen.Color:=printcurail_colour;
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
aq:=rail; // gauge-faces.
if ( (plain_track=False) or (aq=0) or (aq=3) or ((aq>15) and (aq<24)) )
// if plain track, stock rails and adjacent tracks only.
then begin
if (aqyn[aq]=False) or (aqyn[aq+outer_add]=False) // data not for both edges?
then begin
if aqyn[aq]=True then draw_outline_railedge(aq,Pen.Color);
if aqyn[aq+outer_add]=True then draw_outline_railedge(aq+outer_add,Pen.Color);
EXIT;
end;
now_max:=nlmax_array[aq];
if gaunt=False // 0.93.a normal turnout.
then begin
case aq of
1: begin
start:=list_planing_mark_aq1; // start from end of planing - no infill in planing.
if (start<0) or (start>now_max) then EXIT; // ???
end;
2: begin // ditto
start:=list_planing_mark_aq2;
if (start<0) or (start>now_max) then EXIT; // ???
end;
else start:=0; // whole list.
end;//case
end
else start:=0; // 093a gaunt template, no planing
dots_index:=0-1; // first increment is to zero.
edge_started:=False;
for now:=start to now_max do
begin
x_dots:=get_w_dots(aq,now);
y_dots:=get_l_dots(aq,now);
if (w_dims_valid=True) and (l_dims_valid=True)
then begin
edge_started:=True;
Inc(dots_index);
if dots_index>dots_max_c then dots_index:=dots_max_c;
dots[dots_index].X:=x_dots;
dots[dots_index].Y:=y_dots;
end
else if edge_started=True then BREAK; // don't resume adding dots to this edge once started and then gone out of limits.
end;//next now
mid_dots_index:=dots_index;
aq:=rail+outer_add; // outer-edges.
now_max:=nlmax_array[aq];
edge_started:=False;
for now:=now_max downto 0 do
begin
x_dots:=get_w_dots(aq,now);
y_dots:=get_l_dots(aq,now);
if (w_dims_valid=True) and (l_dims_valid=True)
then begin
edge_started:=True;
Inc(dots_index);
if dots_index>dots_max_c then dots_index:=dots_max_c;
dots[dots_index].X:=x_dots;
dots[dots_index].Y:=y_dots;
end
else if edge_started=True then BREAK; // don't resume adding dots to this edge once started and then gone out of limits.
end;//next now
if (rail=16) or (rail=20) // 093a platforms
then begin
Brush.Color:=printplat_infill_colour;
case print_platform_infill_style of
0: Brush.Style:=bsClear;
1: Brush.Style:=bsBDiagonal; // hatched. backward diagonal (forward diagonal on control template timbers).
2: Brush.Style:=bsDiagCross;
3: if (export_black_white=True) or (mapping_colours_print<0) // solid.
then Brush.Style:=bsBDiagonal // impact printer or plotter, or printing black and white or in a single colour.
else Brush.Style:=bsSolid;
else begin // 4 = blank.
Brush.Style:=bsSolid;
Brush.Color:=clWhite; // overide.
end;
end;//case
end
else begin
if ((draw_ts_trackbed_cess_edge=True) and (rail=18))
or ((draw_ms_trackbed_cess_edge=True) and (rail=22)) // 215a
then begin
Brush.Color:=sb_track_bgnd_colour; // cess use same colour as track background
Brush.Style:=bsFDiagonal;
end
else begin // normal rails...
Brush.Color:=printrail_infill_colour_cu;
case rail_infill_i of
1: Brush.Style:=bsBDiagonal; // hatched
2: Brush.Style:=bsSolid; // solid
3: Brush.Style:=bsDiagCross; // cross_hatched
4: begin // blank
Brush.Style:=bsSolid;
Brush.Color:=clWhite;
end;
else Brush.Style:=bsSolid; // ??? solid
end;//case
end;
end;
if dots_index>2
then begin
swap_polygon(on_canvas,canvas_height,Slice(dots,dots_index+1)); // +1, number of points, not index. must have 4 points.
edge_colour:=Pen.Color; // existing rail edges.
if Brush.Style=bsSolid
then blanking_colour:=Brush.Color // infill colour.
else begin // 206b hatched fill...
// output_code 1=sketchboard bitmap, 2=sketchboard metafile, 3=create image file, 4=create EMF file
case output_code of
1,2: blanking_colour:=Brush.Color; // T3-FIRST dtp_settings_form.sb_page_colour_panel.Color;
3: blanking_colour:=export_form.img_bgnd_colour_panel.Color;
4: blanking_colour:=Brush.Color; // for metafile export
else blanking_colour:=clWhite; // assume white background (print, PDF)
end;//case
end;
// remove polygon line across end of planing (not for fixed-diamond)..
// (for gaunt template this removes the polygon line across the rail end)
if ((half_diamond=False) or (fixed_diamond=False)) and ((rail=1) or (rail=2)) then modify_rail_end(0,dots_index,edge_colour,blanking_colour);
// remove polygon lines across stock rail ends...
// and trackbed ends 206b
if (rail=0) or (rail=3) or (rail=18) or (rail=22) // 18,22 added 206b
then begin
modify_rail_end(0,dots_index,edge_colour,blanking_colour); // toe or approach end.
modify_rail_end(mid_dots_index,mid_dots_index+1,edge_colour,blanking_colour); // exit end.
end;
if adjacent_edges=True // platforms
then begin
// 093a blank platform rear edges ...
if (rail=16) and (draw_ts_platform=True) and (draw_ts_platform_rear_edge=False) // 0.93.a TS platform start
then draw_outline_railedge(16,blanking_colour); // blank rear edge
if (rail=20) and (draw_ms_platform=True) and (draw_ms_platform_rear_edge=False) // 0.93.a TS platform start
then draw_outline_railedge(20,blanking_colour); // blank rear edge
// 093a blank platform ends ...
if (rail=16) and (draw_ts_platform=True) and (draw_ts_platform_start_edge=False) // 0.93.a TS platform start
then modify_rail_end(0,dots_index,edge_colour,blanking_colour);
if (rail=16) and (draw_ts_platform=True) and (draw_ts_platform_end_edge=False) // 0.93.a TS platform end
then modify_rail_end(mid_dots_index,mid_dots_index+1,edge_colour,blanking_colour);
if (rail=20) and (draw_ms_platform=True) and (draw_ms_platform_start_edge=False) // 0.93.a MS platform start
then modify_rail_end(0,dots_index,edge_colour,blanking_colour);
if (rail=20) and (draw_ms_platform=True) and (draw_ms_platform_end_edge=False) // 0.93.a MS platform end
then modify_rail_end(mid_dots_index,mid_dots_index+1,edge_colour,blanking_colour);
end;
if (rail=26) or (rail=28)
then begin
modify_rail_end(0,dots_index,edge_colour,blanking_colour); // centre of K-crossing check rails.
end;
end;
end;
end;//with
end;
//////////////////////////////////////////////////////////////////
procedure draw_fill_vee; // do complete vee in one go ...
const
dots_max_c=xy_pts_c*2; // 6000 max xy_pts_c=3000
var
dots:array[0..dots_max_c] of TPoint; // array of points for filled polygon mode.
// 3000 points for each side of rail. if incx is 18" scale (SQRT 9ft scale in 4mm = SQRT(36) =6 mm),
// template max is 4500' scale length.
// ( = 18000 mm or 59ft approx in 4 mm scale).
// ( = 66 A4 sheets long if straight turnout - but normally less for curved turnout).
// N.B. huge standard Pascal array is used instead of our own dynamic integer arrays,
// because needed for the Polygon function.
// total memory = 6000*8 bytes = 48KB
now:integer;
edge_started:boolean;
dots_index:integer;
x_dots,y_dots:integer;
aq:integer;
point_mid_dots_index, splice_mid_dots_index:integer;
edge_colour, blanking_colour:integer;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure modify_vee_end(start_index,stop_index,edge,blank:integer);
begin
if (start_index>=0) and (start_index<=dots_index) and (stop_index>=0) and (stop_index<=dots_index)
then begin
move_to:=dots[start_index];
line_to:=dots[stop_index];
if check_limits(move_to, line_to)=True
then begin
with on_canvas do begin
Pen.Color:=blank; // first blank across..
swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y);
swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y);
Pen.Color:=edge; // then restore the corner points..
swap_move_to(on_canvas,canvas_height,move_to.X, move_to.Y);
swap_line_to(on_canvas,canvas_height,move_to.X, move_to.Y);
swap_move_to(on_canvas,canvas_height,line_to.X, line_to.Y);
swap_line_to(on_canvas,canvas_height,line_to.X, line_to.Y);
end;//with
end;
end;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
begin
if plain_track=True then EXIT; // not if plain track.
if (aqyn[4]=False) or (aqyn[5]=False) or (aqyn[12]=False) or (aqyn[13]=False) // not enough data for filled vee.
or (nlmax_array[4]=0) or (nlmax_array[5]=0) or (nlmax_array[12]=0) or (nlmax_array[13]=0)
then begin
if aqyn[4]=True then draw_outline_railedge(4,printcurail_colour); // draw outline vee...
if aqyn[5]=True then draw_outline_railedge(5,printcurail_colour);
if aqyn[12]=True then draw_outline_railedge(12,printcurail_colour);
if aqyn[13]=True then draw_outline_railedge(13,printcurail_colour);
end
else begin
dots_index:=0-1; // first increment is to zero.
aq:=4;