Merge lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support into lp:~tapaal-contributor/tapaal/cpn-gui-dev

Proposed by Kristian Morsing Pedersen
Status: Merged
Approved by: Jiri Srba
Approved revision: 1579
Merged at revision: 1622
Proposed branch: lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support
Merge into: lp:~tapaal-contributor/tapaal/cpn-gui-dev
Diff against target: 491 lines (+206/-139)
1 file modified
src/net/tapaal/export/TikZExporter.java (+206/-139)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Kenneth Yrke Jørgensen code Pending
Review via email: mp+416464@code.launchpad.net

This proposal supersedes a proposal from 2022-03-06.

Commit message

Added TikZ support for colored nets.
Added a framed box to the Tikz output for global variables/constants/color types.
Removed subscripiting from transition- and place names
Changed \mathrm to \mathit
Added more adjustment options for transitions, places and arcs
Merged with cpn-gui-dev

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.
Subscripting from transition- and place names have been removed, so it looks more like the GUI.
\mathrm has also been replaces with \mathit.

To post a comment you must log in.
Revision history for this message
Kenneth Yrke Jørgensen (yrke) : Posted in a previous version of this proposal
review: Approve (code)
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

It would be nice if instead of (in referendum colored timed):

1′v[1, 2]Voters1 → [1, 4]

one would print:

1′v
[1, 2]
Voters1 → [1, 4]

(on three sepratate lines).

review: Needs Fixing
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

Please, set the default position for arc lables to pos=0.5

review: Needs Fixing
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

At the end of the labels, there is a redundant \\ that makes the spacing look ugly. E.g. in

\node[place, label={[align=left,label distance=0cm]270:$\mathrm{voting} ... $\mathit{4}$ \\}] at (390,-345) (voting) {};

The label should finish with just ... $\mathit{4}$ }] without the extra \\

review: Needs Fixing
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

Also, when exporting age of tokens in the initial marking, please write 0.0 instead of 0,0

review: Needs Fixing
Revision history for this message
Jiri Srba (srba) wrote :

In the tikz export of weights, please use 10\times instead of 10x.

Also, nets that are not colored seem to be exported without the relative label positions. Could all nets be exported to Tikz using the same relative positions as for CPNs?

review: Needs Fixing
1579. By Kristian Morsing Pedersen <email address hidden>

Changed x -> \times in inhibitor arcs

