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