Merge lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support into lp:~tapaal-contributor/tapaal/cpn-gui-dev
- cpn-gui-TikZ-support
- Merge into cpn-gui-dev
Status: | Superseded |
---|---|
Proposed branch: | lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support |
Merge into: | lp:~tapaal-contributor/tapaal/cpn-gui-dev |
Diff against target: |
411 lines (+204/-98) 1 file modified
src/net/tapaal/export/TikZExporter.java (+204/-98) |
To merge this branch: | bzr merge lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Pending | ||
Review via email:
|
This proposal has been superseded by a proposal from 2022-02-09.
Commit message
Added TikZ support for colored nets.
Added a framed box to the Tikz output for global variables/
Description of the change
The TikZ export now shows all of the new features associated with colored nets.
Also added a framed box that contains all the global variables, constants and/or color types for a given net.
- 1572. By Kristian Morsing Pedersen <email address hidden>
-
Removed subscripting from place- and transition names, and changed \mathrm to \mathit
- 1573. By Kristian Morsing Pedersen <email address hidden>
-
Added new adjustment options for labels on arcs, places and transitions
- 1574. By Kristian Morsing Pedersen <email address hidden>
-
Merged with cpn-gui-dev
- 1575. By Kristian Morsing Pedersen <email address hidden>
-
Labels with multiple lines on arcs now displays correctly
- 1576. By Kristian Morsing Pedersen <email address hidden>
-
Changed default pos of arc labels to 0.5
- 1577. By Kristian Morsing Pedersen <email address hidden>
-
Resolved merge conflicts
- 1578. By Kristian Morsing Pedersen <email address hidden>
-
Removed redundant \\ and changed 0,0 -> 0.0 for age of tokens in initial markings
- 1579. By Kristian Morsing Pedersen <email address hidden>
-
Changed x -> \times in inhibitor arcs
Unmerged revisions
Preview Diff
1 | === modified file 'src/net/tapaal/export/TikZExporter.java' | |||
2 | --- src/net/tapaal/export/TikZExporter.java 2022-01-07 17:05:54 +0000 | |||
3 | +++ src/net/tapaal/export/TikZExporter.java 2022-02-09 20:32:33 +0000 | |||
4 | @@ -3,22 +3,27 @@ | |||
5 | 3 | import java.io.FileWriter; | 3 | import java.io.FileWriter; |
6 | 4 | import java.io.IOException; | 4 | import java.io.IOException; |
7 | 5 | import java.io.PrintWriter; | 5 | import java.io.PrintWriter; |
9 | 6 | import java.util.List; | 6 | import java.util.*; |
10 | 7 | import java.util.stream.Collectors; | ||
11 | 7 | 8 | ||
12 | 9 | import dk.aau.cs.model.CPN.Color; | ||
13 | 10 | import dk.aau.cs.model.CPN.ColorType; | ||
14 | 11 | import dk.aau.cs.model.CPN.Variable; | ||
15 | 12 | import dk.aau.cs.model.tapn.Constant; | ||
16 | 8 | import dk.aau.cs.model.tapn.TimedToken; | 13 | import dk.aau.cs.model.tapn.TimedToken; |
17 | 9 | 14 | ||
18 | 15 | import net.tapaal.gui.petrinet.Context; | ||
19 | 10 | import pipe.gui.petrinet.dataLayer.DataLayer; | 16 | import pipe.gui.petrinet.dataLayer.DataLayer; |
20 | 11 | import pipe.gui.TAPAALGUI; | 17 | import pipe.gui.TAPAALGUI; |
25 | 12 | import pipe.gui.petrinet.graphicElements.Arc; | 18 | import pipe.gui.petrinet.graphicElements.*; |
22 | 13 | import pipe.gui.petrinet.graphicElements.ArcPathPoint; | ||
23 | 14 | import pipe.gui.petrinet.graphicElements.Place; | ||
24 | 15 | import pipe.gui.petrinet.graphicElements.Transition; | ||
26 | 16 | import pipe.gui.petrinet.graphicElements.tapn.TimedInhibitorArcComponent; | 19 | import pipe.gui.petrinet.graphicElements.tapn.TimedInhibitorArcComponent; |
27 | 17 | import pipe.gui.petrinet.graphicElements.tapn.TimedInputArcComponent; | 20 | import pipe.gui.petrinet.graphicElements.tapn.TimedInputArcComponent; |
28 | 18 | import pipe.gui.petrinet.graphicElements.tapn.TimedPlaceComponent; | 21 | import pipe.gui.petrinet.graphicElements.tapn.TimedPlaceComponent; |
29 | 19 | import pipe.gui.petrinet.graphicElements.tapn.TimedTransitionComponent; | 22 | import pipe.gui.petrinet.graphicElements.tapn.TimedTransitionComponent; |
30 | 20 | import pipe.gui.petrinet.graphicElements.tapn.TimedTransportArcComponent; | 23 | import pipe.gui.petrinet.graphicElements.tapn.TimedTransportArcComponent; |
31 | 21 | 24 | ||
32 | 25 | import static java.util.stream.Collectors.toList; | ||
33 | 26 | |||
34 | 22 | public class TikZExporter { | 27 | public class TikZExporter { |
35 | 23 | 28 | ||
36 | 24 | public enum TikZOutputOption { | 29 | public enum TikZOutputOption { |
37 | @@ -45,7 +50,7 @@ | |||
38 | 45 | if (option == TikZOutputOption.FULL_LATEX) { | 50 | if (option == TikZOutputOption.FULL_LATEX) { |
39 | 46 | out.println("\\documentclass[a4paper]{article}"); | 51 | out.println("\\documentclass[a4paper]{article}"); |
40 | 47 | out.println("\\usepackage{tikz}"); | 52 | out.println("\\usepackage{tikz}"); |
42 | 48 | out.println("\\usetikzlibrary{petri,arrows}"); | 53 | out.println("\\usetikzlibrary{petri,arrows,positioning}"); |
43 | 49 | out.println("\\usepackage{amstext}"); | 54 | out.println("\\usepackage{amstext}"); |
44 | 50 | out.println(); | 55 | out.println(); |
45 | 51 | out.println("\\begin{document}"); | 56 | out.println("\\begin{document}"); |
46 | @@ -62,6 +67,8 @@ | |||
47 | 62 | out.print(exportTransitions(net.getTransitions())); | 67 | out.print(exportTransitions(net.getTransitions())); |
48 | 63 | out.print(exportArcs(net.getArcs())); | 68 | out.print(exportArcs(net.getArcs())); |
49 | 64 | 69 | ||
50 | 70 | out.println(exportGlobalVariables()); | ||
51 | 71 | |||
52 | 65 | out.println("\\end{tikzpicture}"); | 72 | out.println("\\end{tikzpicture}"); |
53 | 66 | if (option == TikZOutputOption.FULL_LATEX) { | 73 | if (option == TikZOutputOption.FULL_LATEX) { |
54 | 67 | out.println("\\end{document}"); | 74 | out.println("\\end{document}"); |
55 | @@ -144,48 +151,22 @@ | |||
56 | 144 | 151 | ||
57 | 145 | protected String getArcLabels(Arc arc) { | 152 | protected String getArcLabels(Arc arc) { |
58 | 146 | String arcLabel = ""; | 153 | String arcLabel = ""; |
90 | 147 | String arcLabelPositionString = "\\draw (" + (arc.getNameLabel().getX()) + "," + (arc.getNameLabel().getY())*(-1) + ") node {"; | 154 | String arcLabelPositionString = "\\draw (" + (arc.getArcPath().midPoint.getX()) + "," + (arc.getNameLabel().getY())*(-1) + ") node[align=left,xshift=0pt,yshift=0pt] {"; |
91 | 148 | 155 | ||
92 | 149 | if (arc instanceof TimedInputArcComponent) { | 156 | if(!arc.getNameLabel().getText().isEmpty()) { |
93 | 150 | if (!(arc.getSource() instanceof TimedTransitionComponent)) { | 157 | arcLabel += arcLabelPositionString; |
94 | 151 | arcLabel = arcLabelPositionString; | 158 | arcLabel += "\\\\" + handleNameLabel(arc.getNameLabel().getText()) + ""; |
95 | 152 | if (arc.getWeight().value() > 1) { | 159 | } |
96 | 153 | arcLabel += "$" + arc.getWeight().value() + "\\times$\\ "; | 160 | |
97 | 154 | } | 161 | if(!arcLabel.isEmpty()) { |
98 | 155 | 162 | arcLabel += "};\n"; | |
99 | 156 | if(TAPAALGUI.getApp().getCurrentTab().getLens().isTimed()) { | 163 | } else { |
100 | 157 | arcLabel += "$\\mathrm{" + replaceWithMathLatex(getGuardAsStringIfNotHidden((TimedInputArcComponent) arc)) + "}$"; | 164 | arcLabel += "{};\n"; |
101 | 158 | if (arc instanceof TimedTransportArcComponent) | 165 | } |
102 | 159 | arcLabel += ":" + ((TimedTransportArcComponent) arc).getGroupNr(); | 166 | |
72 | 160 | arcLabel += "};\n"; | ||
73 | 161 | } else { | ||
74 | 162 | arcLabel += "};\n"; | ||
75 | 163 | } | ||
76 | 164 | |||
77 | 165 | } else { | ||
78 | 166 | arcLabel = arcLabelPositionString; | ||
79 | 167 | if (arc.getWeight().value() > 1) { | ||
80 | 168 | arcLabel += "$" + arc.getWeight().value() + "\\times$\\ "; | ||
81 | 169 | } | ||
82 | 170 | arcLabel += ":" + ((TimedTransportArcComponent) arc).getGroupNr() + "};\n"; | ||
83 | 171 | } | ||
84 | 172 | |||
85 | 173 | } else { | ||
86 | 174 | if (arc.getWeight().value() > 1) { | ||
87 | 175 | arcLabel += arcLabelPositionString + "$" + arc.getWeight().value() + "\\times$\\ };\n"; | ||
88 | 176 | } | ||
89 | 177 | } | ||
103 | 178 | return arcLabel; | 167 | return arcLabel; |
104 | 179 | } | 168 | } |
105 | 180 | 169 | ||
106 | 181 | private String getGuardAsStringIfNotHidden(TimedInputArcComponent arc) { | ||
107 | 182 | if (!TAPAALGUI.getApp().showZeroToInfinityIntervals() && arc.getGuardAsString().equals("[0,inf)")){ | ||
108 | 183 | return ""; | ||
109 | 184 | } else { | ||
110 | 185 | return arc.getGuardAsString(); | ||
111 | 186 | } | ||
112 | 187 | } | ||
113 | 188 | |||
114 | 189 | private StringBuffer exportTransitions(Transition[] transitions) { | 170 | private StringBuffer exportTransitions(Transition[] transitions) { |
115 | 190 | StringBuffer out = new StringBuffer(); | 171 | StringBuffer out = new StringBuffer(); |
116 | 191 | for (Transition trans : transitions) { | 172 | for (Transition trans : transitions) { |
117 | @@ -234,9 +215,10 @@ | |||
118 | 234 | out.append("%% label for transition " + trans.getName() + "\n"); | 215 | out.append("%% label for transition " + trans.getName() + "\n"); |
119 | 235 | out.append("\\draw ("); | 216 | out.append("\\draw ("); |
120 | 236 | out.append(trans.getNameLabel().getX() + xOffset + "," + (trans.getNameLabel().getY() * -1) + ")"); | 217 | out.append(trans.getNameLabel().getX() + xOffset + "," + (trans.getNameLabel().getY() * -1) + ")"); |
122 | 237 | out.append(" node "); | 218 | out.append(" node[align=left,xshift=0pt,yshift=0pt]"); |
123 | 238 | out.append(" {"); | 219 | out.append(" {"); |
125 | 239 | out.append(exportMathName(trans.getName())); | 220 | out.append("$\\mathit{" + (trans.getName().replace("_","\\_")) + "}$"); |
126 | 221 | out.append(handleNameLabel(trans.getNameLabel().getText())); | ||
127 | 240 | out.append("};\n"); | 222 | out.append("};\n"); |
128 | 241 | } | 223 | } |
129 | 242 | } | 224 | } |
130 | @@ -247,7 +229,7 @@ | |||
131 | 247 | StringBuffer out = new StringBuffer(); | 229 | StringBuffer out = new StringBuffer(); |
132 | 248 | 230 | ||
133 | 249 | for (Place place : places) { | 231 | for (Place place : places) { |
135 | 250 | String invariant = getPlaceInvariantString(place); | 232 | String invariant = "$" + getPlaceInvariantString(place) + "$"; |
136 | 251 | String tokensInPlace = getTokenListStringFor(place); | 233 | String tokensInPlace = getTokenListStringFor(place); |
137 | 252 | 234 | ||
138 | 253 | out.append("\\node[place"); | 235 | out.append("\\node[place"); |
139 | @@ -269,30 +251,58 @@ | |||
140 | 269 | if (place.getAttributesVisible() || !invariant.equals("")){ | 251 | if (place.getAttributesVisible() || !invariant.equals("")){ |
141 | 270 | boolean isLabelAbovePlace = place.getY() > place.getNameLabel().getY(); | 252 | boolean isLabelAbovePlace = place.getY() > place.getNameLabel().getY(); |
142 | 271 | boolean isLabelBehindPlace = place.getX() < place.getNameLabel().getX(); | 253 | boolean isLabelBehindPlace = place.getX() < place.getNameLabel().getX(); |
145 | 272 | double xOffset = place.getName().length() > 6 && !isLabelAbovePlace && !isLabelBehindPlace ? place.getLayerOffset() : 0; | 254 | int longestString = 0; |
146 | 273 | double yOffset = isLabelAbovePlace ? (place.getNameLabel().getHeight() / 2) : 0; | 255 | List<String> listStringNameLabel = place.getNameLabel().getText().lines().collect(toList()); |
147 | 256 | for(int i = 0; i < listStringNameLabel.size(); i++) { | ||
148 | 257 | if(listStringNameLabel.get(i).length() > longestString) { | ||
149 | 258 | longestString = listStringNameLabel.get(i).length(); | ||
150 | 259 | } | ||
151 | 260 | } | ||
152 | 261 | double xOffset = longestString > 8 && !isLabelAbovePlace && !isLabelBehindPlace ? place.getLayerOffset() : 0; | ||
153 | 262 | double yOffset = place.getNameLabel().getText().lines().count() * 5; | ||
154 | 263 | |||
155 | 264 | String nameLabel = place.getNameLabel().getText(); | ||
156 | 274 | 265 | ||
157 | 275 | out.append("%% label for place " + place.getName() + "\n"); | 266 | out.append("%% label for place " + place.getName() + "\n"); |
158 | 276 | out.append("\\draw ("); | 267 | out.append("\\draw ("); |
161 | 277 | out.append((place.getNameLabel().getX() + xOffset) + "," + ((place.getNameLabel().getY() * -1) + yOffset) +")"); | 268 | out.append((place.getNameLabel().getX() + xOffset) + "," + ((place.getNameLabel().getY() + yOffset) * -1) +")"); |
162 | 278 | out.append(" node[align=left] "); | 269 | out.append(" node[align=left,xshift=0pt,yshift=0pt] "); |
163 | 279 | out.append("{"); | 270 | out.append("{"); |
174 | 280 | if(place.getAttributesVisible()) | 271 | if(place.getAttributesVisible()) { |
175 | 281 | out.append(exportMathName(place.getName())); | 272 | out.append("$\\mathit{" + (place.getName().replace("_","\\_")) + "}$"); |
176 | 282 | if(!invariant.equals("")) { | 273 | if (!place.getNameLabel().getText().isEmpty()) { |
177 | 283 | if((place.getAttributesVisible())) | 274 | out.append(handleNameLabel(nameLabel)); |
178 | 284 | out.append("\\\\"); | 275 | } |
179 | 285 | out.append(invariant); | 276 | } |
180 | 286 | }else { | 277 | out.append("};\n"); |
171 | 287 | out.append("};\n"); | ||
172 | 288 | } | ||
173 | 289 | |||
181 | 290 | } | 278 | } |
182 | 291 | } | 279 | } |
183 | 292 | |||
184 | 293 | return out; | 280 | return out; |
185 | 294 | } | 281 | } |
186 | 295 | 282 | ||
187 | 283 | private String handleNameLabel(String nameLabel) { | ||
188 | 284 | String nameLabelsString = ""; | ||
189 | 285 | String[] labelsInName = nameLabel.split("\n"); | ||
190 | 286 | for(int i = 0; i < labelsInName.length; i++) { | ||
191 | 287 | |||
192 | 288 | if(labelsInName[i].contains("[")) { | ||
193 | 289 | nameLabelsString += escapeSpacesInAndOrNot(replaceWithMathLatex(labelsInName[i])); | ||
194 | 290 | nameLabelsString += "\\\\"; | ||
195 | 291 | } | ||
196 | 292 | else if(!labelsInName[i].isEmpty()){ | ||
197 | 293 | nameLabelsString += escapeSpacesInAndOrNot(replaceWithMathLatex(labelsInName[i])); | ||
198 | 294 | nameLabelsString += "\\\\"; | ||
199 | 295 | } else { | ||
200 | 296 | nameLabelsString += "\\\\"; | ||
201 | 297 | } | ||
202 | 298 | } | ||
203 | 299 | return nameLabelsString; | ||
204 | 300 | } | ||
205 | 301 | |||
206 | 302 | private String escapeSpacesInAndOrNot(String str) { | ||
207 | 303 | return str.replace(" and ", "\\ and\\ ").replace(" or", "\\ or\\ ").replace(" not", "\\ not\\ "); | ||
208 | 304 | } | ||
209 | 305 | |||
210 | 296 | private void exportPlaceTokens(Place place, StringBuffer out, int numOfTokens) { | 306 | private void exportPlaceTokens(Place place, StringBuffer out, int numOfTokens) { |
211 | 297 | // Dot radius | 307 | // Dot radius |
212 | 298 | final double tRadius = 1; | 308 | final double tRadius = 1; |
213 | @@ -437,6 +447,116 @@ | |||
214 | 437 | } | 447 | } |
215 | 438 | } | 448 | } |
216 | 439 | 449 | ||
217 | 450 | private StringBuffer exportGlobalVariables() { | ||
218 | 451 | StringBuffer out = new StringBuffer(); | ||
219 | 452 | |||
220 | 453 | Context context = new Context(TAPAALGUI.getCurrentTab()); | ||
221 | 454 | List<ColorType> listColorTypes = context.network().colorTypes(); | ||
222 | 455 | List<Constant> constantsList = new ArrayList<>(context.network().constants()); | ||
223 | 456 | List<Variable> variableList = context.network().variables(); | ||
224 | 457 | |||
225 | 458 | if(!context.network().isColored() || (listColorTypes.isEmpty() && constantsList.isEmpty() && variableList.isEmpty())) { | ||
226 | 459 | out.append("\\node [globalBox] (globalBox) at (current bounding box.north west) [anchor=south west] {"); | ||
227 | 460 | exportConstants(constantsList, out); | ||
228 | 461 | out.append("};"); | ||
229 | 462 | return out; | ||
230 | 463 | } | ||
231 | 464 | |||
232 | 465 | out.append("\\node [globalBox] (globalBox) at (current bounding box.north west) [anchor=south west] {"); | ||
233 | 466 | |||
234 | 467 | exportColorTypes(listColorTypes, out); | ||
235 | 468 | |||
236 | 469 | if(listColorTypes.size() > 0 && (variableList.size() > 0 || constantsList.size() > 0)) { | ||
237 | 470 | out.append("\\\\"); | ||
238 | 471 | } | ||
239 | 472 | |||
240 | 473 | exportVariables(variableList, out); | ||
241 | 474 | |||
242 | 475 | if(variableList.size() > 0 && !constantsList.isEmpty()) { | ||
243 | 476 | out.append("\\\\"); | ||
244 | 477 | } | ||
245 | 478 | |||
246 | 479 | exportConstants(constantsList, out); | ||
247 | 480 | |||
248 | 481 | out.append("};"); | ||
249 | 482 | |||
250 | 483 | return out; | ||
251 | 484 | } | ||
252 | 485 | |||
253 | 486 | private void exportColorTypes(List<ColorType> listColorTypes, StringBuffer out) { | ||
254 | 487 | String stringColorList = ""; | ||
255 | 488 | for(int i = 0; i < listColorTypes.size(); i++) { | ||
256 | 489 | if(i == 0) { | ||
257 | 490 | out.append("Color Types:\\\\"); | ||
258 | 491 | } | ||
259 | 492 | out.append("$\\mathit{" + listColorTypes.get(i).getName() + "}$ \\textbf{is} "); | ||
260 | 493 | |||
261 | 494 | if(listColorTypes.get(i).isProductColorType()) { | ||
262 | 495 | out.append("$\\mathit{<"); | ||
263 | 496 | for(int x = 0; x < listColorTypes.get(i).getProductColorTypes().size(); x++) { | ||
264 | 497 | stringColorList += listColorTypes.get(i).getProductColorTypes().get(x).getName().replace("_", "\\_"); | ||
265 | 498 | |||
266 | 499 | if(x != listColorTypes.get(i).getProductColorTypes().size() - 1){ | ||
267 | 500 | stringColorList += ", "; | ||
268 | 501 | } | ||
269 | 502 | } | ||
270 | 503 | out.append(stringColorList + ">}$\\\\"); | ||
271 | 504 | stringColorList = ""; | ||
272 | 505 | |||
273 | 506 | } else if(listColorTypes.get(i).isIntegerRange()) { | ||
274 | 507 | out.append("$\\mathit{"); | ||
275 | 508 | if(listColorTypes.get(i).size() > 1) { | ||
276 | 509 | int listSize = listColorTypes.get(i).size(); | ||
277 | 510 | out.append("[" + listColorTypes.get(i).getColors().get(0).getColorName().replace("_","\\_") + ".." + listColorTypes.get(i).getColors().get(listSize - 1).getColorName().replace("_","\\_") + "]"); | ||
278 | 511 | } else { | ||
279 | 512 | out.append("[" + listColorTypes.get(i).getFirstColor().getColorName().replace("_","\\_") + "]"); | ||
280 | 513 | } | ||
281 | 514 | out.append("}$\\\\"); | ||
282 | 515 | |||
283 | 516 | } else { | ||
284 | 517 | out.append("$\\mathit{["); | ||
285 | 518 | for(int x = 0; x < listColorTypes.get(i).getColors().size(); x++) { | ||
286 | 519 | stringColorList += listColorTypes.get(i).getColors().get(x).getName().replace("_","\\_"); | ||
287 | 520 | |||
288 | 521 | if(x != listColorTypes.get(i).getColors().size() - 1){ | ||
289 | 522 | stringColorList += ", "; | ||
290 | 523 | } | ||
291 | 524 | } | ||
292 | 525 | out.append(stringColorList + "]}$\\\\"); | ||
293 | 526 | stringColorList = ""; | ||
294 | 527 | } | ||
295 | 528 | } | ||
296 | 529 | } | ||
297 | 530 | |||
298 | 531 | private void exportVariables(List<Variable> variableList, StringBuffer out) { | ||
299 | 532 | String result = ""; | ||
300 | 533 | for(int i = 0; i < variableList.size(); i++) { | ||
301 | 534 | if (i == 0) { | ||
302 | 535 | result += "Variables:\\\\ "; | ||
303 | 536 | } | ||
304 | 537 | result += "$\\mathit{" + variableList.get(i).getName().replace("_","\\_") + " \\textbf{ in } " + variableList.get(i).getColorType().getName().replace("_","\\_") + "}$"; | ||
305 | 538 | if(i != variableList.size() - 1) { | ||
306 | 539 | result += "\\\\"; | ||
307 | 540 | } | ||
308 | 541 | } | ||
309 | 542 | out.append(result); | ||
310 | 543 | } | ||
311 | 544 | |||
312 | 545 | private void exportConstants(List<Constant> constantsList, StringBuffer out) { | ||
313 | 546 | String result = ""; | ||
314 | 547 | |||
315 | 548 | for(int i = 0; i < constantsList.size(); i++) { | ||
316 | 549 | if(i == 0) { | ||
317 | 550 | result += "Constants:\\\\"; | ||
318 | 551 | } | ||
319 | 552 | result += "$\\mathit{" + constantsList.get(i).toString().replace("_","\\_") + "}$"; | ||
320 | 553 | if(i != constantsList.size() - 1) { | ||
321 | 554 | result += "\\\\"; | ||
322 | 555 | } | ||
323 | 556 | } | ||
324 | 557 | out.append(result); | ||
325 | 558 | } | ||
326 | 559 | |||
327 | 440 | protected String getTokenListStringFor(Place place) { | 560 | protected String getTokenListStringFor(Place place) { |
328 | 441 | List<TimedToken> tokens = ((TimedPlaceComponent) place).underlyingPlace().tokens(); | 561 | List<TimedToken> tokens = ((TimedPlaceComponent) place).underlyingPlace().tokens(); |
329 | 442 | 562 | ||
330 | @@ -455,7 +575,7 @@ | |||
331 | 455 | String invariant = ""; | 575 | String invariant = ""; |
332 | 456 | 576 | ||
333 | 457 | if (!((TimedPlaceComponent) place).getInvariantAsString().contains("inf")) | 577 | if (!((TimedPlaceComponent) place).getInvariantAsString().contains("inf")) |
335 | 458 | invariant = "$\\mathrm{" + replaceWithMathLatex(((TimedPlaceComponent) place).getInvariantAsString()) + "}$};\n"; | 578 | invariant = replaceWithMathLatex(((TimedPlaceComponent) place).getInvariantAsString()) + "};\n"; |
336 | 459 | return invariant; | 579 | return invariant; |
337 | 460 | } | 580 | } |
338 | 461 | 581 | ||
339 | @@ -480,12 +600,13 @@ | |||
340 | 480 | StringBuffer out = new StringBuffer(); | 600 | StringBuffer out = new StringBuffer(); |
341 | 481 | 601 | ||
342 | 482 | out.append("\\begin{tikzpicture}[font=\\scriptsize, xscale=0.45, yscale=0.45, x=1.33pt, y=1.33pt]\n"); | 602 | out.append("\\begin{tikzpicture}[font=\\scriptsize, xscale=0.45, yscale=0.45, x=1.33pt, y=1.33pt]\n"); |
344 | 483 | out.append("%% the figure can be scaled by changing xscale and yscale\n"); | 603 | out.append("%% the figure can be scaled by changing xscale and yscale or the size of the x- and y-coordinates\n"); |
345 | 484 | out.append("%% positions of place/transition labels that are currently fixed to label=135 degrees\n"); | 604 | out.append("%% positions of place/transition labels that are currently fixed to label=135 degrees\n"); |
346 | 485 | out.append("%% can be adjusted so that they do not cover arcs\n"); | 605 | out.append("%% can be adjusted so that they do not cover arcs\n"); |
347 | 486 | out.append("%% similarly the curving of arcs can be done by adjusting bend left/right=XX\n"); | 606 | out.append("%% similarly the curving of arcs can be done by adjusting bend left/right=XX\n"); |
350 | 487 | out.append("%% labels may be slightly skewed compared to the tapaal drawing due to rounding.\n"); | 607 | out.append("%% labels may be slightly skewed compared to the Tapaal drawing due to rounding.\n"); |
351 | 488 | out.append("%% This can be adjusted by tuning the coordinates of the label\n"); | 608 | out.append("%% This can be adjusted by tuning the coordinates of the label or adjusting the x- and y-shift for the label\n"); |
352 | 609 | out.append("%% The box containing global variables can also be moved by adjusting the anchor points / bounding box in the [globalBox] node at the end of the Tikz document\n"); | ||
353 | 489 | out.append("\\tikzstyle{arc}=[->,>=stealth,thick]\n"); | 610 | out.append("\\tikzstyle{arc}=[->,>=stealth,thick]\n"); |
354 | 490 | 611 | ||
355 | 491 | out.append("\\tikzstyle{transportArc}=[->,>=diamond,thick]\n"); | 612 | out.append("\\tikzstyle{transportArc}=[->,>=diamond,thick]\n"); |
356 | @@ -496,39 +617,24 @@ | |||
357 | 496 | out.append("\\tikzstyle{every token}=[fill=white,text=black]\n"); | 617 | out.append("\\tikzstyle{every token}=[fill=white,text=black]\n"); |
358 | 497 | out.append("\\tikzstyle{sharedplace}=[place,minimum size=7.5mm,dashed,thin]\n"); | 618 | out.append("\\tikzstyle{sharedplace}=[place,minimum size=7.5mm,dashed,thin]\n"); |
359 | 498 | out.append("\\tikzstyle{sharedtransition}=[transition, fill opacity=0, minimum width=3.5mm, minimum height=6.5mm,dashed]\n"); | 619 | out.append("\\tikzstyle{sharedtransition}=[transition, fill opacity=0, minimum width=3.5mm, minimum height=6.5mm,dashed]\n"); |
362 | 499 | out.append("\\tikzstyle{urgenttransition}=[place,fill=white,minimum size=2.0mm,thin]"); | 620 | out.append("\\tikzstyle{urgenttransition}=[place,fill=white,minimum size=2.0mm,thin]\n"); |
363 | 500 | out.append("\\tikzstyle{uncontrollabletransition}=[transition,fill=white,draw=black,very thick]"); | 621 | out.append("\\tikzstyle{uncontrollabletransition}=[transition,fill=white,draw=black,very thick]\n"); |
364 | 622 | out.append("\\tikzstyle{globalBox} = [draw,thick,align=left]"); | ||
365 | 501 | return out; | 623 | return out; |
366 | 502 | } | 624 | } |
367 | 503 | 625 | ||
368 | 504 | protected String replaceWithMathLatex(String text) { | 626 | protected String replaceWithMathLatex(String text) { |
398 | 505 | return text.replace("inf", "\\infty").replace("<=", "\\leq ").replace("*", "\\cdot "); | 627 | String[] stringList = text.split(" "); |
399 | 506 | } | 628 | String result = ""; |
400 | 507 | 629 | ||
401 | 508 | private String exportMathName(String name) { | 630 | for(int i = 0; i < stringList.length; i++) { |
402 | 509 | StringBuilder out = new StringBuilder("$\\mathrm{"); | 631 | result += "$\\mathit{" + replaceSpecialSymbols(stringList[i]) + "}$ "; |
403 | 510 | int subscripts = 0; | 632 | } |
404 | 511 | for (int i = 0; i < name.length() - 1; i++) { | 633 | return result; |
405 | 512 | char c = name.charAt(i); | 634 | } |
406 | 513 | if (c == '_') { | 635 | |
407 | 514 | out.append("_{"); | 636 | protected String replaceSpecialSymbols(String text) { |
408 | 515 | subscripts++; | 637 | return text.replace("inf", "\\infty").replace("<=", "\\leq").replace("*", "\\cdot") |
409 | 516 | } else { | 638 | .replace("\u2192", "\\rightarrow").replace("\u221E", "\\infty"); |
410 | 517 | out.append(c); | 639 | } |
382 | 518 | } | ||
383 | 519 | } | ||
384 | 520 | |||
385 | 521 | char last = name.charAt(name.length() - 1); | ||
386 | 522 | if (last == '_') { | ||
387 | 523 | out.append("\\_"); | ||
388 | 524 | } else | ||
389 | 525 | out.append(last); | ||
390 | 526 | |||
391 | 527 | for (int i = 0; i < subscripts; i++) { | ||
392 | 528 | out.append('}'); | ||
393 | 529 | } | ||
394 | 530 | out.append("}$"); | ||
395 | 531 | return out.toString(); | ||
396 | 532 | } | ||
397 | 533 | |||
411 | 534 | } | 640 | } |