Merge lp:~tapaal-contributor/tapaal/autodetect-lens-check2 into lp:tapaal
- autodetect-lens-check2
- Merge into trunk
Proposed by
Kenneth Yrke Jørgensen
Status: | Merged |
---|---|
Approved by: | Jiri Srba |
Approved revision: | 1093 |
Merged at revision: | 1091 |
Proposed branch: | lp:~tapaal-contributor/tapaal/autodetect-lens-check2 |
Merge into: | lp:tapaal |
Diff against target: |
292 lines (+37/-93) 6 files modified
src/dk/aau/cs/gui/TabContent.java (+7/-59) src/dk/aau/cs/io/LoadedModel.java (+7/-14) src/dk/aau/cs/io/ModelLoader.java (+9/-10) src/dk/aau/cs/io/PNMLoader.java (+2/-2) src/dk/aau/cs/io/TapnLegacyXmlLoader.java (+3/-3) src/dk/aau/cs/io/TapnXmlLoader.java (+9/-5) |
To merge this branch: | bzr merge lp:~tapaal-contributor/tapaal/autodetect-lens-check2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Approve | ||
Review via email: mp+389844@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
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
1 | === modified file 'src/dk/aau/cs/gui/TabContent.java' | |||
2 | --- src/dk/aau/cs/gui/TabContent.java 2020-08-24 09:50:07 +0000 | |||
3 | +++ src/dk/aau/cs/gui/TabContent.java 2020-08-26 12:31:11 +0000 | |||
4 | @@ -613,60 +613,13 @@ | |||
5 | 613 | 613 | ||
6 | 614 | return tab; | 614 | return tab; |
7 | 615 | } catch (Exception e) { | 615 | } catch (Exception e) { |
9 | 616 | throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString()); | 616 | //throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString()); |
10 | 617 | throw e; | ||
11 | 617 | } | 618 | } |
12 | 618 | 619 | ||
13 | 619 | } | 620 | } |
14 | 620 | 621 | ||
64 | 621 | private TabContent createNewTabFromInputStream(InputStream file, String name, FeatureOption option, boolean isYes) throws Exception { | 622 | public static TabContent createNewEmptyTab(String name, boolean isTimed, boolean isGame){ |
16 | 622 | |||
17 | 623 | try { | ||
18 | 624 | ModelLoader loader = new ModelLoader(); | ||
19 | 625 | LoadedModel loadedModel = loader.load(file); | ||
20 | 626 | |||
21 | 627 | if (loadedModel.getMessages().size() != 0) { | ||
22 | 628 | new Thread(new Runnable() { | ||
23 | 629 | @Override | ||
24 | 630 | public void run() { | ||
25 | 631 | CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); | ||
26 | 632 | String message = "While loading the net we found one or more warnings: \n\n"; | ||
27 | 633 | for (String s : loadedModel.getMessages()) { | ||
28 | 634 | message += s + "\n\n"; | ||
29 | 635 | } | ||
30 | 636 | |||
31 | 637 | new MessengerImpl().displayInfoMessage(message, "Warning"); | ||
32 | 638 | } | ||
33 | 639 | }).start(); | ||
34 | 640 | } | ||
35 | 641 | |||
36 | 642 | TabContent tab; | ||
37 | 643 | |||
38 | 644 | switch (option) { | ||
39 | 645 | case TIME: | ||
40 | 646 | tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), isYes, lens.isGame()); | ||
41 | 647 | break; | ||
42 | 648 | case GAME: | ||
43 | 649 | tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), lens.isTimed(), isYes); | ||
44 | 650 | break; | ||
45 | 651 | default: | ||
46 | 652 | tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), lens.isTimed(), lens.isGame()); | ||
47 | 653 | break; | ||
48 | 654 | } | ||
49 | 655 | |||
50 | 656 | tab.setInitialName(name); | ||
51 | 657 | |||
52 | 658 | tab.selectFirstElements(); | ||
53 | 659 | |||
54 | 660 | tab.setFile(null); | ||
55 | 661 | |||
56 | 662 | return tab; | ||
57 | 663 | } catch (Exception e) { | ||
58 | 664 | throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString()); | ||
59 | 665 | } | ||
60 | 666 | |||
61 | 667 | } | ||
62 | 668 | |||
63 | 669 | public static TabContent createNewEmptyTab(String name, boolean isTimed, boolean isGame){ | ||
65 | 670 | TabContent tab = new TabContent(isTimed, isGame); | 623 | TabContent tab = new TabContent(isTimed, isGame); |
66 | 671 | tab.setInitialName(name); | 624 | tab.setInitialName(name); |
67 | 672 | 625 | ||
68 | @@ -692,7 +645,7 @@ | |||
69 | 692 | PNMLoader loader = new PNMLoader(); | 645 | PNMLoader loader = new PNMLoader(); |
70 | 693 | loadedModel = loader.load(file); | 646 | loadedModel = loader.load(file); |
71 | 694 | 647 | ||
73 | 695 | TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries()); | 648 | TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), loadedModel.getLens()); |
74 | 696 | 649 | ||
75 | 697 | String name = null; | 650 | String name = null; |
76 | 698 | 651 | ||
77 | @@ -816,14 +769,16 @@ | |||
78 | 816 | 769 | ||
79 | 817 | Require.that(network != null, "network cannot be null"); | 770 | Require.that(network != null, "network cannot be null"); |
80 | 818 | Require.notNull(lens, "Lens can't be null"); | 771 | Require.notNull(lens, "Lens can't be null"); |
81 | 772 | |||
82 | 773 | tapnNetwork = network; | ||
83 | 819 | this.lens = lens; | 774 | this.lens = lens; |
84 | 820 | tapnNetwork = network; | ||
85 | 821 | 775 | ||
86 | 822 | guiModels.clear(); | 776 | guiModels.clear(); |
87 | 823 | for (Template template : templates) { | 777 | for (Template template : templates) { |
88 | 824 | addGuiModel(template.model(), template.guiModel()); | 778 | addGuiModel(template.model(), template.guiModel()); |
89 | 825 | zoomLevels.put(template.model(), template.zoomer()); | 779 | zoomLevels.put(template.model(), template.zoomer()); |
90 | 826 | hasPositionalInfos.put(template.model(), template.getHasPositionalInfo()); | 780 | hasPositionalInfos.put(template.model(), template.getHasPositionalInfo()); |
91 | 781 | |||
92 | 827 | for(PetriNetObject o : template.guiModel().getPetriNetObjects()){ | 782 | for(PetriNetObject o : template.guiModel().getPetriNetObjects()){ |
93 | 828 | o.setLens(this.lens); | 783 | o.setLens(this.lens); |
94 | 829 | } | 784 | } |
95 | @@ -867,13 +822,6 @@ | |||
96 | 867 | animationModeController = new CanvasAnimationController(getAnimator()); | 822 | animationModeController = new CanvasAnimationController(getAnimator()); |
97 | 868 | } | 823 | } |
98 | 869 | 824 | ||
99 | 870 | private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries, boolean isTimed, boolean isGame) { | ||
100 | 871 | this(network, templates, tapnqueries, new TAPNLens(isTimed, isGame)); | ||
101 | 872 | } | ||
102 | 873 | |||
103 | 874 | private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries) { | ||
104 | 875 | this(network, templates, tapnqueries, new TAPNLens(true, false)); | ||
105 | 876 | } | ||
106 | 877 | public TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries, TAPNLens lens) { | 825 | public TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries, TAPNLens lens) { |
107 | 878 | this(network, templates, lens); | 826 | this(network, templates, lens); |
108 | 879 | 827 | ||
109 | 880 | 828 | ||
110 | === modified file 'src/dk/aau/cs/io/LoadedModel.java' | |||
111 | --- src/dk/aau/cs/io/LoadedModel.java 2020-08-11 11:11:59 +0000 | |||
112 | +++ src/dk/aau/cs/io/LoadedModel.java 2020-08-26 12:31:11 +0000 | |||
113 | @@ -17,13 +17,6 @@ | |||
114 | 17 | private final Collection<String> messages; | 17 | private final Collection<String> messages; |
115 | 18 | private final TabContent.TAPNLens lens; | 18 | private final TabContent.TAPNLens lens; |
116 | 19 | 19 | ||
117 | 20 | public LoadedModel(TimedArcPetriNetNetwork network, Collection<Template> templates, Collection<TAPNQuery> queries, Collection<String> messages){ | ||
118 | 21 | this(network, templates, queries, messages, TabContent.TAPNLens.Default); | ||
119 | 22 | } | ||
120 | 23 | public LoadedModel(TimedArcPetriNetNetwork network, Collection<Template> templates, Collection<TAPNQuery> queries){ | ||
121 | 24 | this(network, templates, queries, List.of(), TabContent.TAPNLens.Default); | ||
122 | 25 | } | ||
123 | 26 | |||
124 | 27 | public LoadedModel(TimedArcPetriNetNetwork network, Collection<Template> templates, Collection<TAPNQuery> queries, Collection<String> messages, TabContent.TAPNLens lens){ | 20 | public LoadedModel(TimedArcPetriNetNetwork network, Collection<Template> templates, Collection<TAPNQuery> queries, Collection<String> messages, TabContent.TAPNLens lens){ |
125 | 28 | this.templates = templates; | 21 | this.templates = templates; |
126 | 29 | this.network = network; | 22 | this.network = network; |
127 | @@ -38,14 +31,14 @@ | |||
128 | 38 | public Collection<String> getMessages() { return messages; } | 31 | public Collection<String> getMessages() { return messages; } |
129 | 39 | 32 | ||
130 | 40 | public TabContent.TAPNLens getLens(){ | 33 | public TabContent.TAPNLens getLens(){ |
133 | 41 | return lens; | 34 | if (lens != null) { |
134 | 42 | } | 35 | return lens; |
135 | 36 | } else { | ||
136 | 37 | boolean isNetTimed = !network().isUntimed(); | ||
137 | 38 | boolean isNetGame = network().hasUncontrollableTransitions(); | ||
138 | 43 | 39 | ||
144 | 44 | public boolean isTimed() { | 40 | return new TabContent.TAPNLens(isNetTimed, isNetGame); |
145 | 45 | return lens.isTimed(); | 41 | } |
141 | 46 | } | ||
142 | 47 | public boolean isGame() { | ||
143 | 48 | return lens.isGame(); | ||
146 | 49 | } | 42 | } |
147 | 50 | 43 | ||
148 | 51 | } | 44 | } |
149 | 52 | \ No newline at end of file | 45 | \ No newline at end of file |
150 | 53 | 46 | ||
151 | === modified file 'src/dk/aau/cs/io/ModelLoader.java' | |||
152 | --- src/dk/aau/cs/io/ModelLoader.java 2020-07-14 10:47:03 +0000 | |||
153 | +++ src/dk/aau/cs/io/ModelLoader.java 2020-08-26 12:31:11 +0000 | |||
154 | @@ -7,7 +7,6 @@ | |||
155 | 7 | import java.io.InputStream; | 7 | import java.io.InputStream; |
156 | 8 | 8 | ||
157 | 9 | import dk.aau.cs.TCTL.Parsing.ParseException; | 9 | import dk.aau.cs.TCTL.Parsing.ParseException; |
158 | 10 | import dk.aau.cs.io.batchProcessing.LoadedBatchProcessingModel; | ||
159 | 11 | 10 | ||
160 | 12 | public class ModelLoader { | 11 | public class ModelLoader { |
161 | 13 | 12 | ||
162 | @@ -17,19 +16,19 @@ | |||
163 | 17 | public LoadedModel load(File file) throws Exception{ | 16 | public LoadedModel load(File file) throws Exception{ |
164 | 18 | TapnXmlLoader newFormatLoader = new TapnXmlLoader(); | 17 | TapnXmlLoader newFormatLoader = new TapnXmlLoader(); |
165 | 19 | try{ | 18 | try{ |
168 | 20 | return newFormatLoader.load(file); | 19 | return newFormatLoader.load(file); |
169 | 21 | }catch(Throwable e1){ | 20 | }catch(Throwable e1){ |
170 | 22 | try { | 21 | try { |
171 | 23 | TapnLegacyXmlLoader oldFormatLoader = new TapnLegacyXmlLoader(); | 22 | TapnLegacyXmlLoader oldFormatLoader = new TapnLegacyXmlLoader(); |
174 | 24 | return oldFormatLoader.load(file); | 23 | return oldFormatLoader.load(file); |
175 | 25 | } catch(Throwable e2) { | 24 | } catch(Throwable e2) { |
176 | 26 | throw new ParseException(e1.getMessage()); | 25 | throw new ParseException(e1.getMessage()); |
177 | 27 | } | 26 | } |
178 | 28 | } | 27 | } |
179 | 29 | } | 28 | } |
183 | 30 | 29 | ||
184 | 31 | 30 | ||
185 | 32 | public LoadedModel load(InputStream file) throws Exception{ | 31 | public LoadedModel load(InputStream file) throws Exception{ |
186 | 33 | TapnXmlLoader newFormatLoader = new TapnXmlLoader(); | 32 | TapnXmlLoader newFormatLoader = new TapnXmlLoader(); |
187 | 34 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); | 33 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
188 | 35 | byte[] buffer = new byte[1024]; | 34 | byte[] buffer = new byte[1024]; |
189 | @@ -45,13 +44,13 @@ | |||
190 | 45 | 44 | ||
191 | 46 | return newFormatLoader.load(new ByteArrayInputStream(baos.toByteArray())); | 45 | return newFormatLoader.load(new ByteArrayInputStream(baos.toByteArray())); |
192 | 47 | 46 | ||
194 | 48 | }catch(Throwable e1){ | 47 | }catch(Throwable e1){ |
195 | 49 | try { | 48 | try { |
196 | 50 | TapnLegacyXmlLoader oldFormatLoader = new TapnLegacyXmlLoader(); | 49 | TapnLegacyXmlLoader oldFormatLoader = new TapnLegacyXmlLoader(); |
197 | 51 | 50 | ||
198 | 52 | return oldFormatLoader.load(new ByteArrayInputStream(baos.toByteArray())); | 51 | return oldFormatLoader.load(new ByteArrayInputStream(baos.toByteArray())); |
199 | 53 | 52 | ||
201 | 54 | } catch(Throwable e2) { | 53 | } catch(Throwable e2) { |
202 | 55 | throw new ParseException(e1.getMessage()); | 54 | throw new ParseException(e1.getMessage()); |
203 | 56 | } | 55 | } |
204 | 57 | } | 56 | } |
205 | 58 | 57 | ||
206 | === modified file 'src/dk/aau/cs/io/PNMLoader.java' | |||
207 | --- src/dk/aau/cs/io/PNMLoader.java 2020-08-11 12:18:11 +0000 | |||
208 | +++ src/dk/aau/cs/io/PNMLoader.java 2020-08-26 12:31:11 +0000 | |||
209 | @@ -53,7 +53,7 @@ | |||
210 | 53 | 53 | ||
211 | 54 | public class PNMLoader { | 54 | public class PNMLoader { |
212 | 55 | 55 | ||
214 | 56 | private final TabContent.TAPNLens lens = new TabContent.TAPNLens(false, false); | 56 | private final TabContent.TAPNLens lens = TabContent.TAPNLens.Default; |
215 | 57 | 57 | ||
216 | 58 | enum GraphicsType { Position, Offset } | 58 | enum GraphicsType { Position, Offset } |
217 | 59 | 59 | ||
218 | @@ -120,7 +120,7 @@ | |||
219 | 120 | 120 | ||
220 | 121 | network.setPaintNet(isNetDrawable()); | 121 | network.setPaintNet(isNetDrawable()); |
221 | 122 | tapn.setCheckNames(true); | 122 | tapn.setCheckNames(true); |
223 | 123 | return new LoadedModel(network, Arrays.asList(template), new ArrayList<TAPNQuery>()); | 123 | return new LoadedModel(network, Arrays.asList(template), new ArrayList<TAPNQuery>(), new ArrayList<>(), null); |
224 | 124 | } | 124 | } |
225 | 125 | 125 | ||
226 | 126 | private String getTAPNName(Node netNode) { | 126 | private String getTAPNName(Node netNode) { |
227 | 127 | 127 | ||
228 | === modified file 'src/dk/aau/cs/io/TapnLegacyXmlLoader.java' | |||
229 | --- src/dk/aau/cs/io/TapnLegacyXmlLoader.java 2020-08-11 12:18:11 +0000 | |||
230 | +++ src/dk/aau/cs/io/TapnLegacyXmlLoader.java 2020-08-26 12:31:11 +0000 | |||
231 | @@ -84,7 +84,7 @@ | |||
232 | 84 | private final IdResolver idResolver = new IdResolver(); | 84 | private final IdResolver idResolver = new IdResolver(); |
233 | 85 | 85 | ||
234 | 86 | private final Collection<String> messages = new ArrayList<>(10); | 86 | private final Collection<String> messages = new ArrayList<>(10); |
236 | 87 | private final TabContent.TAPNLens lens = new TabContent.TAPNLens(true, false); | 87 | private final TabContent.TAPNLens lens = TabContent.TAPNLens.Default; |
237 | 88 | 88 | ||
238 | 89 | 89 | ||
239 | 90 | public TapnLegacyXmlLoader() {} | 90 | public TapnLegacyXmlLoader() {} |
240 | @@ -145,8 +145,8 @@ | |||
241 | 145 | templates.add(parseTimedArcPetriNetAsOldFormat(nets.item(0), network)); | 145 | templates.add(parseTimedArcPetriNetAsOldFormat(nets.item(0), network)); |
242 | 146 | 146 | ||
243 | 147 | checkThatQueriesUseExistingPlaces(network); | 147 | checkThatQueriesUseExistingPlaces(network); |
246 | 148 | 148 | ||
247 | 149 | return new LoadedModel(network, templates, queries, messages); | 149 | return new LoadedModel(network, templates, queries, messages, null); |
248 | 150 | } | 150 | } |
249 | 151 | 151 | ||
250 | 152 | private void checkThatQueriesUseExistingPlaces(TimedArcPetriNetNetwork network) { | 152 | private void checkThatQueriesUseExistingPlaces(TimedArcPetriNetNetwork network) { |
251 | 153 | 153 | ||
252 | === modified file 'src/dk/aau/cs/io/TapnXmlLoader.java' | |||
253 | --- src/dk/aau/cs/io/TapnXmlLoader.java 2020-08-11 12:18:11 +0000 | |||
254 | +++ src/dk/aau/cs/io/TapnXmlLoader.java 2020-08-26 12:31:11 +0000 | |||
255 | @@ -71,7 +71,8 @@ | |||
256 | 71 | private final IdResolver idResolver = new IdResolver(); | 71 | private final IdResolver idResolver = new IdResolver(); |
257 | 72 | private final Collection<String> messages = new ArrayList<>(10); | 72 | private final Collection<String> messages = new ArrayList<>(10); |
258 | 73 | 73 | ||
260 | 74 | private TabContent.TAPNLens lens; | 74 | boolean hasFeatureTag = false; |
261 | 75 | private TabContent.TAPNLens lens = TabContent.TAPNLens.Default; | ||
262 | 75 | 76 | ||
263 | 76 | public TapnXmlLoader() { | 77 | public TapnXmlLoader() { |
264 | 77 | 78 | ||
265 | @@ -132,8 +133,11 @@ | |||
266 | 132 | parseBound(doc, network); | 133 | parseBound(doc, network); |
267 | 133 | 134 | ||
268 | 134 | 135 | ||
271 | 135 | 136 | if (hasFeatureTag) { | |
272 | 136 | return new LoadedModel(network, templates, queries,messages, lens); | 137 | return new LoadedModel(network, templates, queries, messages, lens); |
273 | 138 | } else { | ||
274 | 139 | return new LoadedModel(network, templates, queries, messages, null); | ||
275 | 140 | } | ||
276 | 137 | } | 141 | } |
277 | 138 | 142 | ||
278 | 139 | private void parseBound(Document doc, TimedArcPetriNetNetwork network){ | 143 | private void parseBound(Document doc, TimedArcPetriNetNetwork network){ |
279 | @@ -147,12 +151,12 @@ | |||
280 | 147 | if (doc.getElementsByTagName("feature").getLength() > 0) { | 151 | if (doc.getElementsByTagName("feature").getLength() > 0) { |
281 | 148 | NodeList nodeList = doc.getElementsByTagName("feature"); | 152 | NodeList nodeList = doc.getElementsByTagName("feature"); |
282 | 149 | 153 | ||
283 | 154 | hasFeatureTag = true; | ||
284 | 155 | |||
285 | 150 | var isTimed = Boolean.parseBoolean(nodeList.item(0).getAttributes().getNamedItem("isTimed").getNodeValue()); | 156 | var isTimed = Boolean.parseBoolean(nodeList.item(0).getAttributes().getNamedItem("isTimed").getNodeValue()); |
286 | 151 | var isGame = Boolean.parseBoolean(nodeList.item(0).getAttributes().getNamedItem("isGame").getNodeValue()); | 157 | var isGame = Boolean.parseBoolean(nodeList.item(0).getAttributes().getNamedItem("isGame").getNodeValue()); |
287 | 152 | 158 | ||
288 | 153 | lens = new TabContent.TAPNLens(isTimed, isGame); | 159 | lens = new TabContent.TAPNLens(isTimed, isGame); |
289 | 154 | } else { | ||
290 | 155 | lens = new TabContent.TAPNLens(true, false); | ||
291 | 156 | } | 160 | } |
292 | 157 | } | 161 | } |
293 | 158 | 162 |