Debian Codegraph @

texmf-dist/tex/latex/tikz-trackschematic/tikzlibrarytrackschematic.measures.code.tex

raw
1 %% symbol library for TikZ track schematics
2 %
3 % Copyright (c) 2018 - 2022, Martin Scheidt (ISC license)
4 %
5 % Permission to use, copy, modify, and/or distribute this file for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6 %
7 \ProvidesFileRCS{tikzlibrarytrackschematic.measures.code.tex}%
8 %
9 %%%%%%%%%%%%%%%
10 % global settings
11 %%%%%%%%%%%%%%%
12 \RequirePackage{tikz,etoolbox}%
13 \usetikzlibrary{calc,intersections,arrows.meta}%
14 %
15 %%%%%%%%%%%%%%%
16 % tikz keys for multiple use
17 %%%%%%%%%%%%%%%
18 \ifdeflength{\objectlength}{}{% Not defined, so define it!
19 \newlength{\objectlength}%
20 }%
21 \setlength{\objectlength}{4cm}%
22 %
23 \pgfkeys{%
24 /tikz/trackschematic/.is family,%
25 /tikz/trackschematic/.cd,%
26 %% face
27 face/.value required,% forward, backward OR bidirectional
28 face/.store in=\face,% forward, backward OR bidirectional
29 /tikz/face/.forward to=/tikz/trackschematic/face,%
30 /tikz/forward/.code={\pgfkeys{/tikz/trackschematic/face=forward}},%
31 /tikz/backward/.code={\pgfkeys{/tikz/trackschematic/face=backward}},%
32 /tikz/bidirectional/.code={\pgfkeys{/tikz/trackschematic/face=bidirectional}},%
33 %% length
34 length/.store in=\objectlength,% default length 4cm
35 /tikz/length/.forward to=/tikz/trackschematic/length,%
36 %% traffic practice
37 traffic practice/.value required,% left OR right
38 traffic practice/.store in=\trafficpractice,%
39 /tikz/traffic practice/.forward to=/tikz/trackschematic/traffic practice,%
40 /tikz/position/.forward to=/tikz/trackschematic/traffic practice,%
41 %% label
42 shift label/.store in=\labelcoord,% (coord)
43 shift label=(none),% DEFAULT
44 /tikz/shift label/.forward to=/tikz/trackschematic/shift label,%
45 }%
46 \tikzset{traffic practice=right}%
47 %
48 % tikz keys
49 \pgfkeys{%
50 /tikz/trackschematic/measures/.is family,%
51 /tikz/trackschematic/measures/.cd,%
52 %% color hectometer
53 color/.store in=\hectometercolor,%
54 color=foreground!50!background,% DEFAULT
55 /tikz/hectometer color/.forward to=/tikz/trackschematic/measures/color,%
56 }%
57 %%%%%%%%%%%%%%%%
58 % symbol train berth
59 %%%%%%%%%%%%%%%
60 %% command
61 \newcommand\berth{}% just for safety
62 \def\berth[#1]#2(#3)#4(#5){% \berth[options] at (coord) length (usable length);
63 \pic[#1] at (#3) {train_berth={#2/#4/#5}}% symbol
64 }%
65 %%
66 %% symbol definition
67 \tikzset{%
68 pics/train_berth/.default=,%
69 pics/train_berth/.style args={#1/#2/#3}{code={%
70 %% settings
71 \def\coordcommand{#1}% beware of leading and tailing spaces!
72 \def\labelcommand{#2}% beware of leading and tailing spaces!
73 \def\labelcontent{#3}%
74 %% face setup
75 \ifdefstring{\face}{bidirectional}{% face
76 \pgfmathsetmacro{\facefactor}{1}%
77 }{%
78 \ifdefstring{\face}{forward}{% face
79 \pgfmathsetmacro{\facefactor}{1}%
80 }{%
81 \ifdefstring{\face}{backward}{% face
82 \pgfmathsetmacro{\facefactor}{-1}%
83 }{% error message
84 \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/face}{“forward“, “backward“ OR “bidirectional“ as key required}}%
85 }%
86 }%
87 }% end \ifdefstring{\face}
88 %% traffic practice setup
89 \ifdefstring{\trafficpractice}{left}{% branch
90 \pgfmathsetmacro{\trafficfactor}{-1}%
91 }{%
92 \ifdefstring{\trafficpractice}{right}{% branch
93 \pgfmathsetmacro{\trafficfactor}{1}%
94 }{% error message
95 \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/trafficcontrol/traffic practice}{“left“ OR “right“ as key required}}%
96 }%
97 }% end \ifdefstring{\trafficpractice}
98 %
99 \tikzset{every path/.style={draw=foreground,line width=0.75pt,line cap=round,dash pattern=on 0pt off 2.4\pgflinewidth}};%
100 \path% berth shape forward
101 ($-0.5*(\objectlength,0) + (-0.05,0) + \trafficfactor*\facefactor*(0,-0.25)$) --%
102 ($-0.5*(\objectlength,0) + (-0.05,0) + \trafficfactor*\facefactor*(0,-0.35)$)%
103 ($-0.5*(\objectlength,0) + (-0.05,0) + \trafficfactor*\facefactor*(0,-0.35) + (\pgflinewidth,0)$) --%
104 ($ 0.5*(\objectlength,0) + ( 0.05,0) + \trafficfactor*\facefactor*(0,-0.35)$)%
105 ($ 0.5*(\objectlength,0) + ( 0.05,0) + \trafficfactor*\facefactor*(0,-0.25)$) --%
106 ($ 0.5*(\objectlength,0) + ( 0.05,0) + \trafficfactor*\facefactor*(0,-0.35)$);% berth shape forward
107 \path[draw=none,fill=foreground]% arrow front
108 ($\facefactor*0.5*(\objectlength,0) + \facefactor*(-0.1,0) + \trafficfactor*\facefactor*(0,-0.35)$) --%
109 ++($(0,-0.04) + \facefactor*(-0.1,0)$) -- ++(0,0.08) -- cycle;% arrow
110 \path[draw=none,fill=foreground]% arrow back
111 ($\facefactor*-0.5*(\objectlength,0) + \facefactor*(0.2,0) + \trafficfactor*\facefactor*(0,-0.35)$) --%
112 ++($(0,-0.04) + \facefactor*(-0.1,0)$) -- ++(0,0.08) -- cycle;% arrow
113 \ifdefstring{\face}{bidirectional}{% bidirectional
114 \pgfmathsetmacro{\facefactor}{-1}%
115 \path% berth shape forward
116 ($-0.5*(\objectlength,0) + (-0.05,0) + \trafficfactor*\facefactor*(0,-0.25)$) --%
117 ($-0.5*(\objectlength,0) + (-0.05,0) + \trafficfactor*\facefactor*(0,-0.35)$)%
118 ($-0.5*(\objectlength,0) + (-0.05,0) + \trafficfactor*\facefactor*(0,-0.35) + (\pgflinewidth,0)$) --%
119 ($ 0.5*(\objectlength,0) + ( 0.05,0) + \trafficfactor*\facefactor*(0,-0.35)$)%
120 ($ 0.5*(\objectlength,0) + ( 0.05,0) + \trafficfactor*\facefactor*(0,-0.25)$) --%
121 ($ 0.5*(\objectlength,0) + ( 0.05,0) + \trafficfactor*\facefactor*(0,-0.35)$);% berth shape forward
122 \path[draw=none,fill=foreground]% arrow front
123 ($\facefactor*0.5*(\objectlength,0) + \facefactor*(-0.1,0) + \trafficfactor*\facefactor*(0,-0.35)$) --%
124 ++($(0,-0.04) + \facefactor*(-0.1,0)$) -- ++(0,0.08) -- cycle;% arrow
125 \path[draw=none,fill=foreground]% arrow back
126 ($\facefactor*-0.5*(\objectlength,0) + \facefactor*(0.2,0) + \trafficfactor*\facefactor*(0,-0.35)$) --%
127 ++($(0,-0.04) + \facefactor*(-0.1,0)$) -- ++(0,0.08) -- cycle;% arrow
128 }{}%
129 %% label
130 \ifdefstring{\labelcontent}{}{}{% label NOT empty
131 \node[fill=background,text=foreground,inner sep=1pt] at ($\facefactor*(0,-0.35)$) {\tiny \labelcontent};%
132 \ifdefstring{\face}{bidirectional}{% bidirectional
133 \pgfmathsetmacro{\facefactor}{1}%
134 \node[fill=background,text=foreground,inner sep=1pt] at ($\facefactor*(0,-0.35)$) {\tiny \labelcontent};%
135 }{}%
136 }%
137 }},% END pics/train_berth/.style args={#1/#2/#3}
138 % symbology entry
139 symbology_train_berth/.pic = {%
140 \maintrack (0,0) -- (6,0);%
141 \berth[forward] at (3,0) length (length);%
142 },%
143 }%
144 %
145 %%%%%%%%%%%%%%%
146 % symbol track distance
147 %%%%%%%%%%%%%%%
148 %
149 %% command
150 \newcommand\trackdistance{}% just for safety
151 \def\trackdistance#1(#2)#3(#4)#5(#6){% \trackdistance between (coord1) and (coord2) distance (distance);
152 \path[draw=background,<->,>={Stealth[foreground,inset=0pt,angle=50:0.2cm]},shorten <=1pt,shorten >=1pt] (#2) -- (#4)% arrow tips
153 node[hectometer base=(current bounding box.center),text=foreground,midway,sloped,rotate=90] {#6};% label
154 }%
155 % symbology entry
156 \tikzset{%
157 symbology_track_distance/.pic = {%
158 \maintrack (0,-0.5) -- (6,-0.5);%
159 \maintrack (0, 0.5) -- (6, 0.5);%
160 \trackdistance between (3, 0.5) and (3,-0.5) distance (distance);%
161 },%
162 }%
163 %
164 %%%%%%%%%%%%%%%
165 % symbol hectometer posts
166 %%%%%%%%%%%%%%%
167 %
168 %% command
169 \newcommand\hectometer{}% just for safety
170 \def\hectometer[#1]#2(#3)#4(#5){% \hectometer[options] at (coord) label (name);
171 \pic[#1] at (#3) {hectometer_posts={#2/#4/#5}}% symbol
172 }%
173 % tikz keys
174 \pgfkeys{%
175 /tikz/trackschematic/measures/hectometer/.is family,%
176 /tikz/trackschematic/measures/hectometer/.cd,%
177 %% hectometer base
178 base/.value required,%
179 base/.store in=\basecoord,%
180 /tikz/hectometer base/.forward to=/tikz/trackschematic/measures/hectometer/base,%
181 %% hectometer base
182 orientation/.value required,%
183 orientation/.store in=\orientation,%
184 /tikz/orientation/.forward to=/tikz/trackschematic/measures/hectometer/orientation,%
185 }%
186 %% symbol definition
187 \tikzset{%
188 pics/hectometer_posts/.default=,%
189 pics/hectometer_posts/.style args={#1/#2/#3}{code={%
190 %% settings
191 \def\coordcommand{#1}% beware of leading and tailing spaces!
192 \def\labelcommand{#2}% beware of leading and tailing spaces!
193 \def\labelcontent{#3}%
194 %
195 %% orientation setup
196 \ifdefstring{\orientation}{left}{% orientation
197 \def\align{right}%
198 }{%
199 \ifdefstring{\orientation}{right}{% orientation
200 \def\align{left}%
201 }{% error message
202 \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/measures/hectometer/orientation}{“left“ OR “right“ as key required}}%
203 }%
204 }% end \ifdefstring{\orientation}
205 %% calculation of coordinates
206 %%
207 %% bend 1 bend 2
208 %% (0,0.75) (ts-hm-b1) (ts-hm-b2)
209 %% (0,0)• • ------- • --------- • ----- •(ts-hm-l) label
210 %%
211 \path let \p1=\basecoord in coordinate (ts-hm-l) at (0,\y1);%
212 \ifdefstring{\labelcoord}{(none)}{%
213 \coordinate (ts-hm-b1) at (ts-hm-l);%
214 \coordinate (ts-hm-b2) at (ts-hm-l);%
215 }{% initialize if NOT default
216 \coordinate (ts-hm-b1) at ($(ts-hm-l) + (0,0.5)$);%
217 \path let \p1=\labelcoord in coordinate (ts-hm-b2) at ($(ts-hm-l) + (\x1,0.25)$);%
218 \path let \p1=\labelcoord in coordinate (ts-hm-l) at ($(ts-hm-l) + (\x1,\y1)$);%
219 }%
220 %% symbol
221 \path[draw=\hectometercolor,dashed,shorten <=0.75cm]%
222 (0,0) -- (ts-hm-b1) -- (ts-hm-b2) -- (ts-hm-l);%
223 %% label
224 \ifdefstring{\labelcontent}{}{}{% label NOT empty
225 \node[font=\sffamily,text=\hectometercolor,rotate=-90,\orientation,align=\align,fill=background] at (ts-hm-l) {\labelcontent};%
226 }%
227 }},% END
228 % symbology entry
229 symbology_hectometer/.pic = {%
230 \tikzset{hectometer base={(0,-2)},orientation=right};%
231 \hectometer[] at (0,0) mileage (hectometer 1);%
232 \hectometer[] at (3,0) mileage (hectometer 2);%
233 \hectometer[shift label={(0.3,0)}] at (3.5,0) mileage (hectometer 3);%
234 \hectometer[] at (6,0) mileage (hectometer 4);%
235 },%
236 }%
237 %
238 %%%%%%%%%%%%%%%
239 % symbol measureline
240 %%%%%%%%%%%%%%%
241 %
242 % command
243 \newcommand\measureline{}% just for safety
244 \def\measureline{\path[MeasureLine]}% \measureline (coord1) -- (coord2);
245 %
246 \tikzset{%
247 MeasureLine/.style={draw=\hectometercolor,dashed,shorten <=0.75cm,shorten >=0.75cm},
248 % symbology entry
249 symbology_measure_line/.pic = {%
250 \measureline (0,0) -- (6,0);%
251 },%
252 }%
253 %%%%%%%%%%%%%%%
254 % symbol track marking
255 %%%%%%%%%%%%%%%
256 %
257 % command
258 \newcommand\trackmarking{}% just for safety
259 \def\trackmarking[#1]{\path[draw,TrackMark,#1]}% \trackmarking[color] (coord1) -- (coord2);
260 %
261 \tikzset{%
262 TrackMark/.style={line width=8pt, opacity=0.4, arrows = {Bar[line cap=round,line width=1pt,width=12pt]-Bar[line cap=round,line width=1pt,width=12pt]},shorten >=1pt,shorten <=1pt},
263 % symbology entry
264 symbology_track_marking/.pic = {%
265 \maintrack (0,0) -- (6,0);%
266 \trackmarking[] (1,0) -- (5,0);%
267 },%
268 }%
269 %
270 %%%%%%%%%%%%%%%
271 % TODO:
272 % * platform length
273 % * direction of milage
274 %
275 %%%%%%%%%%%%%%%
276 \endinput%
277 %