~tapaal-contributor/tapaal/fix-tikz-export-1945642

73 by Mikael Møller
Så er der TikZExporter...
1
package pipe.gui;
2
3
import java.io.FileWriter;
4
import java.io.IOException;
5
import java.io.PrintWriter;
571.2.12 by Kenneth Yrke Joergensen
Removed function // TODO: get rid of getTokens()
6
import java.util.List;
7
8
import dk.aau.cs.model.tapn.TimedToken;
73 by Mikael Møller
Så er der TikZExporter...
9
571.2.6 by Kenneth Yrke Joergensen
Moved DataLayer back
10
import pipe.dataLayer.DataLayer;
1155 by kpede19 at aau
Fixed imports
11
import pipe.gui.graphicElements.Arc;
12
import pipe.gui.graphicElements.ArcPathPoint;
13
import pipe.gui.graphicElements.Place;
14
import pipe.gui.graphicElements.Transition;
571.2.1 by Kenneth Yrke Joergensen
Moved TAPN Elements to graphicElements.tapn
15
import pipe.gui.graphicElements.tapn.TimedInhibitorArcComponent;
16
import pipe.gui.graphicElements.tapn.TimedInputArcComponent;
17
import pipe.gui.graphicElements.tapn.TimedPlaceComponent;
18
import pipe.gui.graphicElements.tapn.TimedTransitionComponent;
19
import pipe.gui.graphicElements.tapn.TimedTransportArcComponent;
73 by Mikael Møller
Så er der TikZExporter...
20
21
public class TikZExporter {
22
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
23
	public enum TikZOutputOption {
24
		FIGURE_ONLY, FULL_LATEX
25
	}
73 by Mikael Møller
Så er der TikZExporter...
26
1067.4.2 by Kenneth Yrke Jørgensen
Made members final
27
	private final DataLayer net;
28
	private final String fullpath;
29
	private final TikZOutputOption option;
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
30
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
31
	public TikZExporter(DataLayer net, String fullpath, TikZOutputOption option) {
73 by Mikael Møller
Så er der TikZExporter...
32
		this.net = net;
33
		this.fullpath = fullpath;
34
		this.option = option;
35
	}
36
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
37
	public void ExportToTikZ() {
73 by Mikael Møller
Så er der TikZExporter...
38
		FileWriter outFile = null;
39
		PrintWriter out = null;
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
40
		try {
73 by Mikael Møller
Så er der TikZExporter...
41
			outFile = new FileWriter(fullpath);
42
			out = new PrintWriter(outFile);
43
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
44
			if (option == TikZOutputOption.FULL_LATEX) {
73 by Mikael Møller
Så er der TikZExporter...
45
				out.println("\\documentclass[a4paper]{article}");
46
				out.println("\\usepackage{tikz}");
47
				out.println("\\usetikzlibrary{petri,arrows}");
214 by Morten Jacobsen
TikZ exporter for colored nets should be functional
48
				out.println("\\usepackage{amstext}");
73 by Mikael Møller
Så er der TikZExporter...
49
				out.println();
50
				out.println("\\begin{document}");
51
				out.println();
52
				out.println();
53
			}
54
55
			out.println("%% TikZ style options %%");
56
			out.print(exportTikZstyle());
57
			out.println();
58
59
			out.println("%% TikZ-figure elements %%");
60
			out.print(exportPlacesWithTokens(net.getPlaces()));
61
			out.print(exportTransitions(net.getTransitions()));
62
			out.print(exportArcs(net.getArcs()));
63
64
			out.println("\\end{tikzpicture}");
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
65
			if (option == TikZOutputOption.FULL_LATEX) {
73 by Mikael Møller
Så er der TikZExporter...
66
				out.println("\\end{document}");
67
68
			}
69
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
70
		} catch (IOException e) {
73 by Mikael Møller
Så er der TikZExporter...
71
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
72
		} finally {
1152 by kpede19 at aau
Now exports curved arcs correctly
73
			if (out != null) {
74
                out.close();
75
            }
76
			if (outFile != null) {
77
                try {
78
                    outFile.close();
79
                } catch (IOException e2) {
73 by Mikael Møller
Så er der TikZExporter...
80
1152 by kpede19 at aau
Now exports curved arcs correctly
81
                }
82
            }
73 by Mikael Møller
Så er der TikZExporter...
83
		}
84
	}
85
86
	private StringBuffer exportArcs(Arc[] arcs) {
87
		StringBuffer out = new StringBuffer();
1152 by kpede19 at aau
Now exports curved arcs correctly
88
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
89
		for (Arc arc : arcs) {
73 by Mikael Møller
Så er der TikZExporter...
90
			String arcPoints = "";
1152 by kpede19 at aau
Now exports curved arcs correctly
91
73 by Mikael Møller
Så er der TikZExporter...
92
			for (int i = 1; i < arc.getArcPath().getEndIndex(); i++) {
1152 by kpede19 at aau
Now exports curved arcs correctly
93
                ArcPathPoint currentPoint = arc.getArcPath().getArcPathPoint(i);
94
95
                if(currentPoint.getPointType() == ArcPathPoint.STRAIGHT) {
96
                    arcPoints += "to[bend right=0] (" + (currentPoint.getX()) + "," + (currentPoint.getY() * (-1)) + ") ";
97
                } else if (currentPoint.getPointType() == ArcPathPoint.CURVED) {
98
                    double xCtrl1 = Math.round(currentPoint.getControl1().getX());
99
                    double yCtrl1 = Math.round(currentPoint.getControl1().getY() * (-1));
100
                    double xCtrl2 = Math.round(currentPoint.getControl2().getX());
101
                    double yCtrl2 = Math.round(currentPoint.getControl2().getY() * (-1));
102
103
                    arcPoints += " .. controls(" + xCtrl1 + "," + yCtrl1 + ")";
104
                    arcPoints += " and ";
105
                    arcPoints += "(" + xCtrl2 + "," + yCtrl2 + ") .. ";
106
                    arcPoints += "(" + currentPoint.getX() + "," + currentPoint.getY() * (-1) + ") ";
107
                }
108
			}
109
110
			String arrowType = getArcArrowType(arc);
213 by Morten Jacobsen
More work on tikz exporter for colored nets
111
			String arcLabel = getArcLabels(arc);
322 by Morten Jacobsen
Export of untimed nets now working properly.
112
73 by Mikael Møller
Så er der TikZExporter...
113
			out.append("\\draw[");
114
			out.append(arrowType);
115
			out.append("] (");
116
			out.append(arc.getSource().getId());
117
			out.append(") ");
118
			out.append(arcPoints);
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
119
			out.append("to[bend right=0]");
120
			out.append(" (");
73 by Mikael Møller
Så er der TikZExporter...
121
			out.append(arc.getTarget().getId());
865.1.13 by Jiri Srba
some last fixes
122
			out.append(") {};\n");
998.12.44 by Kenneth Yrke Joergensen
Replaced a number of places using == insted of equals to compare strings
123
			if(!arcLabel.equals(""))
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
124
				out.append("%% Label for arc between " + arc.getSource().getName() + " and " + arc.getTarget().getName() + "\n");
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
125
			out.append(arcLabel);
73 by Mikael Møller
Så er der TikZExporter...
126
		}
127
		return out;
128
	}
129
1152 by kpede19 at aau
Now exports curved arcs correctly
130
    private String getArcArrowType(Arc arc) {
131
        String arrowType = "";
132
        if (arc instanceof TimedInhibitorArcComponent) {
133
            arrowType = "inhibArc";
134
        } else if (arc instanceof TimedTransportArcComponent) {
135
            arrowType = "transportArc";
136
        } else if (arc instanceof TimedInputArcComponent) {
137
            arrowType = "arc";
138
        } else {
139
            arrowType = "arc";
140
        }
141
        return arrowType;
142
    }
143
213 by Morten Jacobsen
More work on tikz exporter for colored nets
144
	protected String getArcLabels(Arc arc) {
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
145
		String arcLabel = "";
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
146
		String arcLabelPositionString = "\\draw (" + (arc.getNameLabel().getX()) + "," + (arc.getNameLabel().getY())*(-1) + ") node {";
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
147
865.1.5 by Jiri Srba
added weight to tizk export
148
		if (arc instanceof TimedInputArcComponent) {
998.15.3 by Kenneth Yrke Joergensen
Removed last references to NetType and removed NetType
149
            if (!(arc.getSource() instanceof TimedTransitionComponent)) {
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
150
				arcLabel = arcLabelPositionString;
151
                if (arc.getWeight().value() > 1) {
152
                        arcLabel += "$" + arc.getWeight().value() + "\\times$\\ ";
153
                }
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
154
155
                if(CreateGui.getApp().getCurrentTab().getLens().isTimed()) {
156
                    arcLabel += "$\\mathrm{" + replaceWithMathLatex(getGuardAsStringIfNotHidden((TimedInputArcComponent) arc)) + "}$";
157
                    if (arc instanceof TimedTransportArcComponent)
158
                        arcLabel += ":" + ((TimedTransportArcComponent) arc).getGroupNr();
159
                    arcLabel += "};\n";
160
                } else {
161
                    arcLabel += "};\n";
162
                }
163
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
164
			} else {
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
165
				arcLabel = arcLabelPositionString;
166
                if (arc.getWeight().value() > 1) {
167
                        arcLabel += "$" + arc.getWeight().value() + "\\times$\\ ";
168
                }
169
				arcLabel += ":" + ((TimedTransportArcComponent) arc).getGroupNr() + "};\n";
213 by Morten Jacobsen
More work on tikz exporter for colored nets
170
			}
1152 by kpede19 at aau
Now exports curved arcs correctly
171
865.1.5 by Jiri Srba
added weight to tizk export
172
		} else {
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
173
            if (arc.getWeight().value() > 1) {
1152 by kpede19 at aau
Now exports curved arcs correctly
174
                arcLabel += arcLabelPositionString + "$" + arc.getWeight().value() + "\\times$\\ };\n";
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
175
            }
176
    	}
213 by Morten Jacobsen
More work on tikz exporter for colored nets
177
		return arcLabel;
178
	}
179
998.2.161 by Kenneth Yrke Joergensen
Removed method getIntervalAsString(bool), wiht just getIntervalAsString,
180
	private String getGuardAsStringIfNotHidden(TimedInputArcComponent arc) {
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
181
        if (!CreateGui.getApp().showZeroToInfinityIntervals() && arc.getGuardAsString().equals("[0,inf)")){
998.2.161 by Kenneth Yrke Joergensen
Removed method getIntervalAsString(bool), wiht just getIntervalAsString,
182
			return "";
183
		} else {
184
			return arc.getGuardAsString();
185
		}
186
	}
187
73 by Mikael Møller
Så er der TikZExporter...
188
	private StringBuffer exportTransitions(Transition[] transitions) {
189
		StringBuffer out = new StringBuffer();
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
190
		for (Transition trans : transitions) {
191
			String angle = "";
192
			if (trans.getAngle() != 0)
1156 by kpede19 at aau
Now correctly show transition rotations for 45 degree angles
193
				angle = ",rotate=-" + (trans.getAngle());
194
322 by Morten Jacobsen
Export of untimed nets now working properly.
195
329.1.169 by Morten Jacobsen
added support for shared places and transitions in the tikz exporter.
196
			out.append("\\node[transition");
1000.4.2 by ptaankvist at gmail
Now label placement for export tikz works for both places and transitions
197
			out.append(angle);		
73 by Mikael Møller
Så er der TikZExporter...
198
			out.append("] at (");
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
199
			out.append((trans.getPositionX()));
571.2.17 by Kenneth Yrke Joergensen
Code Audit: String literal can be replaced by a character literal
200
			out.append(',');
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
201
			out.append((trans.getPositionY() * (-1)));
73 by Mikael Møller
Så er der TikZExporter...
202
			out.append(") (");
203
			out.append(trans.getId());
204
			out.append(") {};\n");
329.1.169 by Morten Jacobsen
added support for shared places and transitions in the tikz exporter.
205
			
206
			if(((TimedTransitionComponent)trans).underlyingTransition().isShared()){
207
				out.append("\\node[sharedtransition");
208
				out.append(angle);
209
				out.append("] at (");
210
				out.append(trans.getId());
211
				out.append(".center) { };\n");
212
			}
865.1.3 by Jiri Srba
added urgent transitions; should add also weighted arcs
213
                        
1000.4.2 by ptaankvist at gmail
Now label placement for export tikz works for both places and transitions
214
			if(((TimedTransitionComponent)trans).underlyingTransition().isUrgent()){
865.1.3 by Jiri Srba
added urgent transitions; should add also weighted arcs
215
				out.append("\\node[urgenttransition");
216
				out.append(angle);
217
				out.append("] at (");
218
				out.append(trans.getId());
219
				out.append(".center) { };\n");
220
			}
1053.5.14 by lsaid
Game information is saved to Tikz. Message warning when exporting to PNML is also added.
221
            if (((TimedTransitionComponent)trans).underlyingTransition().isUncontrollable()) {
222
                out.append("\\node[uncontrollabletransition");
223
                out.append(angle);
224
                out.append("] at (");
225
                out.append(trans.getId());
226
                out.append(".center) { };\n");
227
            }
1000.4.2 by ptaankvist at gmail
Now label placement for export tikz works for both places and transitions
228
			if (trans.getAttributesVisible()){
1152 by kpede19 at aau
Now exports curved arcs correctly
229
                boolean isLabelAboveTransition = trans.getY() > trans.getNameLabel().getY();
230
                boolean isLabelBehindTrans = trans.getX() < trans.getNameLabel().getX();
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
231
                double xOffset = trans.getName().length() > 5 && !isLabelAboveTransition && !isLabelBehindTrans ? trans.getLayerOffset() : 0;
232
1000.4.2 by ptaankvist at gmail
Now label placement for export tikz works for both places and transitions
233
				out.append("%% label for transition " + trans.getName() + "\n");
234
				out.append("\\draw (");
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
235
				out.append(trans.getNameLabel().getX() + xOffset + "," + (trans.getNameLabel().getY() * -1) + ")");
1000.4.2 by ptaankvist at gmail
Now label placement for export tikz works for both places and transitions
236
				out.append(" node ");
237
				out.append(" {");
238
				out.append(exportMathName(trans.getName()));
239
				out.append("};\n");
240
			}	
73 by Mikael Møller
Så er der TikZExporter...
241
		}
242
		return out;
243
	}
244
245
	private StringBuffer exportPlacesWithTokens(Place[] places) {
246
		StringBuffer out = new StringBuffer();
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
247
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
248
		for (Place place : places) {
212 by Morten Jacobsen
Started implementation of TikZExporter for colored nets
249
			String invariant = getPlaceInvariantString(place);
213 by Morten Jacobsen
More work on tikz exporter for colored nets
250
			String tokensInPlace = getTokenListStringFor(place);
73 by Mikael Møller
Så er der TikZExporter...
251
915.2.3 by Mads Johannsen
Exporting nets as tikz now respects the place/transition name visibility
252
			out.append("\\node[place");
73 by Mikael Møller
Så er der TikZExporter...
253
			out.append("] at (");
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
254
			out.append(place.getPositionX());
571.2.17 by Kenneth Yrke Joergensen
Code Audit: String literal can be replaced by a character literal
255
			out.append(',');
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
256
			out.append(place.getPositionY() * (-1));
73 by Mikael Møller
Så er der TikZExporter...
257
			out.append(") (");
258
			out.append(place.getId());
259
			out.append(") {};\n");
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
260
261
            exportPlaceTokens(place, out, ((TimedPlaceComponent) place).underlyingPlace().tokens().size());
329.1.169 by Morten Jacobsen
added support for shared places and transitions in the tikz exporter.
262
			
263
			if(((TimedPlaceComponent)place).underlyingPlace().isShared()){
264
				out.append("\\node[sharedplace] at (");
265
				out.append(place.getId());
266
				out.append(".center) { };\n");
267
			}
998.12.44 by Kenneth Yrke Joergensen
Replaced a number of places using == insted of equals to compare strings
268
			if (place.getAttributesVisible() || !invariant.equals("")){
1152 by kpede19 at aau
Now exports curved arcs correctly
269
			    boolean isLabelAbovePlace = place.getY() > place.getNameLabel().getY();
270
			    boolean isLabelBehindPlace = place.getX() < place.getNameLabel().getX();
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
271
			    double xOffset = place.getName().length() > 6 && !isLabelAbovePlace && !isLabelBehindPlace ? place.getLayerOffset() : 0;
272
			    double yOffset = isLabelAbovePlace ? (place.getNameLabel().getHeight() / 2) : 0;
273
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
274
				out.append("%% label for place " + place.getName() + "\n");
275
				out.append("\\draw (");
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
276
				out.append((place.getNameLabel().getX() + xOffset)  + "," + ((place.getNameLabel().getY() * -1) + yOffset) +")");
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
277
				out.append(" node[align=left] ");
278
				out.append("{");
279
				if(place.getAttributesVisible())
1000.4.2 by ptaankvist at gmail
Now label placement for export tikz works for both places and transitions
280
					out.append(exportMathName(place.getName()));					
998.12.44 by Kenneth Yrke Joergensen
Replaced a number of places using == insted of equals to compare strings
281
				if(!invariant.equals("")) {
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
282
					if((place.getAttributesVisible()))
283
						out.append("\\\\");
284
					out.append(invariant);
285
				}else {
286
					out.append("};\n");
287
				}
288
					
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
289
			}
73 by Mikael Møller
Så er der TikZExporter...
290
		}
291
292
		return out;
293
	}
294
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
295
	private void exportPlaceTokens(Place place, StringBuffer out, int numOfTokens) {
296
        // Dot radius
297
        final double tRadius = 1;
298
299
        // Token dot position offsets
300
        final double tLeftX = 7;
301
        final double tRightX = 7;
302
        final double tTopY = 7;
303
        final double tBotY = 7;
304
305
        boolean isTimed = CreateGui.getApp().getCurrentTab().getLens().isTimed();
306
307
        double placeXpos = (place.getPositionX());
308
        double placeYpos = (place.getPositionY() * (-1));
309
        double xPos, yPos;
310
311
        if(isTimed && numOfTokens > 0) {
312
            switch (numOfTokens) {
313
                case 2:
314
                    out.append("\\node at ("); // Top
315
                    out.append(placeXpos);
316
                    out.append(",");
317
                    out.append(placeYpos + 4);
318
                    out.append(")");
319
                    out.append("{0,0};\n");
320
321
                    out.append("\\node at ("); // Bottom
322
                    out.append(placeXpos);
323
                    out.append(",");
324
                    out.append(placeYpos - 5);
325
                    out.append(")");
326
                    out.append("{0,0};\n");
327
                    return;
328
                case 1:
329
                    out.append("\\node at ("); // Top
330
                    out.append(placeXpos);
331
                    out.append(",");
332
                    out.append(placeYpos);
333
                    out.append(")");
334
                    out.append("{0,0};\n");
335
                    return;
336
                default:
337
                    out.append("\\node at (");
338
                    out.append(placeXpos);
339
                    out.append(",");
340
                    out.append(placeYpos);
341
                    out.append(")");
342
                    out.append("{$\\mathrm{");
343
                    out.append("\\#" + numOfTokens + "}$};\n");
344
                    return;
345
            }
346
        } else if(numOfTokens > 5 && !isTimed ) {
347
            out.append("\\node at (");
348
            out.append(placeXpos);
349
            out.append(",");
350
            out.append(placeYpos);
351
            out.append(")");
352
            out.append("{$\\mathrm{");
353
            out.append("\\#" + numOfTokens + "}$};\n");
354
            return;
355
        }
356
357
        switch (numOfTokens) {
358
            case 5: // middle
359
                out.append("\\node at (");
360
                out.append(placeXpos);
361
                out.append(",");
362
                out.append(placeYpos);
363
                out.append(")");
364
                out.append("[circle,fill,inner sep=");
365
                out.append(tRadius);
366
                out.append("pt]{};\n");
367
                /* falls through */
368
            case 4: // top left
369
                out.append("\\node at (");
370
                out.append(placeXpos - tLeftX);
371
                out.append(",");
372
                out.append(placeYpos + tTopY);
373
                out.append(")");
374
                out.append("[circle,fill,inner sep=");
375
                out.append(tRadius);
376
                out.append("pt]{};\n");
377
                /* falls through */
378
            case 3:
379
                if(numOfTokens == 5 || numOfTokens == 4) { // top right
380
                    xPos = placeXpos + tRightX;
381
                    yPos = placeYpos + tTopY;
382
                } else { // top left
383
                    xPos = placeXpos - tLeftX;
384
                    yPos = placeYpos + tTopY;
385
                }
386
                out.append("\\node at (");
387
                out.append(xPos);
388
                out.append(",");
389
                out.append(yPos);
390
                out.append(")");
391
                out.append("[circle,fill,inner sep=");
392
                out.append(tRadius);
393
                out.append("pt]{};\n");
394
                /* falls through */
395
            case 2:
396
                if(numOfTokens == 5 || numOfTokens == 4) { // bottom left
397
                    xPos = placeXpos - tLeftX;
398
                    yPos = placeYpos - tBotY;
399
                } else if (numOfTokens == 3){ // middle
400
                    xPos = placeXpos;
401
                    yPos = placeYpos;
402
                } else { // left middle
403
                    xPos = placeXpos - tLeftX;
404
                    yPos = placeYpos;
405
                }
406
                out.append("\\node at (");
407
                out.append(xPos);
408
                out.append(",");
409
                out.append(yPos);
410
                out.append(")");
411
                out.append("[circle,fill,inner sep=");
412
                out.append(tRadius);
413
                out.append("pt]{};\n");
414
                /* falls through */
415
            case 1:
416
                if(numOfTokens == 5 || numOfTokens == 4 || numOfTokens == 3) { // bottom right
417
                    xPos = placeXpos + tRightX;
418
                    yPos = placeYpos - tBotY;
419
                } else if (numOfTokens == 2){ // right middle
420
                    xPos = placeXpos + tRightX;
421
                    yPos = placeYpos;
422
                } else { // middle
423
                    xPos = placeXpos;
424
                    yPos = placeYpos;
425
                }
426
                out.append("\\node at (");
427
                out.append(xPos);
428
                out.append(",");
429
                out.append(yPos);
430
                out.append(")");
431
                out.append("[circle,fill,inner sep=");
432
                out.append(tRadius);
433
                out.append("pt]{};\n");
434
            default:
435
                break;
436
        }
437
    }
438
212 by Morten Jacobsen
Started implementation of TikZExporter for colored nets
439
	protected String getTokenListStringFor(Place place) {
571.2.12 by Kenneth Yrke Joergensen
Removed function // TODO: get rid of getTokens()
440
		List<TimedToken> tokens = ((TimedPlaceComponent) place).underlyingPlace().tokens();
1150 by kpede19 at aau
Improved quality of Tikz export and various fixes
441
212 by Morten Jacobsen
Started implementation of TikZExporter for colored nets
442
		String tokensInPlace = "";
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
443
		if (tokens.size() > 0) {
998.15.3 by Kenneth Yrke Joergensen
Removed last references to NetType and removed NetType
444
            if (tokens.size() == 1) {
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
445
				tokensInPlace = ", structured tokens={" + tokens.get(0).age().setScale(1) + "},";
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
446
			} else {
212 by Morten Jacobsen
Started implementation of TikZExporter for colored nets
447
				tokensInPlace = exportMultipleTokens(tokens);
448
			}
449
		}
450
		return tokensInPlace;
451
	}
452
453
	protected String getPlaceInvariantString(Place place) {
998.15.3 by Kenneth Yrke Joergensen
Removed last references to NetType and removed NetType
454
        String invariant = "";
322 by Morten Jacobsen
Export of untimed nets now working properly.
455
329.1.169 by Morten Jacobsen
added support for shared places and transitions in the tikz exporter.
456
		if (!((TimedPlaceComponent) place).getInvariantAsString().contains("inf"))
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
457
			invariant = "$\\mathrm{" + replaceWithMathLatex(((TimedPlaceComponent) place).getInvariantAsString()) + "}$};\n";
212 by Morten Jacobsen
Started implementation of TikZExporter for colored nets
458
		return invariant;
459
	}
460
571.2.12 by Kenneth Yrke Joergensen
Removed function // TODO: get rid of getTokens()
461
	private String exportMultipleTokens(List<TimedToken> tokens) {
998.3.9 by Kenneth Yrke Jørgensen
Changed from StringBuffer to StringBuilder
462
		StringBuilder out = new StringBuilder();
73 by Mikael Møller
Så er der TikZExporter...
463
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
464
		out.append(", structured tokens={\\#");
998.2.11 by Kenneth Yrke Jørgensen
Removed unneeded cast to string
465
		out.append(tokens.size());
998.2.19 by Kenneth Yrke Jørgensen
Merged trunk
466
73 by Mikael Møller
Så er der TikZExporter...
467
		out.append("},");
998.15.3 by Kenneth Yrke Joergensen
Removed last references to NetType and removed NetType
468
        out.append("pin=above:{\\{");
469
        for (int i = 0; i < tokens.size() - 1; i++) {
470
            out.append(tokens.get(i).age().setScale(1));
471
            out.append(',');
472
        }
473
        out.append(tokens.get(tokens.size() - 1).age().setScale(1));
474
        out.append("\\}},");
475
        return out.toString();
73 by Mikael Møller
Så er der TikZExporter...
476
	}
477
478
	private StringBuffer exportTikZstyle() {
479
		StringBuffer out = new StringBuffer();
480
1158 by kpede19 at aau
Changed unit from px to pt
481
		out.append("\\begin{tikzpicture}[font=\\scriptsize, xscale=0.45, yscale=0.45, x=1.33pt, y=1.33pt]\n");
865.1.13 by Jiri Srba
some last fixes
482
                out.append("%% the figure can be scaled by changing xscale and yscale\n");
993.5.1 by ptaankvist at gmail
arc labels are placed at the same position as they have in latex
483
                out.append("%% positions of place/transition labels that are currently fixed to label=135 degrees\n");
865.1.13 by Jiri Srba
some last fixes
484
                out.append("%% can be adjusted so that they do not cover arcs\n");
485
                out.append("%% similarly the curving of arcs can be done by adjusting bend left/right=XX\n");
1000.4.1 by ptaankvist at gmail
Place labels will keep their position when exporting to tikz
486
                out.append("%% labels may be slightly skewed compared to the tapaal drawing due to rounding.\n");
487
                out.append("%% This can be adjusted by tuning the coordinates of the label\n");
73 by Mikael Møller
Så er der TikZExporter...
488
		out.append("\\tikzstyle{arc}=[->,>=stealth,thick]\n");
370 by Kenneth Yrke Jørgensen
Merged with branch addning support for new 1.5 features
489
998.15.3 by Kenneth Yrke Joergensen
Removed last references to NetType and removed NetType
490
        out.append("\\tikzstyle{transportArc}=[->,>=diamond,thick]\n");
363 by Kenneth Yrke Jørgensen
Merged for fix for bug #731974
491
		out.append("\\tikzstyle{inhibArc}=[->,>=o,thick]\n");
370 by Kenneth Yrke Jørgensen
Merged with branch addning support for new 1.5 features
492
73 by Mikael Møller
Så er der TikZExporter...
493
		out.append("\\tikzstyle{every place}=[minimum size=6mm,thick]\n");
329.1.169 by Morten Jacobsen
added support for shared places and transitions in the tikz exporter.
494
		out.append("\\tikzstyle{every transition} = [fill=black,minimum width=2mm,minimum height=5mm]\n");
73 by Mikael Møller
Så er der TikZExporter...
495
		out.append("\\tikzstyle{every token}=[fill=white,text=black]\n");
329.1.169 by Morten Jacobsen
added support for shared places and transitions in the tikz exporter.
496
		out.append("\\tikzstyle{sharedplace}=[place,minimum size=7.5mm,dashed,thin]\n");
497
		out.append("\\tikzstyle{sharedtransition}=[transition, fill opacity=0, minimum width=3.5mm, minimum height=6.5mm,dashed]\n");
1000.4.2 by ptaankvist at gmail
Now label placement for export tikz works for both places and transitions
498
		out.append("\\tikzstyle{urgenttransition}=[place,fill=white,minimum size=2.0mm,thin]");
1053.5.14 by lsaid
Game information is saved to Tikz. Message warning when exporting to PNML is also added.
499
        out.append("\\tikzstyle{uncontrollabletransition}=[transition,fill=white,draw=black,very thick]");
500
        return out;
73 by Mikael Møller
Så er der TikZExporter...
501
	}
502
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
503
	protected String replaceWithMathLatex(String text) {
865.1.8 by Jiri Srba
improvements to tikz export - still issue when guards export with constants
504
		return text.replace("inf", "\\infty").replace("<=", "\\leq ").replace("*", "\\cdot ");
73 by Mikael Møller
Så er der TikZExporter...
505
	}
506
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
507
	private String exportMathName(String name) {
998.3.9 by Kenneth Yrke Jørgensen
Changed from StringBuffer to StringBuilder
508
		StringBuilder out = new StringBuilder("$\\mathrm{");
73 by Mikael Møller
Så er der TikZExporter...
509
		int subscripts = 0;
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
510
		for (int i = 0; i < name.length() - 1; i++) {
73 by Mikael Møller
Så er der TikZExporter...
511
			char c = name.charAt(i);
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
512
			if (c == '_') {
73 by Mikael Møller
Så er der TikZExporter...
513
				out.append("_{");
514
				subscripts++;
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
515
			} else {
73 by Mikael Møller
Så er der TikZExporter...
516
				out.append(c);
517
			}
518
		}
322 by Morten Jacobsen
Export of untimed nets now working properly.
519
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
520
		char last = name.charAt(name.length() - 1);
521
		if (last == '_') {
73 by Mikael Møller
Så er der TikZExporter...
522
			out.append("\\_");
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
523
		} else
73 by Mikael Møller
Så er der TikZExporter...
524
			out.append(last);
322 by Morten Jacobsen
Export of untimed nets now working properly.
525
329.1.62 by Lasse Jacobsen
- cleaned up the code a bit using the Clean up function in Eclipse
526
		for (int i = 0; i < subscripts; i++) {
571.2.17 by Kenneth Yrke Joergensen
Code Audit: String literal can be replaced by a character literal
527
			out.append('}');
73 by Mikael Møller
Så er der TikZExporter...
528
		}
865.1.1 by Jiri Srba
added mathit to place/transition names
529
		out.append("}$");
73 by Mikael Møller
Så er der TikZExporter...
530
		return out.toString();
531
	}
532
533
}