Revision history for this message
Jiri Srba (srba) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/net/tapaal/export/TikZExporter.java'
--- src/net/tapaal/export/TikZExporter.java 2022-02-21 19:46:59 +0000
+++ src/net/tapaal/export/TikZExporter.java 2022-03-09 14:15:46 +0000
@@ -3,16 +3,17 @@
3import java.io.FileWriter;3import java.io.FileWriter;
4import java.io.IOException;4import java.io.IOException;
5import java.io.PrintWriter;5import java.io.PrintWriter;
6import java.util.List;6import java.util.*;
77
8import dk.aau.cs.model.CPN.ColorType;
9import dk.aau.cs.model.CPN.Variable;
10import dk.aau.cs.model.tapn.Constant;
8import dk.aau.cs.model.tapn.TimedToken;11import dk.aau.cs.model.tapn.TimedToken;
912
13import net.tapaal.gui.petrinet.Context;
10import pipe.gui.petrinet.dataLayer.DataLayer;14import pipe.gui.petrinet.dataLayer.DataLayer;
11import pipe.gui.TAPAALGUI;15import pipe.gui.TAPAALGUI;
12import pipe.gui.petrinet.graphicElements.Arc;16import pipe.gui.petrinet.graphicElements.*;
13import pipe.gui.petrinet.graphicElements.ArcPathPoint;
14import pipe.gui.petrinet.graphicElements.Place;
15import pipe.gui.petrinet.graphicElements.Transition;
16import pipe.gui.petrinet.graphicElements.tapn.TimedInhibitorArcComponent;17import pipe.gui.petrinet.graphicElements.tapn.TimedInhibitorArcComponent;
17import pipe.gui.petrinet.graphicElements.tapn.TimedInputArcComponent;18import pipe.gui.petrinet.graphicElements.tapn.TimedInputArcComponent;
18import pipe.gui.petrinet.graphicElements.tapn.TimedPlaceComponent;19import pipe.gui.petrinet.graphicElements.tapn.TimedPlaceComponent;
@@ -45,7 +46,7 @@
45 if (option == TikZOutputOption.FULL_LATEX) {46 if (option == TikZOutputOption.FULL_LATEX) {
46 out.println("\\documentclass[a4paper]{article}");47 out.println("\\documentclass[a4paper]{article}");
47 out.println("\\usepackage{tikz}");48 out.println("\\usepackage{tikz}");
48 out.println("\\usetikzlibrary{petri,arrows}");49 out.println("\\usetikzlibrary{petri,arrows,positioning}");
49 out.println("\\usepackage{amstext}");50 out.println("\\usepackage{amstext}");
50 out.println();51 out.println();
51 out.println("\\begin{document}");52 out.println("\\begin{document}");
@@ -62,6 +63,8 @@
62 out.print(exportTransitions(net.getTransitions()));63 out.print(exportTransitions(net.getTransitions()));
63 out.print(exportArcs(net.getArcs()));64 out.print(exportArcs(net.getArcs()));
6465
66 out.println(exportGlobalVariables());
67
65 out.println("\\end{tikzpicture}");68 out.println("\\end{tikzpicture}");
66 if (option == TikZOutputOption.FULL_LATEX) {69 if (option == TikZOutputOption.FULL_LATEX) {
67 out.println("\\end{document}");70 out.println("\\end{document}");
@@ -94,7 +97,7 @@
94 ArcPathPoint currentPoint = arc.getArcPath().getArcPathPoint(i);97 ArcPathPoint currentPoint = arc.getArcPath().getArcPathPoint(i);
9598
96 if(currentPoint.getPointType() == ArcPathPoint.STRAIGHT) {99 if(currentPoint.getPointType() == ArcPathPoint.STRAIGHT) {
97 arcPoints += "to[bend right=0] (" + (currentPoint.getX()) + "," + (currentPoint.getY() * (-1)) + ") ";100 arcPoints += "to [bend right=0] (" + (currentPoint.getX()) + "," + (currentPoint.getY() * (-1)) + ") ";
98 } else if (currentPoint.getPointType() == ArcPathPoint.CURVED) {101 } else if (currentPoint.getPointType() == ArcPathPoint.CURVED) {
99 double xCtrl1 = Math.round(currentPoint.getControl1().getX());102 double xCtrl1 = Math.round(currentPoint.getControl1().getX());
100 double yCtrl1 = Math.round(currentPoint.getControl1().getY() * (-1));103 double yCtrl1 = Math.round(currentPoint.getControl1().getY() * (-1));
@@ -109,21 +112,25 @@
109 }112 }
110113
111 String arrowType = getArcArrowType(arc);114 String arrowType = getArcArrowType(arc);
112 String arcLabel = getArcLabels(arc);
113115
116 out.append("% Arc between " + arc.getSource().getName() + " and " + arc.getTarget().getName() + "\n");
114 out.append("\\draw[");117 out.append("\\draw[");
115 out.append(arrowType);118 out.append(arrowType);
116 out.append("] (");119 out.append(",pos=0.5] (");
117 out.append(arc.getSource().getId());120 out.append(arc.getSource().getId());
118 out.append(") ");121 out.append(") ");
119 out.append(arcPoints);122 out.append(arcPoints);
120 out.append("to[bend right=0]");123 out.append("to node[bend right=0,auto,align=left]");
121 out.append(" (");124 out.append(" {");
122 out.append(arc.getTarget().getId());125
123 out.append(") {};\n");126 if(arrowType.equals("inhibArc")) {
124 if(!arcLabel.equals(""))127 out.append(handleNameLabel(arc.getNameLabel().getText().replace("x","\\times")));
125 out.append("%% Label for arc between " + arc.getSource().getName() + " and " + arc.getTarget().getName() + "\n");128 } else {
126 out.append(arcLabel);129 out.append(handleNameLabel(arc.getNameLabel().getText()));
130 }
131
132 out.append("} ");
133 out.append("(" + arc.getTarget().getId() + ");\n");
127 }134 }
128 return out;135 return out;
129 }136 }
@@ -142,50 +149,6 @@
142 return arrowType;149 return arrowType;
143 }150 }
144151
145 protected String getArcLabels(Arc arc) {
146 String arcLabel = "";
147 String arcLabelPositionString = "\\draw (" + (arc.getNameLabel().getX()) + "," + (arc.getNameLabel().getY())*(-1) + ") node {";
148
149 if (arc instanceof TimedInputArcComponent) {
150 if (!(arc.getSource() instanceof TimedTransitionComponent)) {
151 arcLabel = arcLabelPositionString;
152 if (arc.getWeight().value() > 1) {
153 arcLabel += "$" + arc.getWeight().value() + "\\times$\\ ";
154 }
155
156 if(TAPAALGUI.getCurrentTab().getLens().isTimed()) {
157 arcLabel += "$\\mathrm{" + replaceWithMathLatex(getGuardAsStringIfNotHidden((TimedInputArcComponent) arc)) + "}$";
158 if (arc instanceof TimedTransportArcComponent)
159 arcLabel += ":" + ((TimedTransportArcComponent) arc).getGroupNr();
160 arcLabel += "};\n";
161 } else {
162 arcLabel += "};\n";
163 }
164
165 } else {
166 arcLabel = arcLabelPositionString;
167 if (arc.getWeight().value() > 1) {
168 arcLabel += "$" + arc.getWeight().value() + "\\times$\\ ";
169 }
170 arcLabel += ":" + ((TimedTransportArcComponent) arc).getGroupNr() + "};\n";
171 }
172
173 } else {
174 if (arc.getWeight().value() > 1) {
175 arcLabel += arcLabelPositionString + "$" + arc.getWeight().value() + "\\times$\\ };\n";
176 }
177 }
178 return arcLabel;
179 }
180
181 private String getGuardAsStringIfNotHidden(TimedInputArcComponent arc) {
182 if (!TAPAALGUI.getAppGui().showZeroToInfinityIntervals() && arc.getGuardAsString().equals("[0,inf)")){
183 return "";
184 } else {
185 return arc.getGuardAsString();
186 }
187 }
188
189 private StringBuffer exportTransitions(Transition[] transitions) {152 private StringBuffer exportTransitions(Transition[] transitions) {
190 StringBuffer out = new StringBuffer();153 StringBuffer out = new StringBuffer();
191 for (Transition trans : transitions) {154 for (Transition trans : transitions) {
@@ -195,7 +158,8 @@
195158
196159
197 out.append("\\node[transition");160 out.append("\\node[transition");
198 out.append(angle); 161 out.append(angle);
162 out.append(handlePlaceAndTransitionLabel(trans.getNameLabel().getText(), trans.getName(), trans.getAttributesVisible()));
199 out.append("] at (");163 out.append("] at (");
200 out.append((trans.getPositionX()));164 out.append((trans.getPositionX()));
201 out.append(',');165 out.append(',');
@@ -226,31 +190,30 @@
226 out.append(trans.getId());190 out.append(trans.getId());
227 out.append(".center) { };\n");191 out.append(".center) { };\n");
228 }192 }
229 if (trans.getAttributesVisible()){
230 boolean isLabelAboveTransition = trans.getY() > trans.getNameLabel().getY();
231 boolean isLabelBehindTrans = trans.getX() < trans.getNameLabel().getX();
232 double xOffset = trans.getName().length() > 5 && !isLabelAboveTransition && !isLabelBehindTrans ? trans.getLayerOffset() : 0;
233
234 out.append("%% label for transition " + trans.getName() + "\n");
235 out.append("\\draw (");
236 out.append(trans.getNameLabel().getX() + xOffset + "," + (trans.getNameLabel().getY() * -1) + ")");
237 out.append(" node ");
238 out.append(" {");
239 out.append(exportMathName(trans.getName()));
240 out.append("};\n");
241 }
242 }193 }
243 return out;194 return out;
244 }195 }
245196
197 private String handlePlaceAndTransitionLabel(String nameLabelText, String name, boolean isVisible) {
198 if(!isVisible)
199 return "";
200
201 String result = ", label={[align=left,label distance=0cm]90:";
202 result += "$\\mathrm{" + (name.replace("_","\\_")) + "}$";
203 result += handleNameLabel(nameLabelText);
204 result += "}";
205 return result;
206 }
207
246 private StringBuffer exportPlacesWithTokens(Place[] places) {208 private StringBuffer exportPlacesWithTokens(Place[] places) {
247 StringBuffer out = new StringBuffer();209 StringBuffer out = new StringBuffer();
248210
249 for (Place place : places) {211 for (Place place : places) {
250 String invariant = getPlaceInvariantString(place);212 String invariant = "$" + getPlaceInvariantString(place) + "$";
251 String tokensInPlace = getTokenListStringFor(place);213 String tokensInPlace = getTokenListStringFor(place);
252214
253 out.append("\\node[place");215 out.append("\\node[place");
216 out.append(handlePlaceAndTransitionLabel(place.getNameLabel().getText(), place.getName(), place.getAttributesVisible()));
254 out.append("] at (");217 out.append("] at (");
255 out.append(place.getPositionX());218 out.append(place.getPositionX());
256 out.append(',');219 out.append(',');
@@ -262,37 +225,36 @@
262 exportPlaceTokens(place, out, ((TimedPlaceComponent) place).underlyingPlace().tokens().size());225 exportPlaceTokens(place, out, ((TimedPlaceComponent) place).underlyingPlace().tokens().size());
263 226
264 if(((TimedPlaceComponent)place).underlyingPlace().isShared()){227 if(((TimedPlaceComponent)place).underlyingPlace().isShared()){
265 out.append("\\node[sharedplace] at (");228 out.append("\\node[sharedplace ");
229 out.append("] at (");
266 out.append(place.getId());230 out.append(place.getId());
267 out.append(".center) { };\n");231 out.append(".center) { };\n");
268 }232 }
269 if (place.getAttributesVisible() || !invariant.equals("")){
270 boolean isLabelAbovePlace = place.getY() > place.getNameLabel().getY();
271 boolean isLabelBehindPlace = place.getX() < place.getNameLabel().getX();
272 double xOffset = place.getName().length() > 6 && !isLabelAbovePlace && !isLabelBehindPlace ? place.getLayerOffset() : 0;
273 double yOffset = isLabelAbovePlace ? (place.getNameLabel().getHeight() / 2) : 0;
274
275 out.append("%% label for place " + place.getName() + "\n");
276 out.append("\\draw (");
277 out.append((place.getNameLabel().getX() + xOffset) + "," + ((place.getNameLabel().getY() * -1) + yOffset) +")");
278 out.append(" node[align=left] ");
279 out.append("{");
280 if(place.getAttributesVisible())
281 out.append(exportMathName(place.getName()));
282 if(!invariant.equals("")) {
283 if((place.getAttributesVisible()))
284 out.append("\\\\");
285 out.append(invariant);
286 }else {
287 out.append("};\n");
288 }
289
290 }
291 }233 }
292
293 return out;234 return out;
294 }235 }
295236
237 private String handleNameLabel(String nameLabel) {
238 String nameLabelsString = "";
239 String[] labelsInName = nameLabel.split("\n");
240 for(int i = 0; i < labelsInName.length; i++) {
241 if(labelsInName[i].contains("[")) {
242 nameLabelsString += escapeSpacesInAndOrNot(replaceWithMathLatex(labelsInName[i]));
243 }
244 else if(!labelsInName[i].isEmpty()){
245 nameLabelsString += escapeSpacesInAndOrNot(replaceWithMathLatex(labelsInName[i]));
246 }
247 if(i != labelsInName.length - 1) {
248 nameLabelsString += "\\\\";
249 }
250 }
251 return nameLabelsString;
252 }
253
254 private String escapeSpacesInAndOrNot(String str) {
255 return str.replace(" and ", "\\ and\\ ").replace(" or", "\\ or\\ ").replace(" not", "\\ not\\ ");
256 }
257
296 private void exportPlaceTokens(Place place, StringBuffer out, int numOfTokens) {258 private void exportPlaceTokens(Place place, StringBuffer out, int numOfTokens) {
297 // Dot radius259 // Dot radius
298 final double tRadius = 1;260 final double tRadius = 1;
@@ -317,14 +279,14 @@
317 out.append(",");279 out.append(",");
318 out.append(placeYpos + 4);280 out.append(placeYpos + 4);
319 out.append(")");281 out.append(")");
320 out.append("{0,0};\n");282 out.append("{0.0};\n");
321283
322 out.append("\\node at ("); // Bottom284 out.append("\\node at ("); // Bottom
323 out.append(placeXpos);285 out.append(placeXpos);
324 out.append(",");286 out.append(",");
325 out.append(placeYpos - 5);287 out.append(placeYpos - 5);
326 out.append(")");288 out.append(")");
327 out.append("{0,0};\n");289 out.append("{0.0};\n");
328 return;290 return;
329 case 1:291 case 1:
330 out.append("\\node at ("); // Top292 out.append("\\node at ("); // Top
@@ -332,7 +294,7 @@
332 out.append(",");294 out.append(",");
333 out.append(placeYpos);295 out.append(placeYpos);
334 out.append(")");296 out.append(")");
335 out.append("{0,0};\n");297 out.append("{0.0};\n");
336 return;298 return;
337 default:299 default:
338 out.append("\\node at (");300 out.append("\\node at (");
@@ -437,6 +399,124 @@
437 }399 }
438 }400 }
439401
402 private StringBuffer exportGlobalVariables() {
403 StringBuffer out = new StringBuffer();
404
405 Context context = new Context(TAPAALGUI.getCurrentTab());
406 List<ColorType> listColorTypes = context.network().colorTypes();
407 List<Constant> constantsList = new ArrayList<>(context.network().constants());
408 List<Variable> variableList = context.network().variables();
409
410 if(!context.network().isColored()) {
411 if(constantsList.isEmpty()) {
412 return out;
413 }
414 out.append("%%Global box which contains global color types, variables and/or constants.\n");
415 out.append("\\node [globalBox] (globalBox) at (current bounding box.north west) [anchor=south west] {");
416 exportConstants(constantsList, out);
417 out.append("};");
418 return out;
419 }
420
421 if((listColorTypes.isEmpty() && constantsList.isEmpty() && variableList.isEmpty()))
422 return out;
423
424 out.append("%%Global box which contains global color types, variables and/or constants.\n");
425 out.append("\\node [globalBox] (globalBox) at (current bounding box.north west) [anchor=south west] {");
426
427 exportColorTypes(listColorTypes, out);
428
429 if(listColorTypes.size() > 0 && (variableList.size() > 0 || constantsList.size() > 0)) {
430 out.append("\\\\");
431 }
432
433 exportVariables(variableList, out);
434
435 if(variableList.size() > 0 && !constantsList.isEmpty()) {
436 out.append("\\\\");
437 }
438
439 exportConstants(constantsList, out);
440
441 out.append("};");
442
443 return out;
444 }
445
446 private void exportColorTypes(List<ColorType> listColorTypes, StringBuffer out) {
447 String stringColorList = "";
448 for(int i = 0; i < listColorTypes.size(); i++) {
449 if(i == 0) {
450 out.append("Color Types:\\\\");
451 }
452 out.append("$\\mathit{" + listColorTypes.get(i).getName() + "}$ \\textbf{is} ");
453
454 if(listColorTypes.get(i).isProductColorType()) {
455 out.append("$\\mathit{<");
456 for(int x = 0; x < listColorTypes.get(i).getProductColorTypes().size(); x++) {
457 stringColorList += listColorTypes.get(i).getProductColorTypes().get(x).getName().replace("_", "\\_");
458
459 if(x != listColorTypes.get(i).getProductColorTypes().size() - 1){
460 stringColorList += ", ";
461 }
462 }
463 out.append(stringColorList + ">}$\\\\");
464 stringColorList = "";
465
466 } else if(listColorTypes.get(i).isIntegerRange()) {
467 out.append("$\\mathit{");
468 if(listColorTypes.get(i).size() > 1) {
469 int listSize = listColorTypes.get(i).size();
470 out.append("[" + listColorTypes.get(i).getColors().get(0).getColorName().replace("_","\\_") + ".." + listColorTypes.get(i).getColors().get(listSize - 1).getColorName().replace("_","\\_") + "]");
471 } else {
472 out.append("[" + listColorTypes.get(i).getFirstColor().getColorName().replace("_","\\_") + "]");
473 }
474 out.append("}$\\\\");
475
476 } else {
477 out.append("$\\mathit{[");
478 for(int x = 0; x < listColorTypes.get(i).getColors().size(); x++) {
479 stringColorList += listColorTypes.get(i).getColors().get(x).getName().replace("_","\\_");
480
481 if(x != listColorTypes.get(i).getColors().size() - 1){
482 stringColorList += ", ";
483 }
484 }
485 out.append(stringColorList + "]}$\\\\");
486 stringColorList = "";
487 }
488 }
489 }
490
491 private void exportVariables(List<Variable> variableList, StringBuffer out) {
492 String result = "";
493 for(int i = 0; i < variableList.size(); i++) {
494 if (i == 0) {
495 result += "Variables:\\\\ ";
496 }
497 result += "$\\mathit{" + variableList.get(i).getName().replace("_","\\_") + " \\textbf{ in } " + variableList.get(i).getColorType().getName().replace("_","\\_") + "}$";
498 if(i != variableList.size() - 1) {
499 result += "\\\\";
500 }
501 }
502 out.append(result);
503 }
504
505 private void exportConstants(List<Constant> constantsList, StringBuffer out) {
506 String result = "";
507
508 for(int i = 0; i < constantsList.size(); i++) {
509 if(i == 0) {
510 result += "Constants:\\\\";
511 }
512 result += "$\\mathit{" + constantsList.get(i).toString().replace("_","\\_") + "}$";
513 if(i != constantsList.size() - 1) {
514 result += "\\\\";
515 }
516 }
517 out.append(result);
518 }
519
440 protected String getTokenListStringFor(Place place) {520 protected String getTokenListStringFor(Place place) {
441 List<TimedToken> tokens = ((TimedPlaceComponent) place).underlyingPlace().tokens();521 List<TimedToken> tokens = ((TimedPlaceComponent) place).underlyingPlace().tokens();
442522
@@ -455,7 +535,7 @@
455 String invariant = "";535 String invariant = "";
456536
457 if (!((TimedPlaceComponent) place).getInvariantAsString().contains("inf"))537 if (!((TimedPlaceComponent) place).getInvariantAsString().contains("inf"))
458 invariant = "$\\mathrm{" + replaceWithMathLatex(((TimedPlaceComponent) place).getInvariantAsString()) + "}$};\n";538 invariant = replaceWithMathLatex(((TimedPlaceComponent) place).getInvariantAsString()) + "};\n";
459 return invariant;539 return invariant;
460 }540 }
461541
@@ -480,12 +560,14 @@
480 StringBuffer out = new StringBuffer();560 StringBuffer out = new StringBuffer();
481561
482 out.append("\\begin{tikzpicture}[font=\\scriptsize, xscale=0.45, yscale=0.45, x=1.33pt, y=1.33pt]\n");562 out.append("\\begin{tikzpicture}[font=\\scriptsize, xscale=0.45, yscale=0.45, x=1.33pt, y=1.33pt]\n");
483 out.append("%% the figure can be scaled by changing xscale and yscale\n");563 out.append("%% the figure can be scaled by changing xscale and yscale or the size of the x- and y-coordinates\n");
484 out.append("%% positions of place/transition labels that are currently fixed to label=135 degrees\n");564 out.append("%% positions of place/transition labels that are currently fixed to label=135 degrees\n");
485 out.append("%% can be adjusted so that they do not cover arcs\n");565 out.append("%% these can be adjusted by adjusting either the coordinates, the label distance or the label degree\n");
486 out.append("%% similarly the curving of arcs can be done by adjusting bend left/right=XX\n");566 out.append("%% that is placed right after the 'label-distance'. 90: is above (default), 180 is left, 270 is below etc.\n");
487 out.append("%% labels may be slightly skewed compared to the tapaal drawing due to rounding.\n");567 out.append("%% The curving of arcs can be done by adjusting bend left/right=XX\n");
488 out.append("%% This can be adjusted by tuning the coordinates of the label\n");568 out.append("%% labels may be slightly skewed compared to the Tapaal drawing due to rounding.\n");
569 out.append("%% This can be adjusted by tuning the coordinates of the label, or the degree (see above)\n");
570 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");
489 out.append("\\tikzstyle{arc}=[->,>=stealth,thick]\n");571 out.append("\\tikzstyle{arc}=[->,>=stealth,thick]\n");
490572
491 out.append("\\tikzstyle{transportArc}=[->,>=diamond,thick]\n");573 out.append("\\tikzstyle{transportArc}=[->,>=diamond,thick]\n");
@@ -496,39 +578,24 @@
496 out.append("\\tikzstyle{every token}=[fill=white,text=black]\n");578 out.append("\\tikzstyle{every token}=[fill=white,text=black]\n");
497 out.append("\\tikzstyle{sharedplace}=[place,minimum size=7.5mm,dashed,thin]\n");579 out.append("\\tikzstyle{sharedplace}=[place,minimum size=7.5mm,dashed,thin]\n");
498 out.append("\\tikzstyle{sharedtransition}=[transition, fill opacity=0, minimum width=3.5mm, minimum height=6.5mm,dashed]\n");580 out.append("\\tikzstyle{sharedtransition}=[transition, fill opacity=0, minimum width=3.5mm, minimum height=6.5mm,dashed]\n");
499 out.append("\\tikzstyle{urgenttransition}=[place,fill=white,minimum size=2.0mm,thin]");581 out.append("\\tikzstyle{urgenttransition}=[place,fill=white,minimum size=2.0mm,thin]\n");
500 out.append("\\tikzstyle{uncontrollabletransition}=[transition,fill=white,draw=black,very thick]");582 out.append("\\tikzstyle{uncontrollabletransition}=[transition,fill=white,draw=black,very thick]\n");
583 out.append("\\tikzstyle{globalBox} = [draw,thick,align=left]");
501 return out;584 return out;
502 }585 }
503586
504 protected String replaceWithMathLatex(String text) {587 protected String replaceWithMathLatex(String text) {
505 return text.replace("inf", "\\infty").replace("<=", "\\leq ").replace("*", "\\cdot ");588 String[] stringList = text.split(" ");
506 }589 String result = "";
507590
508 private String exportMathName(String name) {591 for(int i = 0; i < stringList.length; i++) {
509 StringBuilder out = new StringBuilder("$\\mathrm{");592 result += "$\\mathit{" + replaceSpecialSymbols(stringList[i]) + "}$ ";
510 int subscripts = 0;593 }
511 for (int i = 0; i < name.length() - 1; i++) {594 return result;
512 char c = name.charAt(i);595 }
513 if (c == '_') {596
514 out.append("_{");597 protected String replaceSpecialSymbols(String text) {
515 subscripts++;598 return text.replace("inf", "\\infty").replace("<=", "\\leq").replace("*", "\\cdot")
516 } else {599 .replace("\u2192", "\\rightarrow").replace("\u221E", "\\infty");
517 out.append(c);600 }
518 }
519 }
520
521 char last = name.charAt(name.length() - 1);
522 if (last == '_') {
523 out.append("\\_");
524 } else
525 out.append(last);
526
527 for (int i = 0; i < subscripts; i++) {
528 out.append('}');
529 }
530 out.append("}$");
531 return out.toString();
532 }
533
534}601}

Subscribers

People subscribed via source and target branches

to all changes: