2020-01-14 17:11:10 +01:00
%% symbol library for TikZ track schematics
%
2022-01-06 20:17:51 +01:00
% Copyright (c) 2018 - 2022, Martin Scheidt (ISC license)
2020-01-14 17:11:10 +01:00
%
% 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.
%
2021-01-02 14:04:05 +01:00
\ProvidesFileRCS { tikzlibrarytrackschematic.measures.code.tex} %
2020-01-14 17:11:10 +01:00
%
%%%%%%%%%%%%%%%
% global settings
%%%%%%%%%%%%%%%
2021-09-30 12:37:31 +02:00
\RequirePackage { tikz,etoolbox} %
2020-01-14 17:11:10 +01:00
\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,%
%% 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 { %
2021-01-02 14:04:05 +01:00
/tikz/trackschematic/measures/.is family,%
/tikz/trackschematic/measures/.cd,%
2020-01-14 17:11:10 +01:00
%% color hectometer
color/.store in=\hectometercolor ,%
color=\foreground !50!\background ,% DEFAULT
2021-01-02 14:04:05 +01:00
/tikz/hectometer color/.forward to=/tikz/trackschematic/measures/color,%
2020-01-14 17:11:10 +01:00
} %
%%%%%%%%%%%%%%%%
% 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 } ;%
} { } %
} %
2021-01-02 14:04:05 +01:00
} } ,% 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);%
} ,%
2020-01-14 17:11:10 +01:00
} %
%
%%%%%%%%%%%%%%%
% symbol track distance
%%%%%%%%%%%%%%%
%
%% command
\newcommand \trackdistance { } % just for safety
2021-01-02 14:04:05 +01:00
\def \trackdistance #1(#2)#3(#4)#5(#6){ % \trackdistance between (coord1) and (coord2) distance (distance);
2020-01-14 17:11:10 +01:00
\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
} %
2021-01-02 14:04:05 +01:00
% 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);%
} ,%
} %
2020-01-14 17:11:10 +01:00
%
%%%%%%%%%%%%%%%
% 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 { %
2021-01-02 14:04:05 +01:00
/tikz/trackschematic/measures/hectometer/.is family,%
/tikz/trackschematic/measures/hectometer/.cd,%
2020-01-14 17:11:10 +01:00
%% hectometer base
base/.value required,%
base/.store in=\basecoord ,%
2021-01-02 14:04:05 +01:00
/tikz/hectometer base/.forward to=/tikz/trackschematic/measures/hectometer/base,%
2020-01-14 17:11:10 +01:00
%% hectometer base
orientation/.value required,%
orientation/.store in=\orientation ,%
2021-01-02 14:04:05 +01:00
/tikz/orientation/.forward to=/tikz/trackschematic/measures/hectometer/orientation,%
2020-01-14 17:11:10 +01:00
} %
%% 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
2021-01-02 14:04:05 +01:00
\pgfkeys { /errors/unknown choice value={ /tikz/trackschematic/measures/hectometer/orientation} { “left“ OR “right“ as key required} } %
2020-01-14 17:11:10 +01:00
} %
} % 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
%%
2022-02-21 16:50:57 +01:00
\path let \p 1=\basecoord in coordinate (ts-hm-l) at (0,\y 1);%
2020-01-14 17:11:10 +01:00
\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 ) $ );%
2022-02-21 16:50:57 +01:00
\path let \p 1=\labelcoord in coordinate (ts-hm-b2) at ($ ( ts - hm - l ) + ( \x 1 , 0 . 25 ) $ );%
\path let \p 1=\labelcoord in coordinate (ts-hm-l) at ($ ( ts - hm - l ) + ( \x 1 , \y 1 ) $ );%
2020-01-14 17:11:10 +01:00
} %
%% 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 } ;%
} %
2021-01-02 14:04:05 +01:00
} } ,% 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);%
} ,%
2020-01-14 17:11:10 +01:00
} %
%
%%%%%%%%%%%%%%%
2021-01-02 14:04:05 +01:00
% 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
2020-01-14 17:11:10 +01:00
%%%%%%%%%%%%%%%
%
% command
2021-01-02 14:04:05 +01:00
\newcommand \trackmarking { } % just for safety
\def \trackmarking [#1] { \path [draw,TrackMark,#1] } % \trackmarking[color] (coord1) -- (coord2);
2020-01-14 17:11:10 +01:00
%
2021-01-02 14:04:05 +01:00
\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);%
} ,%
} %
2020-01-14 17:11:10 +01:00
%
%%%%%%%%%%%%%%%
% TODO:
% * platform length
% * direction of milage
%
%%%%%%%%%%%%%%%
\endinput %
%