-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrouteGraphics.tcl
executable file
·2604 lines (2352 loc) · 60.8 KB
/
routeGraphics.tcl
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
#!/usr/bin/env tclsh8.6
# Configuration
set here [file normalize [file dirname [info script]]]
source [file join $here config.tcl]
set init 0
for {set i 0} {$i < [llength $argv]} {incr i} {
set key [lindex $argv $i]
switch -exact -- $key {
--init {
set init 1
}
--prefix - -p {
incr i
if {$i >= [llength $argv]} {
error "--prefix requires a value"
}
set prefix [lindex $argv $i]
}
}
}
set templateDir [file join $here templates]
# Connect to the database
package require tdbc::postgres
tdbc::postgres::connection create db -db $dbname
namespace eval routeGraphics {
variable templateCache {}
proc init {} {
variable ::pngDir
variable ::tmpDir
variable ::templateDir
variable sawUnknownNetwork
variable didBanner
variable didRoute
variable templateExists
file mkdir $pngDir
set sawUnknownNetwork {}
set didBanner {}
set didRoute {}
file mkdir $tmpDir
foreach template [glob -directory $templateDir -types f -tails *.svg] {
dict set templateExists $template {}
}
}
# Colors for simplified 'flower pot' shields for counties in Ontario
# Any county not listed is black-on-white
variable CA_ON_county_shieldcolors {
Grey white_blue
Halton yellow_blue
Hamilton white_blue
Niagara white_blue
Peel yellow_black
Simcoe blue_white
}
# Haldimand, Huron, Lennox and Addington, Middlesex,
# Norfolk, Prescott and Russell are unverified
# Perth needs special handling for PERTH LINE and PERTH ROAD
# Don't attempt these labels at the moment - they are not
# really useful for markers on maps.
variable CA_ON_county_labels {
"Brant" {BRANT COUNTY}
"Bruce" {BRUCE COUNTY}
"Chatham-Kent" {CHATHAM KENT}
"Dufferin" {DUFFERIN COUNTY}
"Durham" {DURHAM REGION}
"Elgin" {ELGIN COUNTY}
"Essex" {ESSEX COUNTY}
"Frontenac" {FRONTENAC COUNTY}
"Haldimand" {HALDIMAND COUNTY}
"Haliburton" {HALIBURTON COUNTY}
"Hastings" {HASTINGS COUNTY}
"Huron" {HURON COUNTY}
"Kawartha Lakes" {KAWARTHA LAKES}
"Greater Sudbury" {GREATER SUDBURY}
"Lambton" {LAMBTON COUNTY}
"Lanark" {LANARK COUNTY}
"Leeds and Grenville" {"LEEDS AND\nGRENVILLE" COUNTIES}
"Lennox and Addington" {"LENNOX AND\nADDINGTON" COUNTY}
"Middlesex" {MIDDLESEX COUNTY}
"Muskoka" {MUSKOKA {}}
"Norfolk" {NORFOLK COUNTY}
"Northumberland" {NORTHUMBERLAND COUNTY}
"Ottawa" {OTTAWA {}}
"Oxford" {OXFORD COUNTY}
"Peterborough" {PETERBOROUGH COUNTY}
"Prescott and Russell" {"PRESCOTT AND\nRUSSELL" COUNTIES}
"Prince Edward" {"PRINCE\nEDWARD" COUNTY}
"Renfrew" {RENFREW COUNTY}
"Stormont, Dundas and Glengarry" {S.D.G. {}}
"Waterloo" {WATERLOO REGION}
"Wellington" {WELLINGTON COUNTY}
"York" {REGION YORK}
}
# New York has a great many roads that have unique shields.
# List them here
variable US_NY_parkways {
"BMP" US:NY-BMP.svg
"Bear Mountain State Parkway" US:NY-BMP.svg
"BP" US:NY-BP.svg
"Belt Parkway" US:NY-BP.svg
"B" US:NY-BSP.svg
"Bethpage State Parkway" US:NY-BSP.svg
"BRP" US:NY-BRP.svg
"Bronx River Parkway" US:NY-BRP.svg
"CCP" US:NY-CCP.svg
"Cross Country Parkway" US:NY-CCP.svg
"CIP" US:NY-CIP.svg
"Cross Island Parkway" US:NY-CIP.svg
"FDR" US:NY-FDR.svg
"FDRD" US:NY-FDR.svg
"FDR Drive" US:NY-FDR.svg
"Franklin D. Roosevelt East River Drive" US:NY-FDR.svg
"GCP" US:NY-GCP.svg
"Grand Central Parkway" US:NY-GCP.svg
"HRD" US:NY-HRD.svg
"Harlem River Drive" US:NY-HRD.svg
"H" US:NY-HSP.svg
"Heckscher State Parkway" US:NY-HSP.svg
"HHP" US:NY-HHP.svg
"Henry Hudson Parkway" US:NY-HHP.svg
"HRP" US:NY-HRP.svg
"Hutchinson River Parkway" US:NY-HRP.svg
"JRP" US:NY-JRP.svg
"Jackie Robinson Parkway" US:NY-JRP.svg
"KWVP" US:NY-KWVP.svg
"Korean War Veterans Parkway" US:NY-KWVP.svg
"LOSP" US:NY-LOSP.svg
"Lake Ontario State Parkway" US:NY-LOSP.svg
"LE" US:NY-LE.svg
"LaSalle Expressway" US:NY-LE.svg
"LWP" US:NY-LWP.svg
"Lake Welch Parkway" US:NY-LWP.svg
"L" US:NY-LP.svg
"Loop Parkway" US:NY-LP.svg
"M" US:NY-MSP.svg
"Meadowbrook State Parkway" US:NY-MSP.svg
"MP" US:NY-MP.svg
"Mosholu Parkway" US:NY-MP.svg
"N" US:NY-NSP.svg
"NSP" US:NY-NSP.svg
"Northern State Parkway" US:NY-NSP.svg
"O" US:NY-OP.svg
"Ocean Parkway" US:NY-OP.svg
"PIP" US:NY-PIP.svg
"Palisades Interstate Parkway" US:NY-PIP.svg
"PP" US:NY-PP.svg
"Pelham Parkway" US:NY-PP.svg
"Bronx and Pelham Parkway" US:NY-PP.svg
"RM" US:NY-RMC.svg
"Robert Moses Causeway" US:NY-RMC.svg
"RMSP" US:NY-RMSP.svg
"Robert Moses State Parkway" US:NY-RMSP.svg
"SA" US:NY-SASP.svg
"Sagtikos State Parkway" US:NY-SASP.svg
"SMP" US:NY-SMP.svg
"Saw Mill River Parkway" US:NY-SMP.svg
"SLD" US:NY-SLD.svg
"Seven Lakes Drive" US:NY-SLD.svg
"SM" US:NY-SMSP.svg
"Sunken Meadow State Parkway" US:NY-SMSP.svg
"SO" US:NY-SOSP.svg
"Southern State Parkway" US:NY-SOSP.svg
"SBP" US:NY-SBP.svg
"Sprain Brook Parkway" US:NY-SBP.svg
"TSP" US:NY-TSP.svg
"Taconic State Parkway" US:NY-TSP.svg
"W" US:NY-WSP.svg
"Wantagh State Parkway" US:NY-WSP.svg
}
# Ohio abbreviates its county names - expand them here
variable US_OH_county_abbr {
ATH ATHENS
AUG AUGLAIZE
BEL BELMONT
BUT BUTLER
CAR CARROLL
COL COLUMBIANA
COS COSHOCTON
FAI FAIRFIELD
FUL FULTON
GAL GALLIA
GUE GUERNSEY
HAR HARDIN
HAS HARRISON
HEN HENRY
HOC HOCKING
HOL HOLMES
KNO KNOX
JEF JEFFERSON
LAW LAWRENCE
LIC LICKING
LOG LOGAN
LUC LUCAS
MAH MAHONING
MED MEDINA
MOE MONROE
MRW MORROW
NOB NOBLE
OTT OTTAWA
PAU PAULDING
PER PERRY
SCI SCIOTO
SEN SENECA
STA STARK
SUM SUMMIT
TUS TUSCARAWAS
UNI UNION
VIN VINTON
WAY WAYNE
WIL WILLIAMS
WYA WYANDOT
}
proc finish {} {
variable ::tmpDir
file delete -force $tmpDir
}
init
}
proc routeGraphics::launchInkscape {} {
variable inkscapeChan
variable inkscapeCollect
variable inkscapeReady
puts "Launch inkscape"
set inkscapeChan [open "|inkscape --shell" w+]
chan configure $inkscapeChan -blocking 0 -buffering line
set inkscapeCollect {}
set inkscapeReady 0
fileevent $inkscapeChan readable [namespace current]::replyFromInkscape
waitForInkscape
puts "Inkscape ready"
}
proc routeGraphics::waitForInkscape {} {
variable inkscapeReady
while {!$inkscapeReady} {
vwait [namespace current]::inkscapeReady
}
}
proc routeGraphics::runInkscape {svg size png} {
variable inkscapeChan
variable inkscapeReady
waitForInkscape
set inkscapeReady 0
# puts "Is $svg readable? [file readable $svg]"
# puts "Send to Inkscape:"
# puts "\"$svg\" --export-area-snap --export-height=$size\
# --export-png=\"$png\""
puts $inkscapeChan "\"$svg\" --export-area-snap --export-height=$size\
--export-png=\"$png\""
}
proc routeGraphics::closeInkscape {} {
variable inkscapeChan
close $inkscapeChan
}
proc routeGraphics::replyFromInkscape {} {
variable inkscapeChan
variable inkscapeCollect
variable inkscapeReady
set status [catch {read $inkscapeChan} data]
if {$status != 0} {
puts stderr "Inkscape error: $data"
catch {close $inkscapeChan}
} elseif {[string length $data] > 0} {
append inkscapeCollect $data
if {[string range $inkscapeCollect end-1 end] eq "\n>"} {
#puts stderr [string range $inkscapeCollect 0 end-1]
set inkscapeReady 1
set inkscapeCollect {}
}
} elseif {[eof $inkscapeChan]} {
puts stderr $inkscapeCollect
puts stderr "Unexpected EOF from inkscape"
catch {close $inkscapeChan}
}
}
namespace eval routeGraphics {
variable modifierKeys {
Alternate Belt
Business Bypass
City Connector Downtown
Emergency Future Link
Loop Scenic Spur
Toll Truck
}
}
proc routeGraphics::strip_modifiers {network modifiersVar} {
upvar 1 $modifiersVar modifiers
variable modifierKeys
set parts [split $network :]
set mods {}
for {set i [expr {[llength $parts] - 1}]} {$i > 0} {incr i -1} {
set part [lindex $parts $i]
if {$part in $modifierKeys} {
lappend mods $part
} else {
break
}
}
set modifiers [lreverse $mods]
return [join [lrange $parts 0 $i] :]
}
proc routeGraphics::readTemplate {template} {
variable ::templateDir
variable templateCache
if {![dict exists $templateCache $template]} {
set f [open [file join $templateDir $template] r]
dict set templateCache $template [read $f]
close $f
}
return [dict get $templateCache $template]
}
proc routeGraphics::getSVGName {network ref} {
variable ::tmpDir
# Sanitize the file name
set ref [string map {/ :} $ref]
return [file join $tmpDir $network $ref.svg]
}
proc routeGraphics::getPNGName {network ref size} {
variable ::pngDir
set dir [file join $pngDir default $size $network]
file mkdir $dir
# Sanitize the file name
set ref [string map {/ :} $ref]
if {$ref eq ""} { set ref "_" }
return [file join $dir $ref.png]
}
proc routeGraphics::getBannerSVGName {network banner} {
variable ::tmpDir
return [file join $tmpDir $network-$banner.svg]
}
proc routeGraphics::getBannerPNGName {network banner size} {
variable ::pngDir
set bannerDir [file join $pngDir default $size BANNER:$network]
file mkdir $bannerDir
return [file join $bannerDir $banner.png]
}
proc routeGraphics::makeSVG {network ref templateFile keys values} {
variable ::tmpDir
set svgname [getSVGName $network $ref]
if {![file exists $svgname]} {
file mkdir [file dirname $svgname]
set template [readTemplate $templateFile]
set map {}
foreach k $keys v $values {
if {$k != {}} {
lappend map %$k% $v
}
}
set data [string map $map $template]
set f [open $svgname w]
puts -nonewline $f $data
close $f
}
return $svgname
}
proc routeGraphics::makePNGs {network ref {scale 1.0}} {
variable ::sizes
variable makeshield
variable removeshield
db transaction {
set svgName [getSVGName $network $ref]
foreach size $sizes {
set pngName [getPNGName $network $ref $size]
set svgHeight [expr {$size * $scale}]
runInkscape $svgName $svgHeight $pngName
$removeshield allrows [list \
network $network \
ref $ref \
size $size]
$makeshield allrows [list \
network $network \
ref $ref \
size $size \
filename $pngName]
}
}
}
namespace eval routeGraphics {
variable bannerFilesDefault {
ALTERNATE banner:alternate.svg
ALT banner:alt.svg
BELT banner:belt.svg
BUSINESS banner:bus.svg
BYPASS banner:byp.svg
CITY banner:city.svg
CONNECTOR banner:connector.svg
EMERGENCY banner:emergency.svg
LOOP banner:loop.svg
SCENIC banner:scenic.svg
SPUR banner:spur.svg
TOLL banner:toll.svg
TRUCK banner:truck.svg
}
variable bannerFilesI {
FUTURE banner:i:future.svg
SPUR banner:i:spur.svg
}
variable bannerFilesCR {
ALTERNATE banner:cr:alt.svg
SPUR banner:cr:spur.svg
TRUCK banner:cr:truck.svg
}
}
proc routeGraphics::makeBannerSVG {network modifier} {
variable bannerFilesDefault
variable bannerFilesI
variable bannerFilesCR
variable ::templateDir
if {$network eq "US:I"} {
set bannerFiles $bannerFilesI
} elseif {[regexp "US:..:.*" $network]} {
set bannerFiles $bannerFilesCR
} else {
set bannerFiles $bannerFilesDefault
}
if {![dict exists $bannerFiles $modifier]} {
puts stderr "OOPS: No file for modifier $modifier in network $network"
}
set svgname [getBannerSVGName $network $modifier]
set templateFile [file join $templateDir [dict get $bannerFiles $modifier]]
if {![file exists $svgname]} {
set template [readTemplate $templateFile]
set map [list %num% $modifier]
set data [string map $map $template]
set f [open $svgname w]
puts -nonewline $f $data
close $f
}
}
proc routeGraphics::makeBannerPNG {network banner size {scale 0.5}} {
set svgName [getBannerSVGName $network $banner]
set pngName [getBannerPNGName $network $banner $size]
if {![file exists $pngName]} {
#puts "Make PNG $pngName from $svgName at scale $scale and size $size"
runInkscape $svgName [expr {$scale * $size}] $pngName
}
}
proc routeGraphics::stackModifiers {network rootNetwork ref
modifiers {modnw {}}} {
variable didBanner
variable makeshield
variable removeshield
variable ::sizes
if {$modnw eq {}} {
set modnw $rootNetwork
}
set modifiers [string toupper $modifiers]
foreach modifier $modifiers {
if {![dict exists $didBanner $modnw $modifier]} {
makeBannerSVG $modnw $modifier
}
}
db transaction {
foreach size $sizes {
set pngs {}
if {![dict exists $didBanner $modnw $modifiers]} {
foreach modifier $modifiers {
makeBannerPNG $modnw $modifier $size
}
}
foreach modifier $modifiers {
lappend pngs [getBannerPNGName $modnw $modifier $size]
}
lappend pngs [getPNGName $rootNetwork $ref $size]
set stackName [getPNGName $network $ref $size]
waitForInkscape
set status [catch {
exec convert -background transparent -gravity Center \
{*}$pngs -append $stackName
} result]
if {$status != 0} {
puts "ERROR: $result"
}
$removeshield allrows [list \
network $network \
ref $ref \
size $size]
$makeshield allrows [list \
network $network \
ref $ref \
size $size \
filename $stackName]
}
}
foreach modifier $modifiers {
dict set didBanner $network $modifier
}
}
proc routeGraphics::findGenericTemplate {pattern ref} {
variable templateExists
# This procedure is for numbered routes. If there is no number supplied,
# give up at this point so as not to generate blank shields.
if {$ref eq {}} {
return {}
}
switch -regexp -- $ref {
{^[^1]$} { set needwid 1 }
{^.$} { set needwid 0.5 }
{^[^1][^1]$} { set needwid 2 }
{^..$} { set needwid 1.5 }
{^[^1][^1][^1]$} { set needwid 3 }
{^...$} { set needwid 2.5 }
{^[^1][^1][^1][^1]$} { set needwid 4 }
{^....$} { set needwid 3.5 }
{^.....$} { set needwid 5 }
default {
set needwid 6
}
}
set widest {}
for {set wid 0.5} {$wid <= 6} {set wid [format %g [expr {0.5 + $wid}]]} {
set trial ${pattern}_${wid}.svg
if {[dict exists $templateExists $trial]} {
set widest $trial
if {$wid >= $needwid} {
return $widest
}
}
}
return $widest
}
proc routeGraphics::make_pngs {network ref} {
variable didRoute
variable sawUnknownNetwork
if {[dict exists $didRoute $network $ref]} {
return
}
dict set didRoute $network $ref {}
set ok 0
set rootnetwork [strip_modifiers $network modifiers]
set pat ""
switch -regexp -matchvar nwparts $rootnetwork {
lcn - rcn - ncn -
lwn - rwn - nwn {
# Don't process shields for cycleways and footways yet.
return 0
}
{^US:NHS High Priority Corridors} -
{^US:NY:Reference} {
# These should be unsigned_ref!
return 0
}
^CA:AB$ {
if {$ref in {1 16}} {
set mod {ALBERTA}
set pat CA:TCH_1.5.svg
set scale 1.33333
} elseif {[regexp {^[5678]\d\d$} $ref]} {
set mod {}
set pat [findGenericTemplate CA:AB_local $ref]
set num $ref
set scale 1.33333
} else {
set mod {}
set pat [findGenericTemplate CA:AB $ref]
set num $ref
set scale 1.33333
}
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num mod} [list $num $mod]
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:AB:primary$ {
set mod {}
set pat [findGenericTemplate CA:AB $ref]
set num $ref
set scale 1.33333
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num mod} [list $num $mod]
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:AB:secondary$ {
set mod {}
set pat [findGenericTemplate CA:AB_local $ref]
set num $ref
set scale 1.33333
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num mod} [list $num $mod]
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:BC$ -
^CA:BC:primary$ -
^CA:BC:trunk$ {
if {$ref in {1 16}} {
set mod {BRITISH COLUMBIA}
set pat CA:TCH_1.5.svg
set num $ref
set suf {}
set scale 1.3
} elseif {[regexp {^([0-9]+)([A-Z])$} $ref -> num suf]} {
set mod {}
set pat [findGenericTemplate CA:BC_suf $num]
set scale 1.2
} elseif {[regexp {^[0-9]+$} $ref num]} {
set mod {}
set pat [findGenericTemplate CA:BC $num]
set suf {}
set scale 1.2
} else {
puts "No pattern matches $network $ref"
}
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num suf mod} [list $num $suf $mod]
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:MB$ -
^CA:MB:PTH$ {
if {$ref in {1 16 100}} {
set mod {MANITOBA}
set pat [findGenericTemplate CA:TCH $ref]
set num $ref
set suf {}
set scale 1.3
} elseif {[regexp {^([0-9]+)([A-Z])$} $ref -> num suf]} {
set mod {}
set pat [findGenericTemplate CA:MB_suf $num]
set scale 1.25
} elseif {[regexp {^[0-9]+$} $ref num]} {
set mod {}
if {$num >= 200} {
set pat [findGenericTemplate CA:MB_secondary $num]
set scale 1.25
} else {
set pat [findGenericTemplate CA:MB $num]
set scale 1.25
}
set suf {}
} else {
puts "No pattern matches $network $ref"
}
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num suf mod} [list $num $suf $mod]
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:MB:PR$ {
set pat [findGenericTemplate CA:MB_secondary $ref]
set scale 1.25
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat {num} $ref
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NB:primary$ {
set pat [findGenericTemplate CA:NB_green $ref]
set scale 1.0
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat {num} $ref
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NB:secondary$ {
set pat [findGenericTemplate CA:NB_blue $ref]
set scale 1.0
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat {num} $ref
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NB:tertiary$ {
set pat [findGenericTemplate CA:NB_black $ref]
set scale 1.0
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat {num} $ref
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NL$ -
^CA:NL:R$ {
if {$ref in {1}} {
set pat CA:TCH
set scale 1.2
} else {
# Replace dashes with centred dots for compactness
regsub -all -- {-} $ref \u00b7 ref
set pat CA:NL
set scale 1.0
}
set pat [findGenericTemplate $pat $ref]
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat {num} $ref
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NS:T {
if {![string is integer -strict $ref]} {
set ok 0
} else {
set pat [findGenericTemplate US:US $ref]
makeSVG $rootnetwork $ref $pat {num} [list $ref]
makePNGs $rootnetwork $ref 1.0
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NS:H {
if {![string is integer -strict $ref]} {
set ok 0
} else {
set pat CA:NS_arterial_2.5.svg
if {$ref >= 104 && $ref <= 106} {
set pat [findGenericTemplate CA:TCH $ref]
}
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat {num} [list $ref]
makePNGs $rootnetwork $ref 1.2
set ok 1
}
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NS:R {
if {![string is integer -strict $ref]} {
set ok 0
} else {
set pat CA:NS_collector_3.svg
makeSVG $rootnetwork $ref $pat {num} [list $ref]
makePNGs $rootnetwork $ref 0.5
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NS$ {
set scale 1.0
if {![string is integer -strict $ref]} {
set ok 0
} elseif {$ref < 100} {
# Nova Scotia trunk roads look just like US Highways
set pat [findGenericTemplate US:US $ref]
} elseif {$ref >= 104 && $ref <= 106} {
set pat [findGenericTemplate CA:TCH $ref]
} elseif {$ref < 200} {
set pat [findGenericTemplate CA:NS_arterial $ref]
set scale 1.2
} else {
set pat [findGenericTemplate CA:NS_collector $ref]
set scale 0.5
}
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num} [list $ref]
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:NT$ {
set pat [findGenericTemplate CA:NT $ref]
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat {num} $ref
makePNGs $rootnetwork $ref
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:ON:primary$ {
set tpos [lsearch -nocase -exact Toll $modifiers]
if {$tpos >= 0} {
set modifiers [lreplace $modifiers $tpos $tpos]
append rootnetwork :Toll
set num $ref
set suf {}
set pat [findGenericTemplate CA:ON:primary:Toll $num]
set scale 2.0
} else {
switch -regexp -matchvar refparts $ref {
QEW {
set pat CA:ON:primary-QEW.svg
set num QEW
set suf {}
}
{(\d+)([[:alpha:]])} {
lassign $refparts - num suf
set pat [findGenericTemplate CA:ON:primary_suf $num]
}
{\d+} {
set num $ref
set suf {}
set pat [findGenericTemplate CA:ON:primary $num]
}
default {
puts "$network $ref not handled"
}
}
set scale 1.6
}
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num suf} [list $num $suf]
makePNGs $rootnetwork $ref $scale
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:ON:primary:ETR$ {
regsub -- { ETR$} $ref {} num
set pat [findGenericTemplate CA:ON:primary:ETR $num]
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num} [list $num]
makePNGs $rootnetwork $ref 1.0
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:ON:secondary$ {
switch -regexp -matchvar refparts $ref {
{(\d+)([[:alpha:]])} {
lassign $refparts - num suf
set pat [findGenericTemplate CA:ON:secondary_suf $num]
}
{\d+} {
set num $ref
set suf {}
set pat [findGenericTemplate CA:ON:secondary $num]
}
default {
puts "$network $ref not handled"
}
}
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num suf} [list $num $suf]
makePNGs $rootnetwork $ref 1.0
set ok 1
}
if {$ok} {
stackModifiers $network $rootnetwork $ref $modifiers
}
}
^CA:ON:tertiary$ {
set pat [findGenericTemplate CA:ON:tertiary $ref]
if {$pat ne ""} {
makeSVG $rootnetwork $ref $pat \
{num} [list $ref]
makePNGs $rootnetwork $ref 1.0
set ok 1