diff --git a/CMakeLists.txt b/CMakeLists.txt index 616005596..90f52237f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -491,6 +491,13 @@ file(READ "${EDITOR_ICONS}" EDITOR_ICONS_HEX HEX) string(REGEX REPLACE "(................................)" "\\1\n" EDITOR_ICONS_HEX "${EDITOR_ICONS_HEX}") string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," EDITOR_ICONS_HEX "${EDITOR_ICONS_HEX}") file(CONFIGURE OUTPUT "${CMAKE_BINARY_DIR}/geninc/editor_icons_png.inc" CONTENT "${EDITOR_ICONS_HEX}\n") +# and so is the catalogue of the turnouts, a text file read when it's first needed, see editor/editorSwitchDesign.cpp +set(EDITOR_TURNOUTS "${CMAKE_SOURCE_DIR}/editor/data/turnouts.txt") +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${EDITOR_TURNOUTS}") +file(READ "${EDITOR_TURNOUTS}" EDITOR_TURNOUTS_HEX HEX) +string(REGEX REPLACE "(................................)" "\\1\n" EDITOR_TURNOUTS_HEX "${EDITOR_TURNOUTS_HEX}") +string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," EDITOR_TURNOUTS_HEX "${EDITOR_TURNOUTS_HEX}") +file(CONFIGURE OUTPUT "${CMAKE_BINARY_DIR}/geninc/editor_turnouts_txt.inc" CONTENT "${EDITOR_TURNOUTS_HEX}\n") set (PREFIX "") set (SUFFIX "") diff --git a/editor/data/turnouts.txt b/editor/data/turnouts.txt new file mode 100644 index 000000000..08473bc1c --- /dev/null +++ b/editor/data/turnouts.txt @@ -0,0 +1,153 @@ +# The catalogue of the turnouts of the track editor (editor-tracks-domain.md §7): one type a line, the switch tool of the editor and +# the domain model of the track geometry (editor/layout) both read it. Built into the executable (CMakeLists.txt, editor_turnouts_txt.inc), +# so the game data doesn't need it. The templates the user makes in the switch designer are kept in eu07_switch_templates.txt in this +# same format, with their geometry given as parts. +# +# switch ... source +# name in quotes, or with _ for a blank +# type Rz ordinary, Rls symmetric, Rpd double to both sides, Rpj double to one side, Rps symmetric double, +# Rkp single slip, Rkpd double slip, Skrz diamond crossing +# rail 60E1, 49E1, S42, - for none +# The geometry, of a type of the catalogue: +# radius m, of the curve of the diverging track; of the slip curves of a slip +# ratio n of 1:n at the end of the diverging track; of the two tracks parting of a symmetric switch; of the crossing of a slip +# a m, from the start of the switch to the crossing of the tangents (its centre); of a slip or a crossing from its centre to +# the joints, the half length; none: the tangent of the curve +# b m, from the centre on along the main track; none: up to the end of the curve +# diverging m, from the centre along the diverging track where the scheme gives it another length than b +# blades tangent: the diverging track leaves the main one tangentially, its curve starting at the start or a pre-blade stretch +# further where a is longer than the tangent; secant: the blades cut into the stock rails at 25' (S42), the pre-blade +# stretch what a leaves of it, 0.6 m and the angle fitted to a where it leaves none +# cut m, the cut blade tip from the start of the curve (60E1, 49E1); none: where the blade gets 3 mm from the stock rail or +# 5 mm less 125 mm planed, about sqrt(2 R 0.005) - 0.125 +# fit straights | transition | arc_straight_arc: the diverging track fitted to the tangents a and b (not of Id-4) +# stagger m, of a double switch: where its second switch starts along the main track +# radius2 ratio2 a2 b2 diverging2 blades2 cut2 of the second switch of a double switch, as of the first one +# middle of a slip: 0 one arc for its slip curves, -1 a straight in their middle, the blades outside of the diamond +# note shown after the name on the list +# The geometry, of a template of the user: main, a, b, stagger, lead, entry (degrees), tip, lead2, entry2, tip2, heel, throw, and +# parts ( )..., parts2 ...: R 0 a straight, the same R at both ends an arc +# What the catalogue tells besides the geometry, - where it doesn't: +# frog fixed or movable (a movable nose) +# locks the number of the locks of the blades (Id-4 tab. 14-3) +# drive the family of the point machine +# speed km/h on the diverging track of the basic switch, ST-T1-A6 tab. 11.2 (by the radius, as switch_curve::basic_speed) +# bending m, the least radius of the main track of the switch bent one-sided, and the one allowed by way of exception, +# ST-T1-A6 tab. 11.9; - where the table has no such basic switch +# spacing m, the least spacing of the tracks for a single crossover, ST-T1-A6 tab. 11.2; - where the table hasn't the type +# source where the values come from; what is unconfirmed is said so + +# the ordinary and the symmetric switches of Id-4 (PKP PLK, the uniform text of 16.05.2024), tables 8-1 (60E1), 8-2 (49E1) and 8-3 (S42): +# a from the start of the switch to its centre, b on from there along the main track, and along the diverging track where the scheme +# gives it another length +switch "Rz 60E1-190-1:9" type Rz rail 60E1 radius 190 ratio 9 a 10.523 b 16.615 blades tangent cut 1.2483 frog fixed locks - drive - speed 40 bending - spacing 3.7 source Id-4 tab. 8-1; cut tip SKMd-4 (1.248); speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 60E1-300-1:9" type Rz rail 60E1 radius 300 ratio 9 a 16.615 b 16.615 blades tangent cut 1.5 frog fixed locks 2 drive - speed 50 bending 1505.522 749.722 spacing 4.35 source Id-4 tab. 8-1; cut tip SKMd-4 (e1 1.500, e2 1.468); locks Id-4 zał. 4 pkt 4 (a second lock); ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 60E1-500-1:12" type Rz rail 60E1 radius 500 ratio 12 a 20.797 b 20.797 blades tangent cut 2.165 frog fixed locks 2 drive - speed 60 bending 501.73 375.638 spacing 4 source Id-4 tab. 8-1; cut tip SKMd-4 (e1 2.165, e2 2.142); locks Id-4 tab. 14-3; ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 60E1-500-1:12 movable nose" type Rz rail 60E1 radius 500 ratio 12 a 20.797 b 20.797 blades tangent cut 2.165 frog movable locks 2 drive - speed 60 bending 501.73 375.638 spacing 4 source Id-4 tab. 8-1; cut tip SKMd-4 (e1 2.165, e2 2.142); locks Id-4 tab. 14-3; ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 60E1-760-1:14" type Rz rail 60E1 radius 760 ratio 14 a 27.108 b 27.108 blades tangent cut 2.633 frog fixed locks 3 drive - speed 80 bending 497.25 497.25 spacing 4.75 source Id-4 tab. 8-1; cut tip 2.633 unconfirmed (no SKMd-4 sheet found); locks Id-4 tab. 14-3; ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 60E1-1200-1:18,5" type Rz rail 60E1 radius 1200 ratio 18.5 a 32.409 b 32.409 blades tangent cut 3.3347 frog fixed locks 3 drive - speed 100 bending 750.001 750.001 spacing 4.35 source Id-4 tab. 8-1; cut tip SKMd-4 (e1 3.335, e2 3.321); locks Id-4 tab. 14-3; ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 60E1-1200-1:18,5 movable nose" type Rz rail 60E1 radius 1200 ratio 18.5 a 32.409 b 32.409 blades tangent cut 3.3347 frog movable locks 3 drive - speed 100 bending 750.001 750.001 spacing 4.35 source Id-4 tab. 8-1; cut tip SKMd-4 (e1 3.335, e2 3.321); locks Id-4 tab. 14-3; ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 60E1-2500-1:26,5 movable nose" type Rz rail 60E1 radius 2500 ratio 26.5 a 47.153 b 47.153 blades tangent frog movable locks - drive - speed 130 bending 1510 1510 spacing 4.8 source Id-4 tab. 8-1, a and b unconfirmed (editor-tracks-domain.md §6.5 pkt 5), Id-4 confirms 130 km/h and the chord offsets of R 2500; no blade data: the tip by the rule sqrt(2 R 0.005) - 0.125; ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 49E1-190-1:7,5" type Rz rail 49E1 radius 190 ratio 7.5 a 12.611 b 12.611 blades tangent cut 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); speed ST-T1-A6 tab. 11.2 +switch "Rz 49E1-190-1:7,5 long" type Rz rail 49E1 radius 190 ratio 7.5 a 12.611 b 17.428 blades tangent cut 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); speed ST-T1-A6 tab. 11.2 +switch "Rz 49E1-190-1:9" type Rz rail 49E1 radius 190 ratio 9 a 10.523 b 16.615 blades tangent cut 1.2483 frog fixed locks - drive - speed 40 bending - spacing 3.7 source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 49E1-190-1:9 gauge 1524" type Rz rail 49E1 radius 190 ratio 9 a 10.523 b 17.417 blades tangent cut 1.2483 frog fixed locks - drive - speed 40 bending - spacing 3.7 source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 49E1-190-1:7,5/1:6,6" type Rz rail 49E1 radius 190 ratio 6.6 a 14.312 b 10.910 diverging 14.312 blades tangent cut 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); speed ST-T1-A6 tab. 11.2 +switch "Rz 49E1-300-1:9" type Rz rail 49E1 radius 300 ratio 9 a 16.615 b 16.615 blades tangent cut 1.5 frog fixed locks - drive - speed 50 bending 1505.522 749.722 spacing 4.35 source Id-4 tab. 8-2; cut tip SKMd-4 (e1 1.500, e2 1.468); ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 49E1-300-1:9,403" type Rz rail 49E1 radius 300 ratio 9.403 a 15.907 b 17.343 diverging 17.322 blades tangent cut 1.5 frog fixed locks - drive - speed 50 bending 1505.522 749.722 spacing 4 source Id-4 tab. 8-2; cut tip SKMd-4 (e1 1.500, e2 1.468); ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 49E1-500-1:12" type Rz rail 49E1 radius 500 ratio 12 a 20.797 b 20.797 blades tangent cut 2.165 frog fixed locks 2 drive - speed 60 bending 501.73 375.638 spacing 4 source Id-4 tab. 8-2; cut tip SKMd-4 (e1 2.165, e2 2.142); locks Id-4 tab. 14-3; ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rz 49E1-500-1:14" type Rz rail 49E1 radius 500 ratio 14 a 17.834 b 24.537 blades tangent cut 2.165 frog fixed locks - drive - speed 60 bending 501.73 375.638 spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (e1 2.165, e2 2.142); ST-T1-A6 tab. 11.9; speed ST-T1-A6 tab. 11.2 +switch "Rz 49E1-1200-1:18,5" type Rz rail 49E1 radius 1200 ratio 18.5 a 32.409 b 32.409 blades tangent cut 3.3347 frog fixed locks - drive - speed 100 bending 750.001 750.001 spacing 4.35 source Id-4 tab. 8-2; cut tip SKMd-4 (e1 3.335, e2 3.321); ST-T1-A6 tab. 11.9; speed, spacing ST-T1-A6 tab. 11.2 +switch "Rls 49E1-215-1:4,8" type Rls rail 49E1 radius 215 ratio 4.8 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 3-2 without a scheme: a and b of the geometry; no blade data: the tips where the blades part by 3 mm; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-190-1:6,6" type Rz rail S42 radius 190 ratio 6.6 a 13.374 b 12.560 diverging 14.172 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-190-1:7" type Rz rail S42 radius 190 ratio 7 a 12.573 b 13.361 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-190-1:7,5" type Rz rail S42 radius 190 ratio 7.5 a 11.691 b 14.243 diverging 14.235 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-205-1:9 I" type Rz rail S42 radius 205 ratio 9 a 10.517 b 16.500 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-205-1:9 II" type Rz rail S42 radius 205 ratio 9 a 10.517 b 17.591 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-230-1:9,51 I" type Rz rail S42 radius 230 ratio 9.51 a 11.046 b 16.008 diverging 16.308 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-230-1:9,51 II" type Rz rail S42 radius 230 ratio 9.51 a 11.046 b 18.342 diverging 18.642 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-230-1:9,51 III" type Rz rail S42 radius 230 ratio 9.51 a 11.046 b 16.008 diverging 18.642 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-265-1:10 I" type Rz rail S42 radius 265 ratio 10 a 11.9692 b 18.1508 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-265-1:10 II" type Rz rail S42 radius 265 ratio 10 a 11.9692 b 19.1918 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-500-1:9" type Rz rail S42 radius 500 ratio 9 a 25.055 b 13.743 diverging 27.513 blades secant frog fixed locks - drive - speed 60 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-500-1:12" type Rz rail S42 radius 500 ratio 12 a 18.21526 b 20.58234 diverging 20.58202 blades secant frog fixed locks - drive - speed 60 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-500-1:14" type Rz rail S42 radius 500 ratio 14 a 15.288 b 26.323 blades secant frog fixed locks - drive - speed 60 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-70-1:5 industrial" type Rz rail S42 radius 70 ratio 5 a 7.112 b 8.708 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-140-1:7 industrial" type Rz rail S42 radius 140 ratio 7 a 7.670 b 12.932 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant, the pre-blade stretch forced to 0.6 m and the angle fitted to a (76.7'), unconfirmed; speed ST-T1-A6 tab. 11.2 +switch "Rls S42-140-1:5 industrial" type Rls rail S42 radius 140 ratio 5 a 7.131 b 8.715 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rls S42-200-1:7 industrial" type Rls rail S42 radius 200 ratio 7 a 6.493 b 12.148 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-205-1:6,6 industrial" type Rz rail S42 radius 205 ratio 6.6 a 14.588 b 13.602 diverging 15.352 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-205-1:7 industrial" type Rz rail S42 radius 205 ratio 7 a 13.710 b 14.480 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-205-1:7,5 industrial" type Rz rail S42 radius 205 ratio 7.5 a 12.754 b 15.436 diverging 15.427 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-300-1:9 industrial" type Rz rail S42 radius 300 ratio 9 a 16.615 b 16.615 blades tangent frog fixed locks - drive - speed 50 bending - spacing - source Id-4 tab. 8-3; blades tangent: its a is too long for blades cutting in at 25'; no blade data: the tip by the rule sqrt(2 R 0.005) - 0.125; speed ST-T1-A6 tab. 11.2 +switch "Rz S42-205-1:9 gauge 1524" type Rz rail S42 radius 205 ratio 9 a 10.513 b 18.394 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed, the pre-blade stretch what a leaves; speed ST-T1-A6 tab. 11.2 + +# not of Id-4: the tangents as measured, too long for one arc alone, the diverging track fitted to them +switch "Rz S42-140-1:6,6 16/12" type Rz rail S42 radius 140 ratio 6.6 a 16 b 12 fit straights blades tangent frog fixed locks - drive - speed 40 bending - spacing - source measured on a scenery, not of Id-4 +switch "Rz S42-140-1:6,6 16/12 KP" type Rz rail S42 radius 140 ratio 6.6 a 16 b 12 fit transition blades tangent frog fixed locks - drive - speed 40 bending - spacing - source measured on a scenery, not of Id-4 +switch "Rz S42-140-1:6,6 16/12 łuk-prosta-łuk" type Rz rail S42 radius 140 ratio 6.6 a 16 b 12 fit arc_straight_arc blades tangent frog fixed locks - drive - speed 40 bending - spacing - source measured on a scenery, not of Id-4 + +# the double switches: the second one starts on the main track of the first, as far on as the schemes of Id-4 give it. A one sided +# double switch of Id-4 has its second switch on the diverging track of the first, here on the main one at the same place (approx.). +# Rps: not in Id-4 but for its scheme, the same switch to both sides, the second one as close behind the first one as their blades let +# them, past the heel of the blades of the first one and the short track between the two (designed) +switch "Rpd 49E1-190-1:7,5/1:7,5" type Rpd rail 49E1 radius 190 ratio 7.5 a 12.611 b 12.611 diverging 16.615 blades tangent cut 1.2483 stagger 10.523 radius2 190 ratio2 7.5 a2 12.611 b2 12.611 blades2 tangent cut2 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd 49E1-190-1:9/1:7,5" type Rpd rail 49E1 radius 190 ratio 9 a 10.523 b 16.615 blades tangent cut 1.2483 stagger 10.523 radius2 190 ratio2 7.5 a2 12.611 b2 12.611 blades2 tangent cut2 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd 49E1-190-1:9/1:9" type Rpd rail 49E1 radius 190 ratio 9 a 10.523 b 16.615 blades tangent cut 1.2483 stagger 10.523 radius2 190 ratio2 9 a2 10.523 b2 16.615 blades2 tangent cut2 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd 49E1-190-1:7,5/1:7,5/1:6,6" type Rpd rail 49E1 radius 190 ratio 7.5 a 12.611 b 12.611 blades tangent cut 1.2483 stagger 10.523 radius2 190 ratio2 6.6 a2 14.312 b2 10.910 diverging2 14.312 blades2 tangent cut2 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd 49E1-190-1:7,5/1:6,6/1:7,5" type Rpd rail 49E1 radius 190 ratio 6.6 a 14.312 b 10.910 diverging 14.312 blades tangent cut 1.2483 stagger 10.523 radius2 190 ratio2 7.5 a2 12.611 b2 12.611 blades2 tangent cut2 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd 49E1-190-1:7,5/1:6,6/1:7,5/1:6,6" type Rpd rail 49E1 radius 190 ratio 6.6 a 14.312 b 10.910 diverging 14.312 blades tangent cut 1.2483 stagger 10.523 radius2 190 ratio2 6.6 a2 14.312 b2 10.910 diverging2 14.312 blades2 tangent cut2 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd 49E1-190-1:9/1:7,5/1:6,6" type Rpd rail 49E1 radius 190 ratio 9 a 10.523 b 16.615 blades tangent cut 1.2483 stagger 10.523 radius2 190 ratio2 6.6 a2 14.312 b2 10.910 diverging2 14.312 blades2 tangent cut2 1.2483 frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2; cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpj 49E1-190-1:9" type Rpj rail 49E1 radius 190 ratio 9 a 10.523 b 16.615 blades tangent cut 1.2483 stagger 5.258 radius2 190 ratio2 9 a2 10.523 b2 16.615 blades2 tangent cut2 1.2483 note "(approx.)" frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2, the second switch on the main track (approx.); cut tip SKMd-4 (1.248); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd S42-190-1:9" type Rpd rail S42 radius 190 ratio 9 a 10.523 b 16.615 blades tangent stagger 10.523 radius2 190 ratio2 9 a2 10.523 b2 16.615 blades2 tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; no blade data: the tip by the rule; a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd S42-190-1:9 II" type Rpd rail S42 radius 190 ratio 9 a 9.626 b 15.500 blades secant stagger 9.5 radius2 190 ratio2 9 a2 9.626 b2 17.591 blades2 secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant at 25', unconfirmed; a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpj S42-190/180-1:10" type Rpj rail S42 radius 190 ratio 10 b 19.192 blades tangent stagger 5.504 radius2 180 ratio2 10 b2 19.192 blades2 tangent note "(approx.)" frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3, a of the geometry, the second switch on the main track (approx.); no blade data: the tip by the rule; a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpj S42-140-1:9 industrial" type Rpj rail S42 radius 140 ratio 9 a 9.274 b 17.590 blades tangent stagger 9.263 radius2 140 ratio2 9 a2 9.274 b2 17.590 blades2 tangent note "(approx.)" frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3, the second switch on the main track (approx.); no blade data: the tip by the rule; a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rpd S42-140-1:7 industrial" type Rpd rail S42 radius 140 ratio 7 a 7.670 b 12.932 blades secant stagger 6.9 radius2 140 ratio2 7 a2 7.670 b2 12.932 blades2 secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3; blades secant, the pre-blade stretch forced to 0.6 m and the angle fitted to a, unconfirmed; a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rps 60E1-300-1:9" type Rps rail 60E1 radius 300 ratio 9 a 16.615 b 16.615 blades tangent cut 1.5 stagger 14.2 note "(designed)" frog fixed locks - drive - speed 50 bending - spacing - source designed for the scheme of Id-4, not in it; cut tip SKMd-4 (e1 1.500, e2 1.468); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 +switch "Rps 60E1-500-1:12" type Rps rail 60E1 radius 500 ratio 12 a 20.797 b 20.797 blades tangent cut 2.165 stagger 18 note "(designed)" frog fixed locks - drive - speed 60 bending - spacing - source designed for the scheme of Id-4, not in it; cut tip SKMd-4 (e1 2.165, e2 2.142); a double switch isn't bent (ST-T1-A6 11.4 pkt 4a); speed ST-T1-A6 tab. 11.2 + +# the slips of Id-4: the half length a from the crossing to the joint, the angle of the crossing, the radius of the slip curves; +# with the blades outside of the diamond a straight in the middle of the slip curves, along which the near rails touch. The +# asymmetric slips of Id-4 (1:9/1:7,5, 1:9/1:6,6) are left out, both of their curves being the same here. No data of their +# blades was found: the slip curves have the blades of the ordinary switch of the same rail, radius and angle +switch "Rkp 60E1-190-1:9" type Rkp rail 60E1 radius 190 ratio 9 middle 0 a 16.615 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-1 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkp 49E1-190-1:9" type Rkp rail 49E1 radius 190 ratio 9 middle 0 a 16.615 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkp 49E1-190-1:6,6" type Rkp rail 49E1 radius 190 ratio 6.6 middle -1 a 17.396 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkp 49E1-300-1:9" type Rkp rail 49E1 radius 300 ratio 9 middle -1 a 22.639 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkp 49E1-500-1:9" type Rkp rail 49E1 radius 500 ratio 9 middle -1 a 27.693 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkp S42-230-1:9,51" type Rkp rail S42 radius 230 ratio 9.51 middle 0 a 18.642 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3 (the half length); blade data not found: secant at 25' as the ordinary switch, unconfirmed; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkp S42-265-1:10" type Rkp rail S42 radius 265 ratio 10 middle 0 a 19.192 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3 (the half length); blade data not found: secant at 25' as the ordinary switch, unconfirmed; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd 60E1-190-1:9" type Rkpd rail 60E1 radius 190 ratio 9 middle 0 a 16.615 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-1 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd 49E1-190-1:9" type Rkpd rail 49E1 radius 190 ratio 9 middle 0 a 16.615 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd 49E1-190-1:6,6" type Rkpd rail 49E1 radius 190 ratio 6.6 middle -1 a 17.396 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd 49E1-300-1:9" type Rkpd rail 49E1 radius 300 ratio 9 middle -1 a 22.639 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd 49E1-500-1:9" type Rkpd rail 49E1 radius 500 ratio 9 middle -1 a 27.693 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd 49E1-190-1:9 gauge 1524" type Rkpd rail 49E1 radius 190 ratio 9 middle 0 a 17.420 blades tangent frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-2 (the half length); blade data not found: the cut tip of the ordinary switch of the radius; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd S42-205-1:9" type Rkpd rail S42 radius 205 ratio 9 middle 0 a 17.591 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3 (the half length); blade data not found: secant at 25' as the ordinary switch, unconfirmed; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd S42-205-1:9 II" type Rkpd rail S42 radius 205 ratio 9 middle 0 a 18.394 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3 (the half length); blade data not found: secant at 25' as the ordinary switch, unconfirmed; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd S42-230-1:9,51" type Rkpd rail S42 radius 230 ratio 9.51 middle 0 a 18.642 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3 (the half length); blade data not found: secant at 25' as the ordinary switch, unconfirmed; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd S42-230-1:9,51 Ia" type Rkpd rail S42 radius 230 ratio 9.51 middle 0 a 18.342 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3 (the half length); blade data not found: secant at 25' as the ordinary switch, unconfirmed; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Rkpd S42-265-1:10" type Rkpd rail S42 radius 265 ratio 10 middle 0 a 19.192 blades secant frog fixed locks - drive - speed 40 bending - spacing - source Id-4 tab. 8-3 (the half length); blade data not found: secant at 25' as the ordinary switch, unconfirmed; a slip isn't bent (ST-T1-A6 11.4 pkt 4b) + +# the diamond crossings of Id-4: the half length a from the crossing to the joint and the angle +switch "Skrz 60E1-1:9" type Skrz rail 60E1 ratio 9 a 16.615 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-1 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 60E1-1:4,444" type Skrz rail 60E1 ratio 4.444 a 10.907 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-1 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:2,9008" type Skrz rail 49E1 ratio 2.9008 a 6.904 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:3,224" type Skrz rail 49E1 ratio 3.224 a 7.920 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:3,683" type Skrz rail 49E1 ratio 3.683 a 9.881 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:4,44" type Skrz rail 49E1 ratio 4.44 a 10.907 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:6,6" type Skrz rail 49E1 ratio 6.6 a 17.396 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:7,5" type Skrz rail 49E1 ratio 7.5 a 18.512 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:9" type Skrz rail 49E1 ratio 9 a 16.615 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:9 long" type Skrz rail 49E1 ratio 9 a 17.016 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz 49E1-1:18,5" type Skrz rail 49E1 ratio 18.5 a 32.409 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-2 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:2" type Skrz rail S42 ratio 2 a 5.743 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:2,9008" type Skrz rail S42 ratio 2.9008 a 8.250 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:3,429" type Skrz rail S42 ratio 3.429 a 9.681 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:3,43" type Skrz rail S42 ratio 3.43 a 8.421 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:4,44" type Skrz rail S42 ratio 4.44 a 11.788 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:4,444 gauge 1524" type Skrz rail S42 ratio 4.444 a 12.189 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:7" type Skrz rail S42 ratio 7 a 12.932 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:9" type Skrz rail S42 ratio 9 a 17.591 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) +switch "Skrz S42-1:10" type Skrz rail S42 ratio 10 a 19.192 frog fixed locks - drive - speed - bending - spacing - source Id-4 tab. 8-3 (the half length); a crossing isn't bent (ST-T1-A6 11.4 pkt 4b) diff --git a/editor/editorSwitchDesign.cpp b/editor/editorSwitchDesign.cpp index 10fee732e..fd6f3c5c7 100644 --- a/editor/editorSwitchDesign.cpp +++ b/editor/editorSwitchDesign.cpp @@ -17,9 +17,15 @@ http://mozilla.org/MPL/2.0/. #include "utilities/utilities.h" #include +#include +#include #include #include +#include #include +#include +#include +#include #include namespace switch_design @@ -209,18 +215,6 @@ void write_parts(std::ostream &Output, std::vector const &Parts) Output << ' ' << format("%.4f %.4f %.4f", part.length, part.radius1, part.radius2); } -bool read_parts(std::istream &Input, std::vector &Parts) -{ - std::size_t count{0}; - Input >> count; - if (Input.fail() || count > 64) - return false; - Parts.resize(count); - for (auto &part : Parts) - Input >> part.length >> part.radius1 >> part.radius2; - return false == Input.fail(); -} - } // namespace bool double_switch(std::string const &Type) @@ -336,7 +330,7 @@ std::pair secant_blade(std::string const &Rail, double const Rad { if (Rail != "S42" || Ratio <= 0.0) return {0.0, 0.0}; - for (auto const &entry : catalogue()) + for (auto const &entry : catalogue_entries()) { if (entry.type != "Rz" || entry.rail != Rail || entry.entry <= 0.0 || entry.parts.empty() || std::abs(entry.parts.front().radius1 - Radius) > 0.5) continue; @@ -780,270 +774,605 @@ bool fit_clicks(design &Design, std::vector const &Clicks, tangent_f return true; } -std::vector catalogue() +namespace { - // the switches of the instruction Id-4 of PKP PLK, tables 8-1 (60E1), 8-2 (49E1) and 8-3 (S42): a from the start of the switch - // to its centre, b on from there along the main track, and along the diverging track where the scheme gives it another length - struct ordinary - { - char const *name; - char const *rail; - double radius; - double ratio; // at the end of the diverging track; of the two tracks parting, for a symmetric switch - double a; // 0: from the geometry - double b; // 0: the diverging track curved up to its end - double diverging{0.0}; // 0: the same as b - bool movable{false}; - char const *type{"Rz"}; - bool tangent{false}; // an S42 switch with blades lying tangent to the stock rails, its a too long for blades cutting into them at 25' - }; - ordinary const ordinaries[] = { - {"Rz 60E1-190-1:9", "60E1", 190.0, 9.0, 10.523, 16.615}, - {"Rz 60E1-300-1:9", "60E1", 300.0, 9.0, 16.615, 16.615}, - {"Rz 60E1-500-1:12", "60E1", 500.0, 12.0, 20.797, 20.797}, - {"Rz 60E1-500-1:12 movable nose", "60E1", 500.0, 12.0, 20.797, 20.797, 0.0, true}, - {"Rz 60E1-760-1:14", "60E1", 760.0, 14.0, 27.108, 27.108}, - {"Rz 60E1-1200-1:18,5", "60E1", 1200.0, 18.5, 32.409, 32.409}, - {"Rz 60E1-1200-1:18,5 movable nose", "60E1", 1200.0, 18.5, 32.409, 32.409, 0.0, true}, - {"Rz 60E1-2500-1:26,5 movable nose", "60E1", 2500.0, 26.5, 47.153, 47.153, 0.0, true}, - {"Rz 49E1-190-1:7,5", "49E1", 190.0, 7.5, 12.611, 12.611}, - {"Rz 49E1-190-1:7,5 long", "49E1", 190.0, 7.5, 12.611, 17.428}, - {"Rz 49E1-190-1:9", "49E1", 190.0, 9.0, 10.523, 16.615}, - {"Rz 49E1-190-1:9 gauge 1524", "49E1", 190.0, 9.0, 10.523, 17.417}, - {"Rz 49E1-190-1:7,5/1:6,6", "49E1", 190.0, 6.6, 14.312, 10.910, 14.312}, - {"Rz 49E1-300-1:9", "49E1", 300.0, 9.0, 16.615, 16.615}, - {"Rz 49E1-300-1:9,403", "49E1", 300.0, 9.403, 15.907, 17.343, 17.322}, - {"Rz 49E1-500-1:12", "49E1", 500.0, 12.0, 20.797, 20.797}, - {"Rz 49E1-500-1:14", "49E1", 500.0, 14.0, 17.834, 24.537}, - {"Rz 49E1-1200-1:18,5", "49E1", 1200.0, 18.5, 32.409, 32.409}, - // table 3-2, without a scheme - {"Rls 49E1-215-1:4,8", "49E1", 215.0, 4.8, 0.0, 0.0, 0.0, false, "Rls"}, - {"Rz S42-190-1:6,6", "S42", 190.0, 6.6, 13.374, 12.560, 14.172}, - {"Rz S42-190-1:7", "S42", 190.0, 7.0, 12.573, 13.361}, - {"Rz S42-190-1:7,5", "S42", 190.0, 7.5, 11.691, 14.243, 14.235}, - {"Rz S42-205-1:9 I", "S42", 205.0, 9.0, 10.517, 16.500}, - {"Rz S42-205-1:9 II", "S42", 205.0, 9.0, 10.517, 17.591}, - {"Rz S42-230-1:9,51 I", "S42", 230.0, 9.51, 11.046, 16.008, 16.308}, - {"Rz S42-230-1:9,51 II", "S42", 230.0, 9.51, 11.046, 18.342, 18.642}, - {"Rz S42-230-1:9,51 III", "S42", 230.0, 9.51, 11.046, 16.008, 18.642}, - {"Rz S42-265-1:10 I", "S42", 265.0, 10.0, 11.9692, 18.1508}, - {"Rz S42-265-1:10 II", "S42", 265.0, 10.0, 11.9692, 19.1918}, - {"Rz S42-500-1:9", "S42", 500.0, 9.0, 25.055, 13.743, 27.513}, - {"Rz S42-500-1:12", "S42", 500.0, 12.0, 18.21526, 20.58234, 20.58202}, - {"Rz S42-500-1:14", "S42", 500.0, 14.0, 15.288, 26.323}, - {"Rz S42-70-1:5 industrial", "S42", 70.0, 5.0, 7.112, 8.708}, - {"Rz S42-140-1:7 industrial", "S42", 140.0, 7.0, 7.670, 12.932}, - {"Rls S42-140-1:5 industrial", "S42", 140.0, 5.0, 7.131, 8.715, 0.0, false, "Rls"}, - {"Rls S42-200-1:7 industrial", "S42", 200.0, 7.0, 6.493, 12.148, 0.0, false, "Rls"}, - {"Rz S42-205-1:6,6 industrial", "S42", 205.0, 6.6, 14.588, 13.602, 15.352}, - {"Rz S42-205-1:7 industrial", "S42", 205.0, 7.0, 13.710, 14.480}, - {"Rz S42-205-1:7,5 industrial", "S42", 205.0, 7.5, 12.754, 15.436, 15.427}, - {"Rz S42-300-1:9 industrial", "S42", 300.0, 9.0, 16.615, 16.615, 0.0, false, "Rz", true}, - {"Rz S42-205-1:9 gauge 1524", "S42", 205.0, 9.0, 10.513, 18.394}, - }; - auto const make = [](ordinary const &Ordinary) { - design entry; - entry.name = Ordinary.name; - entry.rail = Ordinary.rail; - entry.type = Ordinary.type; - entry.movable = Ordinary.movable; - auto const symmetric{symmetric_switch(entry.type)}; - // each track of a symmetric switch turns by a half of the angle between them - auto const angle{std::atan(1.0 / Ordinary.ratio) * (symmetric ? 0.5 : 1.0)}; - auto const radius{Ordinary.radius}; - auto const tangent{radius * std::tan(angle * 0.5)}; - auto const a{Ordinary.a > 0.0 ? Ordinary.a : tangent}; - auto const across = [&](double const Entry) { return radius * (std::cos(Entry) - std::cos(angle)); }; - // the centre nearer than the tangent of the arc: the blade meets the stock rail at an angle and the arc turns the rest of the way; - // further: the diverging track runs along the main one for a while - // within a couple of centimetres of the tangent the catalogue only rounds it - auto const centre = [&](double const Entry) { return radius * (std::sin(angle) - std::sin(Entry)) - across(Entry) / std::tan(angle); }; - auto const fit = [&](double const Centre) { - auto low{0.0}; - auto high{angle}; - for (int i = 0; i < 60; ++i) - { - auto const middle{(low + high) * 0.5}; - (centre(middle) > Centre ? low : high) = middle; - } - return (low + high) * 0.5; }; - auto entryangle{0.0}; - auto lead{a > tangent + 0.02 ? a - tangent : 0.0}; - if (entry.rail == "S42" && false == Ordinary.tangent) + +// the catalogue as the build wrote it out of editor/data/turnouts.txt, the bytes of its text +constexpr unsigned char kCatalogueText[]{ +#include "editor_turnouts_txt.inc" +}; + +// a switch of the catalogue as its line gives it: what the instruction tells of it, which its parts are made of +struct ordinary +{ + std::string name; + std::string rail; + double radius{0.0}; + double ratio{0.0}; // at the end of the diverging track; of the two tracks parting, for a symmetric switch + double a{0.0}; // 0: from the geometry + double b{0.0}; // 0: the diverging track curved up to its end + double diverging{0.0}; // 0: the same as b + bool movable{false}; + std::string type{"Rz"}; + bool secant{false}; // the blades cut into the stock rails at 25' (S42) + double cut{0.0}; // the cut tip of the blade from the start of the curve, 0: none told +}; + +design made_of(ordinary const &Ordinary) +{ + design entry; + entry.name = Ordinary.name; + entry.rail = Ordinary.rail; + entry.type = Ordinary.type; + entry.movable = Ordinary.movable; + auto const symmetric{symmetric_switch(entry.type)}; + // each track of a symmetric switch turns by a half of the angle between them + auto const angle{std::atan(1.0 / Ordinary.ratio) * (symmetric ? 0.5 : 1.0)}; + auto const radius{Ordinary.radius}; + auto const tangent{radius * std::tan(angle * 0.5)}; + auto const a{Ordinary.a > 0.0 ? Ordinary.a : tangent}; + auto const across = [&](double const Entry) { return radius * (std::cos(Entry) - std::cos(angle)); }; + // the centre nearer than the tangent of the arc: the blade meets the stock rail at an angle and the arc turns the rest of the way; + // further: the diverging track runs along the main one for a while + // within a couple of centimetres of the tangent the catalogue only rounds it + auto const centre = [&](double const Entry) { return radius * (std::sin(angle) - std::sin(Entry)) - across(Entry) / std::tan(angle); }; + auto const fit = [&](double const Centre) { + auto low{0.0}; + auto high{angle}; + for (int i = 0; i < 60; ++i) { - entryangle = glm::radians(kSecantAngle) * (symmetric ? 0.5 : 1.0); - lead = a - centre(entryangle); - if (lead <= 0.0) - { - lead = kSecantLead; - entryangle = fit(a - lead); - } + auto const middle{(low + high) * 0.5}; + (centre(middle) > Centre ? low : high) = middle; } - else if (a < tangent - 0.02) - entryangle = fit(a); - else if (auto const cut{cut_tip(entry.rail, radius)}; cut > 0.0 && false == symmetric) - entry.tip = lead + cut; - entry.entry = glm::degrees(entryangle); - entry.lead = lead; - entry.a = a; - auto const arcend{across(entryangle) / std::sin(angle)}; - entry.b = Ordinary.b > 0.0 ? Ordinary.b : arcend; - entry.parts.push_back({radius * (angle - entryangle), radius, radius}); - auto const rest{(Ordinary.diverging > 0.0 ? Ordinary.diverging : entry.b) - arcend}; - if (rest > 0.05) - entry.parts.push_back({rest, 0.0, 0.0}); - if (false == symmetric) - entry.main = a + entry.b; - if (Ordinary.a <= 0.0 || Ordinary.b <= 0.0) - entry.note = "(from the geometry)"; - return entry; - }; - std::vector result; - for (auto const &ordinary : ordinaries) - result.push_back(make(ordinary)); - // not of Id-4: the tangents as measured, too long for one arc alone - for (auto const &[name, kind] : {std::pair{"Rz S42-140-1:6,6 16/12", tangent_fit::straights}, std::pair{"Rz S42-140-1:6,6 16/12 KP", tangent_fit::transition}, std::pair{"Rz S42-140-1:6,6 16/12 łuk-prosta-łuk", tangent_fit::arc_straight_arc}}) + return (low + high) * 0.5; }; + auto entryangle{0.0}; + auto lead{a > tangent + 0.02 ? a - tangent : 0.0}; + if (Ordinary.secant) { - design fitted; - fitted.name = name; - fitted.rail = "S42"; - std::string problem; - if (fit_tangents(fitted, 140.0, 6.6, 16.0, 12.0, kind, problem)) - result.push_back(fitted); + entryangle = glm::radians(kSecantAngle) * (symmetric ? 0.5 : 1.0); + lead = a - centre(entryangle); + if (lead <= 0.0) + { + lead = kSecantLead; + entryangle = fit(a - lead); + } } - // double switches: the second one starts on the main track of the first, as far on as the schemes give it, a one sided double - // switch of Id-4 has its second switch on the diverging track of the first, here on the main one at the same place - ordinary const r190_75{"", "", 190.0, 7.5, 12.611, 12.611}; - ordinary const r190_75long{"", "", 190.0, 7.5, 12.611, 12.611, 16.615}; - ordinary const r190_9{"", "", 190.0, 9.0, 10.523, 16.615}; - ordinary const r190_9tangent{"", "", 190.0, 9.0, 10.523, 16.615, 0.0, false, "Rz", true}; - ordinary const r190_66{"", "", 190.0, 6.6, 14.312, 10.910, 14.312}; - ordinary const r300_9{"", "", 300.0, 9.0, 16.615, 16.615}; - ordinary const r500_12{"", "", 500.0, 12.0, 20.797, 20.797}; - struct twofold + else if (a < tangent - 0.02) + entryangle = fit(a); + else if (Ordinary.cut > 0.0 && false == symmetric) + entry.tip = lead + Ordinary.cut; + entry.entry = glm::degrees(entryangle); + entry.lead = lead; + entry.a = a; + auto const arcend{across(entryangle) / std::sin(angle)}; + entry.b = Ordinary.b > 0.0 ? Ordinary.b : arcend; + entry.parts.push_back({radius * (angle - entryangle), radius, radius}); + auto const rest{(Ordinary.diverging > 0.0 ? Ordinary.diverging : entry.b) - arcend}; + if (rest > 0.05) + entry.parts.push_back({rest, 0.0, 0.0}); + if (false == symmetric) + entry.main = a + entry.b; + if (Ordinary.a <= 0.0 || Ordinary.b <= 0.0) + entry.note = "(from the geometry)"; + return entry; +} + +// the words of a line of the file: blanks between them, a word in quotes keeping its blanks; what follows the word source is the rest +// of the line as it is +struct line_words +{ + std::vector words; + std::vector quoted; + std::string source; + bool sourced{false}; +}; + +bool split_words(std::string_view const Line, line_words &Into, std::string &Error) +{ + std::size_t at{0}; + while (at < Line.size()) + { + if (Line[at] == ' ' || Line[at] == '\t' || Line[at] == '\r') + { + ++at; + continue; + } + if (Line[at] == '"') + { + auto const close{Line.find('"', at + 1)}; + if (close == std::string_view::npos) + { + Error = "a quote not closed"; + return false; + } + Into.words.emplace_back(Line.substr(at + 1, close - at - 1)); + Into.quoted.push_back(true); + at = close + 1; + continue; + } + auto end{Line.find_first_of(" \t\r", at)}; + if (end == std::string_view::npos) + end = Line.size(); + auto const word{Line.substr(at, end - at)}; + at = end; + if (word == "source" && Into.words.size() >= 2) + { + auto rest{Line.substr(std::min(at + 1, Line.size()))}; + while (false == rest.empty() && (rest.back() == '\r' || rest.back() == ' ')) + rest.remove_suffix(1); + Into.source = rest; + Into.sourced = true; + return true; + } + Into.words.emplace_back(word); + Into.quoted.push_back(false); + } + return true; +} + +bool number_of(std::string_view const Text, double &Value) +{ + auto const *first{Text.data()}; + auto const *last{Text.data() + Text.size()}; + auto const [end, error]{std::from_chars(first, last, Value)}; + return error == std::errc{} && end == last && std::isfinite(Value); +} + +// the values of an entry by their keys, each key once +class entry_values +{ + public: + std::string name; + std::string source; + std::vector parts; + std::vector parts2; + bool has_parts{false}; + bool has_parts2{false}; + double bending{0.0}; + double bending_exception{0.0}; + + bool read(line_words const &Line, std::string &Error) + { + auto const &words{Line.words}; + name = Line.quoted[1] ? words[1] : unword(words[1]); + source = Line.source; + std::size_t at{2}; + while (at < words.size()) + { + auto const &key{words[at++]}; + if (m_values.contains(key) || ((key == "parts" || key == "parts2") && (key == "parts" ? has_parts : has_parts2))) + { + Error = std::format("{} given twice", key); + return false; + } + if (key == "parts" || key == "parts2") + { + if (false == read_parts(words, at, key == "parts" ? parts : parts2)) + { + Error = std::format("{} not as many as said, or not numbers", key); + return false; + } + (key == "parts" ? has_parts : has_parts2) = true; + continue; + } + if (key == "bending") + { + if (false == read_bending(words, at)) + { + Error = "bending is - or two radii"; + return false; + } + m_values[key] = ""; + continue; + } + if (false == known(key)) + { + Error = std::format("'{}' isn't a key", key); + return false; + } + if (at >= words.size()) + { + Error = std::format("{} has no value", key); + return false; + } + m_values[key] = words[at++]; + } + return true; + } + bool has(std::string const &Key) const { return m_values.contains(Key); } + std::string text(std::string const &Key, std::string const &Otherwise = {}) const + { + auto const found{m_values.find(Key)}; + return found != m_values.end() ? found->second : Otherwise; + } + // the number of the key, 0 where it isn't given or is -; false where it isn't a number + bool number(std::string const &Key, double &Value) const + { + Value = 0.0; + auto const found{m_values.find(Key)}; + if (found == m_values.end() || found->second == "-") + return true; + return number_of(found->second, Value); + } + + private: + std::map m_values; + + static bool known(std::string_view const Key) + { + static constexpr std::array keys{"type", "rail", "radius", "ratio", "a", "b", "diverging", "blades", "cut", "fit", "stagger", "radius2", + "ratio2", "a2", "b2", "diverging2", "blades2", "cut2", "middle", "note", "frog", "locks", "drive", "speed", + "spacing", "main", "lead", "entry", "tip", "lead2", "entry2", "tip2", "heel", "throw", "movable"}; + return std::ranges::find(keys, Key) != keys.end(); + } + static bool read_parts(std::vector const &Words, std::size_t &At, std::vector &Parts) + { + double count{0.0}; + if (At >= Words.size() || false == number_of(Words[At++], count) || count < 0.0 || count > 64.0 || count != std::floor(count)) + return false; + Parts.resize(static_cast(count)); + for (auto &each : Parts) + { + if (At + 3 > Words.size() || false == number_of(Words[At], each.length) || false == number_of(Words[At + 1], each.radius1) || false == number_of(Words[At + 2], each.radius2)) + return false; + At += 3; + } + return true; + } + bool read_bending(std::vector const &Words, std::size_t &At) + { + if (At < Words.size() && Words[At] == "-") + { + ++At; + return true; + } + if (At + 2 > Words.size() || false == number_of(Words[At], bending) || false == number_of(Words[At + 1], bending_exception)) + return false; + At += 2; + return true; + } +}; + +// the switch of the keys with the suffix: the first one of a double switch with none, its second one with 2 +bool ordinary_of(entry_values const &Values, std::string const &Suffix, ordinary &Result, std::string &Error) +{ + Result.rail = Values.text("rail", "-"); + Result.type = Values.text("type", "Rz"); + Result.movable = Values.text("frog") == "movable"; + auto const blades{Values.text("blades" + Suffix, "tangent")}; + if (blades != "tangent" && blades != "secant") + { + Error = "blades are tangent or secant"; + return false; + } + Result.secant = blades == "secant"; + if (false == Values.number("radius" + Suffix, Result.radius) || false == Values.number("ratio" + Suffix, Result.ratio) || false == Values.number("a" + Suffix, Result.a) || + false == Values.number("b" + Suffix, Result.b) || false == Values.number("diverging" + Suffix, Result.diverging) || false == Values.number("cut" + Suffix, Result.cut)) + { + Error = "a value of the geometry isn't a number"; + return false; + } + if (Result.radius < kMinRadius || Result.ratio <= 1.0) + { + Error = std::format("no radius{} of 10 m at least or no ratio{} above 1", Suffix, Suffix); + return false; + } + return true; +} + +// the switch given by its parts, as the template editor makes it +design explicit_of(entry_values const &Values, std::string &Error) +{ + design entry; + entry.type = Values.text("type", "Rz"); + entry.rail = Values.text("rail", "-"); + entry.parts = Values.parts; + entry.parts2 = Values.parts2; + struct numbered + { + char const *key; + double *value; + }; + std::array const numbers{numbered{"main", &entry.main}, numbered{"stagger", &entry.stagger}, numbered{"a", &entry.a}, numbered{"b", &entry.b}, + numbered{"lead", &entry.lead}, numbered{"entry", &entry.entry}, numbered{"tip", &entry.tip}, numbered{"heel", &entry.heel}, + numbered{"throw", &entry.bladethrow}}; + for (auto const &[key, value] : numbers) + if (false == Values.number(key, *value)) + Error = std::format("{} isn't a number", key); + // of the second switch, negative: the same as the first + for (auto const &[key, value] : {numbered{"lead2", &entry.lead2}, numbered{"entry2", &entry.entry2}, numbered{"tip2", &entry.tip2}}) + if (Values.has(key) && false == Values.number(key, *value)) + Error = std::format("{} isn't a number", key); + return entry; +} + +std::optional design_of(entry_values const &Values, std::string &Error) +{ + auto const type{Values.text("type", "Rz")}; + if (type != "Rz" && false == symmetric_switch(type) && false == double_switch(type) && false == slip_switch(type)) + { + Error = std::format("no type {}", type); + return std::nullopt; + } + design made; + if (Values.has_parts) + made = explicit_of(Values, Error); + else if (Values.has("fit")) + { + auto const kind{Values.text("fit")}; + std::array const kinds{std::pair{"straights", tangent_fit::straights}, std::pair{"transition", tangent_fit::transition}, std::pair{"arc_straight_arc", tangent_fit::arc_straight_arc}, + std::pair{"two_arcs", tangent_fit::two_arcs}}; + auto const found{std::ranges::find_if(kinds, [&](auto const &Each) { return kind == Each.first; })}; + ordinary given; + if (found == kinds.end()) + Error = std::format("no fit {}", kind); + else if (ordinary_of(Values, "", given, Error)) + { + made.rail = given.rail; + if (false == fit_tangents(made, given.radius, given.ratio, given.a, given.b, found->second, Error)) + return std::nullopt; + made.radius = given.radius; + made.ratio = given.ratio; + } + } + else if (slip_switch(type)) + { + made.type = type; + made.rail = Values.text("rail", "-"); + if (false == Values.number("radius", made.radius) || false == Values.number("ratio", made.ratio) || false == Values.number("middle", made.middle) || + false == Values.number("a", made.a)) + Error = "a value of the geometry isn't a number"; + else if (made.ratio <= 0.0 || made.a <= 0.0 || (type != "Skrz" && made.radius < kMinRadius)) + Error = "a slip has a radius, a ratio and a half length a, a crossing a ratio and a"; + } + else if (double_switch(type)) { - char const *name; - char const *type; - char const *rail; ordinary first; ordinary second; - double stagger; - char const *note; - }; - twofold const twofolds[] = { - {"Rpd 49E1-190-1:7,5/1:7,5", "Rpd", "49E1", r190_75long, r190_75, 10.523, ""}, - {"Rpd 49E1-190-1:9/1:7,5", "Rpd", "49E1", r190_9, r190_75, 10.523, ""}, - {"Rpd 49E1-190-1:9/1:9", "Rpd", "49E1", r190_9, r190_9, 10.523, ""}, - {"Rpd 49E1-190-1:7,5/1:7,5/1:6,6", "Rpd", "49E1", r190_75, r190_66, 10.523, ""}, - {"Rpd 49E1-190-1:7,5/1:6,6/1:7,5", "Rpd", "49E1", r190_66, r190_75, 10.523, ""}, - {"Rpd 49E1-190-1:7,5/1:6,6/1:7,5/1:6,6", "Rpd", "49E1", r190_66, r190_66, 10.523, ""}, - {"Rpd 49E1-190-1:9/1:7,5/1:6,6", "Rpd", "49E1", r190_9, r190_66, 10.523, ""}, - {"Rpj 49E1-190-1:9", "Rpj", "49E1", r190_9, r190_9, 5.258, "(approx.)"}, - {"Rpd S42-190-1:9", "Rpd", "S42", r190_9tangent, r190_9tangent, 10.523, ""}, - {"Rpd S42-190-1:9 II", "Rpd", "S42", {"", "", 190.0, 9.0, 9.626, 15.500}, {"", "", 190.0, 9.0, 9.626, 17.591}, 9.5, ""}, - {"Rpj S42-190/180-1:10", "Rpj", "S42", {"", "", 190.0, 10.0, 0.0, 19.192, 0.0, false, "Rz", true}, {"", "", 180.0, 10.0, 0.0, 19.192, 0.0, false, "Rz", true}, 5.504, "(approx.)"}, - {"Rpj S42-140-1:9 industrial", "Rpj", "S42", {"", "", 140.0, 9.0, 9.274, 17.590, 0.0, false, "Rz", true}, {"", "", 140.0, 9.0, 9.274, 17.590, 0.0, false, "Rz", true}, 9.263, "(approx.)"}, - {"Rpd S42-140-1:7 industrial", "Rpd", "S42", {"", "", 140.0, 7.0, 7.670, 12.932}, {"", "", 140.0, 7.0, 7.670, 12.932}, 6.9, ""}, - // symmetric double switches, not in Id-4 but for its scheme: the same switch to both sides, the second one starting as close behind - // the first one as their blades let them, past the heel of the blades of the first one and the short track between the two - {"Rps 60E1-300-1:9", "Rps", "60E1", r300_9, r300_9, 14.2, "(designed)"}, - {"Rps 60E1-500-1:12", "Rps", "60E1", r500_12, r500_12, 18.0, "(designed)"}, - }; - for (auto const &entry : twofolds) - { - auto first{entry.first}; - auto other{entry.second}; - first.rail = other.rail = entry.rail; - auto made{make(first)}; - auto const second{make(other)}; - made.name = entry.name; - made.rail = entry.rail; - made.type = entry.type; - made.stagger = entry.stagger; - if (made.type != "Rps") + double stagger{0.0}; + if (ordinary_of(Values, "", first, Error) && (type == "Rps" || ordinary_of(Values, "2", second, Error)) && Values.number("stagger", stagger)) { - made.parts2 = second.parts; - made.lead2 = second.lead; - made.entry2 = second.entry; - made.tip2 = second.tip; + // the both switches of a symmetric double switch have the shape of the first one + if (type == "Rps") + second = first; + made = made_of(first); + auto const other{made_of(second)}; + made.type = type; + made.stagger = stagger; + if (made.type != "Rps") + { + made.parts2 = other.parts; + made.lead2 = other.lead; + made.entry2 = other.entry; + made.tip2 = other.tip; + } + made.main = 0.0; + made.b = 0.0; + made.note.clear(); + made.radius = first.radius; + made.ratio = first.ratio; } - made.main = 0.0; - made.b = 0.0; - made.note = entry.note; - result.push_back(made); } + else + { + ordinary given; + if (ordinary_of(Values, "", given, Error)) + { + made = made_of(given); + made.radius = given.radius; + made.ratio = given.ratio; + } + } + if (false == Error.empty()) + return std::nullopt; + made.name = Values.name; + if (Values.has("note")) + made.note = Values.text("note"); + made.movable = Values.text("frog") == "movable" || Values.text("movable") == "1"; + made.blades = Values.text("blades"); + double locks{0.0}; + if (false == Values.number("cut", made.cut) || false == Values.number("speed", made.speed) || false == Values.number("spacing", made.spacing) || false == Values.number("locks", locks)) + { + Error = "cut, speed, spacing or locks isn't a number"; + return std::nullopt; + } + made.locks = static_cast(locks); + made.drive = Values.text("drive") == "-" ? std::string{} : Values.text("drive"); + made.bending = Values.bending; + made.bending_exception = Values.bending_exception; + made.source = Values.source; + return made; +} + +} // namespace + +bool slip_switch(std::string const &Type) +{ + return Type == "Rkp" || Type == "Rkpd" || Type == "Skrz"; +} + +glm::dvec2 slip_curve::point(double const Along) const +{ + auto const arc = [](glm::dvec2 const &From, double const Heading, double const Radius, double const Length) { + if (Radius <= 0.0) + return From + glm::dvec2{std::cos(Heading), std::sin(Heading)} * Length; + auto const to{Heading + Length / Radius}; + return From + Radius * glm::dvec2{std::sin(to) - std::sin(Heading), std::cos(Heading) - std::cos(to)}; + }; + auto const along{Along - lead}; + auto result{arc({0.0, 0.0}, 0.0, 0.0, std::min(Along, lead))}; + if (along > 0.0) + result = arc(result, entry, radius, std::min(along, ends)); + if (along > ends) + result = arc(result, heading(lead + ends), middle, std::min(along - ends, between)); + if (along > ends + between) + result = arc(result, heading(lead + ends + between), radius, std::min(along - ends - between, ends)); + if (along > 2.0 * ends + between) + result = arc(result, angle, 0.0, along - 2.0 * ends - between); + return result; +} + +double slip_curve::heading(double const Along) const +{ + if (Along < lead) + return 0.0; + if (Along > length() - lead) + return angle; + auto const along{Along - lead}; + auto const inside{std::clamp(along - ends, 0.0, between)}; + return entry + (std::min(along, ends) + std::max(0.0, along - ends - between)) / radius + (middle > 0.0 ? inside / middle : 0.0); +} + +double slip_curve::tangent() const +{ + auto const end{point(length())}; + return end.x - end.y / std::tan(angle); +} + +double slip_curve::offset() const +{ + return glm::distance(point(length() * 0.5), glm::dvec2{tangent(), 0.0}); +} + +slip_curve slip_of(double const Radius, double const Middle, double const Angle, double const Pass, double const Lead, double const Entry) +{ + if (Entry > 0.0 && Angle * 0.5 <= Entry + 1e-6) + return slip_of(Radius, Middle, Angle, Pass); + auto const make = [&](double const Turn) { + return slip_curve{Radius, Radius * Turn, Middle, Middle * (Angle - 2.0 * (Turn + Entry)), Angle, 0.0, Lead, Entry}; + }; + if (Middle < 0.0 && Angle >= 1e-6) + { + // a straight in the middle, as long as the arcs of Radius turning by a half of Angle pass the crossing as near + auto low{0.0}; + auto high{4.0 * Pass / std::tan(Angle * 0.5)}; + for (int i = 0; i < 60; ++i) + { + auto const between{(low + high) * 0.5}; + (slip_curve{Radius, Radius * (Angle * 0.5 - Entry), 0.0, between, Angle, 0.0, Lead, Entry}.offset() > Pass ? high : low) = between; + } + return {Radius, Radius * (Angle * 0.5 - Entry), 0.0, (low + high) * 0.5, Angle, 0.0, Lead, Entry}; + } + if (Middle <= 0.0 || Angle < 1e-6) + return make(Angle * 0.5 - Entry); + // the curve passes the crossing nearer as its end arcs turn further, the middle one being flatter + auto low{0.0}; + auto high{Angle * 0.5 - Entry}; + for (int i = 0; i < 60; ++i) + { + auto const turn{(low + high) * 0.5}; + ((make(turn).offset() > Pass) == (Middle > Radius) ? low : high) = turn; + } + return make((low + high) * 0.5); +} + +std::vector read_designs(std::string_view const Text, std::vector *Errors) +{ + std::vector result; + std::size_t start{0}; + int number{0}; + while (start < Text.size()) + { + auto end{Text.find('\n', start)}; + if (end == std::string_view::npos) + end = Text.size(); + auto const line{Text.substr(start, end - start)}; + start = end + 1; + ++number; + line_words words; + std::string error; + if (false == split_words(line, words, error)) + { + if (Errors != nullptr) + Errors->push_back(std::format("line {}: {}", number, error)); + continue; + } + if (words.words.empty() || words.words.front().starts_with('#') || words.words.front() != "switch") + continue; + entry_values values; + if (words.words.size() < 2 || false == values.read(words, error)) + { + if (Errors != nullptr) + Errors->push_back(std::format("line {}: {}", number, error.empty() ? "no name" : error)); + continue; + } + auto made{design_of(values, error)}; + if (false == made.has_value() || made->name.empty()) + { + if (Errors != nullptr) + Errors->push_back(std::format("line {} ({}): {}", number, values.name, error.empty() ? "no name" : error)); + continue; + } + result.push_back(std::move(*made)); + } + return result; +} + +std::string_view catalogue_text() +{ + static std::string const text{std::begin(kCatalogueText), std::end(kCatalogueText)}; + return text; +} + +std::vector const &catalogue_entries() +{ + static std::vector const entries{read_designs(catalogue_text())}; + return entries; +} + +std::vector catalogue() +{ + std::vector result; + for (auto const &entry : catalogue_entries()) + if (false == slip_switch(entry.type)) + result.push_back(entry); + return result; +} + +std::vector slips() +{ + std::vector result; + for (auto const &entry : catalogue_entries()) + if (slip_switch(entry.type)) + result.push_back(entry); return result; } std::vector own() { - std::vector result; - std::ifstream file{own_path()}; + std::ifstream file{own_path(), std::ios::binary}; if (false == file.is_open()) - return result; - std::string text; - while (std::getline(file, text)) - { - if (text.empty() || text.front() == '#') - continue; - std::istringstream line{text}; - design entry; + return {}; + std::string const text{std::istreambuf_iterator(file), std::istreambuf_iterator()}; + auto result{read_designs(text)}; + // a template of the user is given by its parts; a line giving a switch the way the catalogue does is taken too + for (auto &entry : result) entry.own = true; - std::string keyword; - std::string name; - line >> keyword >> name; - if (keyword != "switch") - continue; - entry.name = unword(name); - bool good{true}; - while (good && line >> keyword) - { - if (keyword == "type") - line >> entry.type; - else if (keyword == "rail") - { - line >> entry.rail; - if (entry.rail.empty()) - entry.rail = "-"; - } - else if (keyword == "main") - line >> entry.main; - else if (keyword == "stagger") - line >> entry.stagger; - else if (keyword == "lead") - line >> entry.lead; - else if (keyword == "entry") - line >> entry.entry; - else if (keyword == "lead2") - line >> entry.lead2; - else if (keyword == "entry2") - line >> entry.entry2; - else if (keyword == "tip") - line >> entry.tip; - else if (keyword == "tip2") - line >> entry.tip2; - else if (keyword == "heel") - line >> entry.heel; - else if (keyword == "throw") - line >> entry.bladethrow; - else if (keyword == "a") - line >> entry.a; - else if (keyword == "b") - line >> entry.b; - else if (keyword == "parts") - good = read_parts(line, entry.parts); - else if (keyword == "parts2") - good = read_parts(line, entry.parts2); - else - good = false; - good = good && false == line.fail(); - } - if (good && false == entry.name.empty()) - result.push_back(std::move(entry)); - } return result; } +std::string own_line(design const &Design) +{ + std::string line{"switch " + word(Design.name) + " type " + Design.type + " rail " + word(Design.rail) + ' ' + + format("main %.4f stagger %.4f a %.4f b %.4f lead %.4f entry %.4f tip %.4f", Design.main, Design.stagger, Design.a, Design.b, Design.lead, Design.entry, Design.tip)}; + if (Design.lead2 >= 0.0 || Design.entry2 >= 0.0 || Design.tip2 >= 0.0) + line += format(" lead2 %.4f entry2 %.4f tip2 %.4f", Design.lead2, Design.entry2, Design.tip2); + if (Design.heel > 0.0 || Design.bladethrow > 0.0) + line += format(" heel %.4f throw %.4f", Design.heel, Design.bladethrow); + // only where it's so: the builds before this one leave out a template with a key they don't know + if (Design.movable) + line += " frog movable"; + std::ostringstream parts; + parts << " parts"; + write_parts(parts, Design.parts); + if (false == Design.parts2.empty()) + { + parts << " parts2"; + write_parts(parts, Design.parts2); + } + return line + parts.str(); +} + bool save_own(std::vector const &Designs, std::string &Error) { auto const path{own_path()}; @@ -1056,25 +1385,11 @@ bool save_own(std::vector const &Designs, std::string &Error) Error = format(STR_C("Can't write %s"), path.string().c_str()); return false; } - file << "# switch templates made in the track editor of MaSzyna\n"; - file << "# switch type rail main stagger a b lead entry tip [lead2 entry2 tip2 ] [heel throw ] parts ( )... parts2 ...\n"; + file << "# switch templates made in the track editor of MaSzyna, in the format of the catalogue of the editor (editor/data/turnouts.txt)\n"; + file << "# switch type rail main stagger a b lead entry tip [lead2 entry2 tip2 ] [heel throw ] [frog movable] parts ( )... parts2 ...\n"; file << "# R 0 is a straight, the same R at both ends an arc, different ones a transition curve; 0 for main, a, b: from the geometry\n"; for (auto const &entry : Designs) - { - file << "switch " << word(entry.name) << " type " << entry.type << " rail " << word(entry.rail) << ' ' << format("main %.4f stagger %.4f a %.4f b %.4f lead %.4f entry %.4f tip %.4f", entry.main, entry.stagger, entry.a, entry.b, entry.lead, entry.entry, entry.tip); - if (entry.lead2 >= 0.0 || entry.entry2 >= 0.0 || entry.tip2 >= 0.0) - file << format(" lead2 %.4f entry2 %.4f tip2 %.4f", entry.lead2, entry.entry2, entry.tip2); - if (entry.heel > 0.0 || entry.bladethrow > 0.0) - file << format(" heel %.4f throw %.4f", entry.heel, entry.bladethrow); - file << " parts"; - write_parts(file, entry.parts); - if (false == entry.parts2.empty()) - { - file << " parts2"; - write_parts(file, entry.parts2); - } - file << '\n'; - } + file << own_line(entry) << '\n'; if (file.fail()) { Error = format(STR_C("Can't write %s"), path.string().c_str()); diff --git a/editor/editorSwitchDesign.hpp b/editor/editorSwitchDesign.hpp index c4ca5720d..28664a9f7 100644 --- a/editor/editorSwitchDesign.hpp +++ b/editor/editorSwitchDesign.hpp @@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/. #pragma once #include +#include #include #include "world/Segment.h" @@ -17,7 +18,8 @@ http://mozilla.org/MPL/2.0/. // switches described by their geometry, of the catalogue and made by the user in the template editor: the main track is a // straight, the diverging track a chain of parts of linearly changing curvature from the start of the switch; a symmetric // switch (Rls) has both tracks turning by the same parts to both sides; a double switch (Rpd to both sides, Rpj to one side) -// is two switches, the second starting on the main track of the first +// is two switches, the second starting on the main track of the first. The catalogue is a data file (editor/data/turnouts.txt, +// built into the executable), the templates of the user a file of the same format; the slips and the crossings are in it too namespace switch_design { @@ -50,10 +52,56 @@ struct design std::string note; // shown after the name on the list bool own{false}; // made in the template editor, kept in the file of the user bool movable{false}; // the frog with a movable nose + // what the catalogue tells of the type besides its geometry (editor-tracks-domain.md §7); 0 or empty where it doesn't + std::string blades; // "tangent": the diverging track leaves the main one tangentially; "secant": the blades cut into the stock rails + double cut{0.0}; // m, the cut tip of the blade from the start of the curve, as the sheets of the rail give it + int locks{0}; // of the blades (Id-4 tab. 14-3) + std::string drive; // the family of the point machine + double speed{0.0}; // km/h on the diverging track of the basic switch, ST-T1-A6 tab. 11.2 + double bending{0.0}; // m, the least radius of the main track bent one-sided, ST-T1-A6 tab. 11.9; 0: not bent + double bending_exception{0.0}; // m, the one allowed by way of exception + double spacing{0.0}; // m, the least spacing of the tracks for a single crossover, ST-T1-A6 tab. 11.2 + std::string source; // where the values come from, what is unconfirmed said so + // the radius of the curve and the ratio 1:n as the catalogue gives them, of the first switch of a double one, 0 for a template of the + // user; of a slip (Rkp, Rkpd) or a diamond crossing (Skrz) the radius of the slip curves and the ratio of the crossing, a its half + // length from the crossing to the joints, and the middle of the slip curves: 0 one arc, below 0 a straight there, above 0 an arc of + // that radius + double radius{0.0}; + double ratio{0.0}; + double middle{0.0}; }; bool double_switch(std::string const &Type); bool symmetric_switch(std::string const &Type); +// a single or a double slip, or a diamond crossing +bool slip_switch(std::string const &Type); + +// the diverging curve of a slip turning by Angle: arcs of Radius at both ends, each Ends long, and the arc of Middle, Between long, +// between them; a straight when Middle is 0. With blades cutting into the stock rails the curve starts and ends with a straight Lead +// long along them, the arcs of Radius meeting it at Entry. The curve starts at the origin heading along x and turns towards y +struct slip_curve +{ + double radius{0.0}; + double ends{0.0}; + double middle{0.0}; + double between{0.0}; + double angle{0.0}; + double tip{0.0}; // of the blades from each end of the curve, 0: where the blades get as thin as they may + double lead{0.0}; + double entry{0.0}; // radians + double length() const { return 2.0 * (lead + ends) + between; } + // the point and the heading at Along of the curve; the heading at the ends of the leads is the one of the arcs + glm::dvec2 point(double const Along) const; + double heading(double const Along) const; + // from the start of the curve to the crossing of its tangents + double tangent() const; + // from the middle of the curve to the crossing of its tangents + double offset() const; + slip_curve scaled(double const Factor) const { return {radius * Factor, ends * Factor, middle * Factor, between * Factor, angle, Factor == 1.0 ? tip : 0.0, lead * Factor, entry}; } +}; +// one arc of Radius, or with Middle the slip curves of a double slip with the blades outside of the diamond, their near rails touching +// in its middle: Pass from the crossing, half of the gauge and the width of the head; a straight there when Middle < 0 +slip_curve slip_of(double const Radius, double const Middle, double const Angle, double const Pass, double const Lead = 0.0, double const Entry = 0.0); // diverging track of the chain of parts from the start, with the first direction along +z and turning to +x struct path @@ -120,9 +168,20 @@ struct clicks_fit }; bool fit_clicks(design &Design, std::vector const &Clicks, tangent_fit Kind, double First, clicks_fit &Result, std::string &Error); +// the designs of the text of a file of the catalogue's format, in its order; a line which isn't one is left out, why in Errors +std::vector read_designs(std::string_view Text, std::vector *Errors = nullptr); +// the text of the catalogue built into the executable, editor/data/turnouts.txt +std::string_view catalogue_text(); +// all the types of the catalogue, read once: the switches, then the slips and the crossings +std::vector const &catalogue_entries(); +// the switches of the catalogue (Rz, Rls, Rpd, Rpj, Rps), as the designer and the switch tool list them std::vector catalogue(); -// templates of the user, kept in eu07_switch_templates.txt in the configuration directory +// the slips and the diamond crossings of the catalogue +std::vector slips(); +// templates of the user, kept in eu07_switch_templates.txt in the configuration directory, in the format of the catalogue std::vector own(); bool save_own(std::vector const &Designs, std::string &Error); +// a template of the user as a line of that file +std::string own_line(design const &Design); } // namespace switch_design diff --git a/editor/editorTrack.cpp b/editor/editorTrack.cpp index 32084bc00..e280d2699 100644 --- a/editor/editorTrack.cpp +++ b/editor/editorTrack.cpp @@ -3176,81 +3176,6 @@ std::optional editor_track::template_of(switch_de return entry; } -glm::dvec2 editor_track::slip_curve::point(double const Along) const -{ - auto const arc = [](glm::dvec2 const &From, double const Heading, double const Radius, double const Length) { - if (Radius <= 0.0) - return From + glm::dvec2{std::cos(Heading), std::sin(Heading)} * Length; - auto const to{Heading + Length / Radius}; - return From + Radius * glm::dvec2{std::sin(to) - std::sin(Heading), std::cos(Heading) - std::cos(to)}; - }; - auto const along{Along - lead}; - auto result{arc({0.0, 0.0}, 0.0, 0.0, std::min(Along, lead))}; - if (along > 0.0) - result = arc(result, entry, radius, std::min(along, ends)); - if (along > ends) - result = arc(result, heading(lead + ends), middle, std::min(along - ends, between)); - if (along > ends + between) - result = arc(result, heading(lead + ends + between), radius, std::min(along - ends - between, ends)); - if (along > 2.0 * ends + between) - result = arc(result, angle, 0.0, along - 2.0 * ends - between); - return result; -} - -double editor_track::slip_curve::heading(double const Along) const -{ - if (Along < lead) - return 0.0; - if (Along > length() - lead) - return angle; - auto const along{Along - lead}; - auto const inside{std::clamp(along - ends, 0.0, between)}; - return entry + (std::min(along, ends) + std::max(0.0, along - ends - between)) / radius + (middle > 0.0 ? inside / middle : 0.0); -} - -double editor_track::slip_curve::tangent() const -{ - auto const end{point(length())}; - return end.x - end.y / std::tan(angle); -} - -double editor_track::slip_curve::offset() const -{ - return glm::distance(point(length() * 0.5), glm::dvec2{tangent(), 0.0}); -} - -editor_track::slip_curve editor_track::slip_of(double const Radius, double const Middle, double const Angle, double const Pass, double const Lead, double const Entry) -{ - if (Entry > 0.0 && Angle * 0.5 <= Entry + 1e-6) - return slip_of(Radius, Middle, Angle, Pass); - auto const make = [&](double const Turn) { - return slip_curve{Radius, Radius * Turn, Middle, Middle * (Angle - 2.0 * (Turn + Entry)), Angle, 0.0, Lead, Entry}; - }; - if (Middle < 0.0 && Angle >= 1e-6) - { - // a straight in the middle, as long as the arcs of Radius turning by a half of Angle pass the crossing as near - auto low{0.0}; - auto high{4.0 * Pass / std::tan(Angle * 0.5)}; - for (int i = 0; i < 60; ++i) - { - auto const between{(low + high) * 0.5}; - (slip_curve{Radius, Radius * (Angle * 0.5 - Entry), 0.0, between, Angle, 0.0, Lead, Entry}.offset() > Pass ? high : low) = between; - } - return {Radius, Radius * (Angle * 0.5 - Entry), 0.0, (low + high) * 0.5, Angle, 0.0, Lead, Entry}; - } - if (Middle <= 0.0 || Angle < 1e-6) - return make(Angle * 0.5 - Entry); - // the curve passes the crossing nearer as its end arcs turn further, the middle one being flatter - auto low{0.0}; - auto high{Angle * 0.5 - Entry}; - for (int i = 0; i < 60; ++i) - { - auto const turn{(low + high) * 0.5}; - ((make(turn).offset() > Pass) == (Middle > Radius) ? low : high) = turn; - } - return make((low + high) * 0.5); -} - std::string editor_track::rail_of(TTrack const *Track) { if (Track == nullptr || (Track->iCategoryFlag & 15) != 1) @@ -3283,96 +3208,28 @@ std::vector editor_track::standard_switch_templat entry->design = static_cast(i); result.push_back(std::move(*entry)); } - // the slips and crossings of Id-4: the angle comes from the straights clicked, the half length from the crossing to the joint - // to a and the label; the slips with the blades outside of the diamond have a straight in the middle of their curves, along which - // the near rails touch. The asymmetric slips of Id-4 (1:9/1:7,5, 1:9/1:6,6) are left out, both of their curves being the same here - struct slipping - { - char const *type; - char const *name; - double radius; - double middle; - double half; - }; - slipping const slips[] = { - {"Rkp", "60E1-190-1:9", 190.0, 0.0, 16.615}, - {"Rkp", "49E1-190-1:9", 190.0, 0.0, 16.615}, - {"Rkp", "49E1-190-1:6,6", 190.0, -1.0, 17.396}, - {"Rkp", "49E1-300-1:9", 300.0, -1.0, 22.639}, - {"Rkp", "49E1-500-1:9", 500.0, -1.0, 27.693}, - {"Rkp", "S42-230-1:9,51", 230.0, 0.0, 18.642}, - {"Rkp", "S42-265-1:10", 265.0, 0.0, 19.192}, - {"Rkpd", "60E1-190-1:9", 190.0, 0.0, 16.615}, - {"Rkpd", "49E1-190-1:9", 190.0, 0.0, 16.615}, - {"Rkpd", "49E1-190-1:6,6", 190.0, -1.0, 17.396}, - {"Rkpd", "49E1-300-1:9", 300.0, -1.0, 22.639}, - {"Rkpd", "49E1-500-1:9", 500.0, -1.0, 27.693}, - {"Rkpd", "49E1-190-1:9 gauge 1524", 190.0, 0.0, 17.420}, - {"Rkpd", "S42-205-1:9", 205.0, 0.0, 17.591}, - {"Rkpd", "S42-205-1:9 II", 205.0, 0.0, 18.394}, - {"Rkpd", "S42-230-1:9,51", 230.0, 0.0, 18.642}, - {"Rkpd", "S42-230-1:9,51 Ia", 230.0, 0.0, 18.342}, - {"Rkpd", "S42-265-1:10", 265.0, 0.0, 19.192}, - }; - auto const ratio_of = [](std::string const &Name) { - auto const at{Name.find("1:")}; - auto number{Name.substr(at + 2)}; - std::replace(number.begin(), number.end(), ',', '.'); - return std::stod(number); - }; - for (auto const &entry : slips) + // the slips and crossings of the catalogue (Id-4): the angle comes from the straights clicked, the half length from the crossing to the + // joint to a and the label; the slips with the blades outside of the diamond have a straight in the middle of their curves, along + // which the near rails touch + for (auto const &entry : switch_design::slips()) { switch_template slip; slip.double_slip = true; slip.type = entry.type; slip.radius = entry.radius; slip.middle = entry.middle; - slip.a = entry.half; - slip.ratio = ratio_of(entry.name); - slip.rail = std::string{entry.name}.substr(0, std::string{entry.name}.find('-')); - slip.label = std::string{entry.type} + ' ' + entry.name + format(" a %.3f", entry.half) + (slip.type == "Rkp" ? " single slip" : " double slip") + - (entry.middle < 0.0 ? ", the blades outside of the diamond" : "") + - (slip.type == "Rkp" ? " (click at a crossing of two straights, on the side of the joined tracks, or drag it out on a straight)" : " (click at a crossing of two straights, or drag it out on a straight)"); + slip.a = entry.a; + slip.ratio = entry.ratio; + slip.rail = entry.rail; + // the name of the catalogue after its type, which the label puts before it + auto const name{entry.name.starts_with(entry.type + ' ') ? entry.name.substr(entry.type.size() + 1) : entry.name}; + if (slip.type == "Skrz") + slip.label = std::string{"Skrz "} + name + format(" a %.3f", entry.a) + " crossing (click at a crossing of two straights, or drag it out on a straight)"; + else + slip.label = slip.type + ' ' + name + format(" a %.3f", entry.a) + (slip.type == "Rkp" ? " single slip" : " double slip") + (entry.middle < 0.0 ? ", the blades outside of the diamond" : "") + + (slip.type == "Rkp" ? " (click at a crossing of two straights, on the side of the joined tracks, or drag it out on a straight)" : " (click at a crossing of two straights, or drag it out on a straight)"); result.push_back(slip); } - struct crossing - { - char const *name; - double half; - }; - crossing const crossings[] = { - {"60E1-1:9", 16.615}, - {"60E1-1:4,444", 10.907}, - {"49E1-1:2,9008", 6.904}, - {"49E1-1:3,224", 7.920}, - {"49E1-1:3,683", 9.881}, - {"49E1-1:4,44", 10.907}, - {"49E1-1:6,6", 17.396}, - {"49E1-1:7,5", 18.512}, - {"49E1-1:9", 16.615}, - {"49E1-1:9 long", 17.016}, - {"49E1-1:18,5", 32.409}, - {"S42-1:2", 5.743}, - {"S42-1:2,9008", 8.250}, - {"S42-1:3,429", 9.681}, - {"S42-1:3,43", 8.421}, - {"S42-1:4,44", 11.788}, - {"S42-1:4,444 gauge 1524", 12.189}, - {"S42-1:7", 12.932}, - {"S42-1:9", 17.591}, - {"S42-1:10", 19.192}, - }; - for (auto const &entry : crossings) - { - switch_template plain; - plain.double_slip = true; - plain.type = "Skrz"; - plain.a = entry.half; - plain.ratio = ratio_of(entry.name); - plain.rail = std::string{entry.name}.substr(0, std::string{entry.name}.find('-')); - plain.label = std::string{"Skrz "} + entry.name + format(" a %.3f", entry.half) + " crossing (click at a crossing of two straights, or drag it out on a straight)"; - result.push_back(plain); - } return result; } diff --git a/editor/editorTrack.hpp b/editor/editorTrack.hpp index 769d9dabd..26e4cc9e7 100644 --- a/editor/editorTrack.hpp +++ b/editor/editorTrack.hpp @@ -470,33 +470,12 @@ class editor_track // the full label gives std::string title() const; }; - // the diverging curve of a slip turning by Angle: arcs of Radius at both ends, each Ends long, and the arc of Middle, - // Between long, between them; a straight when Middle is 0. With blades cutting into the stock rails the curve starts and ends - // with a straight Lead long along them, the arcs of Radius meeting it at Entry - struct slip_curve + // the diverging curve of a slip, of the catalogue (switch_design), which the domain model lays its slips with too + using slip_curve = switch_design::slip_curve; + static slip_curve slip_of(double const Radius, double const Middle, double const Angle, double const Pass, double const Lead = 0.0, double const Entry = 0.0) { - double radius{0.0}; - double ends{0.0}; - double middle{0.0}; - double between{0.0}; - double angle{0.0}; - double tip{0.0}; // of the blades from each end of the curve, 0: where the blades get as thin as they may - double lead{0.0}; - double entry{0.0}; // radians - double length() const { return 2.0 * (lead + ends) + between; } - // the point and the heading at Along of the curve starting at the origin along x and turning towards y; the heading at the ends - // of the leads is the one of the arcs - glm::dvec2 point(double const Along) const; - double heading(double const Along) const; - // from the start of the curve to the crossing of its tangents - double tangent() const; - // from the middle of the curve to the crossing of its tangents - double offset() const; - slip_curve scaled(double const Factor) const { return {radius * Factor, ends * Factor, middle * Factor, between * Factor, angle, Factor == 1.0 ? tip : 0.0, lead * Factor, entry}; } - }; - // one arc of Radius, or with Middle the slip curves of a double slip with the blades outside of the diamond, their near rails - // touching in its middle: Pass from the crossing, half of the gauge and the width of the head; a straight there when Middle < 0 - static slip_curve slip_of(double const Radius, double const Middle, double const Angle, double const Pass, double const Lead = 0.0, double const Entry = 0.0); + return switch_design::slip_of(Radius, Middle, Angle, Pass, Lead, Entry); + } static std::vector standard_switch_templates(); // the rail of the switch templates fitting the track, by the rail profile it's laid with; empty where the profile doesn't tell static std::string rail_of(TTrack const *Track); diff --git a/tests/unit/test_turnout_catalogue.cpp b/tests/unit/test_turnout_catalogue.cpp new file mode 100644 index 000000000..254207974 --- /dev/null +++ b/tests/unit/test_turnout_catalogue.cpp @@ -0,0 +1,549 @@ +// the catalogue of the turnouts as a data file (editor/data/turnouts.txt, editor-tracks-domain.md §7): the switches read from it the same +// to the bit as the catalogue the editor had in its code, kept here as it was; the slips and the crossings as the switch tool had them; +// each type against what the instruction and the standard tell of it (a, b, R, the angle, the pre-blade stretch, the tip and the angle of +// the blade, the speed, the bending and the spacing of tab. 11.9 and 11.2); the rules for a blade tip where no data is, against the types +// which have it; the templates of the user in the same format keeping a movable nose + +#include "stdafx.h" +#include "doctest.h" +#include "editor/editorSwitchCurve.hpp" +#include "editor/editorSwitchDesign.hpp" + +#include +#include +#include +#include +#include + +namespace { + +// the catalogue as editorSwitchDesign.cpp had it in its code before it became a data file +namespace frozen { + +using namespace switch_design; +double constexpr kSecantAngle{25.0 / 60.0}; +double constexpr kSecantLead{0.6}; + +// clang-format off +std::vector old_catalogue() +{ + // the switches of the instruction Id-4 of PKP PLK, tables 8-1 (60E1), 8-2 (49E1) and 8-3 (S42): a from the start of the switch + // to its centre, b on from there along the main track, and along the diverging track where the scheme gives it another length + struct ordinary + { + char const *name; + char const *rail; + double radius; + double ratio; // at the end of the diverging track; of the two tracks parting, for a symmetric switch + double a; // 0: from the geometry + double b; // 0: the diverging track curved up to its end + double diverging{0.0}; // 0: the same as b + bool movable{false}; + char const *type{"Rz"}; + bool tangent{false}; // an S42 switch with blades lying tangent to the stock rails, its a too long for blades cutting into them at 25' + }; + ordinary const ordinaries[] = { + {"Rz 60E1-190-1:9", "60E1", 190.0, 9.0, 10.523, 16.615}, + {"Rz 60E1-300-1:9", "60E1", 300.0, 9.0, 16.615, 16.615}, + {"Rz 60E1-500-1:12", "60E1", 500.0, 12.0, 20.797, 20.797}, + {"Rz 60E1-500-1:12 movable nose", "60E1", 500.0, 12.0, 20.797, 20.797, 0.0, true}, + {"Rz 60E1-760-1:14", "60E1", 760.0, 14.0, 27.108, 27.108}, + {"Rz 60E1-1200-1:18,5", "60E1", 1200.0, 18.5, 32.409, 32.409}, + {"Rz 60E1-1200-1:18,5 movable nose", "60E1", 1200.0, 18.5, 32.409, 32.409, 0.0, true}, + {"Rz 60E1-2500-1:26,5 movable nose", "60E1", 2500.0, 26.5, 47.153, 47.153, 0.0, true}, + {"Rz 49E1-190-1:7,5", "49E1", 190.0, 7.5, 12.611, 12.611}, + {"Rz 49E1-190-1:7,5 long", "49E1", 190.0, 7.5, 12.611, 17.428}, + {"Rz 49E1-190-1:9", "49E1", 190.0, 9.0, 10.523, 16.615}, + {"Rz 49E1-190-1:9 gauge 1524", "49E1", 190.0, 9.0, 10.523, 17.417}, + {"Rz 49E1-190-1:7,5/1:6,6", "49E1", 190.0, 6.6, 14.312, 10.910, 14.312}, + {"Rz 49E1-300-1:9", "49E1", 300.0, 9.0, 16.615, 16.615}, + {"Rz 49E1-300-1:9,403", "49E1", 300.0, 9.403, 15.907, 17.343, 17.322}, + {"Rz 49E1-500-1:12", "49E1", 500.0, 12.0, 20.797, 20.797}, + {"Rz 49E1-500-1:14", "49E1", 500.0, 14.0, 17.834, 24.537}, + {"Rz 49E1-1200-1:18,5", "49E1", 1200.0, 18.5, 32.409, 32.409}, + // table 3-2, without a scheme + {"Rls 49E1-215-1:4,8", "49E1", 215.0, 4.8, 0.0, 0.0, 0.0, false, "Rls"}, + {"Rz S42-190-1:6,6", "S42", 190.0, 6.6, 13.374, 12.560, 14.172}, + {"Rz S42-190-1:7", "S42", 190.0, 7.0, 12.573, 13.361}, + {"Rz S42-190-1:7,5", "S42", 190.0, 7.5, 11.691, 14.243, 14.235}, + {"Rz S42-205-1:9 I", "S42", 205.0, 9.0, 10.517, 16.500}, + {"Rz S42-205-1:9 II", "S42", 205.0, 9.0, 10.517, 17.591}, + {"Rz S42-230-1:9,51 I", "S42", 230.0, 9.51, 11.046, 16.008, 16.308}, + {"Rz S42-230-1:9,51 II", "S42", 230.0, 9.51, 11.046, 18.342, 18.642}, + {"Rz S42-230-1:9,51 III", "S42", 230.0, 9.51, 11.046, 16.008, 18.642}, + {"Rz S42-265-1:10 I", "S42", 265.0, 10.0, 11.9692, 18.1508}, + {"Rz S42-265-1:10 II", "S42", 265.0, 10.0, 11.9692, 19.1918}, + {"Rz S42-500-1:9", "S42", 500.0, 9.0, 25.055, 13.743, 27.513}, + {"Rz S42-500-1:12", "S42", 500.0, 12.0, 18.21526, 20.58234, 20.58202}, + {"Rz S42-500-1:14", "S42", 500.0, 14.0, 15.288, 26.323}, + {"Rz S42-70-1:5 industrial", "S42", 70.0, 5.0, 7.112, 8.708}, + {"Rz S42-140-1:7 industrial", "S42", 140.0, 7.0, 7.670, 12.932}, + {"Rls S42-140-1:5 industrial", "S42", 140.0, 5.0, 7.131, 8.715, 0.0, false, "Rls"}, + {"Rls S42-200-1:7 industrial", "S42", 200.0, 7.0, 6.493, 12.148, 0.0, false, "Rls"}, + {"Rz S42-205-1:6,6 industrial", "S42", 205.0, 6.6, 14.588, 13.602, 15.352}, + {"Rz S42-205-1:7 industrial", "S42", 205.0, 7.0, 13.710, 14.480}, + {"Rz S42-205-1:7,5 industrial", "S42", 205.0, 7.5, 12.754, 15.436, 15.427}, + {"Rz S42-300-1:9 industrial", "S42", 300.0, 9.0, 16.615, 16.615, 0.0, false, "Rz", true}, + {"Rz S42-205-1:9 gauge 1524", "S42", 205.0, 9.0, 10.513, 18.394}, + }; + auto const make = [](ordinary const &Ordinary) { + design entry; + entry.name = Ordinary.name; + entry.rail = Ordinary.rail; + entry.type = Ordinary.type; + entry.movable = Ordinary.movable; + auto const symmetric{symmetric_switch(entry.type)}; + // each track of a symmetric switch turns by a half of the angle between them + auto const angle{std::atan(1.0 / Ordinary.ratio) * (symmetric ? 0.5 : 1.0)}; + auto const radius{Ordinary.radius}; + auto const tangent{radius * std::tan(angle * 0.5)}; + auto const a{Ordinary.a > 0.0 ? Ordinary.a : tangent}; + auto const across = [&](double const Entry) { return radius * (std::cos(Entry) - std::cos(angle)); }; + // the centre nearer than the tangent of the arc: the blade meets the stock rail at an angle and the arc turns the rest of the way; + // further: the diverging track runs along the main one for a while + // within a couple of centimetres of the tangent the catalogue only rounds it + auto const centre = [&](double const Entry) { return radius * (std::sin(angle) - std::sin(Entry)) - across(Entry) / std::tan(angle); }; + auto const fit = [&](double const Centre) { + auto low{0.0}; + auto high{angle}; + for (int i = 0; i < 60; ++i) + { + auto const middle{(low + high) * 0.5}; + (centre(middle) > Centre ? low : high) = middle; + } + return (low + high) * 0.5; }; + auto entryangle{0.0}; + auto lead{a > tangent + 0.02 ? a - tangent : 0.0}; + if (entry.rail == "S42" && false == Ordinary.tangent) + { + entryangle = glm::radians(kSecantAngle) * (symmetric ? 0.5 : 1.0); + lead = a - centre(entryangle); + if (lead <= 0.0) + { + lead = kSecantLead; + entryangle = fit(a - lead); + } + } + else if (a < tangent - 0.02) + entryangle = fit(a); + else if (auto const cut{cut_tip(entry.rail, radius)}; cut > 0.0 && false == symmetric) + entry.tip = lead + cut; + entry.entry = glm::degrees(entryangle); + entry.lead = lead; + entry.a = a; + auto const arcend{across(entryangle) / std::sin(angle)}; + entry.b = Ordinary.b > 0.0 ? Ordinary.b : arcend; + entry.parts.push_back({radius * (angle - entryangle), radius, radius}); + auto const rest{(Ordinary.diverging > 0.0 ? Ordinary.diverging : entry.b) - arcend}; + if (rest > 0.05) + entry.parts.push_back({rest, 0.0, 0.0}); + if (false == symmetric) + entry.main = a + entry.b; + if (Ordinary.a <= 0.0 || Ordinary.b <= 0.0) + entry.note = "(from the geometry)"; + return entry; + }; + std::vector result; + for (auto const &ordinary : ordinaries) + result.push_back(make(ordinary)); + // not of Id-4: the tangents as measured, too long for one arc alone + for (auto const &[name, kind] : {std::pair{"Rz S42-140-1:6,6 16/12", tangent_fit::straights}, std::pair{"Rz S42-140-1:6,6 16/12 KP", tangent_fit::transition}, std::pair{"Rz S42-140-1:6,6 16/12 \xc5\x82uk-prosta-\xc5\x82uk", tangent_fit::arc_straight_arc}}) + { + design fitted; + fitted.name = name; + fitted.rail = "S42"; + std::string problem; + if (fit_tangents(fitted, 140.0, 6.6, 16.0, 12.0, kind, problem)) + result.push_back(fitted); + } + // double switches: the second one starts on the main track of the first, as far on as the schemes give it, a one sided double + // switch of Id-4 has its second switch on the diverging track of the first, here on the main one at the same place + ordinary const r190_75{"", "", 190.0, 7.5, 12.611, 12.611}; + ordinary const r190_75long{"", "", 190.0, 7.5, 12.611, 12.611, 16.615}; + ordinary const r190_9{"", "", 190.0, 9.0, 10.523, 16.615}; + ordinary const r190_9tangent{"", "", 190.0, 9.0, 10.523, 16.615, 0.0, false, "Rz", true}; + ordinary const r190_66{"", "", 190.0, 6.6, 14.312, 10.910, 14.312}; + ordinary const r300_9{"", "", 300.0, 9.0, 16.615, 16.615}; + ordinary const r500_12{"", "", 500.0, 12.0, 20.797, 20.797}; + struct twofold + { + char const *name; + char const *type; + char const *rail; + ordinary first; + ordinary second; + double stagger; + char const *note; + }; + twofold const twofolds[] = { + {"Rpd 49E1-190-1:7,5/1:7,5", "Rpd", "49E1", r190_75long, r190_75, 10.523, ""}, + {"Rpd 49E1-190-1:9/1:7,5", "Rpd", "49E1", r190_9, r190_75, 10.523, ""}, + {"Rpd 49E1-190-1:9/1:9", "Rpd", "49E1", r190_9, r190_9, 10.523, ""}, + {"Rpd 49E1-190-1:7,5/1:7,5/1:6,6", "Rpd", "49E1", r190_75, r190_66, 10.523, ""}, + {"Rpd 49E1-190-1:7,5/1:6,6/1:7,5", "Rpd", "49E1", r190_66, r190_75, 10.523, ""}, + {"Rpd 49E1-190-1:7,5/1:6,6/1:7,5/1:6,6", "Rpd", "49E1", r190_66, r190_66, 10.523, ""}, + {"Rpd 49E1-190-1:9/1:7,5/1:6,6", "Rpd", "49E1", r190_9, r190_66, 10.523, ""}, + {"Rpj 49E1-190-1:9", "Rpj", "49E1", r190_9, r190_9, 5.258, "(approx.)"}, + {"Rpd S42-190-1:9", "Rpd", "S42", r190_9tangent, r190_9tangent, 10.523, ""}, + {"Rpd S42-190-1:9 II", "Rpd", "S42", {"", "", 190.0, 9.0, 9.626, 15.500}, {"", "", 190.0, 9.0, 9.626, 17.591}, 9.5, ""}, + {"Rpj S42-190/180-1:10", "Rpj", "S42", {"", "", 190.0, 10.0, 0.0, 19.192, 0.0, false, "Rz", true}, {"", "", 180.0, 10.0, 0.0, 19.192, 0.0, false, "Rz", true}, 5.504, "(approx.)"}, + {"Rpj S42-140-1:9 industrial", "Rpj", "S42", {"", "", 140.0, 9.0, 9.274, 17.590, 0.0, false, "Rz", true}, {"", "", 140.0, 9.0, 9.274, 17.590, 0.0, false, "Rz", true}, 9.263, "(approx.)"}, + {"Rpd S42-140-1:7 industrial", "Rpd", "S42", {"", "", 140.0, 7.0, 7.670, 12.932}, {"", "", 140.0, 7.0, 7.670, 12.932}, 6.9, ""}, + // symmetric double switches, not in Id-4 but for its scheme: the same switch to both sides, the second one starting as close behind + // the first one as their blades let them, past the heel of the blades of the first one and the short track between the two + {"Rps 60E1-300-1:9", "Rps", "60E1", r300_9, r300_9, 14.2, "(designed)"}, + {"Rps 60E1-500-1:12", "Rps", "60E1", r500_12, r500_12, 18.0, "(designed)"}, + }; + for (auto const &entry : twofolds) + { + auto first{entry.first}; + auto other{entry.second}; + first.rail = other.rail = entry.rail; + auto made{make(first)}; + auto const second{make(other)}; + made.name = entry.name; + made.rail = entry.rail; + made.type = entry.type; + made.stagger = entry.stagger; + if (made.type != "Rps") + { + made.parts2 = second.parts; + made.lead2 = second.lead; + made.entry2 = second.entry; + made.tip2 = second.tip; + } + made.main = 0.0; + made.b = 0.0; + made.note = entry.note; + result.push_back(made); + } + return result; +} +// clang-format on + +// the slips and the crossings of the switch tool (editorTrack.cpp) before they became lines of the data file +struct slipping { + char const *type; + char const *name; + double radius; + double middle; + double half; +}; +std::vector const slips{ + {"Rkp", "60E1-190-1:9", 190.0, 0.0, 16.615}, + {"Rkp", "49E1-190-1:9", 190.0, 0.0, 16.615}, + {"Rkp", "49E1-190-1:6,6", 190.0, -1.0, 17.396}, + {"Rkp", "49E1-300-1:9", 300.0, -1.0, 22.639}, + {"Rkp", "49E1-500-1:9", 500.0, -1.0, 27.693}, + {"Rkp", "S42-230-1:9,51", 230.0, 0.0, 18.642}, + {"Rkp", "S42-265-1:10", 265.0, 0.0, 19.192}, + {"Rkpd", "60E1-190-1:9", 190.0, 0.0, 16.615}, + {"Rkpd", "49E1-190-1:9", 190.0, 0.0, 16.615}, + {"Rkpd", "49E1-190-1:6,6", 190.0, -1.0, 17.396}, + {"Rkpd", "49E1-300-1:9", 300.0, -1.0, 22.639}, + {"Rkpd", "49E1-500-1:9", 500.0, -1.0, 27.693}, + {"Rkpd", "49E1-190-1:9 gauge 1524", 190.0, 0.0, 17.420}, + {"Rkpd", "S42-205-1:9", 205.0, 0.0, 17.591}, + {"Rkpd", "S42-205-1:9 II", 205.0, 0.0, 18.394}, + {"Rkpd", "S42-230-1:9,51", 230.0, 0.0, 18.642}, + {"Rkpd", "S42-230-1:9,51 Ia", 230.0, 0.0, 18.342}, + {"Rkpd", "S42-265-1:10", 265.0, 0.0, 19.192}, +}; +struct crossing { + char const *name; + double half; +}; +std::vector const crossings{ + {"60E1-1:9", 16.615}, {"60E1-1:4,444", 10.907}, {"49E1-1:2,9008", 6.904}, {"49E1-1:3,224", 7.920}, {"49E1-1:3,683", 9.881}, + {"49E1-1:4,44", 10.907}, {"49E1-1:6,6", 17.396}, {"49E1-1:7,5", 18.512}, {"49E1-1:9", 16.615}, {"49E1-1:9 long", 17.016}, + {"49E1-1:18,5", 32.409}, {"S42-1:2", 5.743}, {"S42-1:2,9008", 8.250}, {"S42-1:3,429", 9.681}, {"S42-1:3,43", 8.421}, + {"S42-1:4,44", 11.788}, {"S42-1:4,444 gauge 1524", 12.189}, {"S42-1:7", 12.932}, {"S42-1:9", 17.591}, {"S42-1:10", 19.192}, +}; +double ratio_of(std::string const &Name) { + auto const at{Name.find("1:")}; + auto number{Name.substr(at + 2)}; + std::replace(number.begin(), number.end(), ',', '.'); + return std::stod(number); +} + +} // namespace frozen + +void check_same_parts(std::vector const &Old, std::vector const &New) { + REQUIRE(New.size() == Old.size()); + for (std::size_t i = 0; i < Old.size(); ++i) { + CAPTURE(i); + CHECK(New[i].length == Old[i].length); + CHECK(New[i].radius1 == Old[i].radius1); + CHECK(New[i].radius2 == Old[i].radius2); + } +} + +// the values the editor had: the same doubles, not within a tolerance +void check_same(switch_design::design const &Old, switch_design::design const &New) { + CHECK(New.name == Old.name); + CHECK(New.type == Old.type); + CHECK(New.rail == Old.rail); + CHECK(New.main == Old.main); + check_same_parts(Old.parts, New.parts); + CHECK(New.lead == Old.lead); + CHECK(New.entry == Old.entry); + CHECK(New.tip == Old.tip); + CHECK(New.heel == Old.heel); + CHECK(New.bladethrow == Old.bladethrow); + CHECK(New.stagger == Old.stagger); + check_same_parts(Old.parts2, New.parts2); + CHECK(New.lead2 == Old.lead2); + CHECK(New.entry2 == Old.entry2); + CHECK(New.tip2 == Old.tip2); + CHECK(New.a == Old.a); + CHECK(New.b == Old.b); + CHECK(New.note == Old.note); + CHECK(New.own == Old.own); + CHECK(New.movable == Old.movable); +} + +double constexpr kSecant{25.0 / 60.0}; // degrees, the angle of the secant blades of S42 + +// ST-T1-A6 tab. 11.2: the least spacing of the tracks of a single crossover by the basic switch, of 60E1 and 49E1 +double table_11_2_spacing(double const Radius, double const Ratio) { + struct row { + double radius; + double ratio; + double spacing; + }; + static constexpr std::array rows{row{190.0, 9.0, 3.70}, row{300.0, 9.403, 4.00}, row{300.0, 9.0, 4.35}, row{500.0, 12.0, 4.00}, row{760.0, 14.0, 4.75}, row{1200.0, 18.5, 4.35}, row{2500.0, 26.5, 4.80}}; + for (auto const &each : rows) { + if (std::abs(each.radius - Radius) < 0.5 && std::abs(each.ratio - Ratio) < 1e-6) { + return each.spacing; + } + } + return 0.0; +} + +} // namespace + +TEST_CASE("turnout catalogue: the switches of the data file are the ones the editor had in its code, to the bit") { + auto const old{frozen::old_catalogue()}; + auto const now{switch_design::catalogue()}; + REQUIRE(now.size() == old.size()); + for (std::size_t i = 0; i < old.size(); ++i) { + CAPTURE(old[i].name); + check_same(old[i], now[i]); + } +} + +TEST_CASE("turnout catalogue: the slips and the crossings of the data file are the ones of the switch tool") { + auto const now{switch_design::slips()}; + REQUIRE(now.size() == frozen::slips.size() + frozen::crossings.size()); + std::size_t at{0}; + for (auto const &old : frozen::slips) { + auto const &entry{now[at++]}; + auto const name{std::string{old.name}}; + CAPTURE(name); + CHECK(entry.type == old.type); + CHECK(entry.name == std::string{old.type} + ' ' + name); + CHECK(entry.rail == name.substr(0, name.find('-'))); + CHECK(entry.radius == old.radius); + CHECK(entry.middle == old.middle); + CHECK(entry.a == old.half); + CHECK(entry.ratio == frozen::ratio_of(name)); + CHECK(entry.blades == (entry.rail == "S42" ? "secant" : "tangent")); + } + for (auto const &old : frozen::crossings) { + auto const &entry{now[at++]}; + auto const name{std::string{old.name}}; + CAPTURE(name); + CHECK(entry.type == "Skrz"); + CHECK(entry.name == "Skrz " + name); + CHECK(entry.rail == name.substr(0, name.find('-'))); + CHECK(entry.a == old.half); + CHECK(entry.ratio == frozen::ratio_of(name)); + } +} + +TEST_CASE("turnout catalogue: every line of the data file is read, each type with its source") { + std::vector errors; + auto const all{switch_design::read_designs(switch_design::catalogue_text(), &errors)}; + for (auto const &error : errors) { + CAPTURE(error); + CHECK(false); + } + CHECK(all.size() == switch_design::catalogue_entries().size()); + CHECK(all.size() == switch_design::catalogue().size() + switch_design::slips().size()); + std::map names; + for (auto const &entry : all) { + CAPTURE(entry.name); + CHECK(++names[entry.name] == 1); + CHECK_FALSE(entry.source.empty()); + CHECK_FALSE(entry.own); + } +} + +TEST_CASE("turnout catalogue: each switch against Id-4 and ST-T1-A6, a, b, R, the angle, the pre-blade stretch, the blade, the speed") { + for (auto const &entry : switch_design::catalogue()) { + CAPTURE(entry.name); + std::string error; + auto const shape{switch_design::build(entry, error)}; + REQUIRE(error.empty()); + REQUIRE(shape.paths.size() >= 2); + auto const twofold{switch_design::double_switch(entry.type)}; + auto const symmetric{switch_design::symmetric_switch(entry.type)}; + REQUIRE(entry.radius > 0.0); + REQUIRE(entry.ratio > 1.0); + // R and the angle 1:n at the end of the diverging track, of the two tracks of a symmetric switch + if (false == twofold) { + CHECK(shape.radius == doctest::Approx(entry.radius).epsilon(1e-12)); + } + CHECK(shape.ratio == doctest::Approx(entry.ratio).epsilon(1e-9)); + // a as the catalogue gives it, the tangent of the arc where it gives none; the main track a + b + auto const angle{std::atan(1.0 / entry.ratio) * (symmetric ? 0.5 : 1.0)}; + auto const tangent{entry.radius * std::tan(angle * 0.5)}; + CHECK(shape.a == entry.a); + if (entry.type == "Rz") { + CHECK(shape.length == doctest::Approx(entry.a + entry.b).epsilon(1e-12)); + } + // the blades: tangent ones leave the main track at no angle, from the start of the curve or a pre-blade stretch where a is longer + // than the tangent of the arc; secant ones of S42 cut into the stock rail at 25', the pre-blade stretch what a leaves + REQUIRE((entry.blades == "tangent" || entry.blades == "secant")); + // fitted to the tangents measured, not of Id-4 + auto const fitted{entry.source.find("not of Id-4") != std::string::npos}; + auto const tip{switch_design::blade_tip(entry.parts, entry.lead, entry.entry, entry.tip, symmetric)}; + if (entry.blades == "secant") { + CHECK(entry.rail == "S42"); + CHECK(entry.lead > 0.0); + CHECK(tip == entry.lead); + if (entry.name != "Rz S42-140-1:7 industrial" && entry.name != "Rpd S42-140-1:7 industrial") { + CHECK(entry.entry == doctest::Approx(symmetric ? 0.5 * kSecant : kSecant).epsilon(1e-12)); + } + } else if (entry.a < tangent - 0.02) { + // a shorter than the tangent: the blade meets the stock rail at the angle which makes it + CHECK(entry.entry > 0.0); + } else if (false == fitted) { + CHECK(entry.entry == 0.0); + CHECK(entry.lead == (entry.a > tangent + 0.02 ? doctest::Approx(entry.a - tangent).epsilon(1e-12) : doctest::Approx(0.0))); + if (entry.cut > 0.0) { + CHECK(entry.tip == doctest::Approx(entry.lead + entry.cut).epsilon(1e-12)); + CHECK(tip == entry.tip); + } else if (false == symmetric && entry.parts.front().radius1 == entry.radius) { + // no data of the blade: where it gets 5 mm from the stock rail, 125 mm of it planed + CHECK(std::abs(tip - entry.lead - (std::sqrt(2.0 * entry.radius * 0.005) - 0.125)) <= 0.01); + } + } + // the speed of tab. 11.2 by the radius, of the sharper switch of a double one + auto sharpest{entry.radius}; + if (twofold && false == entry.parts2.empty()) { + sharpest = std::min(sharpest, entry.parts2.front().radius1); + } + CHECK(entry.speed == switch_curve::basic_speed(sharpest)); + // the bending of tab. 11.9: the basic switches of 60E1 and 49E1 of the radii it lists, none of the double and symmetric ones + auto const limit{switch_curve::bent_limit_of(entry.radius)}; + if (limit.has_value() && entry.type == "Rz" && entry.rail != "S42") { + CHECK(entry.bending == limit->main); + CHECK(entry.bending_exception == limit->main_exception); + } else { + CHECK(entry.bending == 0.0); + } + // the spacing of tab. 11.2 + CHECK(entry.spacing == (entry.type == "Rz" && entry.rail != "S42" ? table_11_2_spacing(entry.radius, entry.ratio) : 0.0)); + CHECK(entry.movable == (entry.name.find("movable nose") != std::string::npos)); + } +} + +TEST_CASE("turnout catalogue: the rules for a blade tip where no data is, against the types which have it") { + // the cut tips of 60E1 and 49E1 from the sheets SKMd-4, from the start of the curve: e1 of the straight blade, e2 of the curved one + struct sheet { + double radius; + double e1; + double e2; + }; + std::array const sheets{sheet{190.0, 1.248, 1.248}, sheet{300.0, 1.500, 1.468}, sheet{500.0, 2.165, 2.142}, sheet{1200.0, 3.335, 3.321}}; + for (auto const &each : sheets) { + CAPTURE(each.radius); + // the rule of the editor: where the blade gets 5 mm from the stock rail, 125 mm of it planed, about sqrt(2R 0.005) - 0.125 (the + // gauge face turning away by a few millimetres); and where the axes are 4.5 mm apart + switch_design::part const arc{each.radius * 0.1, each.radius, each.radius}; + auto const editor{switch_design::blade_tip({arc}, 0.0, 0.0, 0.0, false)}; + auto const rule{std::sqrt(2.0 * each.radius * 0.005) - 0.125}; + auto const offset{std::sqrt(2.0 * each.radius * 0.0045)}; + MESSAGE("R ", each.radius, ": SKMd-4 ", each.e1, " / ", each.e2, ", the editor's rule ", editor, " (", editor - each.e1, "), sqrt(2R 0.005) - 0.125 ", rule, " (", rule - each.e1, "), 4.5 mm off ", offset, " (", + offset - each.e1, ")"); + CHECK(std::abs(editor - rule) <= 0.005); + CHECK(std::abs(editor - each.e1) <= 0.11); + CHECK(std::abs(offset - each.e1) <= 0.15); + // the catalogue keeps the sheets' values, not the rule + for (auto const &entry : switch_design::catalogue()) { + if (entry.type == "Rz" && entry.rail != "S42" && std::abs(entry.radius - each.radius) < 0.5 && entry.cut > 0.0) { + CAPTURE(entry.name); + CHECK(std::abs(entry.cut - each.e1) < 0.001); + } + } + } + // the secant blades of S42: no sheet found, the angle of 25' is the rule + for (auto const &entry : switch_design::catalogue()) { + if (entry.blades == "secant") { + CAPTURE(entry.name); + CHECK(entry.source.find("unconfirmed") != std::string::npos); + } + } +} + +TEST_CASE("turnout catalogue: a template of the user is a line of the same format and keeps its movable nose") { + switch_design::design own; + own.name = "My switch 1"; + own.type = "Rz"; + own.rail = "60E1"; + own.main = 41.594; + own.a = 20.797; + own.b = 20.797; + own.parts = {{41.5, 500.0, 500.0}, {0.25, 0.0, 0.0}}; + own.movable = true; + auto const line{switch_design::own_line(own)}; + CAPTURE(line); + CHECK(line.find("frog movable") != std::string::npos); + CHECK(line.find("switch My_switch_1 ") == 0); + std::vector errors; + auto const back{switch_design::read_designs(line, &errors)}; + CHECK(errors.empty()); + REQUIRE(back.size() == 1); + CHECK(back.front().name == own.name); + CHECK(back.front().movable); + CHECK(back.front().main == own.main); + CHECK(back.front().a == own.a); + check_same_parts(own.parts, back.front().parts); + // without one, the line as the builds before wrote it, which read no key they don't know + own.movable = false; + CHECK(switch_design::own_line(own).find("frog") == std::string::npos); + // and a line they wrote reads as it did + auto const older{switch_design::read_designs("# switch templates\nswitch Old_one type Rpd rail 49E1 main 0.0000 stagger 10.5230 a 0.0000 b 0.0000 lead 0.0000 entry 0.0000 tip 0.0000 lead2 0.0000 " + "entry2 0.0000 tip2 0.0000 parts 2 12.6110 190.0000 190.0000 4.0000 0.0000 0.0000 parts2 1 12.6110 190.0000 190.0000\r\n")}; + REQUIRE(older.size() == 1); + CHECK(older.front().name == "Old one"); + CHECK(older.front().type == "Rpd"); + CHECK(older.front().stagger == 10.523); + CHECK_FALSE(older.front().movable); + CHECK(older.front().parts.size() == 2); + CHECK(older.front().parts2.size() == 1); + CHECK(older.front().lead2 == 0.0); + std::string error; + CHECK(switch_design::build(older.front(), error).paths.size() == 5); +} + +TEST_CASE("turnout catalogue: a line which isn't one is left out, why told") { + std::vector errors; + auto const read{switch_design::read_designs("switch \"A\" type Rz rail 60E1 radius 500 ratio 12 colour red\n" + "switch \"B\" type Rz rail 60E1 radius 500 ratio twelve\n" + "switch \"C\" type Rz rail 60E1 radius 500 radius 300 ratio 12\n" + "switch \"D type Rz rail 60E1 radius 500 ratio 12\n" + "switch \"E\" type Rq rail 60E1 radius 500 ratio 12\n" + "switch \"F\" type Rz rail 60E1 radius 500 ratio 12 a 20.797 b 20.797 source made up\n", + &errors)}; + REQUIRE(read.size() == 1); + CHECK(read.front().name == "F"); + CHECK(read.front().source == "made up"); + REQUIRE(errors.size() == 5); + CHECK(errors[0].find("colour") != std::string::npos); + CHECK(errors[1].find("number") != std::string::npos); + CHECK(errors[2].find("twice") != std::string::npos); + CHECK(errors[3].find("quote") != std::string::npos); + CHECK(errors[4].find("Rq") != std::string::npos); +}