%% 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.trafficcontrol.code.tex}%
%
%%%%%%%%%%%%%%%
% Requirements
%%%%%%%%%%%%%%%
\RequirePackage{tikz,etoolbox}%
\usetikzlibrary{calc}%
%
%%%%%%%%%%%%%%%
% tikz keys for multiple use
%%%%%%%%%%%%%%%
\pgfkeys{%
 /tikz/trackschematic/.is family,%
 /tikz/trackschematic/.cd,%
 %% face
 face/.value required,% forward OR backward
 face/.store in=\face,% forward OR backward
 /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}},%
 %% traffic practice
 traffic practice/.value required,% left OR right
 traffic practice/.store in=\trafficpractice,%
 traffic practice=right,% DEFAULT
 /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,%
}%
%
\pgfkeys{%
 /tikz/trackschematic/trafficcontrol/.is family,%
 /tikz/trackschematic/trafficcontrol/.cd,%
 %% type
 type/.value required,% balise OR loop
 type/.store in=\type,% balise OR loop
 /tikz/type/.forward to=/tikz/trackschematic/trafficcontrol/type,%
 %% block signal type
 block type/.value forbidden,%
 block type/.code={\settoggle{is_block_type}{true}},%
 /tikz/block/.forward to=/tikz/trackschematic/trafficcontrol/block type,%
 %% route signal type
 route type/.value forbidden,%
 route type/.code={\settoggle{is_route_type}{true}},%
 /tikz/route/.forward to=/tikz/trackschematic/trafficcontrol/route type,%
}%
% options
\newtoggle{is_block_type}\settoggle{is_block_type}{false}%
\newtoggle{is_route_type}\settoggle{is_route_type}{false}%
%%%%%%%%%%%%%%%
% symbol signal
%%%%%%%%%%%%%%%
% command
\newcommand\signal{}% just for safety
\def\signal[#1]#2(#3)#4(#5){% \signal[options] at (coord) label (name);
 \pic[#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\distantsignal{}% just for safety
\def\distantsignal[#1]#2(#3)#4(#5){% \distantsignal[options] at (coord) label (name);
 \pic[distant,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\speedsign{}% just for safety
\def\speedsign[#1]#2(#3)#4(#5){% \speedsign[options] at (coord) label (name);
 \pic[speed type,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\speedsignal{}% just for safety
\def\speedsignal[#1]#2(#3)#4(#5){% \speedsignal[options] at (coord) label (name);
 \pic[speed type,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\speeddistantsignal{}% just for safety
\def\speeddistantsignal[#1]#2(#3)#4(#5){% \speedsignal[options] at (coord) label (name);
 \pic[speed type,distant,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\blocksignal{}% just for safety
\def\blocksignal[#1]#2(#3)#4(#5){% \blocksignal[options] at (coord) label (name);
 \pic[block,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\routesignal{}% just for safety
\def\routesignal[#1]#2(#3)#4(#5){% \routesignal[options] at (coord) label (name);
 \pic[route,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\shuntsignal{}% just for safety
\def\shuntsignal[#1]#2(#3)#4(#5){% \shuntsignal[options] at (coord) label (name);
 \pic[shunting,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\shuntlimit{}% just for safety
\def\shuntlimit[#1]#2(#3)#4(#5){% \shuntlimit[options] at (coord) label (name);
 \pic[shunt limit,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\berthsignal{}% just for safety
\def\berthsignal[#1]#2(#3)#4(#5){% \berthsignal[options] at (coord) label (name);
 \pic[berth,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
\newcommand\berthsign{}% just for safety
\def\berthsign[#1]#2(#3)#4(#5){% \berthsign[options] at (coord) label (name);
 \pic[berth,#1] at (#3) {signal={#2/#4/#5}}% symbol
}%
% tikz keys
\pgfkeys{%
 /tikz/trackschematic/trafficcontrol/signal/.is family,%
 /tikz/trackschematic/trafficcontrol/signal/.cd,%
 %% distant signal type
 distant type/.value forbidden,%
 distant type/.code={\settoggle{is_distant_type}{true}},%
 /tikz/distant/.forward to=/tikz/trackschematic/trafficcontrol/signal/distant type,%
 %% block signal type
 speed type/.value forbidden,%
 speed type/.code={\settoggle{is_speed_type}{true}},%
 /tikz/speed type/.forward to=/tikz/trackschematic/trafficcontrol/signal/speed type,%
 %% shunting signal type
 shunting type/.value forbidden,%
 shunting type/.code={\settoggle{is_shunting_type}{true}},%
 /tikz/shunting/.forward to=/tikz/trackschematic/trafficcontrol/signal/shunting type,%
 %% shunting signal type
 shunt limit/.value forbidden,%
 shunt limit/.code={\settoggle{is_shunt_limit}{true}},%
 /tikz/shunt limit/.forward to=/tikz/trackschematic/trafficcontrol/signal/shunt limit,%
 %% berth signal type
 berth type/.value forbidden,%
 berth type/.code={\settoggle{is_berth_type}{true}},%
 /tikz/berth/.forward to=/tikz/trackschematic/trafficcontrol/signal/berth type,%
 %% speed value
 speed/.store in=\speed,% number
 speed=,% number
 /tikz/speed/.forward to=/tikz/trackschematic/trafficcontrol/signal/speed,%
 %% speed value
 distant speed/.store in=\distantspeed,% number
 distant speed=,% number
 /tikz/distant speed/.forward to=/tikz/trackschematic/trafficcontrol/signal/distant speed,%
 %% locked signal
 locked/.value forbidden,%
 locked/.code={\settoggle{is_locked}{true}},%
 /tikz/locked/.forward to=/tikz/trackschematic/trafficcontrol/signal/locked,%
}%
% options
\newtoggle{is_distant_type}\settoggle{is_distant_type}{false}%
\newtoggle{is_speed_type}\settoggle{is_speed_type}{false}%
\newtoggle{is_shunting_type}\settoggle{is_shunting_type}{false}%
\newtoggle{is_shunt_limit}\settoggle{is_shunt_limit}{false}%
\newtoggle{is_berth_type}\settoggle{is_berth_type}{false}%
\newtoggle{is_locked}\settoggle{is_locked}{false}%
% symbol definition
\tikzset{% generic symbol
 pics/signal/.default=,%
 pics/signal/.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}%
   %
   %% 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}
   %% face setup
   \ifdefstring{\face}{forward}{% face
     \pgfmathsetmacro{\facefactor}{1}%
     \def\align{left}%
     \def\rotate{-90}%
   }{%
     \ifdefstring{\face}{backward}{% face
       \pgfmathsetmacro{\facefactor}{-1}%
       \def\align{right}%
       \def\rotate{90}%
     }{% error message
       \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/face}{“forward“ OR “backward“ as key required}}%
     }%
   }% end \ifdefstring{\face}
   \tikzset{every path/.style={draw=foreground,line width=1pt}};%
   \tikzset{every node/.style={text=foreground,inner sep=1pt}};%
   %% signal pole
   \path (0,0) -- ++($\trafficfactor*\facefactor*(0,-0.4)$) -- ++($\facefactor*(0.7,0)$);% signal pole
   %
   %% label
   \ifdefstring{\labelcontent}{}{}{% label NOT empty
     \coordinate (ts-s-l) at ($\trafficfactor*\facefactor*(0,-0.4)$);%
     \ifdefstring{\labelcoord}{(none)}{}{% initialize if NOT default
       \path let \p1=\labelcoord in coordinate (ts-s-l) at ($(ts-s-l)+(\x1,\y1)$);%
     }%
     \node[\align] at (ts-s-l) {\footnotesize \labelcontent};%
   }%
   \tikzset{every path/.style={draw=foreground,line width=1pt,fill=background},rounded corners=0.1pt};%
   %% signal marker
   \iftoggle{is_distant_type}{% marker for distant signal
     \path ($\trafficfactor*\facefactor*(0,-0.4) + \facefactor*(0.35,0)$) --%
         ++($\trafficfactor*\facefactor*(0,-0.2) + \facefactor*(0.35,0)$) --%
         ++($\trafficfactor*\facefactor*(0, 0.4)$) -- cycle;% signal marker
   %
   }{}%
   \iftoggle{is_speed_type}{% marker for speed signal
     \path ($\trafficfactor*\facefactor*(0,-0.2) + \facefactor*(0.35,0)$) --%
         ++($\trafficfactor*\facefactor*(0,-0.4)$) --%
         ++($\trafficfactor*\facefactor*(0, 0.2) + \facefactor*(0.35,0)$) -- cycle;% signal marker
     %
   }{}%
   \iftoggle{is_block_type}{% marker for block signal
     \path ($\trafficfactor*\facefactor*(0,-0.6) + \facefactor*(0.7,0)$) rectangle%
         ++($\trafficfactor*\facefactor*(0, 0.4) + \facefactor*(0.4,0)$);% signal marker
     %
   }{}%
   \iftoggle{is_route_type}{% marker for route signal
     \path ($\trafficfactor*\facefactor*(0,-0.4) + \facefactor*(0.9,0)$) circle (0.2);% signal marker
     %
   }{}%
   \iftoggle{is_shunting_type}{% marker for shunting signal
     \path ($\trafficfactor*\facefactor*(0,-0.3) + \facefactor*(0.6,0)$) circle (0.1);% signal marker
     %
   }{}%
   \iftoggle{is_shunt_limit}{% marker for shunting signal
     \tikzset{semicircle/.pic={\path (0,0) arc (180:0:0.1) -- cycle;};}%
     \pgfmathsetmacro{\trafficfactorTEST}{-1}%
     \ifdefequal{\trafficfactor}{\trafficfactorTEST}{%
       \pgfmathsetmacro{\trafficfactorX}{-2}%
     }{%
       \pgfmathsetmacro{\trafficfactorX}{1}%
     }%
     \pic[rotate=\rotate] at ($\trafficfactorX*\facefactor*(0,-0.2) + \facefactor*(0.6,0)$) {semicircle}; % signal marker
     %
   }{}%
   \iftoggle{is_berth_type}{% marker for berth signal
     \path ($\trafficfactor*\facefactor*(0,-0.575) + \facefactor*(0.3,0)$) rectangle%
         ++($\trafficfactor*\facefactor*(0, 0.35 ) + \facefactor*(0.5,0)$);% % signal marker
     \path[line width=0.75pt] ($\trafficfactor*\facefactor*(0,-0.3) + \facefactor*(0.375,0)$) -- ++($\facefactor*(0.35,0)$);%
     \path[line width=0.75pt] ($\trafficfactor*\facefactor*(0,-0.5) + \facefactor*(0.55 ,0)$) -- ++($\trafficfactor*\facefactor*(0,0.2)$);%
     \path[line width=0.75pt] ($\trafficfactor*\facefactor*(0,-0.5) + \facefactor*(0.375,0)$) -- ++($\facefactor*(0.35,0)$);%
     %
   }{}%
   %% speed indicator
   \ifdefstring{\speed}{}{}{% speed NOT empty
     \tikzset{every node/.style={font=\sffamily,text=foreground}};%
     \iftoggle{is_speed_type}{% marker for speed signal
       \node[rotate=\rotate] at ($\trafficfactor*\facefactor*(0,-0.4) + \facefactor*(0.85,0)$) {\speed};%
     }{%
       \iftoggle{is_shunting_type}{}{% is NOT shunting tyoe
         \node[rotate=\rotate] at ($\trafficfactor*\facefactor*(0,-0.4) + \facefactor*(1.3,0)$) {\speed};%
       }%
     }%
   }%
   \ifdefstring{\distantspeed}{}{}{% distant speed NOT empty
     \tikzset{every node/.style={font=\sffamily,text=foreground,fill=background,inner sep=0.5pt}};%
     \node[rotate=\rotate] at ($\trafficfactor*\facefactor*(0,-0.4) + \facefactor*(0.2,0)$) {\distantspeed};%
   }%
   %% locked
   \iftoggle{is_locked}{% marker for route signal
     \iftoggle{is_block_type}{% marker for block signal
       \path ($\trafficfactor*\facefactor*(0,-0.2) + \facefactor*(0.9,0)$) --%
           ++($\trafficfactor*\facefactor*(0,-0.4)$);% signal aspect
     }{}%
     \iftoggle{is_route_type}{% marker for route signal
       \path ($\trafficfactor*\facefactor*(0,-0.2) + \facefactor*(0.9,0)$) --%
           ++($\trafficfactor*\facefactor*(0,-0.4)$);% signal aspect
     }{}%
     \iftoggle{is_shunting_type}{%
       \path ($\trafficfactor*\facefactor*(0,-0.2) + \facefactor*(0.6,0)$) --%
           ++($\trafficfactor*\facefactor*(0,-0.2)$);% signal aspect
     }{}%
   }{}%
 }},% end pics/signal/.style args={#1/#2/#3}
 % symbology entry
 symbology_distant_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \distantsignal[forward] at (3,0) label ();%
 },%
 % symbology entry
 symbology_distant_speed_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \distantsignal[forward,distant speed={s}] at (3,0) label ();%
 },%
 % symbology entry
 symbology_speed_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \speedsignal[forward,speed={s}] at (3,0) label ();%
 },%
 % symbology entry
 symbology_block_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \blocksignal[forward] at (3,0) label ();%
 },%
 % symbology entry
 symbology_route_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \routesignal[forward] at (3,0) label ();%
 },%
 % symbology entry
 symbology_combined_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \signal[distant,block,route,forward,distant speed={ds},speed={s}] at (3,0) label ();%
 },%
 % symbology entry
 symbology_shunt_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \shuntsignal[forward] at (3,0) label ();%
 },%
 % symbology entry
 symbology_locked_shunt_signal/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \shuntsignal[forward,locked] at (3,0) label ();%
 },%
 % symbology entry
 symbology_shunt_limit/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \shuntlimit[forward] at (3,0) label ();%
 },%
 % symbology entry
 symbology_train_berth_sign/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \berthsignal[forward] at (3,0) label ();%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol clearing point
%%%%%%%%%%%%%%%
% command
\newcommand\clearingpoint{}% just for safety
\def\clearingpoint[#1]#2(#3)#4(#5){% \clearingpoint[options] at (coord) label (name);
 \pic[standard,#1] at (#3) {clearing_point={#2/#4/#5}}% symbol
}%
\newcommand\blockclearing{}% just for safety
\def\blockclearing[#1]#2(#3)#4(#5){% \blockclearing[options] at (coord) label (name);
 \pic[block,#1] at (#3) {clearing_point={#2/#4/#5}}% symbol
}%
\newcommand\routeclearing{}% just for safety
\def\routeclearing[#1]#2(#3)#4(#5){% \routeclearing[options] at (coord) label (name);
 \pic[route,#1] at (#3) {clearing_point={#2/#4/#5}}% symbol
}%
\pgfkeys{%
 /tikz/trackschematic/trafficcontrol/clearing point/.is family,%
 /tikz/trackschematic/trafficcontrol/clearing point/.cd,%
 %% standard type
 standard type/.value forbidden,%
 standard type/.code={\settoggle{is_standard_type}{true}},%
 /tikz/standard/.forward to=/tikz/trackschematic/trafficcontrol/clearing point/standard type,%
}%
% options
\newtoggle{is_standard_type}\settoggle{is_standard_type}{false}%
% symbol definition
\tikzset{%
 pics/clearing_point/.default=,%
 pics/clearing_point/.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}%
   %
   %% 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}
   %% face setup
   \ifdefstring{\face}{backward}{% face
     \pgfmathsetmacro{\facefactor}{-1}%
   }{% default case
     \pgfmathsetmacro{\facefactor}{1}%
   }% end \ifdefstring{\face}
   \tikzset{every path/.style={draw=foreground,line width=1pt}};%
   %% marker
   \path ($\trafficfactor*\facefactor*(0,-0.1)$) -- ++($\trafficfactor*\facefactor*(0,0.2)$);% marker
   %% sign
   \iftoggle{is_standard_type}{% marker for block signal
     \path ($\trafficfactor*\facefactor*(0,-0.1) + \facefactor*(0.1,0)$) -- ++($\facefactor*(-0.2,0)$);% sign
   }{}%
   \iftoggle{is_block_type}{% marker for block signal
     \path ($\trafficfactor*\facefactor*(0,-0.1)$) --%
         ++($\trafficfactor*\facefactor*(0,-0.1) + \facefactor*(-0.1,0)$) --%
         ++($\trafficfactor*\facefactor*(0,-0.1) + \facefactor*( 0.1,0)$) --%
         ++($\trafficfactor*\facefactor*(0, 0.1) + \facefactor*( 0.1,0)$) -- cycle;% sign
   }{}%
   \iftoggle{is_route_type}{% marker for route signal
     \path ($\trafficfactor*\facefactor*(0,-0.2)$) circle (0.1);% sign
   }{}%
   %% label
   \ifdefstring{\labelcontent}{}{}{% label NOT empty
     \tikzset{every node/.style={font=\sffamily,text=foreground}};%
     \coordinate (ts-cp-l) at ($\trafficfactor*\facefactor*(0,0.25)$);%
     \ifdefstring{\labelcoord}{(none)}{}{% initialize if NOT default
       \path let \p1=\labelcoord in coordinate (ts-cp-l) at ($(ts-cp-l)+(\x1,\y1)$);%
     }%
     \node at (ts-cp-l) {\footnotesize \labelcontent};%
   }%
 }},% end pics/clearing_point/.style args={#1/#2/#3}
 % symbology entry
 symbology_clearing_point/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \clearingpoint[forward] at (3,0) label ();%
 },%
 % symbology entry
 symbology_block_clearing_point/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \blockclearing[forward] at (3,0) label ();%
 },%
 % symbology entry
 symbology_route_clearing_point/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \routeclearing[forward] at (3,0) label ();%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol trackloop
%%%%%%%%%%%%%%%
% command
\newcommand\trackloop{}% just for safety
\def\trackloop[#1]#2(#3)#4(#5){% \trackloop[options] at (coord) label (name);
 \pic[#1] at (#3) {trackloop={#2/#4/#5}}% symbol
}%
% symbol definition
\tikzset{%
 pics/trackloop/.default=,%
 pics/trackloop/.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}%
   %% 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}
   %% marker
   \tikzset{every path/.style={draw=foreground}};%
   \path[line width=1pt] ($\trafficfactor*(0,-0.175)$) -- ++(-0.0625,-0.0625) -- ++(-0.2,0) -- ++(-0.125,0.125) -- ++(-0.1,0) -- ++(0,-0.125) -- ++(0.1,0) -- ++(0.125,0.125) -- ++(0.2,0) -- ++(0.125,-0.125) -- ++(0.2,0) -- ++(0.125,0.125) -- ++(0.1,0) -- ++(0,-0.125) -- ++(-0.1,0) -- ++(-0.125,0.125) -- ++(-0.2,0) -- cycle;% loop marker
   %% label
   \ifdefstring{\labelcontent}{}{}{% label NOT empty
     \tikzset{every node/.style={font=\sffamily,text=foreground}};%
     \coordinate (ts-tm-l) at ($\trafficfactor*(0,0.25)$);%
     \ifdefstring{\labelcoord}{(none)}{}{% initialize if NOT default
       \path let \p1=\labelcoord in coordinate (ts-tm-l) at ($(ts-tm-l)+(\x1,\y1)$);%
     }%
     \node at (ts-tm-l) {\footnotesize \labelcontent};%
   }%
 }},% end pics/transmitter/.style args={#1/#2/#3}
 % symbology entry
 symbology_trackloop/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \trackloop[forward] at (3,0) label ();%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol balise
%%%%%%%%%%%%%%%
% command
\newcommand\balise{}% just for safety
\def\balise[#1]#2(#3)#4(#5){% \balise[options] at (coord) label (name);
 \pic[#1] at (#3) {balise={#2/#4/#5}}% symbol
}%
\pgfkeys{%
 /tikz/trackschematic/trafficcontrol/.is family,%
 /tikz/trackschematic/trafficcontrol/.cd,%
 %% route signal type
 switched/.value forbidden,%
 switched/.code={\settoggle{switched}{true}},%
 /tikz/switched/.forward to=/tikz/trackschematic/trafficcontrol/switched,%
 %% balises along the direction
 along/.store in=\along,% array of integer
 along=none,% DEFAULT
 /tikz/along/.forward to=/tikz/trackschematic/trafficcontrol/along,%
 %% balises oppose the direction
 oppose/.store in=\oppose,% array of integer
 oppose=none,% DEFAULT
 /tikz/oppose/.forward to=/tikz/trackschematic/trafficcontrol/oppose,%
 %% balises along the direction
 along switched/.store in=\alongswitched,% array of integer
 along switched=none,% DEFAULT
 /tikz/along switched/.forward to=/tikz/trackschematic/trafficcontrol/along switched,%
 %% balises oppose the direction
 oppose switched/.store in=\opposeswitched,% array of integer
 oppose switched=none,% DEFAULT
 /tikz/oppose switched/.forward to=/tikz/trackschematic/trafficcontrol/oppose switched,%
 %% display index number
 index number/.value forbidden,%
 index number/.code={\settoggle{index_number}{true}},%
 /tikz/index/.forward to=/tikz/trackschematic/trafficcontrol/index number,%
}%
% options
\newtoggle{unnumberd}\settoggle{unnumberd}{true}% DEFAULT
\newtoggle{switched}\settoggle{switched}{false}%
\newtoggle{index_number}\settoggle{index_number}{false}%
% symbol definition
\tikzset{%
 pics/balise/.default=,%
 pics/balise/.style args={#1/#2/#3}{code={%
   %%
   %%%%%%%[steps]%%%%%%
   %% 0. setup settings
   %% 1. draw marker
   %% 2. draw label
   %%%%%%%%%%%%%%%%%%%%
   %% 0. 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}{forward}{% face
     \pgfmathsetmacro{\facefactor}{1}%
   }{%
     \ifdefstring{\face}{backward}{% face
       \pgfmathsetmacro{\facefactor}{-1}%
     }{% error message
       \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/face}{“forward“ OR “backward“ 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}
   %%
   %% number of balises known?
   \ifdefstring{\along}{none}{}{% a number has been set
     \settoggle{unnumberd}{false}%
   }%
   %% number of balises known?
   \ifdefstring{\oppose}{none}{}{% a number has been set
     \settoggle{unnumberd}{false}%
   }%
   %% number of balises known?
   \ifdefstring{\alongswitched}{none}{}{% a number has been set
     \settoggle{unnumberd}{false}%
   }%
   %% number of balises known?
   \ifdefstring{\opposeswitched}{none}{}{% a number has been set
     \settoggle{unnumberd}{false}%
   }%
   %%
   %%%%%%%%%%%%%%%%%%%%
   %% 1. marker
   \tikzset{every path/.style={draw=foreground,line width=0.75pt,rounded corners=0.2pt}};%
   %%
   \iftoggle{unnumberd}{% no number has been set
     %% marker for undefined balises
     \path[fill=background] ($(-0.3,0)$) rectangle ($\trafficfactor*\facefactor*(0,-0.25) + (0.3,0)$);% balise marker
     \iftoggle{switched}{% balises can be switched
       \path[fill=foreground] ($\trafficfactor*\facefactor*(0,-0.075) + (-0.225,0)$) rectangle%
                               ($\trafficfactor*\facefactor*(0,-0.175) + ( 0.225,0)$);% switch marker
     }{}%
   }{% a number has been set
     %% marker for numbered balises
     \ifdefstring{\along}{none}{}{
       \foreach \n in \along{%
         \path[fill=background] ($\n*\facefactor*(0.2,0)$) rectangle%
                                 ($\n*\facefactor*(0.2,0) + (0.2 ,0) + \trafficfactor*\facefactor*(0,-0.25)$);% balise marker
         \iftoggle{index_number}{%
           \node[text=foreground] at ($\n*\facefactor*(0.2,0) + (0.1,0) + \trafficfactor*\facefactor*(0,-0.125)$) {\tiny\n};%
         }{}%
       }%
     }%
     \ifdefstring{\oppose}{none}{}{
       \foreach \n in \oppose{%
         \path[fill=background] ($\n*\facefactor*(0.2,0)$) rectangle%
                                 ($\n*\facefactor*(0.2,0) + (0.2 ,0) + \trafficfactor*\facefactor*(0,0.25)$);% balise marker
         \iftoggle{index_number}{%
           \node[text=foreground] at ($\n*\facefactor*(0.2,0) + (0.1,0) + \trafficfactor*\facefactor*(0,0.125)$) {\tiny\n};%
         }{}%
       }%
     }%
     \ifdefstring{\alongswitched}{none}{}{
       \foreach \n in \alongswitched{%
         \path[fill=background] ($\n*\facefactor*(0.2,0)$) rectangle%
                                 ($\n*\facefactor*(0.2,0) + (0.2 ,0) + \trafficfactor*\facefactor*(0,-0.25)$);% balise marker
         \path[fill=foreground] ($\n*\facefactor*(0.2,0) + (0.05,0) + \trafficfactor*\facefactor*(0,-0.05)$) rectangle%
                                 ($\n*\facefactor*(0.2,0) + (0.15,0) + \trafficfactor*\facefactor*(0,-0.2)$);% switch marker
         \iftoggle{index_number}{%
           \node[text=background] at ($\n*\facefactor*(0.2,0) + (0.1,0) + \trafficfactor*\facefactor*(0,-0.125)$) {\tiny\n};%
         }{}%
       }%
     }%
     \ifdefstring{\opposeswitched}{none}{}{
       \foreach \n in \opposeswitched{%
         \path[fill=background] ($\n*\facefactor*(0.2,0)$) rectangle%
                                 ($\n*\facefactor*(0.2,0) + (0.2 ,0) + \trafficfactor*\facefactor*(0,0.25)$);% balise marker
         \path[fill=foreground] ($\n*\facefactor*(0.2,0) + (0.05,0) + \trafficfactor*\facefactor*(0,0.05)$) rectangle%
                                 ($\n*\facefactor*(0.2,0) + (0.15,0) + \trafficfactor*\facefactor*(0,0.2)$);% switch marker
         \iftoggle{index_number}{%
           \node[text=background] at ($\n*\facefactor*(0.2,0) + (0.1,0) + \trafficfactor*\facefactor*(0,0.125)$) {\tiny\n};%
         }{}%
       }%
     }%
   }%
   %%
   %%%%%%%%%%%%%%%%%%%%
   %% 2. label
   \ifdefstring{\labelcontent}{}{}{% label NOT empty
     %% coord
     \iftoggle{unnumberd}{% no number has been set
       \coordinate (label-coord) at ($\trafficfactor*\facefactor*(0,-0.25)$);%
     }{%
       \coordinate (label-coord) at ($\trafficfactor*\facefactor*(0,-0.25) + (0.1,0)$);%
     }%
     \ifdefstring{\labelcoord}{(none)}{}{% initialize if NOT default
       \path let \p1=\labelcoord in coordinate (label-coord) at ($(label-coord)+(\x1,\y1)$);%
     }%
     %% label style
     \tikzset{every node/.style={font=\sffamily,text=foreground}};%
     %
     \ifdefstring{\trafficpractice}{left}{%
       \tikzset{every node/.append style={left,align=right}};%
     }{%
       \tikzset{every node/.append style={right,align=left}};%
     }%
     \ifdefstring{\face}{forward}{%
       \tikzset{every node/.append style={rotate=270}};%
     }{%
       \tikzset{every node/.append style={rotate=90}};%
     }%
     %% label
     \node at (label-coord) {\footnotesize \labelcontent};%
   }%
 }},% end pics/balise/.style args={#1/#2/#3}
 % symbology entry
 symbology_balise_group/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \balise[forward] at (2,0) label (A);%
   \balise[forward,switched] at (4,0) label (B);%
 },%
 symbology_balise_individual/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \balise[forward,along={0,1,2}] at (2,0) label (A);%
   \balise[forward,along switched={0,1,2}] at (4,0) label (B);%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol view point
%%%%%%%%%%%%%%%
% command
\newcommand\viewpoint{}% just for safety
\def\viewpoint[#1]#2(#3){% \viewpoint[options] at (coord);
 \pic[#1] at (#3) {view_point={#2}};% symbol
}%
% symbol definition
\tikzset{%
 pics/view_point/.default=,%
 pics/view_point/.style args={#1}{code={%
   %% face setup
   \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“ OR “backward“ 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}
   %% arrow
   \path[draw=foreground,<-,>=latex,line width=1pt]%
     ($\facefactor*\trafficfactor*(0,-0.1)$) -- ++($\facefactor*\trafficfactor*(0,-0.3)$) -- ++($\facefactor*(0.2,0)$);% arrow
   %% eye
   \filldraw[foreground] ($\facefactor*(0.4,0) + \facefactor*\trafficfactor*(0,-0.4)$) circle (0.1);% pupil
   \path[draw=foreground, line width=1pt]% eye contour
     ($\facefactor*(0.4, 0) + \facefactor*\trafficfactor*(0,-0.15)$) .. controls%
     ($\facefactor*(0.25,0) + \facefactor*\trafficfactor*(0,-0.25)$) and%
     ($\facefactor*(0.25,0) + \facefactor*\trafficfactor*(0,-0.55)$) ..%
     ($\facefactor*(0.4, 0) + \facefactor*\trafficfactor*(0,-0.65)$) .. controls%
     ($\facefactor*(0.55,0) + \facefactor*\trafficfactor*(0,-0.55)$) and%
     ($\facefactor*(0.55,0) + \facefactor*\trafficfactor*(0,-0.25)$) ..%
     ($\facefactor*(0.4, 0) + \facefactor*\trafficfactor*(0,-0.15)$) --cycle;% eye contour
 }},% END pics/view_point/.style args={#1}
 % symbology entry
 symbology_view_point/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \viewpoint[forward] at (3,0);%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol end of authority marker
%%%%%%%%%%%%%%%
% command
\newcommand\movementauthority{}% just for safety
\def\movementauthority[#1]#2(#3)#4(#5){% \movementauthority[options] at (coord) label (name);
 \pic[#1] at (#3) {movement_authority_marker={#2/#4/#5}}% symbol
}%
% symbol definition
\tikzset{%
 pics/movement_authority_marker/.default=,%
 pics/movement_authority_marker/.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}%
   %
   %% 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}
   %% face setup
   \ifdefstring{\face}{forward}{% face
     \pgfmathsetmacro{\facefactor}{1}%
     \def\align{left}%
   }{%
     \ifdefstring{\face}{backward}{% face
       \pgfmathsetmacro{\facefactor}{-1}%
       \def\align{right}%
     }{% error message
       \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/face}{“forward“ OR “backward“ as key required}}%
     }%
   }% end \ifdefstring{\face}
   \tikzset{every path/.style={draw=foreground,line width=1pt}};%
   %% marker
     \path ($\trafficfactor*\facefactor*(0,-0.55) + \facefactor*(0.3,0)$) rectangle%
         ++($\trafficfactor*\facefactor*(0, 0.3) + \facefactor*(0.3,0)$);%
   %% arrow
   \path[draw=foreground,<-,>=latex,line width=1pt]%
     ($\facefactor*\trafficfactor*(0,-0.1)$) -- ++($\facefactor*\trafficfactor*(0,-0.3)$) -- ++($\facefactor*(0.2,0)$);% arrow
   %% label
   \ifdefstring{\labelcontent}{}{}{% label NOT empty
     \tikzset{every node/.style={font=\sffamily,text=foreground}};%
     \coordinate (ts-ma-l) at ($\trafficfactor*\facefactor*(0,-0.6) + \facefactor*(0.3,0)$);%
     \ifdefstring{\labelcoord}{(none)}{}{% initialize if NOT default
       \path let \p1=\labelcoord in coordinate (ts-ma-l) at ($(ts-ma-l)+(\x1,\y1)$);%
     }%
     \node[\align] at (ts-ma-l) {\footnotesize \labelcontent};%
   }%
 }},% END pics/movement_authority_marker/.style args={#1/#2/#3}
 % symbology entry
 symbology_end_of_authority/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \movementauthority[forward] at (3,0) label ();%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol braking point
%%%%%%%%%%%%%%%
% command
\newcommand\brakingpoint{}% just for safety
\def\brakingpoint[#1]#2(#3)#4(#5){% \brakingpoint[options] at (coord) label (name);
 \pic[#1] at (#3) {braking_point_marker={#2/#4/#5}}% symbol
}%
% symbol definition
\tikzset{%
 pics/braking_point_marker/.default=,%
 pics/braking_point_marker/.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}%
   %
   %% 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}
   %% face setup
   \ifdefstring{\face}{forward}{% face
     \pgfmathsetmacro{\facefactor}{1}%
     \def\align{left}%
   }{%
     \ifdefstring{\face}{backward}{% face
       \pgfmathsetmacro{\facefactor}{-1}%
       \def\align{right}%
     }{% error message
       \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/face}{“forward“ OR “backward“ as key required}}%
     }%
   }% end \ifdefstring{\face}
   \tikzset{every path/.style={draw=foreground,line width=1pt}};%
   %% marker
     \path ($\trafficfactor*\facefactor*(0,-0.4) + \facefactor*(0.3,0)$) --%
         ++($\trafficfactor*\facefactor*(0,-0.15) + \facefactor*(0.25,0)$) --%
         ++($\trafficfactor*\facefactor*(0, 0.3)$) -- cycle;% signal marker
   %% arrow
   \path[draw=foreground,<-,>=latex,line width=1pt]%
     ($\facefactor*\trafficfactor*(0,-0.1)$) -- ++($\facefactor*\trafficfactor*(0,-0.3)$) -- ++($\facefactor*(0.2,0)$);% arrow
   %% label
   \ifdefstring{\labelcontent}{}{}{% label NOT empty
     \tikzset{every node/.style={font=\sffamily,text=foreground}};%
     \coordinate (ts-bp-l) at ($\trafficfactor*\facefactor*(0,-0.6) + \facefactor*(0.3,0)$);%
     \ifdefstring{\labelcoord}{(none)}{}{% initialize if NOT default
       \path let \p1=\labelcoord in coordinate (ts-bp-l) at ($(ts-bp-l)+(\x1,\y1)$);%
     }%
     \node[\align] at (ts-bp-l) {\footnotesize \labelcontent};%
   }%
 }},% END pics/braking_point_marker/.style args={#1/#2/#3}
 % symbology entry
 symbology_braking_point/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \brakingpoint[forward] at (3,0) label ();%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol danger point
%%%%%%%%%%%%%%%
% command
\newcommand\dangerpoint{}% just for safety
\def\dangerpoint[#1]#2(#3)#4(#5){% \dangerpoint[options] at (coord) label (name);
 \pic[#1] at (#3) {danger_point_marker={#2/#4/#5}}% symbol
}%
% symbol definition
\tikzset{%
 pics/danger_point_marker/.default=,%
 pics/danger_point_marker/.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}%
   %
   %% 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}
   %% face setup
   \ifdefstring{\face}{forward}{% face
     \pgfmathsetmacro{\facefactor}{1}%
     \def\align{left}%
   }{%
     \ifdefstring{\face}{backward}{% face
       \pgfmathsetmacro{\facefactor}{-1}%
       \def\align{right}%
     }{% error message
       \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/face}{“forward“ OR “backward“ as key required}}%
     }%
   }% end \ifdefstring{\face}
   \tikzset{every path/.style={draw=foreground,line width=1pt}};%
   %% marker
     \path ($\trafficfactor*\facefactor*(0,-0.4)$) --%
         ++($\trafficfactor*\facefactor*(0,-0.1) + \facefactor*(-0.1,0)$) --%
         ++($\trafficfactor*\facefactor*(0,-0.1) + \facefactor*( 0.1,0)$) --%
         ++($\trafficfactor*\facefactor*(0, 0.1) + \facefactor*( 0.1,0)$) -- cycle;% sign
   %% arrow
   \path[draw=foreground,<-,>=latex,line width=1pt]%
     ($\facefactor*\trafficfactor*(0,-0.1)$) -- ++($\facefactor*\trafficfactor*(0,-0.25)$);% arrow
   %% label
   \ifdefstring{\labelcontent}{}{}{% label NOT empty
     \tikzset{every node/.style={font=\sffamily,text=foreground}};%
     \coordinate (ts-dp-l) at ($\trafficfactor*\facefactor*(0,0.25)$);%
     \ifdefstring{\labelcoord}{(none)}{}{% initialize if NOT default
       \path let \p1=\labelcoord in coordinate (ts-dp-l) at ($(ts-dp-l)+(\x1,\y1)$);%
     }%
     \node at (ts-dp-l) {\footnotesize \labelcontent};%
   }%
 }},% END pics/danger_point_marker/.style args={#1/#2/#3}
 % symbology entry
 symbology_danger_point/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \dangerpoint[forward] at (3,0) label ();%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol route
%%%%%%%%%%%%%%%
% command
\newcommand\route{}% just for safety
\def\route[#1]#2(#3){% \route[options] at (coord);
 \pic[#1] at (#3) {route={#2}}% symbol
}%
% symbol definition
\tikzset{%
 pics/route/.default=,%
 pics/route/.style args={#1}{code={%
   %% settings
   \def\coordcommand{#1} % beware of leading and tailing spaces!
   %% face setup
   \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“ OR “backward“ as key required}}%
     }%
   }% end \ifdefstring{\face}
   %% symbol
   \fill[foreground] ($\facefactor*(-0.175,0)+(0,-0.15)$) --%
                      ($\facefactor*(-0.175,0)+(0, 0.15)$) --%
                      ($\facefactor*( 0.175,0)+(0, 0   )$) -- cycle;%
 }},% END pics/route/.style args={#1}
 % symbology entry
 symbology_route/.pic = {%
   \maintrack (0,0) -- (6,0);%
   \route[forward]  at (3,0);%
 },%
}%
%
%%%%%%%%%%%%%%%
% symbol direction control
%%%%%%%%%%%%%%%
% command
\newcommand\directioncontrol{}% just for safety
\def\directioncontrol[#1]#2(#3){% \directioncontrol[options] at (coord);
 \pic[#1] at (#3) {direction_control={#2}}% symbol
}%
% symbol definition
\tikzset{%
 pics/direction_control/.default=,%
 pics/direction_control/.style args={#1}{code={%
   %% settings
   \def\coordcommand{#1}% beware of leading and tailing spaces!
   %
   %% 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}
   %
   %% face setup
   \ifdefstring{\face}{forward}{% face
     \path[draw=foreground,line width=0.5pt,densely dotted]%
       ($\trafficfactor*(0,0.1) + (-0.0125,0)$) -- ($\trafficfactor*(0,0.25) + (-0.2125,0)$) -- ($\trafficfactor*(0,0.4) + (-0.0125,0)$) --%
       ($\trafficfactor*(0,0.325) + (-0.0125,0)$) -- ($\trafficfactor*(0,0.325) + (0.1875,0)$) -- ($\trafficfactor*(0,0.175) + (0.1875,0)$) --%
       ($\trafficfactor*(0,0.175) + (-0.0125,0)$) -- cycle;% arrow backward
     \fill[foreground]%
       ($\trafficfactor*(0,-0.1) + (0.0125,0)$) -- ($\trafficfactor*(0,-0.25) + (0.2125,0)$) -- ($\trafficfactor*(0,-0.4) + (0.0125,0)$) --%
       ($\trafficfactor*(0,-0.325) + (0.0125,0)$) -- ($\trafficfactor*(0,-0.325)+(-0.1875,0)$) -- ($\trafficfactor*(0,-0.175) + (-0.1875,0)$) --%
       ($\trafficfactor*(0,-0.175) + (0.0125,0)$) -- cycle;% arrow forward
   }{%
     \ifdefstring{\face}{backward}{% face
       \fill[foreground]%
         ($\trafficfactor*(0,0.1) + (-0.0125,0)$) -- ($\trafficfactor*(0,0.25) + (-0.2125,0)$) -- ($\trafficfactor*(0,0.4) + (-0.0125,0)$) --%
         ($\trafficfactor*(0,0.325) + (-0.0125,0)$) -- ($\trafficfactor*(0,0.325) + (0.1875,0)$) -- ($\trafficfactor*(0,0.175) + (0.1875,0)$) --%
         ($\trafficfactor*(0,0.175) + (-0.0125,0)$) -- cycle;% arrow backward
       \path[draw=foreground,line width=0.5pt,densely dotted]%
         ($\trafficfactor*(0,-0.1) + (0.0125,0)$) -- ($\trafficfactor*(0,-0.25) + (0.2125,0)$) -- ($\trafficfactor*(0,-0.4) + (0.0125,0)$) --%
         ($\trafficfactor*(0,-0.325)+(0.0125,0)$) -- ($\trafficfactor*(0,-0.325)+(-0.1875,0)$) -- ($\trafficfactor*(0,-0.175) + (-0.1875,0)$) --%
         ($\trafficfactor*(0,-0.175) + (0.0125,0)$) -- cycle;% arrow forward
     }{
       \ifdefstring{\face}{bidirectional}{% face
         \path[draw=foreground,line width=0.5pt]%
           ($\trafficfactor*(0,0.1) + (-0.0125,0)$) -- ($\trafficfactor*(0,0.25) + (-0.2125,0)$) -- ($\trafficfactor*(0,0.4) + (-0.0125,0)$) --%
           ($\trafficfactor*(0,0.325) +(-0.0125,0)$) -- ($\trafficfactor*(0,0.325) +(0.1875,0)$) -- ($\trafficfactor*(0,0.175) + (0.1875,0)$) --%
           ($\trafficfactor*(0,0.175) + (-0.0125,0)$) -- cycle;% arrow backward
         \path[draw=foreground,line width=0.5pt]%
           ($\trafficfactor*(0,-0.1) + (0.0125,0)$) -- ($\trafficfactor*(0,-0.25) + (0.2125,0)$) -- ($\trafficfactor*(0,-0.4) + (0.0125,0)$) --%
           ($\trafficfactor*(0,-0.325)+(0.0125,0)$) -- ($\trafficfactor*(0,-0.325)+(-0.1875,0)$) -- ($\trafficfactor*(0,-0.175)+(-0.1875,0)$) --%
           ($\trafficfactor*(0,-0.175) + (0.0125,0)$) -- cycle;% arrow forward
       }{% error message
         \pgfkeys{/errors/unknown choice value={/tikz/trackschematic/face}{“forward“, “backward“ OR “bidirectional“ as key required}}%
       }%
     }%
   }% end \ifdefstring{\face}
   %% frame
   % \path[draw=foreground,line width=0.5pt]%
   %   (-0.3, 0.1) -- (-0.3, 0.5) -- (0.3, 0.5) -- (0.3, 0.1)
   %   (-0.3,-0.1) -- (-0.3,-0.5) -- (0.3,-0.5) -- (0.3,-0.1);
 }},% END pics/direction_control/.style args={#1}
 % symbology entry
 symbology_direction_control/.pic = {%
   \maintrack (0,0) -- (2.9,0);%
   \maintrack (3.1,0) -- (6,0);%
   \directioncontrol[bidirectional]  at (2,0);%
   \directioncontrol[forward]  at (4,0);%
 },%
}%
%
%%%%%%%%%%%%%%%
\endinput%
%