35
33
import pipe.dataLayer.DataLayer;
36
34
import pipe.dataLayer.PetriNetObject;
37
import pipe.dataLayer.TAPNQuery;
38
import pipe.dataLayer.TAPNQuery.SearchOption;
39
import pipe.dataLayer.TAPNQuery.TraceOption;
40
35
import pipe.gui.widgets.FileBrowser;
41
import dk.aau.cs.debug.Logger;
42
import dk.aau.cs.petrinet.PipeTapnToAauTapnTransformer;
43
import dk.aau.cs.petrinet.TAPN;
44
import dk.aau.cs.petrinet.colors.ColoredPipeTapnToColoredAauTapnTransformer;
45
import dk.aau.cs.petrinet.degree2converters.NaiveDegree2Converter;
46
import dk.aau.cs.translations.ReductionOption;
47
import dk.aau.cs.translations.tapn.BroadcastTranslation;
48
import dk.aau.cs.translations.tapn.Degree2BroadcastTranslation;
49
import dk.aau.cs.translations.tapn.OptimizedStandardSymmetryTranslation;
50
import dk.aau.cs.translations.tapn.OptimizedStandardTranslation;
51
import dk.aau.cs.translations.tapn.StandardSymmetryTranslation;
52
import dk.aau.cs.translations.tapn.StandardTranslation;
57
38
* Class for exporting things to other formats, as well as printing.
60
42
public class Export {
64
46
public static final int PRINTER = 3;
65
47
public static final int TIKZ = 5;
68
public static void toPostScript(Object g,String filename)
69
throws PrintException, IOException {
49
public static void toPostScript(Object g, String filename)
50
throws PrintException, IOException {
70
51
// Input document type
71
52
DocFlavor flavour = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
72
53
// Output stream MIME type
73
54
String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
75
56
// Look up a print service factory that can handle this job
76
StreamPrintServiceFactory[] factories =
77
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
57
StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
58
.lookupStreamPrintServiceFactories(flavour, psMimeType);
79
59
if (factories.length == 0) {
80
throw new RuntimeException("No suitable factory found for export to PS");
60
throw new RuntimeException(
61
"No suitable factory found for export to PS");
83
64
FileOutputStream f = new FileOutputStream(filename);
92
public static void toPNG(JComponent g,String filename) throws IOException {
72
public static void toPNG(JComponent g, String filename) throws IOException {
93
73
Iterator<ImageWriter> i = ImageIO.getImageWritersBySuffix("png");
94
74
if (!i.hasNext()) {
95
75
throw new RuntimeException("No ImageIO exporters can handle PNG");
98
78
File f = new File(filename);
99
BufferedImage img = new BufferedImage(g.getPreferredSize().width,
100
g.getPreferredSize().height,
101
BufferedImage.TYPE_3BYTE_BGR);
79
BufferedImage img = new BufferedImage(g.getPreferredSize().width, g.getPreferredSize().height, BufferedImage.TYPE_3BYTE_BGR);
102
80
g.print(img.getGraphics());
103
81
ImageIO.write(img, "png", f);
106
84
private static void toPrinter(Object g) throws PrintException {
108
86
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
109
87
DocFlavor flavour = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
110
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavour, pras);
88
PrintService printService[] = PrintServiceLookup.lookupPrintServices(
112
91
if (printService.length == 0) {
113
throw new PrintException("\nUnable to locate a compatible printer service." +
114
"\nTry exporting to PostScript.");
92
throw new PrintException(
93
"\nUnable to locate a compatible printer service."
94
+ "\nTry exporting to PostScript.");
116
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
117
PrintService service =
118
ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavour, pras);
96
PrintService defaultService = PrintServiceLookup
97
.lookupDefaultPrintService();
98
PrintService service = ServiceUI.printDialog(null, 200, 200,
99
printService, defaultService, flavour, pras);
119
100
if (service != null) {
120
101
DocPrintJob job = service.createPrintJob();
121
102
DocAttributeSet das = new HashDocAttributeSet();
122
103
Doc doc = new SimpleDoc(g, flavour, das);
123
104
job.print(doc, pras);
127
PrinterJob pjob = PrinterJob.getPrinterJob();
128
PageFormat pf = pjob.defaultPage();
129
pjob.setPrintable(g, pf);
131
if (pjob.printDialog()) pjob.print();
132
} catch (PrinterException e) {
108
* The AWT way: PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat
109
* pf = pjob.defaultPage(); pjob.setPrintable(g, pf); try { if
110
* (pjob.printDialog()) pjob.print(); } catch (PrinterException e) {
111
* error=e.toString(); } //
139
public static void exportGuiView(GuiView g,int format, DataLayer model) {
115
public static void exportGuiView(DrawingSurfaceImpl g, int format,
140
117
if (g.getComponentCount() == 0) {
144
121
String filename = null;
145
122
if (CreateGui.getFile() != null) {
146
filename=CreateGui.getFile().getAbsolutePath();
123
filename = CreateGui.getFile().getAbsolutePath();
147
124
// change file extension
148
125
int dotpos = filename.lastIndexOf('.');
149
126
if (dotpos > filename.lastIndexOf(System.getProperty("file.separator"))) {
150
127
// dot is for extension
151
filename = filename.substring(0,dotpos+1);
128
filename = filename.substring(0, dotpos + 1);
152
129
switch (format) {
157
134
filename += "ps";
160
137
filename += "tex";
169
146
switch (format) {
171
filename = new FileBrowser("PNG image","png",filename).saveFile();
148
filename = new FileBrowser("PNG image", "png", filename).saveFile();
172
149
if (filename != null) {
173
150
toPNG(g, filename);
177
filename = new FileBrowser("PostScript file","ps",filename).saveFile();
154
filename = new FileBrowser("PostScript file", "ps", filename)
178
156
if (filename != null) {
179
157
toPostScript(g, filename);
186
Object[] possibilities = {"Only the TikZ figure", "Full compilable LaTex including your figure"};
187
String figureOptions = (String)JOptionPane.showInputDialog(
189
"Choose how you would like your TikZ figure outputted: \n",
191
JOptionPane.PLAIN_MESSAGE,
194
"Only the TikZ figure");
195
TikZExporter.TikZOutputOption tikZOption = TikZExporter.TikZOutputOption.FIGURE_ONLY;
196
if(figureOptions == null)
164
Object[] possibilities = { "Only the TikZ figure",
165
"Full compilable LaTex including your figure" };
166
String figureOptions = (String) JOptionPane.showInputDialog(
168
"Choose how you would like your TikZ figure outputted: \n",
169
"Export to TikZ", JOptionPane.PLAIN_MESSAGE,
170
null, possibilities, "Only the TikZ figure");
171
TikZExporter.TikZOutputOption tikZOption = TikZExporter.TikZOutputOption.FIGURE_ONLY;
172
if (figureOptions == null)
199
if(figureOptions == possibilities[0])
175
if (figureOptions == possibilities[0])
200
176
tikZOption = TikZExporter.TikZOutputOption.FIGURE_ONLY;
201
if(figureOptions == possibilities[1])
177
if (figureOptions == possibilities[1])
202
178
tikZOption = TikZExporter.TikZOutputOption.FULL_LATEX;
204
filename=new FileBrowser("TikZ figure","tex",filename).saveFile();
205
if (filename!=null) {
207
if(!model.isUsingColors()){
208
output = new TikZExporter(model,filename,tikZOption);
210
output = new TikZExporterForColoredTAPN(model, filename, tikZOption);
180
filename = new FileBrowser("TikZ figure", "tex", filename).saveFile();
181
if (filename != null) {
182
TikZExporter output = new TikZExporter(model, filename, tikZOption);
212
183
output.ExportToTikZ();
243
212
Grid.disableGrid();
248
public static void exportUppaalXMLFromQuery(DataLayer appModel, TAPNQuery input, String modelFile, String queryFile) {
249
File xmlfile=null, qfile=null;
251
xmlfile = new File(modelFile);
252
qfile = new File(queryFile);
253
} catch (NullPointerException e2) {
254
// TODO Auto-generated catch block
255
e2.printStackTrace();
260
PipeTapnToAauTapnTransformer transformer = null;
262
if(appModel.isUsingColors()){
263
transformer = new ColoredPipeTapnToColoredAauTapnTransformer();
265
transformer = new PipeTapnToAauTapnTransformer();
270
model = transformer.getAAUTAPN(appModel, 0);
271
} catch (Exception e) {
275
if (CreateGui.getApp().getComponentCount() == 0) {
281
capacity = input.getCapacity();
282
String inputQuery = input.getQuery();
283
TraceOption traceOption = input.getTraceOption();
284
SearchOption searchOption = input.getSearchOption();
285
String verifytaOptions = "";
287
if (traceOption == TraceOption.SOME){
288
verifytaOptions = "-t0";
289
}else if (traceOption == TraceOption.FASTEST){
290
verifytaOptions = "-t2";
291
}else if (traceOption == TraceOption.NONE){
292
verifytaOptions = "";
295
if (searchOption == SearchOption.BFS){
296
verifytaOptions += "-o0";
297
}else if (searchOption == SearchOption.DFS ){
298
verifytaOptions += "-o1";
299
}else if (searchOption == SearchOption.RDFS ){
300
verifytaOptions += "-o2";
301
}else if (searchOption == SearchOption.CLOSE_TO_TARGET_FIRST){
302
verifytaOptions += "-o6";
305
if (inputQuery == null) {return;}
307
// TODO: Refactor so translation to dk.aau.cs.petrinet.TAPNQuery happens exactly once
309
// Select the model based on selected export option.
310
if (input.getReductionOption() == ReductionOption.STANDARDSYMMETRY){
312
StandardSymmetryTranslation t = new StandardSymmetryTranslation();
314
t.autoTransform(model, new PrintStream(xmlfile), new PrintStream(qfile), new dk.aau.cs.petrinet.TAPNQuery(input.getProperty(), 0), capacity);
315
} catch (FileNotFoundException e) {
316
// TODO Auto-generated catch block
320
} else if (input.getReductionOption() == ReductionOption.OPTIMIZEDSTANDARDSYMMETRY){
322
OptimizedStandardSymmetryTranslation t = new OptimizedStandardSymmetryTranslation();
324
t.autoTransform(model, new PrintStream(xmlfile), new PrintStream(qfile), new dk.aau.cs.petrinet.TAPNQuery(input.getProperty(), 0), capacity);
325
} catch (FileNotFoundException e) {
326
// TODO Auto-generated catch block
329
}else if (input.getReductionOption() == ReductionOption.OPTIMIZEDSTANDARD){
330
Logger.log("Using ADV_NOSYMQ");
331
OptimizedStandardTranslation t = new OptimizedStandardTranslation();
333
t.autoTransform(model, new PrintStream(xmlfile), new PrintStream(qfile), new dk.aau.cs.petrinet.TAPNQuery(input.getProperty(), 0), capacity);
334
} catch (FileNotFoundException e) {
335
// TODO Auto-generated catch block
340
} else if(input.getReductionOption() == ReductionOption.BROADCAST || input.getReductionOption() == ReductionOption.BROADCASTSYMMETRY){
341
BroadcastTranslation broadcastTransformer = null;
342
if(appModel.isUsingColors()){
343
broadcastTransformer = new dk.aau.cs.translations.coloredtapn.ColoredBroadcastTranslation(capacity, input.getReductionOption() == ReductionOption.BROADCASTSYMMETRY);
345
broadcastTransformer = new dk.aau.cs.translations.tapn.BroadcastTranslation(capacity, input.getReductionOption() == ReductionOption.BROADCASTSYMMETRY);
348
dk.aau.cs.TA.NTA nta = broadcastTransformer.transformModel(model);
349
nta.outputToUPPAALXML(new PrintStream(xmlfile));
350
dk.aau.cs.TA.UPPAALQuery query = broadcastTransformer.transformQuery(new dk.aau.cs.petrinet.TAPNQuery(input.getProperty(), capacity + 1 + model.getTokens().size()));
351
query.output(new PrintStream(qfile));
352
}catch(FileNotFoundException e){
354
} catch (Exception e) {
355
// TODO Auto-generated catch block
358
} else if(input.getReductionOption() == ReductionOption.DEGREE2BROADCASTSYMMETRY || input.getReductionOption() == ReductionOption.DEGREE2BROADCAST){
359
Degree2BroadcastTranslation broadcastTransformer = null;
360
if(appModel.isUsingColors()){
361
broadcastTransformer = new dk.aau.cs.translations.coloredtapn.ColoredDegree2BroadcastTranslation(capacity, input.getReductionOption() == ReductionOption.DEGREE2BROADCASTSYMMETRY);
363
broadcastTransformer = new dk.aau.cs.translations.tapn.Degree2BroadcastTranslation(capacity, input.getReductionOption() == ReductionOption.DEGREE2BROADCASTSYMMETRY);
366
dk.aau.cs.TA.NTA nta = broadcastTransformer.transformModel(model);
367
nta.outputToUPPAALXML(new PrintStream(xmlfile));
368
dk.aau.cs.TA.UPPAALQuery query = broadcastTransformer.transformQuery(new dk.aau.cs.petrinet.TAPNQuery(input.getProperty(), capacity + 1 + model.getTokens().size()));
369
query.output(new PrintStream(qfile));
370
}catch(FileNotFoundException e){
372
} catch (Exception e) {
373
// TODO Auto-generated catch block
380
model.convertToConservative();
381
} catch (Exception e1) {
382
// TODO Auto-generated catch block
383
e1.printStackTrace();
387
NaiveDegree2Converter deg2Converter = new NaiveDegree2Converter();
388
model = deg2Converter.transform(model);
389
} catch (Exception e1) {
390
// TODO Auto-generated catch block
391
e1.printStackTrace();
396
//Create uppaal xml file
398
StandardTranslation t2 = new StandardTranslation(model, new PrintStream(xmlfile), capacity);
400
t2.transformQueriesToUppaal(capacity, new dk.aau.cs.petrinet.TAPNQuery(input.getProperty(), 0), new PrintStream(qfile));
401
} catch (FileNotFoundException e) {
402
// TODO Auto-generated catch block
404
} catch (Exception e) {
405
// TODO Auto-generated catch block