~tapaal-contributor/tapaal/weight-values-fix-1770637

« back to all changes in this revision

Viewing changes to src/pipe/gui/Export.java

merged branch lp:~tapaal-contributor/tapaal/ctl-query-fix-1540367

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import java.awt.print.PrinterException;
12
12
import java.awt.print.PrinterJob;
13
13
import java.io.File;
 
14
import java.io.FileNotFoundException;
14
15
import java.io.FileOutputStream;
15
16
import java.io.IOException;
 
17
import java.io.PrintStream;
16
18
import java.util.Iterator;
17
19
 
18
20
import javax.imageio.ImageIO;
30
32
 
31
33
import org.w3c.dom.DOMException;
32
34
 
 
35
import dk.aau.cs.TCTL.visitors.CTLQueryVisitor;
 
36
import dk.aau.cs.TCTL.visitors.RenameAllPlacesVisitor;
 
37
import dk.aau.cs.TCTL.visitors.RenameAllTransitionsVisitor;
33
38
import dk.aau.cs.gui.TabContent;
34
39
import dk.aau.cs.io.PNMLWriter;
35
 
import dk.aau.cs.io.TimedArcPetriNetNetworkWriter;
36
40
import dk.aau.cs.model.tapn.NetworkMarking;
 
41
import dk.aau.cs.verification.ITAPNComposer;
 
42
import dk.aau.cs.verification.NameMapping;
 
43
import dk.aau.cs.verification.TAPNComposer;
37
44
import pipe.dataLayer.DataLayer;
38
45
import pipe.dataLayer.NetWriter;
 
46
import pipe.dataLayer.TAPNQuery;
39
47
import pipe.gui.GuiFrame.GUIMode;
40
48
import pipe.gui.graphicElements.PetriNetObject;
41
49
import pipe.gui.widgets.FileBrowser;
52
60
        public static final int PRINTER = 3;
53
61
        public static final int TIKZ = 5;
54
62
        public static final int PNML = 6;
 
63
        public static final int QUERY = 7;      
55
64
 
56
65
        private static void toPnml(DrawingSurfaceImpl g, String filename) 
57
66
                        throws NullPointerException, DOMException, TransformerConfigurationException, 
74
83
                        currentTab.network().setMarking(currentMarking);
75
84
                }
76
85
        }
 
86
        
 
87
        private static void toQueryXML(DrawingSurfaceImpl g, String filename){
 
88
                try{
 
89
                        TabContent currentTab = CreateGui.getCurrentTab();
 
90
                        ITAPNComposer composer = new TAPNComposer(new MessengerImpl(), true);
 
91
                        NameMapping mapping = composer.transformModel(currentTab.network()).value2();
 
92
                        Iterator<TAPNQuery> queryIterator = currentTab.queries().iterator();
 
93
                        PrintStream queryStream = new PrintStream(filename);
 
94
                        CTLQueryVisitor XMLVisitor = new CTLQueryVisitor();
 
95
                        
 
96
                        while(queryIterator.hasNext()){
 
97
                            TAPNQuery clonedQuery = queryIterator.next().copy();
 
98
                            clonedQuery.getProperty().accept(new RenameAllPlacesVisitor(mapping), null);
 
99
                            clonedQuery.getProperty().accept(new RenameAllTransitionsVisitor(mapping), null);
 
100
                            XMLVisitor.buildXMLQuery(clonedQuery.getProperty(), clonedQuery.getName());
 
101
                        }
 
102
                        queryStream.print(XMLVisitor.getFormatted());
 
103
                        
 
104
                        queryStream.close();
 
105
                } catch(FileNotFoundException e) {
 
106
                        System.err.append("An error occurred while exporting the queries to XML.");
 
107
                }
 
108
        }
77
109
 
78
110
        public static void toPostScript(Object g, String filename)
79
111
                        throws PrintException, IOException {
146
178
                                        break;
147
179
                                case TIKZ:
148
180
                                        filename += "tex";
 
181
                                        break;
149
182
                                case PNML:
150
183
                                        filename += "pnml";
 
184
                                        break;
 
185
                                case QUERY:
 
186
                                        filename = filename.substring(0, dotpos);
 
187
                                        filename += "-queries.xml";
 
188
                                        break;
151
189
                                }
 
190
                                
152
191
                        }
153
192
                }
154
193
 
202
241
                                if (filename != null) {
203
242
                                        toPnml(g, filename);
204
243
                                }
 
244
                                break;
 
245
                        case QUERY:
 
246
                                filename = new FileBrowser("Query XML file", "xml", filename).saveFile(CreateGui.appGui.getCurrentTabName().replaceAll(".xml", "-queries"));
 
247
                                if (filename != null) {
 
248
                                        toQueryXML(g, filename);
 
249
                                }
 
250
                                break;
205
251
                        }
 
252
                } catch (NullPointerException e) {
206
253
                } catch (Exception e) {
207
254
                        // There was some problem with the action
208
255
                        JOptionPane.showMessageDialog(CreateGui.getApp(),