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

Proposed by Kristian Morsing Pedersen
Status: Superseded
Proposed branch: lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support
Merge into: lp:~tapaal-contributor/tapaal/cpn-gui-dev
Diff against target: 485 lines (+200/-139)
1 file modified
src/net/tapaal/export/TikZExporter.java (+200/-139)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/cpn-gui-TikZ-support
Reviewer Review Type Date Requested Status
Jiri Srba Needs Fixing
Kenneth Yrke Jørgensen code Pending
Review via email: mp+416423@code.launchpad.net

This proposal supersedes a proposal from 2022-02-21.

This proposal has been superseded by a proposal from 2022-03-07.

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 :

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 :

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

review: Needs Fixing
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

[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-07 14:26:18 +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,19 @@
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 out.append(handleNameLabel(arc.getNameLabel().getText()));
123 out.append(") {};\n");126 out.append("} ");
124 if(!arcLabel.equals(""))127 out.append("(" + arc.getTarget().getId() + ");\n");
125 out.append("%% Label for arc between " + arc.getSource().getName() + " and " + arc.getTarget().getName() + "\n");
126 out.append(arcLabel);
127 }128 }
128 return out;129 return out;
129 }130 }
@@ -142,50 +143,6 @@
142 return arrowType;143 return arrowType;
143 }144 }
144145
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) {146 private StringBuffer exportTransitions(Transition[] transitions) {
190 StringBuffer out = new StringBuffer();147 StringBuffer out = new StringBuffer();
191 for (Transition trans : transitions) {148 for (Transition trans : transitions) {
@@ -195,7 +152,8 @@
195152
196153
197 out.append("\\node[transition");154 out.append("\\node[transition");
198 out.append(angle); 155 out.append(angle);
156 out.append(handlePlaceAndTransitionLabel(trans.getNameLabel().getText(), trans.getName(), trans.getAttributesVisible()));
199 out.append("] at (");157 out.append("] at (");
200 out.append((trans.getPositionX()));158 out.append((trans.getPositionX()));
201 out.append(',');159 out.append(',');
@@ -226,31 +184,30 @@
226 out.append(trans.getId());184 out.append(trans.getId());
227 out.append(".center) { };\n");185 out.append(".center) { };\n");
228 }186 }
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 }187 }
243 return out;188 return out;
244 }189 }
245190
191 private String handlePlaceAndTransitionLabel(String nameLabelText, String name, boolean isVisible) {
192 if(!isVisible)
193 return "";
194
195 String result = ", label={[align=left,label distance=0cm]90:";
196 result += "$\\mathrm{" + (name.replace("_","\\_")) + "}$";
197 result += handleNameLabel(nameLabelText);
198 result += "}";
199 return result;
200 }
201
246 private StringBuffer exportPlacesWithTokens(Place[] places) {202 private StringBuffer exportPlacesWithTokens(Place[] places) {
247 StringBuffer out = new StringBuffer();203 StringBuffer out = new StringBuffer();
248204
249 for (Place place : places) {205 for (Place place : places) {
250 String invariant = getPlaceInvariantString(place);206 String invariant = "$" + getPlaceInvariantString(place) + "$";
251 String tokensInPlace = getTokenListStringFor(place);207 String tokensInPlace = getTokenListStringFor(place);
252208
253 out.append("\\node[place");209 out.append("\\node[place");
210 out.append(handlePlaceAndTransitionLabel(place.getNameLabel().getText(), place.getName(), place.getAttributesVisible()));
254 out.append("] at (");211 out.append("] at (");
255 out.append(place.getPositionX());212 out.append(place.getPositionX());
256 out.append(',');213 out.append(',');
@@ -262,37 +219,36 @@
262 exportPlaceTokens(place, out, ((TimedPlaceComponent) place).underlyingPlace().tokens().size());219 exportPlaceTokens(place, out, ((TimedPlaceComponent) place).underlyingPlace().tokens().size());
263 220
264 if(((TimedPlaceComponent)place).underlyingPlace().isShared()){221 if(((TimedPlaceComponent)place).underlyingPlace().isShared()){
265 out.append("\\node[sharedplace] at (");222 out.append("\\node[sharedplace ");
223 out.append("] at (");
266 out.append(place.getId());224 out.append(place.getId());
267 out.append(".center) { };\n");225 out.append(".center) { };\n");
268 }226 }
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 }227 }
292
293 return out;228 return out;
294 }229 }
295230
231 private String handleNameLabel(String nameLabel) {
232 String nameLabelsString = "";
233 String[] labelsInName = nameLabel.split("\n");
234 for(int i = 0; i < labelsInName.length; i++) {
235 if(labelsInName[i].contains("[")) {
236 nameLabelsString += escapeSpacesInAndOrNot(replaceWithMathLatex(labelsInName[i]));
237 }
238 else if(!labelsInName[i].isEmpty()){
239 nameLabelsString += escapeSpacesInAndOrNot(replaceWithMathLatex(labelsInName[i]));
240 }
241 if(i != labelsInName.length - 1) {
242 nameLabelsString += "\\\\";
243 }
244 }
245 return nameLabelsString;
246 }
247
248 private String escapeSpacesInAndOrNot(String str) {
249 return str.replace(" and ", "\\ and\\ ").replace(" or", "\\ or\\ ").replace(" not", "\\ not\\ ");
250 }
251
296 private void exportPlaceTokens(Place place, StringBuffer out, int numOfTokens) {252 private void exportPlaceTokens(Place place, StringBuffer out, int numOfTokens) {
297 // Dot radius253 // Dot radius
298 final double tRadius = 1;254 final double tRadius = 1;
@@ -317,14 +273,14 @@
317 out.append(",");273 out.append(",");
318 out.append(placeYpos + 4);274 out.append(placeYpos + 4);
319 out.append(")");275 out.append(")");
320 out.append("{0,0};\n");276 out.append("{0.0};\n");
321277
322 out.append("\\node at ("); // Bottom278 out.append("\\node at ("); // Bottom
323 out.append(placeXpos);279 out.append(placeXpos);
324 out.append(",");280 out.append(",");
325 out.append(placeYpos - 5);281 out.append(placeYpos - 5);
326 out.append(")");282 out.append(")");
327 out.append("{0,0};\n");283 out.append("{0.0};\n");
328 return;284 return;
329 case 1:285 case 1:
330 out.append("\\node at ("); // Top286 out.append("\\node at ("); // Top
@@ -332,7 +288,7 @@
332 out.append(",");288 out.append(",");
333 out.append(placeYpos);289 out.append(placeYpos);
334 out.append(")");290 out.append(")");
335 out.append("{0,0};\n");291 out.append("{0.0};\n");
336 return;292 return;
337 default:293 default:
338 out.append("\\node at (");294 out.append("\\node at (");
@@ -437,6 +393,124 @@
437 }393 }
438 }394 }
439395
396 private StringBuffer exportGlobalVariables() {
397 StringBuffer out = new StringBuffer();
398
399 Context context = new Context(TAPAALGUI.getCurrentTab());
400 List<ColorType> listColorTypes = context.network().colorTypes();
401 List<Constant> constantsList = new ArrayList<>(context.network().constants());
402 List<Variable> variableList = context.network().variables();
403
404 if(!context.network().isColored()) {
405 if(constantsList.isEmpty()) {
406 return out;
407 }
408 out.append("%%Global box which contains global color types, variables and/or constants.\n");
409 out.append("\\node [globalBox] (globalBox) at (current bounding box.north west) [anchor=south west] {");
410 exportConstants(constantsList, out);
411 out.append("};");
412 return out;
413 }
414
415 if((listColorTypes.isEmpty() && constantsList.isEmpty() && variableList.isEmpty()))
416 return out;
417
418 out.append("%%Global box which contains global color types, variables and/or constants.\n");
419 out.append("\\node [globalBox] (globalBox) at (current bounding box.north west) [anchor=south west] {");
420
421 exportColorTypes(listColorTypes, out);
422
423 if(listColorTypes.size() > 0 && (variableList.size() > 0 || constantsList.size() > 0)) {
424 out.append("\\\\");
425 }
426
427 exportVariables(variableList, out);
428
429 if(variableList.size() > 0 && !constantsList.isEmpty()) {
430 out.append("\\\\");
431 }
432
433 exportConstants(constantsList, out);
434
435 out.append("};");
436
437 return out;
438 }
439
440 private void exportColorTypes(List<ColorType> listColorTypes, StringBuffer out) {
441 String stringColorList = "";
442 for(int i = 0; i < listColorTypes.size(); i++) {
443 if(i == 0) {
444 out.append("Color Types:\\\\");
445 }
446 out.append("$\\mathit{" + listColorTypes.get(i).getName() + "}$ \\textbf{is} ");
447
448 if(listColorTypes.get(i).isProductColorType()) {
449 out.append("$\\mathit{<");
450 for(int x = 0; x < listColorTypes.get(i).getProductColorTypes().size(); x++) {
451 stringColorList += listColorTypes.get(i).getProductColorTypes().get(x).getName().replace("_", "\\_");
452
453 if(x != listColorTypes.get(i).getProductColorTypes().size() - 1){
454 stringColorList += ", ";
455 }
456 }
457 out.append(stringColorList + ">}$\\\\");
458 stringColorList = "";
459
460 } else if(listColorTypes.get(i).isIntegerRange()) {
461 out.append("$\\mathit{");
462 if(listColorTypes.get(i).size() > 1) {
463 int listSize = listColorTypes.get(i).size();
464 out.append("[" + listColorTypes.get(i).getColors().get(0).getColorName().replace("_","\\_") + ".." + listColorTypes.get(i).getColors().get(listSize - 1).getColorName().replace("_","\\_") + "]");
465 } else {
466 out.append("[" + listColorTypes.get(i).getFirstColor().getColorName().replace("_","\\_") + "]");
467 }
468 out.append("}$\\\\");
469
470 } else {
471 out.append("$\\mathit{[");
472 for(int x = 0; x < listColorTypes.get(i).getColors().size(); x++) {
473 stringColorList += listColorTypes.get(i).getColors().get(x).getName().replace("_","\\_");
474
475 if(x != listColorTypes.get(i).getColors().size() - 1){
476 stringColorList += ", ";
477 }
478 }
479 out.append(stringColorList + "]}$\\\\");
480 stringColorList = "";
481 }
482 }
483 }
484
485 private void exportVariables(List<Variable> variableList, StringBuffer out) {
486 String result = "";
487 for(int i = 0; i < variableList.size(); i++) {
488 if (i == 0) {
489 result += "Variables:\\\\ ";
490 }
491 result += "$\\mathit{" + variableList.get(i).getName().replace("_","\\_") + " \\textbf{ in } " + variableList.get(i).getColorType().getName().replace("_","\\_") + "}$";
492 if(i != variableList.size() - 1) {
493 result += "\\\\";
494 }
495 }
496 out.append(result);
497 }
498
499 private void exportConstants(List<Constant> constantsList, StringBuffer out) {
500 String result = "";
501
502 for(int i = 0; i < constantsList.size(); i++) {
503 if(i == 0) {
504 result += "Constants:\\\\";
505 }
506 result += "$\\mathit{" + constantsList.get(i).toString().replace("_","\\_") + "}$";
507 if(i != constantsList.size() - 1) {
508 result += "\\\\";
509 }
510 }
511 out.append(result);
512 }
513
440 protected String getTokenListStringFor(Place place) {514 protected String getTokenListStringFor(Place place) {
441 List<TimedToken> tokens = ((TimedPlaceComponent) place).underlyingPlace().tokens();515 List<TimedToken> tokens = ((TimedPlaceComponent) place).underlyingPlace().tokens();
442516
@@ -455,7 +529,7 @@
455 String invariant = "";529 String invariant = "";
456530
457 if (!((TimedPlaceComponent) place).getInvariantAsString().contains("inf"))531 if (!((TimedPlaceComponent) place).getInvariantAsString().contains("inf"))
458 invariant = "$\\mathrm{" + replaceWithMathLatex(((TimedPlaceComponent) place).getInvariantAsString()) + "}$};\n";532 invariant = replaceWithMathLatex(((TimedPlaceComponent) place).getInvariantAsString()) + "};\n";
459 return invariant;533 return invariant;
460 }534 }
461535
@@ -480,12 +554,14 @@
480 StringBuffer out = new StringBuffer();554 StringBuffer out = new StringBuffer();
481555
482 out.append("\\begin{tikzpicture}[font=\\scriptsize, xscale=0.45, yscale=0.45, x=1.33pt, y=1.33pt]\n");556 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");557 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");558 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");559 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");560 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");561 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");562 out.append("%% labels may be slightly skewed compared to the Tapaal drawing due to rounding.\n");
563 out.append("%% This can be adjusted by tuning the coordinates of the label, or the degree (see above)\n");
564 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");565 out.append("\\tikzstyle{arc}=[->,>=stealth,thick]\n");
490566
491 out.append("\\tikzstyle{transportArc}=[->,>=diamond,thick]\n");567 out.append("\\tikzstyle{transportArc}=[->,>=diamond,thick]\n");
@@ -496,39 +572,24 @@
496 out.append("\\tikzstyle{every token}=[fill=white,text=black]\n");572 out.append("\\tikzstyle{every token}=[fill=white,text=black]\n");
497 out.append("\\tikzstyle{sharedplace}=[place,minimum size=7.5mm,dashed,thin]\n");573 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");574 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]");575 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]");576 out.append("\\tikzstyle{uncontrollabletransition}=[transition,fill=white,draw=black,very thick]\n");
577 out.append("\\tikzstyle{globalBox} = [draw,thick,align=left]");
501 return out;578 return out;
502 }579 }
503580
504 protected String replaceWithMathLatex(String text) {581 protected String replaceWithMathLatex(String text) {
505 return text.replace("inf", "\\infty").replace("<=", "\\leq ").replace("*", "\\cdot ");582 String[] stringList = text.split(" ");
506 }583 String result = "";
507584
508 private String exportMathName(String name) {585 for(int i = 0; i < stringList.length; i++) {
509 StringBuilder out = new StringBuilder("$\\mathrm{");586 result += "$\\mathit{" + replaceSpecialSymbols(stringList[i]) + "}$ ";
510 int subscripts = 0;587 }
511 for (int i = 0; i < name.length() - 1; i++) {588 return result;
512 char c = name.charAt(i);589 }
513 if (c == '_') {590
514 out.append("_{");591 protected String replaceSpecialSymbols(String text) {
515 subscripts++;592 return text.replace("inf", "\\infty").replace("<=", "\\leq").replace("*", "\\cdot")
516 } else {593 .replace("\u2192", "\\rightarrow").replace("\u221E", "\\infty");
517 out.append(c);594 }
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}595}

Subscribers

People subscribed via source and target branches

to all changes: