%!TEX TS-program = pdflatexmk

% Copyright 2018 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.

\documentclass[tikz,border=2]{standalone}

\usepackage{lmodern}
\usepackage[prefix=]{xcolor-solarized}

\def\rootTrackschematic{../../tikz-trackschematic}
\def\srcTrackschematic{\rootTrackschematic/src}
\input{\srcTrackschematic/topology.tikz}
\input{\srcTrackschematic/trafficControl.tikz}
\input{\srcTrackschematic/constructions.tikz}

\begin{document}
  \begin{tikzpicture}[font=\sffamily]
  {   % stations
    \tikzset{every node/.style={base00}};
    \node[right,align=left] at ( 0,2) {to and from\\ Wenden};
    \node[left,align=right] at ( 8,4.0) {Sidings};
    \node                   at (22.5,6.3) {{\LARGE Rebenau}};
    \node[left,align=right] at (42,2) {to and from\\ Okerbach};
    \node[left,align=right] at (42,5) {to and from\\ Pockelsdorf};
  }
  {   % tracks
    \draw[line width=2pt] ( 0, 0) -- ++(42, 0); % track 1
    \draw[line width=2pt] ( 5, 0) -- ++( 1, 1);
    \draw[line width=2pt] ( 0, 1) -- ++( 8, 0) -- ++(2,2) -- ++(26,0) -- ++(2,-2) -- ++(4,0);  % track 3
    \draw[line width=1pt] ( 9, 1) -- ++( 6, 0); % track 21
    \draw[line width=1pt] ( 8, 4) -- ++( 7, 0); % track 41
    \draw[line width=1pt] (12, 4) -- ++( 1,-1);
    \draw[line width=2pt] (14, 3) --   (15, 4) -- ++(27,0);  % track 4
    \draw[line width=2pt] (14, 0) -- ++( 1, 1) -- ++(18, 0); % track 2
    \draw[line width=2pt] (15, 3) -- ++( 2,-2);
    \draw[line width=2pt] (16, 4) --   (17, 5) -- (29, 5) -- ++(5,-5); % track 5
    \draw[line width=2pt] (28, 1) -- ++( 1, 1) -- ++(5,0) -- ++ (2,2);
    \draw[line width=1pt] (26, 5) -- ++( 1, 1) -- ++(3,0);  % track 51

    % track numbers
    \node[fill=white] at ( 9.0, 4) {41};
    \node[fill=white] at (10.0, 1) {21};
    \node[fill=white] at (22.5, 0) { 1};
    \node[fill=white] at (22.5, 1) { 2};
    \node[fill=white] at (22.5, 3) { 3};
    \node[fill=white] at (22.5, 4) { 4};
    \node[fill=white] at (22.5, 5) { 5};
    \node[fill=white] at (29.0, 6) {51};
    % % bufferstops
    \pic  at ( 9, 1) {bufferstop_backward};
    \pic  at (30, 6) {bufferstop_forward};
    % turnouts
    \pic  at ( 5,0) {turnout_left_forward};
    \node at ( 5,-0.2) {\footnotesize W1};
    % \pic at ( 5,0) {fouling_point_left_forward};
    \pic  at ( 6,1) {turnout_left_backward};
    \node at ( 6,1.2) {\footnotesize W2};
    % \pic at ( 6,1) {fouling_point_left_backward};
    \pic  at (11,4) {derailer_left_forward};
    \node[left,align=right] at (11.1,4.2) {\footnotesize Gs41};
    \pic  at (12,4) {turnout_right_forward};
    \node at (12,4.2) {\footnotesize W3};
    % \pic at (12,4) {fouling_point_right_forward};
    \pic  at (13,3) {turnout_right_backward};
    \node at (13,2.8) {\footnotesize W4};
    % \pic at (13,3) {fouling_point_right_backward};
    \pic  at (14,3) {turnout_left_forward};
    \node at (14,2.8) {\footnotesize W5};
    % \pic at (14,3) {fouling_point_left_forward};
    \pic  at (15,4) {turnout_left_backward};
    \node at (15,4.2) {\footnotesize W6};
    % \pic at (15,4) {fouling_point_left_backward};
    \pic  at (14,0) {turnout_left_forward};
    \node at (14,-0.2) {\footnotesize W10};
    % \pic at (14.0,0) {fouling_point_left_forward};
    \pic  at (15,1) {turnout_left_backward};
    \node at (15,1.2) {\footnotesize W11};
    % \pic at (15,1) {fouling_point_left_backward};
    \pic  at (14,1) {derailer_left_forward};
    \node[left,align=right] at (14.1,1.2) {\footnotesize Gs21};
    \pic  at (15,3) {turnout_right_forward};
    \node at (15,3.2) {\footnotesize W8};
    % \pic at (15,3) {fouling_point_right_forward};
    \pic  at (16,4) {turnout_left_forward};
    \node at (16,3.8) {\footnotesize W7};
    % \pic at (16,4) {fouling_point_left_forward};
    \pic  at (17,1) {turnout_right_backward};
    \node at (17,0.8) {\footnotesize W9};
    % \pic at (17,1) {fouling_point_right_backward};

    \pic  at (28,1) {turnout_left_forward};
    \node at (28,0.8) {\footnotesize W15};
    % \pic at (28,1) {fouling_point_left_forward};
    \pic  at (26,5) {turnout_left_forward};
    \node at (26,4.8) {\footnotesize W12};
    % \pic at (28,5) {fouling_point_right_forward};
    \pic [rotate=45] at (26.7,5.7) {derailer_right_backward};
    \node[right,align=left] at (26.8,5.6) {\footnotesize Gs51};
    \pic  at (30,4) {turnout_right_forward};
    \pic  at (30,4) {turnout_right_backward};
    \pic  at (30,4) {slip_right_forward};
    \pic  at (30,4) {slip_right_backward};
    \node[left,align=right] at (29.7,4.2) {\footnotesize W13ab};
    \node[right,align=left] at (30.3,3.8) {\footnotesize W13cd};
    % \pic at (30,4) {fouling_point_right_backward};
    % \pic at (30,4) {fouling_point_right_forward};
    \pic  at (31,3) {turnout_right_forward};
    \pic  at (31,3) {turnout_right_backward};
    \pic  at (31,3) {slip_right_forward};
    \pic  at (31,3) {slip_right_backward};
    \node[left,align=right] at (30.7,3.2) {\footnotesize W14ab};
    \node[right,align=left] at (31.3,2.8) {\footnotesize W14cd};
    % \pic at (31,3) {fouling_point_right_backward};
    % \pic at (31,3) {fouling_point_right_forward};
    \pic  at (32,2) {turnout_right_forward=none};
    \pic  at (32,2) {turnout_right_backward=none};
    \node[right,align=left] at (31.9,2.2) {\footnotesize K16};
    % \pic at (32,2) {fouling_point_right_backward};
    % \pic at (32,2) {fouling_point_right_forward};
    \pic  at (33,1) {turnout_right_backward};
    \node[right,align=left] at (32.9,1.2) {\footnotesize W17};
    % \pic at (33,1) {fouling_point_right_backward};
    \pic  at (34,0) {turnout_right_backward};
    \node at (34,-0.2) {\footnotesize W18};
    % \pic at (34,0) {fouling_point_right_backward};
    \pic  at (35,3) {turnout_left_forward};
    \pic  at (35,3) {turnout_left_backward};
    \pic  at (35,3) {slip_left_forward};
    \pic  at (35,3) {slip_left_backward};
    \node[left,align=right] at (34.7,2.8) {\footnotesize W19ab};
    \node[right,align=left] at (35.3,3.2) {\footnotesize W19cd};
    % \pic at (35,3) {fouling_point_left_backward};
    % \pic at (35,3) {fouling_point_left_forward};
    \pic  at (36,4) {turnout_left_backward};
    \node at (36,4.2) {\footnotesize W20};
    % \pic at (36,4) {fouling_point_left_backward};

    % % platforms
    \pic  at (19.5,0) {platform_right=6};
    \pic  at (19.5,1) {platform_left=6};
    \pic  at (19.5,3) {platform_right=6};
  }
  {   % signals
    \pic at ( 1,0) {route_signal_forward};
    \node[left] at (1,-0.4) {A};
    \pic at ( 1,1) {route_signal_forward};
    \node[left] at (1, 0.6) {AA};
    \pic at ( 3,0) {shunt_limit_backward};
    \pic at ( 4,0) {shunt_signal_forward};
    \node[left] at ( 4,-0.4) {W1X};
    \pic at ( 7,1) {shunt_signal_backward};
    \node[right] at ( 7, 1.4) {W2Y};
    \pic at ( 7,0) {shunt_signal_backward};
    \node[right] at ( 7, 0.4) {W1Y};
    \pic at (11,3) {shunt_signal_forward};
    \node[left] at (11, 2.6) {W4X};
    \pic at (10,4) {shunt_signal_forward};
    \node[left] at (10, 3.6) {41X};
    \pic at (13,0) {shunt_signal_forward};
    \node[left] at (13,-0.4) {W10X};
    \pic at (13,1) {shunt_signal_forward};
    \node[left] at (13, 0.6) {21X};
    \pic at (18.5,0) {route_signal_backward};
    \node[right] at (18.5, 0.4) {P1};
    \pic at (18.5,1) {route_signal_backward};
    \node[right] at (18.5, 1.4) {P2};
    \pic at (18.5,3) {route_signal_backward};
    \node[right] at (18.5, 3.4) {P3};
    \pic at (18.5,4) {route_signal_backward};
    \node[right] at (18.5, 4.4) {P4};
    \pic at (18.5,5) {route_signal_backward};
    \node[right] at (18.5, 5.4) {P5};

    \pic at (24.5,5) {route_signal_forward};
    \node[left] at (24.5, 4.6) {N5};
    \pic at (26.5,1) {route_signal_forward};
    \node[left] at (26.5, 0.6) {N2};
    \pic at (26.5,3) {route_signal_forward};
    \node[left] at (26.5, 2.6) {N3};
    \pic at (26.5,4) {route_signal_forward};
    \node[left] at (26.5, 3.6) {N4};
    \pic at (27.5,6) {shunt_signal_backward};
    \node[right] at ( 27.5, 6.4) {51Y};
    \pic at (30.0,0) {route_signal_forward};
    \node[left] at (30.0,-0.4) {N1};
    \pic at (35.0,0) {shunt_signal_backward};
    \node[right] at ( 35, 0.4) {W18Y};
    \pic[rotate=-45] at (36.8,2.2) {shunt_signal_backward};
    \node[right,rotate=-45] at ( 37.0, 2.5) {W19Y};
    \pic at (37.0,4) {shunt_signal_backward};
    \node[right] at ( 37, 4.4) {W20Y};
    \pic at (39.0,1) {shunt_limit_forward};
    \pic at (39.0,4) {shunt_limit_forward};
    \pic at (41.0,0) {route_signal_backward};
    \node[right] at (41.0, 0.4) {FF};
    \pic at (41.0,1) {route_signal_backward};
    \node[right] at (41.0, 1.4) {F};
    \pic at (41.0,4) {route_signal_backward};
    \node[right] at (41.0, 4.4) {G};
  }
  {   % hectometer posts
    \tikzset{every node/.style={base00,rotate=-90},every path/.style={base00,dashed}};
    \draw    (01.0,-0.85) -- ++(0,-0.7) node [right,align= left] {15.000};
    \draw    (14.5,-0.85) -- ++(0,-0.7) node [right,align= left] {15.800};
    \draw    (14.5, 4.35) -- ++(0, 1.2) node [ left,align=right] {15.800};
    \draw    (15.8,-0.35) -- ++(0,-1.2) node [right,align= left] {15.900};
    \draw    (15.8, 4.35) -- ++(0, 1.2) node [ left,align=right] {15.900};
    \draw    (18.5,-0.35) -- ++(0,-1.2) node [right,align= left] {16.000};
    \draw    (22.5,-0.85) -- ++(0,-0.7) node [right,align= left] {16.300};
    \draw    (24.5, 5.35) -- ++(0, 0.7) node [ left,align=right] {16.400};
    \draw    (26.5,-0.35) -- ++(0,-1.2) node [right,align= left] {16.500};
    \draw    (30.0,-0.85) -- ++(0,-0.7) node [right,align= left] {16.600};
    \draw    (30.0, 6.35) -- ++(0, 0.3) node [ left,align=right] {16.600};
    \draw    (30.0, 4.75) -- ++(0, 0.7);
    \draw    (31.5,-0.85) -- ++(0,-0.7) node [right,align= left] {16.700};
    \draw    (31.5, 4.35) -- ++(0, 0.7) node [ left,align=right] {16.700};
    \draw    (33.3,-0.35) -- ++(0,-1.2) node [right,align= left] {16.800};
    \draw    (41.0,-0.35) -- ++(0,-1.2) node [right,align= left] {17.200};
  }
  \end{tikzpicture}
\end{document}