-
Notifications
You must be signed in to change notification settings - Fork 1
/
cd-switch.sty
100 lines (100 loc) · 3.65 KB
/
cd-switch.sty
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
% cd-switch.sty
% from http://www.taylorgruppe.de/circdia/
% File created by Stefan Krause -- version 1.3.
% Supports additional switch and relay symbols for circdia.sty.
\newcommand{\cdelemxfirst}{}
\newcommand{\cdelemyfirst}{}
\newcommand{\cdorientfirst}{}
% Relays
\newcommand{\relay}[6][]{
\prepareelement{S}{relay}{#4}{#5}{#6}
\renewcommand{\cdelemx}{#2}
\renewcommand{\cdelemy}{#3}
\begin{scope}[shift = {(#2, #3)}]
\expandafter\csname relay\cdorient\endcsname{#1}
\drawrefval
\end{scope}
}
\newcommand{\relayH}[1]{
\setstandardtextpos{ud}
\placerefvalH{-2}{0}{2}{-3.75}{0}{3.75}
#1
\draw [cdmedlines] (-1.5, -2.45) rectangle (1.5, 2.45) (-1.5, -1.5) -- (1.5, 1.5);
\draw (-1.5, 0) -- (-2, 0) (1.5, 0) -- (2, 0);
}
\newcommand{\relayV}[1]{
\setstandardtextpos{r}
\placerefvalV{-3}{0}{3}{-2.75}{0}{2.75}
#1
\draw [cdmedlines] (-2.45, -1.5) rectangle (2.45, 1.5) (-1.5, -1.5) -- (1.5, 1.5);
\draw (0, -1.5) -- (0, -2) (0, 1.5) -- (0, 2);
}
\newcommand{\relayandswitch}[2]{
#1
\edef\cdelemxfirst{\cdelemx}
\edef\cdelemyfirst{\cdelemy}
\edef\cdorientfirst{\cdorient}
#2
\ifthenelse{\equal{\cdorientfirst}{H}}{
\ifthenelse{\equal{\cdorient}{L}\OR\equal{\cdorient}{R}}{
\FPiflt\cdelemy\cdelemyfirst
\draw [cddashedlines] (\cdelemxfirst, \cdelemyfirst-2.45) |- (\cdelemx, \cdelemyfirst-3.5) -- (\cdelemx, \cdelemy);
\else
\draw [cddashedlines] (\cdelemxfirst, \cdelemyfirst+2.45) |- (\cdelemx, \cdelemyfirst+3.5) -- (\cdelemx, \cdelemy);
\fi
}{
\FPiflt\cdelemy\cdelemyfirst
\draw [cddashedlines] (\cdelemxfirst, \cdelemyfirst-2.45) |- (\cdelemx, \cdelemy);
\else
\draw [cddashedlines] (\cdelemxfirst, \cdelemyfirst+2.45) |- (\cdelemx, \cdelemy);
\fi
}
}{
\ifthenelse{\equal{\cdorient}{L}\OR\equal{\cdorient}{R}}{
\FPiflt\cdelemx\cdelemxfirst
\draw [cddashedlines] (\cdelemxfirst-2.45, \cdelemyfirst) -| (\cdelemx, \cdelemy);
\else
\draw [cddashedlines] (\cdelemxfirst+2.45, \cdelemyfirst) -| (\cdelemx, \cdelemy);
\fi
}{
\FPiflt\cdelemx\cdelemxfirst
\draw [cddashedlines] (\cdelemxfirst-2.45, \cdelemyfirst) -| (\cdelemxfirst-3.5, \cdelemy) -- (\cdelemx, \cdelemy);
\else
\draw [cddashedlines] (\cdelemxfirst+2.45, \cdelemyfirst) -| (\cdelemxfirst+3.5, \cdelemy) -- (\cdelemx, \cdelemy);
\fi
}
}
}
% Additional wires
\let\wireelemSswitch=\wireelemS
\renewcommand{\wireelemS}[2]{
\wireelemSswitch{#1}{#2}
\ifthenelse{\equal{#1}{L}}{
\ifthenelse{\equal{\cdorient}{H}}{\draw (-2, 0) -- ++(-#2, 0);}{}
}{}
\ifthenelse{\equal{#1}{R}}{
\ifthenelse{\equal{\cdorient}{H}}{\draw (2, 0) -- ++(#2, 0);}{}
}{}
\ifthenelse{\equal{#1}{U}}{
\ifthenelse{\equal{\cdorient}{V}}{\draw (0, 2) -- ++(0, #2);}{}
}{}
\ifthenelse{\equal{#1}{D}}{
\ifthenelse{\equal{\cdorient}{V}}{\draw (0, -2) -- ++(0, -#2);}{}
}{}
}
% Voltage arrows
\let\voltarrowswitch=\voltarrow
\renewcommand{\voltarrow}[2]{
\ifthenelse{\equal{\cdelem}{S}\AND\equal{\cdtype}{relay}}{
\ifthenelse{\equal{#1}{UL}}{\cdbigarrow[4.2]{-2.1}{3.25}{180}\cdputtext{0}{4.75}{c}{#2}}{}
\ifthenelse{\equal{#1}{UR}}{\cdbigarrow[4.2]{2.1}{3.25}{0}\cdputtext{0}{4.75}{c}{#2}}{}
\ifthenelse{\equal{#1}{DL}}{\cdbigarrow[4.2]{-2.1}{-3.25}{180}\cdputtext{0}{-4.75}{c}{#2}}{}
\ifthenelse{\equal{#1}{DR}}{\cdbigarrow[4.2]{2.1}{-3.25}{0}\cdputtext{0}{-4.75}{c}{#2}}{}
\ifthenelse{\equal{#1}{LU}}{\cdbigarrow[4.2]{-3.25}{2.1}{90}\cdputtext{-3.75}{0}{r}{#2}}{}
\ifthenelse{\equal{#1}{LD}}{\cdbigarrow[4.2]{-3.25}{-2.1}{-90}\cdputtext{-3.75}{0}{r}{#2}}{}
\ifthenelse{\equal{#1}{RU}}{\cdbigarrow[4.2]{3.25}{2.1}{90}\cdputtext{3.75}{0}{l}{#2}}{}
\ifthenelse{\equal{#1}{RD}}{\cdbigarrow[4.2]{3.25}{-2.1}{-90}\cdputtext{3.75}{0}{l}{#2}}{}
}{
\voltarrowswitch{#1}{#2}
}
}