-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgaps_unit.pas
More file actions
756 lines (551 loc) · 21.3 KB
/
gaps_unit.pas
File metadata and controls
756 lines (551 loc) · 21.3 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
(*
================================================================================
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 gaps_unit;
{$MODE Delphi}
{$ALIGN OFF}
interface
uses
StdCtrls, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ComCtrls;
type
Tgaps_form = class(TForm)
hide_panel: TPanel;
hide_button: TButton;
help_shape: TShape;
help_button: TButton;
Label1: TLabel;
slide_button: TButton;
blue_corner_panel: TPanel;
size_updown: TUpDown;
colour_panel: TPanel;
colour_patch: TImage;
symbol_on_check_rail_checkbox: TCheckBox;
add_symbol_button: TButton;
delete_symbol_button: TButton;
modify_symbol_button: TButton;
delete_all_symbols_button: TButton;
symbol_id_edit: TEdit;
Label2: TLabel;
Label3: TLabel;
replace_fill_colour_label: TLabel;
gap_colour_panel: TPanel;
gap_colour_button: TButton;
symbols_retain_on_mint_checkbox: TCheckBox;
symbols_retain_on_make_checkbox: TCheckBox;
Label6: TLabel;
symbols_visible_listbox: TListBox;
size_groupbox: TGroupBox;
small_radio: TRadioButton;
medium_radio: TRadioButton;
large_radio: TRadioButton;
giant_radio: TRadioButton;
radio_shape: TShape;
sticker_radio: TRadioButton;
gap_radio: TRadioButton;
dropper_radio: TRadioButton;
Label5: TLabel;
Label4: TLabel;
dropper_colour_panel: TPanel;
dropper_colour_button: TButton;
Label7: TLabel;
sticker_colour_panel: TPanel;
sticker_colour_button: TButton;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
show_hide_button: TButton;
rail_panel: TPanel;
rail_4_radio: TRadioButton;
rail_3_radio: TRadioButton;
rail_2_radio: TRadioButton;
rail_1_radio: TRadioButton;
procedure FormCreate(Sender: TObject);
procedure hide_buttonClick(Sender: TObject);
procedure size_updownClick(Sender: TObject; Button: TUDBtnType);
procedure colour_panelClick(Sender: TObject);
procedure symbol_id_editClick(Sender: TObject);
procedure symbol_id_editExit(Sender: TObject);
procedure delete_all_symbols_buttonClick(Sender: TObject);
procedure slide_buttonClick(Sender: TObject);
procedure add_symbol_buttonClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure gap_colour_buttonClick(Sender: TObject);
procedure symbols_visible_listboxClick(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure dropper_colour_buttonClick(Sender: TObject);
procedure sticker_colour_buttonClick(Sender: TObject);
procedure symbols_visible_listboxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure show_hide_buttonClick(Sender: TObject);
procedure symbols_visible_listboxExit(Sender: TObject);
procedure delete_symbol_buttonClick(Sender: TObject);
procedure modify_symbol_buttonClick(Sender: TObject);
procedure help_buttonClick(Sender: TObject);
procedure rail_1_radioClick(Sender: TObject);
procedure rail_2_radioClick(Sender: TObject);
procedure rail_3_radioClick(Sender: TObject);
procedure rail_4_radioClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
gaps_form:Tgaps_form;
highlit_symbol:integer=-1;
procedure update_symbols_dialog;
procedure symbols_visible_listbox_clicked(n:integer);
procedure delete_all_symbols;
function a_symbol_selected:boolean;
procedure set_radio_shape(rail:integer);
procedure delete_existing_symbols_by_code(symbol_code:integer); // 239a
//______________________________________________________________________________
implementation
{$R *.lfm}
uses
pad_unit,math_unit,keep_select,bgkeeps_unit,colour_unit,alert_unit,control_room;
//______________________________________________________________________________
procedure Tgaps_form.FormCreate(Sender: TObject);
begin
pad_form.InsertControl(gaps_form);
ClientWidth:=660;
ClientHeight:=424;
AutoScroll:=True;
end;
//______________________________________________________________________________
procedure Tgaps_form.hide_buttonClick(Sender: TObject);
begin
Hide;
end;
//______________________________________________________________________________
procedure Tgaps_form.FormHide(Sender: TObject);
begin
highlit_symbol:=-1;
radio_shape.Visible:=False;
pad_form.show_locator_menu_entry.Checked:=False;
redraw(True);
end;
//______________________________________________________________________________
procedure Tgaps_form.size_updownClick(Sender: TObject; Button: TUDBtnType);
begin
if size_updown.Position>size_updown.Tag // ! position goes up, size goes down.
then ScaleBy(9,10); // scale the form contents down.
if size_updown.Position<size_updown.Tag
then ScaleBy(10,9); // scale the form contents up.
ClientHeight:=VertScrollBar.Range; // allow 4 pixel right margin.
ClientWidth:=HorzScrollBar.Range+4; // don't need bottom margin - datestamp label provides this.
ClientHeight:=VertScrollBar.Range; // do this twice, as each affects the other.
size_updown.Tag:=size_updown.Position; // and save for the next click.
end;
//______________________________________________________________________________
procedure Tgaps_form.colour_panelClick(Sender: TObject);
begin
Color:=get_colour('choose a new window colour for the symbols dialog',Color);
end;
//______________________________________________________________________________
procedure Tgaps_form.symbol_id_editClick(Sender: TObject);
begin
pad_form.KeyPreview:=False;
symbol_id_edit.SetFocus;
end;
//______________________________________________________________________________
procedure Tgaps_form.symbol_id_editExit(Sender: TObject);
begin
pad_form.KeyPreview:=True; // reset
end;
//______________________________________________________________________________
function any_symbols:integer;
begin
RESULT:=Length(current_symbols);
end;
//______________________________________________________________________________
function a_symbol_selected:boolean;
begin
RESULT:=(any_symbols>0) and (gaps_form.symbols_visible_listbox.ItemIndex>-1);
end;
//______________________________________________________________________________
procedure update_symbols_dialog;
var
n,sel:integer;
begin
with gaps_form do begin
modify_symbol_button.Enabled:=(any_symbols>0);
delete_symbol_button.Enabled:=(any_symbols>0);
delete_all_symbols_button.Enabled:=(any_symbols>0);
if plain_track=True
then begin
rail_1_radio.Caption:='1. MS running rail';
rail_2_radio.Enabled:=False;
rail_3_radio.Enabled:=False;
rail_4_radio.Caption:='4. TS running rail';
end
else begin
rail_1_radio.Caption:='1. main-road stock rail';
rail_2_radio.Enabled:=True;
rail_3_radio.Enabled:=True;
rail_4_radio.Caption:='4. turnout-road stock rail';
end;
if (locator_rail<1) or (locator_rail>4)
then locator_rail:=1;
rail_1_radio.Checked:=(locator_rail=1);
rail_2_radio.Checked:=(locator_rail=2);
rail_3_radio.Checked:=(locator_rail=3);
rail_4_radio.Checked:=(locator_rail=4);
set_radio_shape(locator_rail);
sel:=symbols_visible_listbox.ItemIndex;
symbols_visible_listbox.Items.Clear;
if Length(current_symbols)>0
then for n:=0 to Length(current_symbols)-1 do symbols_visible_listbox.Items.Add(current_symbols[n].symbol_data.symb_list_str);
if (sel>-1) and (sel<symbols_visible_listbox.Items.Count) // keep it selected
then symbols_visible_listbox.ItemIndex:=sel;
end;//with form
end;
//______________________________________________________________________________
procedure delete_all_symbols;
var
n:integer;
begin
if any_symbols<1 then EXIT;
SetLength(current_symbols,0);
gaps_form.symbols_visible_listbox.Items.Clear;
redraw(True);
end;
//______________________________________________________________________________
procedure Tgaps_form.delete_all_symbols_buttonClick(Sender: TObject);
begin
if alert(7,' delete all symbols ?',
'You are about to delete all the symbols from this template.',
'','','','','cancel','delete all symbols',0)=5
then EXIT;
delete_all_symbols;
update_symbols_dialog;
end;
//______________________________________________________________________________
procedure Tgaps_form.slide_buttonClick(Sender: TObject);
begin
set_radio_shape(locator_rail);
pad_form.move_locator_menu_entry.Click;
end;
//______________________________________________________________________________
procedure Tgaps_form.add_symbol_buttonClick(Sender: TObject);
var
n,t:integer;
str,list_str:string;
begin
if (locator_rail<1) or (locator_rail>4)
then begin
show_modal_message('Unable to add a symbol - the marker is not currently on one of the rails.'
+#13+#13+'Click one of the buttons to select a rail and slide the marker along it.');
EXIT;
end;
str:=Trim(symbol_id_edit.Text);
if str='GAP' then str:='---'; // don't use id from a previously selected gap
if Length(str)>12
then begin
str:=Copy(str,1,12);
show_modal_message('symbol ID is : '+str+#13+#13+'(max 12 characters)');
end;
if dropper_radio.Checked=True
then t:=0
else if gap_radio.Checked=True
then t:=1
else t:=2;
case t of
0: list_str:='> '+str; // dropper
1: list_str:='| GAP'; // gap
else list_str:='# '+str; // sticker
end;//case
SetLength(current_symbols,Length(current_symbols)+1); // create a new line in symbols list
n:=HIGH(current_symbols); // index to it
with current_symbols[n].symbol_data do begin
str:=str+' '; // ensure file is filled..
list_str:=list_str+' ';
symb_list_str:=Copy(list_str,1,14);
symb_id_str:=Copy(str,1,12);
symb_check_rail:=symbol_on_check_rail_checkbox.Checked;
case t of
0: symb_colour:=dropper_colour_panel.Color;
1: symb_colour:=gap_colour_panel.Color;
else symb_colour:=sticker_colour_panel.Color;
end;//case
symb_type:=t;
symb_size:=0; // init
if medium_radio.Checked=True then symb_size:=1;
if large_radio.Checked=True then symb_size:=2;
if giant_radio.Checked=True then symb_size:=3;
symb_rail:=locator_rail;
symb_code:=0; // normal
symb_spare_float:=0;
symb_x:=locatorx-xorg; // from CTRL-1 to allow roaming and tools>make etc.
end;//with
update_symbols_dialog;
highlit_symbol:=-1; // reset
redraw(True);
end;
//______________________________________________________________________________
procedure Tgaps_form.FormShow(Sender: TObject);
begin
update_symbols_dialog;
end;
//______________________________________________________________________________
procedure Tgaps_form.dropper_colour_buttonClick(Sender: TObject);
begin
dropper_colour_panel.Color:=get_colour('choose a dropper colour',dropper_colour_panel.Color);
end;
//______________________________________________________________________________
procedure Tgaps_form.gap_colour_buttonClick(Sender: TObject);
begin
gap_colour_panel.Color:=get_colour('choose a gap colour',gap_colour_panel.Color);
end;
//______________________________________________________________________________
procedure Tgaps_form.sticker_colour_buttonClick(Sender: TObject);
begin
sticker_colour_panel.Color:=get_colour('choose a sticker colour',sticker_colour_panel.Color);
end;
//______________________________________________________________________________
procedure symbols_visible_listbox_clicked(n:integer);
begin
if (n<0) or (n>(Length(current_symbols)-1)) then EXIT;
with gaps_form do begin
highlit_symbol:=n; // global for highlighting
with current_symbols[n].symbol_data do begin // list should correspond
case symb_type of
0: begin
dropper_radio.Checked:=True;
dropper_colour_panel.Color:=symb_colour;
symbol_id_edit.Text:=symb_id_str;
end;
1: begin
gap_radio.Checked:=True;
gap_colour_panel.Color:=symb_colour;
symbol_id_edit.Text:='GAP';
end;
2: begin
sticker_radio.Checked:=True;
sticker_colour_panel.Color:=symb_colour;
symbol_id_edit.Text:=symb_id_str;
end;
end;//case
symbol_on_check_rail_checkbox.Checked:=symb_check_rail;
case symb_size of
0: small_radio.Checked:=True;
1: medium_radio.Checked:=True;
2: large_radio.Checked:=True;
3: giant_radio.Checked:=True;
end;//case
// put locator on it ...
locatorx:=xorg+symb_x;
locator_rail:=symb_rail;
set_radio_shape(locator_rail);
pad_form.show_locator_menu_entry.Checked:=True;
end;//with
end;//with form
redraw(True); // for highlighting and update dialog
end;
//______________________________________________________________________________
procedure Tgaps_form.symbols_visible_listboxClick(Sender: TObject);
begin
symbols_visible_listbox_clicked(symbols_visible_listbox.ItemIndex);
end;
//______________________________________________________________________________
procedure Tgaps_form.symbols_visible_listboxDrawItem(Control:TWinControl; Index:Integer; Rect:TRect; State:TOwnerDrawState);
begin
if (Index<0) or (Index>(symbols_visible_listbox.Items.Count-1)) then EXIT; // ???
with (Control as TListBox).Canvas do begin
if (odSelected in State)=True
then begin
Brush.Color:=$00FF7700; // light blue
Font.Color:=clWhite;
end
else begin
Brush.Color:=$00E8E8E8;
Font.Color:=current_symbols[Index].symbol_data.symb_colour;
end;
TextOut(Rect.Left,Rect.Top,(Control as TListBox).Items.Strings[Index]+' ');
end;//with
end;
//______________________________________________________________________________
procedure Tgaps_form.show_hide_buttonClick(Sender: TObject);
begin
if pad_form.show_template_symbols_menu_entry.Checked=True
then pad_form.hide_template_symbols_menu_entry.Click
else pad_form.show_template_symbols_menu_entry.Click; // toggle
highlit_symbol:=-1;
redraw(True); // for no highlighting
end;
//______________________________________________________________________________
procedure Tgaps_form.symbols_visible_listboxExit(Sender: TObject);
begin
highlit_symbol:=-1;
redraw(True); // for no highlighting
end;
//______________________________________________________________________________
procedure delete_existing_symbols_by_code(symbol_code:integer); // if any 239a
// code 1 is a chair options sticker
var
n,i:integer;
begin
if (Length(current_symbols)<1) then EXIT;
repeat
n:=-1; // init
for i:=0 to Length(current_symbols)-1 do begin
if current_symbols[i].symbol_data.symb_code=symbol_code
then begin
n:=i;
BREAK;
end;
end;//next
if n>(Length(current_symbols)-1) then EXIT; // ???
if n<0
then begin
update_symbols_dialog;
redraw(True);
EXIT;
end;
if n<(Length(current_symbols)-1) // not deleting the final element
then for i:=n+1 to Length(current_symbols)-1 do current_symbols[i-1]:=current_symbols[i]; // shift up
current_symbols:=Copy(current_symbols,0,Length(current_symbols)-1); // truncate final element
until n<0;
end;
//______________________________________________________________________________
procedure Tgaps_form.delete_symbol_buttonClick(Sender: TObject);
var
n,i:integer;
begin
if a_symbol_selected=False
then begin
show_modal_message('Click the list to select the symbol to be deleted.');
EXIT;
end;
n:=symbols_visible_listbox.ItemIndex;
if (Length(current_symbols)<1) or (n<0) or (n>(Length(current_symbols)-1)) then EXIT;
if n<(Length(current_symbols)-1) // not deleting the final element
then for i:=n+1 to Length(current_symbols)-1 do current_symbols[i-1]:=current_symbols[i]; // shift up
current_symbols:=Copy(current_symbols,0,Length(current_symbols)-1); // truncate final element
update_symbols_dialog;
redraw(True);
end;
//______________________________________________________________________________
procedure Tgaps_form.modify_symbol_buttonClick(Sender: TObject);
var
n,t:integer;
str,list_str:string;
begin
if a_symbol_selected=False
then begin
show_modal_message('Click the list to select the symbol to be modified.');
EXIT;
end;
n:=symbols_visible_listbox.ItemIndex;
str:=Trim(symbol_id_edit.Text);
if Length(str)>12
then begin
str:=Copy(str,1,12);
show_modal_message('symbol ID is : '+str+#13+#13+'(max 12 characters)');
end;
if dropper_radio.Checked=True
then t:=0
else if gap_radio.Checked=True
then t:=1
else t:=2;
case t of
0: list_str:='> '+str; // dropper
1: list_str:='| GAP'; // gap
else list_str:='# '+str; // sticker
end;//case
with current_symbols[n].symbol_data do begin
str:=str+' '; // ensure file is filled..
list_str:=list_str+' ';
symb_list_str:=Copy(list_str,1,14);
symb_id_str:=Copy(str,1,12);
symb_check_rail:=symbol_on_check_rail_checkbox.Checked;
case t of
0: symb_colour:=dropper_colour_panel.Color;
1: symb_colour:=gap_colour_panel.Color;
else symb_colour:=sticker_colour_panel.Color;
end;//case
symb_type:=t;
symb_size:=0; // init
if medium_radio.Checked=True then symb_size:=1;
if large_radio.Checked=True then symb_size:=2;
if giant_radio.Checked=True then symb_size:=3;
end;//with
update_symbols_dialog;
highlit_symbol:=-1; // reset
redraw(True);
end;
//______________________________________________________________________________
procedure set_radio_shape(rail:integer);
begin
with gaps_form do begin
case rail of
1: begin
radio_shape.top:=rail_panel.Top+rail_1_radio.Top+((rail_1_radio.Height-radio_shape.Height) DIV 2)+1;
radio_shape.Visible:=True;
end;
2: begin
radio_shape.top:=rail_panel.Top+rail_2_radio.Top+((rail_2_radio.Height-radio_shape.Height) DIV 2)+1;
radio_shape.Visible:=True;
end;
3: begin
radio_shape.top:=rail_panel.Top+rail_3_radio.Top+((rail_3_radio.Height-radio_shape.Height) DIV 2)+1;
radio_shape.Visible:=True;
end;
4: begin
radio_shape.top:=rail_panel.Top+rail_4_radio.Top+((rail_4_radio.Height-radio_shape.Height) DIV 2)+1;
radio_shape.Visible:=True;
end;
end;//case
end;//with form
end;
//______________________________________________________________________________
procedure Tgaps_form.help_buttonClick(Sender: TObject);
begin
go_to_templot_companion_page('construction_symbols.php');
end;
//______________________________________________________________________________
procedure Tgaps_form.rail_1_radioClick(Sender: TObject);
begin
locator_rail:=1;
update_symbols_dialog;
redraw(True); // move locator to rail
end;
//______________________________________________________________________________
procedure Tgaps_form.rail_2_radioClick(Sender: TObject);
begin
locator_rail:=2;
update_symbols_dialog;
redraw(True); // move locator to rail
end;
//______________________________________________________________________________
procedure Tgaps_form.rail_3_radioClick(Sender: TObject);
begin
locator_rail:=3;
update_symbols_dialog;
redraw(True); // move locator to rail
end;
//______________________________________________________________________________
procedure Tgaps_form.rail_4_radioClick(Sender: TObject);
begin
locator_rail:=4;
update_symbols_dialog;
redraw(True); // move locator to rail
end;
//______________________________________________________________________________
end.