summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/bondgraph/bondgraph.sty
blob: 0820d37ff115a04f639750188f4415f00fb30de5 (plain)
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
%% bondgraph.sty
%% Copyright (c) 2010, Jean-Francois Dupuis
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Jean-Francois Dupuis.
%
% This work consists of the files bondgraph.sty, bondgraph_arrows.tex 
% and bondgraph_example.tex.


% The Defines commands to draw bond graph using the graph layout tools
% TikZ and PGF.

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{bondgraph}[2010/06/04 v1.0]
\RequirePackage{tikz}
\RequirePackage{ifthen}

\usepgflibrary{arrows}
\usetikzlibrary{positioning}

% % Arrow definition
\pgfarrowsdeclarecombine[\pgflinewidth]
{combined}{combined}{left to}{left to}{|}{|}%

\tikzstyle{outbond}=[-left to]
\tikzstyle{inbond}=[left to-]
\tikzstyle{outbonde}=[-combined]
\tikzstyle{inbonde}=[combined-]
\tikzstyle{outbondf}=[|-left to]
\tikzstyle{inbondf}=[left to-|]



%usefull command
\newcommand{\bondleft}[2]{ 
\begin{tikzpicture}[auto,baseline]
\draw [left to-] (0pt,0.7ex) to node {\scriptsize$\textstyle #1$} node [swap] {\scriptsize$\textstyle #2$} (3ex,0.7ex);
\end{tikzpicture}
}

\newcommand{\bondright}[2]{ 
\begin{tikzpicture}[auto,baseline]
\draw [-left to] (0pt,0.7ex) to node {\scriptsize$\textstyle #1$} node [swap] {\scriptsize$\textstyle #2$} (3ex,0.7ex);
\end{tikzpicture}
}

\newcommand{\bondrighte}[2]{
\begin{tikzpicture}[auto,baseline]
\draw[-combined] (0pt,0.7ex) to node {\scriptsize$\textstyle #1$} node [swap] {\scriptsize$\textstyle #2$} (3ex,0.7ex);
\end{tikzpicture}
}
\newcommand{\bondrightf}[2]{
\begin{tikzpicture}[auto,baseline]
\draw[|-left to] (0pt,0.7ex) to node {\scriptsize$\textstyle #1$} node [swap] {\scriptsize$\textstyle #2$} (3ex,0.7ex);
\end{tikzpicture}
}
\newcommand{\bondlefte}[2]{
\begin{tikzpicture}[auto, baseline]
\draw[combined-] (0pt,0.7ex) to node {\scriptsize$\textstyle #1$} node [swap] {\scriptsize$\textstyle #2$} (3ex,0.7ex);
\end{tikzpicture}
}
\newcommand{\bondleftf}[2]{
\begin{tikzpicture}[auto, baseline]
\draw[left to-|] (0pt,0.7ex) to node {\scriptsize$\textstyle #1$} node [swap] {\scriptsize$\textstyle #2$} (3ex,0.7ex);
\end{tikzpicture}
}

% % % Style definition

\tikzstyle{nodemodpoint}=[
	% The shape:
	rectangle,
	% The size:
	minimum size=6mm,
	% The border:
	very thick,
	draw=red!50!black!50, % 50% red and 50% black, and that mixed with 50% white
	% The filling:
	top color=white, % a shading that is white at the top...
	bottom color=red!50!black!20, % and something else at the bottom
	% Font
	%font=\itshape,
	% Seperation
	outer sep=2pt
]

\tikzstyle{bondmodpoint}=[
	% The shape:
	rectangle,
	% The size:
	minimum size=2.5mm,
	% The border:
	very thick,
	draw=red!50!black!50, % 50% red and 50% black, and that mixed with 50% white
	% Seperation
	outer sep=2pt
]

\tikzstyle{newelement}=[
	color=red!50!black!75,
	thick
]


% % Bond graph creation command

\newcommand{\bgComponentNoBond} [2] {
	%1 Node style
	%2 Node reference name
	%3 Node displayed name
	\node (#1) {#2};
}

\newcommand{\bgComponent} [6] {
	%1 Node style
	%2 Node reference
	%3 Node name
	%4 Position
	%5 Position reference
	%6 Bond style
	\node [#1] (#2) [#4 #5] {#3}
	edge [#6]  (#5);
}

\newcommand{\bgComponentWithBondLabel} [9] {
	%1 Node style
	%2 Node reference
	%3 Node name
	%4 Position
	%5 Position reference
	%6 Bond style
	%7 Label style
	%8 Effort label name
	%9 Flow label name
	\ifthenelse{\equal{#4}{right of=}\or\equal{#4}{left of=}}%
	{ %Place label above and below
	\node [#1] (#2) [#4 #5] {#3}
		edge [#6]  node  [#7] [above]{#8} node  [#7] [below]{#9} (#5);
	}{ %Place labels left and right
	\node [#1] (#2) [#4 #5] {#3}
		edge [#6]  node  [#7] [left]{#8} node  [#7] [right]{#9} (#5);
}
}

\newcommand{\bgComponentWithPosBondLabel} [9] {
	%1 Node style
	%2 Node reference
	%3 Node name
	%4 Position
	%5 Position reference
	%6 Bond style
	%7 Label style
	%8 Label position
	%9 Label name
	\node [#1] (#2) [#4 #5] {#3}
	edge [#6]  node  [#7] [#8]{#9} (#5);
}

\newcommand{\bgComponentWithBondMarkup} [7] {
	%1 Node style
	%2 Node reference
	%3 Node name
	%4 Position
	%5 Position reference
	%6 Bond style
	%7 Markup style
	\node [#1] (#2) [#4 #5] {#3}
		edge [#6] node [#7] {} (#5);
}

\newcommand{\bgComponentWithBondMarkupTagged} [8] {
	%1 Node style
	%2 Node reference
	%3 Node name
	%4 Position
	%5 Position reference
	%6 Bond style
	%7 Markup style
	%8 Tag
	\ifthenelse{\equal{#4}{right of=}\or\equal{#4}{left of=}}%
	{ %Place label above and below
		\node [#1] (#2) [#4 #5] {#3}
			edge [#6] node [font=\scriptsize,above=0.75ex]{#8} node [#7] {} (#5);
	}{ %Place labels left and right
		\node [#1] (#2) [#4 #5] {#3}
			edge [#6] node [font=\scriptsize, left=0.75ex]{#8} node [#7] {} (#5);
	}
}