1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
%% symbol library for TikZ track schematics
%
% Copyright (c) 2018 - 2022, 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.measures.code.tex}%
%
%%%%%%%%%%%%%%%
% global settings
%%%%%%%%%%%%%%%
\RequirePackage{tikz,etoolbox}%
\usetikzlibrary{calc,intersections,arrows.meta}%
%
%%%%%%%%%%%%%%%
% 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,%
%% 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/measures/.is family,%
/tikz/trackschematic/measures/.cd,%
%% color hectometer
color/.store in=\hectometercolor,%
color=foreground!50!background,% DEFAULT
/tikz/hectometer color/.forward to=/tikz/trackschematic/measures/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}
% symbology entry
symbology_train_berth/.pic = {%
\maintrack (0,0) -- (6,0);%
\berth[forward] at (3,0) length (length);%
},%
}%
%
%%%%%%%%%%%%%%%
% symbol track distance
%%%%%%%%%%%%%%%
%
%% command
\newcommand\trackdistance{}% just for safety
\def\trackdistance#1(#2)#3(#4)#5(#6){% \trackdistance between (coord1) and (coord2) distance (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
}%
% symbology entry
\tikzset{%
symbology_track_distance/.pic = {%
\maintrack (0,-0.5) -- (6,-0.5);%
\maintrack (0, 0.5) -- (6, 0.5);%
\trackdistance between (3, 0.5) and (3,-0.5) distance (distance);%
},%
}%
%
%%%%%%%%%%%%%%%
% 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/measures/hectometer/.is family,%
/tikz/trackschematic/measures/hectometer/.cd,%
%% hectometer base
base/.value required,%
base/.store in=\basecoord,%
/tikz/hectometer base/.forward to=/tikz/trackschematic/measures/hectometer/base,%
%% hectometer base
orientation/.value required,%
orientation/.store in=\orientation,%
/tikz/orientation/.forward to=/tikz/trackschematic/measures/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}%
%
%% 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/measures/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
%%
\path let \p1=\basecoord in coordinate (ts-hm-l) at (0,\y1);%
\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)$);%
\path let \p1=\labelcoord in coordinate (ts-hm-b2) at ($(ts-hm-l) + (\x1,0.25)$);%
\path let \p1=\labelcoord in coordinate (ts-hm-l) at ($(ts-hm-l) + (\x1,\y1)$);%
}%
%% 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};%
}%
}},% END
% symbology entry
symbology_hectometer/.pic = {%
\tikzset{hectometer base={(0,-2)},orientation=right};%
\hectometer[] at (0,0) mileage (hectometer 1);%
\hectometer[] at (3,0) mileage (hectometer 2);%
\hectometer[shift label={(0.3,0)}] at (3.5,0) mileage (hectometer 3);%
\hectometer[] at (6,0) mileage (hectometer 4);%
},%
}%
%
%%%%%%%%%%%%%%%
% symbol measureline
%%%%%%%%%%%%%%%
%
% command
\newcommand\measureline{}% just for safety
\def\measureline{\path[MeasureLine]}% \measureline (coord1) -- (coord2);
%
\tikzset{%
MeasureLine/.style={draw=\hectometercolor,dashed,shorten <=0.75cm,shorten >=0.75cm},
% symbology entry
symbology_measure_line/.pic = {%
\measureline (0,0) -- (6,0);%
},%
}%
%%%%%%%%%%%%%%%
% symbol track marking
%%%%%%%%%%%%%%%
%
% command
\newcommand\trackmarking{}% just for safety
\def\trackmarking[#1]{\path[draw,TrackMark,#1]}% \trackmarking[color] (coord1) -- (coord2);
%
\tikzset{%
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},
% symbology entry
symbology_track_marking/.pic = {%
\maintrack (0,0) -- (6,0);%
\trackmarking[] (1,0) -- (5,0);%
},%
}%
%
%%%%%%%%%%%%%%%
% TODO:
% * platform length
% * direction of milage
%
%%%%%%%%%%%%%%%
\endinput%
%
|