Merge lp:~danilovesky/workcraft/trunk-bug-1334772 into lp:workcraft
- trunk-bug-1334772
- Merge into trunk
Proposed by
Danil Sokolov
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 512 | ||||
Proposed branch: | lp:~danilovesky/workcraft/trunk-bug-1334772 | ||||
Merge into: | lp:workcraft | ||||
Diff against target: |
824 lines (+237/-246) 7 files modified
CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSimulationTool.java (+4/-5) DfsPlugin/src/org/workcraft/plugins/dfs/tools/SimulationTool.java (+4/-4) MpsatPlugin/src/org/workcraft/plugins/mpsat/gui/SolutionPanel.java (+3/-3) PetriNetPlugin/src/org/workcraft/plugins/petri/tools/PetriNetSimulationTool.java (+137/-193) PolicyNetPlugin/src/org/workcraft/plugins/policy/tools/SimulationTool.java (+4/-4) STGPlugin/src/org/workcraft/plugins/stg/tools/STGSimulationTool.java (+10/-9) WorkcraftCore/src/org/workcraft/Trace.java (+75/-28) |
||||
To merge this branch: | bzr merge lp:~danilovesky/workcraft/trunk-bug-1334772 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danil Sokolov | Approve | ||
Review via email: mp+224918@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Danil Sokolov (danilovesky) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSimulationTool.java' | |||
2 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSimulationTool.java 2014-06-04 13:07:53 +0000 | |||
3 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSimulationTool.java 2014-06-28 22:44:31 +0000 | |||
4 | @@ -106,12 +106,11 @@ | |||
5 | 106 | VisualContact contact = (VisualContact) node; | 106 | VisualContact contact = (VisualContact) node; |
6 | 107 | String transitionId = null; | 107 | String transitionId = null; |
7 | 108 | Node transition2 = null; | 108 | Node transition2 = null; |
10 | 109 | if (branchTrace != null && branchStep < branchTrace.size()) { | 109 | if (branchTrace.canProgress()) { |
11 | 110 | transitionId = branchTrace.get(branchStep); | 110 | transitionId = branchTrace.getCurrent(); |
12 | 111 | transition2 = net.getNodeByReference(transitionId); | 111 | transition2 = net.getNodeByReference(transitionId); |
16 | 112 | } else if (branchTrace == null && trace != null | 112 | } else if (branchTrace.isEmpty() && mainTrace.canProgress()) { |
17 | 113 | && traceStep < trace.size()) { | 113 | transitionId = mainTrace.getCurrent(); |
15 | 114 | transitionId = trace.get(traceStep); | ||
18 | 115 | transition2 = net.getNodeByReference(transitionId); | 114 | transition2 = net.getNodeByReference(transitionId); |
19 | 116 | } | 115 | } |
20 | 117 | 116 | ||
21 | 118 | 117 | ||
22 | === modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/tools/SimulationTool.java' | |||
23 | --- DfsPlugin/src/org/workcraft/plugins/dfs/tools/SimulationTool.java 2014-01-28 17:11:19 +0000 | |||
24 | +++ DfsPlugin/src/org/workcraft/plugins/dfs/tools/SimulationTool.java 2014-06-28 22:44:31 +0000 | |||
25 | @@ -131,11 +131,11 @@ | |||
26 | 131 | public Decoration getDecoration(Node node) { | 131 | public Decoration getDecoration(Node node) { |
27 | 132 | String transitionId = null; | 132 | String transitionId = null; |
28 | 133 | Node transition = null; | 133 | Node transition = null; |
31 | 134 | if (branchTrace != null && branchStep < branchTrace.size()) { | 134 | if (branchTrace.canProgress()) { |
32 | 135 | transitionId = branchTrace.get(branchStep); | 135 | transitionId = branchTrace.getCurrent(); |
33 | 136 | transition = net.getNodeByReference(transitionId); | 136 | transition = net.getNodeByReference(transitionId); |
36 | 137 | } else if (branchTrace == null && trace != null && traceStep < trace.size()) { | 137 | } else if (branchTrace.isEmpty() && mainTrace.canProgress()) { |
37 | 138 | transitionId = trace.get(traceStep); | 138 | transitionId = mainTrace.getCurrent(); |
38 | 139 | transition = net.getNodeByReference(transitionId); | 139 | transition = net.getNodeByReference(transitionId); |
39 | 140 | } | 140 | } |
40 | 141 | 141 | ||
41 | 142 | 142 | ||
42 | === modified file 'MpsatPlugin/src/org/workcraft/plugins/mpsat/gui/SolutionPanel.java' | |||
43 | --- MpsatPlugin/src/org/workcraft/plugins/mpsat/gui/SolutionPanel.java 2014-04-29 16:23:15 +0000 | |||
44 | +++ MpsatPlugin/src/org/workcraft/plugins/mpsat/gui/SolutionPanel.java 2014-06-28 22:44:31 +0000 | |||
45 | @@ -26,14 +26,14 @@ | |||
46 | 26 | private JPanel buttonsPanel; | 26 | private JPanel buttonsPanel; |
47 | 27 | private JTextArea traceText; | 27 | private JTextArea traceText; |
48 | 28 | 28 | ||
50 | 29 | public SolutionPanel(final MpsatChainTask task, final Trace t, final ActionListener closeAction) { | 29 | public SolutionPanel(final MpsatChainTask task, final Trace trace, final ActionListener closeAction) { |
51 | 30 | super (new TableLayout(new double[][] | 30 | super (new TableLayout(new double[][] |
52 | 31 | { { TableLayout.FILL, TableLayout.PREFERRED }, | 31 | { { TableLayout.FILL, TableLayout.PREFERRED }, |
53 | 32 | {TableLayout.FILL} } | 32 | {TableLayout.FILL} } |
54 | 33 | )); | 33 | )); |
55 | 34 | 34 | ||
56 | 35 | traceText = new JTextArea(); | 35 | traceText = new JTextArea(); |
58 | 36 | traceText.setText(t.toString()); | 36 | traceText.setText(trace.toString()); |
59 | 37 | 37 | ||
60 | 38 | final JScrollPane scrollPane = new JScrollPane(); | 38 | final JScrollPane scrollPane = new JScrollPane(); |
61 | 39 | scrollPane.setViewportView(traceText); | 39 | scrollPane.setViewportView(traceText); |
62 | @@ -63,7 +63,7 @@ | |||
63 | 63 | } | 63 | } |
64 | 64 | final ToolboxPanel toolbox = currentEditor.getToolBox(); | 64 | final ToolboxPanel toolbox = currentEditor.getToolBox(); |
65 | 65 | final PetriNetSimulationTool tool = toolbox.getToolInstance(PetriNetSimulationTool.class); | 65 | final PetriNetSimulationTool tool = toolbox.getToolInstance(PetriNetSimulationTool.class); |
67 | 66 | tool.setTrace(t); | 66 | tool.setTrace(trace); |
68 | 67 | toolbox.selectTool(tool); | 67 | toolbox.selectTool(tool); |
69 | 68 | closeAction.actionPerformed(null); | 68 | closeAction.actionPerformed(null); |
70 | 69 | } | 69 | } |
71 | 70 | 70 | ||
72 | === modified file 'PetriNetPlugin/src/org/workcraft/plugins/petri/tools/PetriNetSimulationTool.java' | |||
73 | --- PetriNetPlugin/src/org/workcraft/plugins/petri/tools/PetriNetSimulationTool.java 2014-01-28 17:11:19 +0000 | |||
74 | +++ PetriNetPlugin/src/org/workcraft/plugins/petri/tools/PetriNetSimulationTool.java 2014-06-28 22:44:31 +0000 | |||
75 | @@ -68,6 +68,7 @@ | |||
76 | 68 | import org.workcraft.dom.visual.VisualModel; | 68 | import org.workcraft.dom.visual.VisualModel; |
77 | 69 | import org.workcraft.dom.visual.connections.VisualConnection; | 69 | import org.workcraft.dom.visual.connections.VisualConnection; |
78 | 70 | import org.workcraft.gui.Coloriser; | 70 | import org.workcraft.gui.Coloriser; |
79 | 71 | import org.workcraft.gui.ExceptionDialog; | ||
80 | 71 | import org.workcraft.gui.events.GraphEditorKeyEvent; | 72 | import org.workcraft.gui.events.GraphEditorKeyEvent; |
81 | 72 | import org.workcraft.gui.events.GraphEditorMouseEvent; | 73 | import org.workcraft.gui.events.GraphEditorMouseEvent; |
82 | 73 | import org.workcraft.gui.graph.tools.AbstractTool; | 74 | import org.workcraft.gui.graph.tools.AbstractTool; |
83 | @@ -97,21 +98,14 @@ | |||
84 | 97 | 98 | ||
85 | 98 | private JSlider speedSlider; | 99 | private JSlider speedSlider; |
86 | 99 | private JButton randomButton, playButton, stopButton, backwardButton, forwardButton; | 100 | private JButton randomButton, playButton, stopButton, backwardButton, forwardButton; |
88 | 100 | private JButton copyStateButton, pasteStateButton, saveMarkingButton, loadMarkingButton, mergeTraceButton; | 101 | private JButton copyStateButton, pasteStateButton, mergeTraceButton; |
89 | 101 | 102 | ||
90 | 102 | final double DEFAULT_SIMULATION_DELAY = 0.3; | 103 | final double DEFAULT_SIMULATION_DELAY = 0.3; |
91 | 103 | final double EDGE_SPEED_MULTIPLIER = 10; | 104 | final double EDGE_SPEED_MULTIPLIER = 10; |
92 | 104 | 105 | ||
93 | 105 | protected Map<Place, Integer> initialMarking; | 106 | protected Map<Place, Integer> initialMarking; |
103 | 106 | Map<Place, Integer> savedMarking = null; | 107 | protected final Trace mainTrace = new Trace(); |
104 | 107 | int savedStep = 0; | 108 | protected final Trace branchTrace = new Trace(); |
96 | 108 | private Trace savedBranchTrace; | ||
97 | 109 | private int savedBranchStep = 0; | ||
98 | 110 | |||
99 | 111 | protected Trace branchTrace; | ||
100 | 112 | protected int branchStep = 0; | ||
101 | 113 | protected Trace trace; | ||
102 | 114 | protected int traceStep = 0; | ||
105 | 115 | 109 | ||
106 | 116 | private Timer timer = null; | 110 | private Timer timer = null; |
107 | 117 | private boolean random = false; | 111 | private boolean random = false; |
108 | @@ -131,8 +125,6 @@ | |||
109 | 131 | 125 | ||
110 | 132 | copyStateButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-trace-copy.svg"), "Copy trace to clipboard"); | 126 | copyStateButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-trace-copy.svg"), "Copy trace to clipboard"); |
111 | 133 | pasteStateButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-trace-paste.svg"), "Paste trace from clipboard"); | 127 | pasteStateButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-trace-paste.svg"), "Paste trace from clipboard"); |
112 | 134 | saveMarkingButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-marking-save.svg"), "Save marking to memory"); | ||
113 | 135 | loadMarkingButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-marking-load.svg"), "Load marking from memory"); | ||
114 | 136 | mergeTraceButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-trace-merge.svg"), "Merge branch into trace"); | 128 | mergeTraceButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-trace-merge.svg"), "Merge branch into trace"); |
115 | 137 | 129 | ||
116 | 138 | int buttonWidth = (int)Math.round(playButton.getPreferredSize().getWidth() + 5); | 130 | int buttonWidth = (int)Math.round(playButton.getPreferredSize().getWidth() + 5); |
117 | @@ -161,8 +153,6 @@ | |||
118 | 161 | traceControl.add(new JSeparator()); | 153 | traceControl.add(new JSeparator()); |
119 | 162 | traceControl.add(copyStateButton); | 154 | traceControl.add(copyStateButton); |
120 | 163 | traceControl.add(pasteStateButton); | 155 | traceControl.add(pasteStateButton); |
121 | 164 | traceControl.add(saveMarkingButton); | ||
122 | 165 | traceControl.add(loadMarkingButton); | ||
123 | 166 | traceControl.add(mergeTraceButton); | 156 | traceControl.add(mergeTraceButton); |
124 | 167 | 157 | ||
125 | 168 | controlPanel = new JPanel(); | 158 | controlPanel = new JPanel(); |
126 | @@ -186,8 +176,7 @@ | |||
127 | 186 | speedSlider.addChangeListener(new ChangeListener() { | 176 | speedSlider.addChangeListener(new ChangeListener() { |
128 | 187 | @Override | 177 | @Override |
129 | 188 | public void stateChanged(ChangeEvent e) { | 178 | public void stateChanged(ChangeEvent e) { |
132 | 189 | if(timer != null) | 179 | if(timer != null) { |
131 | 190 | { | ||
133 | 191 | timer.stop(); | 180 | timer.stop(); |
134 | 192 | timer.setInitialDelay(getAnimationDelay()); | 181 | timer.setInitialDelay(getAnimationDelay()); |
135 | 193 | timer.setDelay(getAnimationDelay()); | 182 | timer.setDelay(getAnimationDelay()); |
136 | @@ -201,7 +190,6 @@ | |||
137 | 201 | @Override | 190 | @Override |
138 | 202 | public void actionPerformed(ActionEvent e) { | 191 | public void actionPerformed(ActionEvent e) { |
139 | 203 | if (timer == null) { | 192 | if (timer == null) { |
140 | 204 | random = true; | ||
141 | 205 | timer = new Timer(getAnimationDelay(), new ActionListener() { | 193 | timer = new Timer(getAnimationDelay(), new ActionListener() { |
142 | 206 | @Override | 194 | @Override |
143 | 207 | public void actionPerformed(ActionEvent e) { | 195 | public void actionPerformed(ActionEvent e) { |
144 | @@ -209,10 +197,13 @@ | |||
145 | 209 | } | 197 | } |
146 | 210 | }); | 198 | }); |
147 | 211 | timer.start(); | 199 | timer.start(); |
149 | 212 | } else { | 200 | random = true; |
150 | 201 | } else if (random) { | ||
151 | 213 | timer.stop(); | 202 | timer.stop(); |
152 | 214 | timer = null; | 203 | timer = null; |
153 | 215 | random = false; | 204 | random = false; |
154 | 205 | } else { | ||
155 | 206 | random = true; | ||
156 | 216 | } | 207 | } |
157 | 217 | updateState(editor); | 208 | updateState(editor); |
158 | 218 | } | 209 | } |
159 | @@ -222,7 +213,6 @@ | |||
160 | 222 | @Override | 213 | @Override |
161 | 223 | public void actionPerformed(ActionEvent e) { | 214 | public void actionPerformed(ActionEvent e) { |
162 | 224 | if (timer == null) { | 215 | if (timer == null) { |
163 | 225 | random = false; | ||
164 | 226 | timer = new Timer(getAnimationDelay(), new ActionListener() { | 216 | timer = new Timer(getAnimationDelay(), new ActionListener() { |
165 | 227 | @Override | 217 | @Override |
166 | 228 | public void actionPerformed(ActionEvent e) { | 218 | public void actionPerformed(ActionEvent e) { |
167 | @@ -230,10 +220,13 @@ | |||
168 | 230 | } | 220 | } |
169 | 231 | }); | 221 | }); |
170 | 232 | timer.start(); | 222 | timer.start(); |
172 | 233 | } else { | 223 | random = false; |
173 | 224 | } else if (!random) { | ||
174 | 234 | timer.stop(); | 225 | timer.stop(); |
175 | 235 | timer = null; | 226 | timer = null; |
176 | 236 | random = false; | 227 | random = false; |
177 | 228 | } else { | ||
178 | 229 | random = false; | ||
179 | 237 | } | 230 | } |
180 | 238 | updateState(editor); | 231 | updateState(editor); |
181 | 239 | } | 232 | } |
182 | @@ -274,20 +267,6 @@ | |||
183 | 274 | } | 267 | } |
184 | 275 | }); | 268 | }); |
185 | 276 | 269 | ||
186 | 277 | saveMarkingButton.addActionListener(new ActionListener() { | ||
187 | 278 | @Override | ||
188 | 279 | public void actionPerformed(ActionEvent e) { | ||
189 | 280 | saveMarking(editor); | ||
190 | 281 | } | ||
191 | 282 | }); | ||
192 | 283 | |||
193 | 284 | loadMarkingButton.addActionListener(new ActionListener() { | ||
194 | 285 | @Override | ||
195 | 286 | public void actionPerformed(ActionEvent e) { | ||
196 | 287 | loadMarking(editor); | ||
197 | 288 | } | ||
198 | 289 | }); | ||
199 | 290 | |||
200 | 291 | mergeTraceButton.addActionListener(new ActionListener() { | 270 | mergeTraceButton.addActionListener(new ActionListener() { |
201 | 292 | @Override | 271 | @Override |
202 | 293 | public void actionPerformed(ActionEvent e) { | 272 | public void actionPerformed(ActionEvent e) { |
203 | @@ -300,18 +279,28 @@ | |||
204 | 300 | public void mouseClicked(MouseEvent e) { | 279 | public void mouseClicked(MouseEvent e) { |
205 | 301 | int column = traceTable.getSelectedColumn(); | 280 | int column = traceTable.getSelectedColumn(); |
206 | 302 | int row = traceTable.getSelectedRow(); | 281 | int row = traceTable.getSelectedRow(); |
213 | 303 | if (column==0) { | 282 | if (column == 0) { |
214 | 304 | if ((trace != null) && (row < trace.size())) { | 283 | if (row < mainTrace.size()) { |
215 | 305 | boolean work=true; | 284 | boolean work = true; |
216 | 306 | while (branchStep>0&&work) work=quietStepBack(); | 285 | while (work && (branchTrace.getPosition() > 0)) { |
217 | 307 | while (traceStep>row&&work) work=quietStepBack(); | 286 | work = quietStepBack(); |
218 | 308 | while (traceStep<row&&work) work=quietStep(); | 287 | } |
219 | 288 | while (work && (mainTrace.getPosition() > row)) { | ||
220 | 289 | work = quietStepBack(); | ||
221 | 290 | } | ||
222 | 291 | while (work && (mainTrace.getPosition() < row)) { | ||
223 | 292 | work = quietStep(); | ||
224 | 293 | } | ||
225 | 309 | } | 294 | } |
226 | 310 | } else { | 295 | } else { |
231 | 311 | if ((branchTrace != null) && (row >= traceStep) && (row < traceStep+branchTrace.size())) { | 296 | if ((row >= mainTrace.getPosition()) && (row < mainTrace.getPosition() + branchTrace.size())) { |
232 | 312 | boolean work=true; | 297 | boolean work = true; |
233 | 313 | while (traceStep+branchStep>row&&work) work=quietStepBack(); | 298 | while (work && (mainTrace.getPosition() + branchTrace.getPosition() > row)) { |
234 | 314 | while (traceStep+branchStep<row&&work) work=quietStep(); | 299 | work = quietStepBack(); |
235 | 300 | } | ||
236 | 301 | while (work && (mainTrace.getPosition() + branchTrace.getPosition() < row)) { | ||
237 | 302 | work = quietStep(); | ||
238 | 303 | } | ||
239 | 315 | } | 304 | } |
240 | 316 | } | 305 | } |
241 | 317 | updateState(editor); | 306 | updateState(editor); |
242 | @@ -342,9 +331,8 @@ | |||
243 | 342 | visualNet = getUnderlyingModel(editor.getModel()); | 331 | visualNet = getUnderlyingModel(editor.getModel()); |
244 | 343 | net = (PetriNetModel)visualNet.getMathModel(); | 332 | net = (PetriNetModel)visualNet.getMathModel(); |
245 | 344 | initialMarking = readMarking(); | 333 | initialMarking = readMarking(); |
249 | 345 | traceStep = 0; | 334 | mainTrace.clear(); |
250 | 346 | branchTrace = null; | 335 | branchTrace.clear(); |
248 | 347 | branchStep = 0; | ||
251 | 348 | if (visualNet == editor.getModel()) { | 336 | if (visualNet == editor.getModel()) { |
252 | 349 | editor.getWorkspaceEntry().captureMemento(); | 337 | editor.getWorkspaceEntry().captureMemento(); |
253 | 350 | } | 338 | } |
254 | @@ -371,7 +359,7 @@ | |||
255 | 371 | if (net.getPlaces().contains(p)) { | 359 | if (net.getPlaces().contains(p)) { |
256 | 372 | p.setTokens(marking.get(p)); | 360 | p.setTokens(marking.get(p)); |
257 | 373 | } else { | 361 | } else { |
259 | 374 | //ExceptionDialog.show(null, new RuntimeException("Place "+p.toString()+" is not in the model")); | 362 | ExceptionDialog.show(null, new RuntimeException("Place "+p.toString()+" is not in the model")); |
260 | 375 | } | 363 | } |
261 | 376 | } | 364 | } |
262 | 377 | } | 365 | } |
263 | @@ -381,22 +369,25 @@ | |||
264 | 381 | playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg")); | 369 | playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg")); |
265 | 382 | randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg")); | 370 | randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg")); |
266 | 383 | } else { | 371 | } else { |
269 | 384 | if (!random && (trace == null || traceStep == trace.size())) { | 372 | if (random) { |
270 | 385 | playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg")); | 373 | playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg")); |
271 | 374 | randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_pause.svg")); | ||
272 | 375 | timer.setDelay(getAnimationDelay()); | ||
273 | 376 | } else if (branchTrace.canProgress() || (branchTrace.isEmpty() && mainTrace.canProgress())) { | ||
274 | 377 | playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-pause.svg")); | ||
275 | 378 | randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg")); | ||
276 | 379 | timer.setDelay(getAnimationDelay()); | ||
277 | 380 | } else { | ||
278 | 381 | playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg")); | ||
279 | 382 | randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg")); | ||
280 | 386 | timer.stop(); | 383 | timer.stop(); |
281 | 387 | timer = null; | 384 | timer = null; |
282 | 388 | } else { | ||
283 | 389 | playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-pause.svg")); | ||
284 | 390 | randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_pause.svg")); | ||
285 | 391 | timer.setDelay(getAnimationDelay()); | ||
286 | 392 | } | 385 | } |
287 | 393 | } | 386 | } |
294 | 394 | playButton.setEnabled(trace != null && traceStep < trace.size()); | 387 | playButton.setEnabled(branchTrace.canProgress() || (branchTrace.isEmpty() && mainTrace.canProgress())); |
295 | 395 | stopButton.setEnabled(trace != null || branchTrace != null); | 388 | stopButton.setEnabled(!mainTrace.isEmpty() || !branchTrace.isEmpty()); |
296 | 396 | backwardButton.setEnabled(traceStep > 0 || branchStep > 0); | 389 | backwardButton.setEnabled((mainTrace.getPosition() > 0) || (branchTrace.getPosition() > 0)); |
297 | 397 | forwardButton.setEnabled(branchTrace==null && trace != null && traceStep < trace.size() || branchTrace != null && branchStep < branchTrace.size()); | 390 | forwardButton.setEnabled(branchTrace.canProgress() || (branchTrace.isEmpty() && mainTrace.canProgress())); |
292 | 398 | saveMarkingButton.setEnabled(true); | ||
293 | 399 | loadMarkingButton.setEnabled(savedMarking != null); | ||
298 | 400 | traceTable.tableChanged(new TableModelEvent(traceTable.getModel())); | 391 | traceTable.tableChanged(new TableModelEvent(traceTable.getModel())); |
299 | 401 | editor.requestFocus(); | 392 | editor.requestFocus(); |
300 | 402 | editor.repaint(); | 393 | editor.repaint(); |
301 | @@ -405,14 +396,14 @@ | |||
302 | 405 | private boolean quietStepBack() { | 396 | private boolean quietStepBack() { |
303 | 406 | boolean result = false; | 397 | boolean result = false; |
304 | 407 | String transitionId = null; | 398 | String transitionId = null; |
306 | 408 | int traceDec = 0; | 399 | int mainDec = 0; |
307 | 409 | int branchDec = 0; | 400 | int branchDec = 0; |
310 | 410 | if (branchTrace != null && branchStep > 0) { | 401 | if (branchTrace.getPosition() > 0) { |
311 | 411 | transitionId = branchTrace.get(branchStep-1); | 402 | transitionId = branchTrace.get(branchTrace.getPosition()-1); |
312 | 412 | branchDec = 1; | 403 | branchDec = 1; |
316 | 413 | } else if (trace != null && traceStep > 0) { | 404 | } else if (mainTrace.getPosition() > 0) { |
317 | 414 | transitionId = trace.get(traceStep-1); | 405 | transitionId = mainTrace.get(mainTrace.getPosition() - 1); |
318 | 415 | traceDec = 1; | 406 | mainDec = 1; |
319 | 416 | } | 407 | } |
320 | 417 | Transition transition = null; | 408 | Transition transition = null; |
321 | 418 | if (transitionId != null) { | 409 | if (transitionId != null) { |
322 | @@ -423,10 +414,10 @@ | |||
323 | 423 | } | 414 | } |
324 | 424 | if (transition != null && net.isUnfireEnabled(transition)) { | 415 | if (transition != null && net.isUnfireEnabled(transition)) { |
325 | 425 | net.unFire(transition); | 416 | net.unFire(transition); |
330 | 426 | traceStep -= traceDec; | 417 | mainTrace.decPosition(mainDec); |
331 | 427 | branchStep -= branchDec; | 418 | branchTrace.decPosition(branchDec); |
332 | 428 | if (branchStep == 0 && trace != null) { | 419 | if ((branchTrace.getPosition() == 0) && !mainTrace.isEmpty()) { |
333 | 429 | branchTrace=null; | 420 | branchTrace.clear(); |
334 | 430 | } | 421 | } |
335 | 431 | result = true; | 422 | result = true; |
336 | 432 | } | 423 | } |
337 | @@ -442,14 +433,14 @@ | |||
338 | 442 | private boolean quietStep() { | 433 | private boolean quietStep() { |
339 | 443 | boolean result = false; | 434 | boolean result = false; |
340 | 444 | String transitionId = null; | 435 | String transitionId = null; |
342 | 445 | int traceInc = 0; | 436 | int mainInc = 0; |
343 | 446 | int branchInc = 0; | 437 | int branchInc = 0; |
346 | 447 | if (branchTrace != null && branchStep < branchTrace.size()) { | 438 | if (branchTrace.canProgress()) { |
347 | 448 | transitionId = branchTrace.get(branchStep); | 439 | transitionId = branchTrace.getCurrent(); |
348 | 449 | branchInc = 1; | 440 | branchInc = 1; |
352 | 450 | } else if (trace != null && traceStep < trace.size()) { | 441 | } else if (mainTrace.canProgress()) { |
353 | 451 | transitionId = trace.get(traceStep); | 442 | transitionId = mainTrace.getCurrent(); |
354 | 452 | traceInc = 1; | 443 | mainInc = 1; |
355 | 453 | } | 444 | } |
356 | 454 | Transition transition = null; | 445 | Transition transition = null; |
357 | 455 | if (transitionId != null) { | 446 | if (transitionId != null) { |
358 | @@ -461,8 +452,8 @@ | |||
359 | 461 | if (transition != null && net.isEnabled(transition)) { | 452 | if (transition != null && net.isEnabled(transition)) { |
360 | 462 | net.fire(transition); | 453 | net.fire(transition); |
361 | 463 | coloriseTokens(transition); | 454 | coloriseTokens(transition); |
364 | 464 | traceStep += traceInc; | 455 | mainTrace.incPosition(mainInc); |
365 | 465 | branchStep += branchInc; | 456 | branchTrace.incPosition(branchInc); |
366 | 466 | result = true; | 457 | result = true; |
367 | 467 | } | 458 | } |
368 | 468 | return result; | 459 | return result; |
369 | @@ -523,16 +514,9 @@ | |||
370 | 523 | } | 514 | } |
371 | 524 | 515 | ||
372 | 525 | private void reset(final GraphEditor editor) { | 516 | private void reset(final GraphEditor editor) { |
383 | 526 | if (traceStep == 0 && branchTrace == null) { | 517 | applyMarking(initialMarking); |
384 | 527 | trace = null; | 518 | mainTrace.clear(); |
385 | 528 | traceStep = 0; | 519 | branchTrace.clear(); |
376 | 529 | branchStep=0; | ||
377 | 530 | } else { | ||
378 | 531 | applyMarking(initialMarking); | ||
379 | 532 | traceStep = 0; | ||
380 | 533 | branchStep=0; | ||
381 | 534 | branchTrace=null; | ||
382 | 535 | } | ||
386 | 536 | if (timer != null) { | 520 | if (timer != null) { |
387 | 537 | timer.stop(); | 521 | timer.stop(); |
388 | 538 | timer = null; | 522 | timer = null; |
389 | @@ -542,9 +526,8 @@ | |||
390 | 542 | 526 | ||
391 | 543 | private void copyState(final GraphEditor editor) { | 527 | private void copyState(final GraphEditor editor) { |
392 | 544 | Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); | 528 | Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); |
396 | 545 | String st = ((trace!=null)?trace.toString():"")+"\n"+traceStep+"\n"; | 529 | StringSelection stringSelection = new StringSelection( |
397 | 546 | String st2 = (branchTrace!=null)?branchTrace.toString()+"\n"+branchStep:""; | 530 | mainTrace.toString() + "\n" + branchTrace.toString() + "\n"); |
395 | 547 | StringSelection stringSelection = new StringSelection(st+st2); | ||
398 | 548 | clip.setContents(stringSelection, this); | 531 | clip.setContents(stringSelection, this); |
399 | 549 | updateState(editor); | 532 | updateState(editor); |
400 | 550 | } | 533 | } |
401 | @@ -567,69 +550,43 @@ | |||
402 | 567 | ex.printStackTrace(); | 550 | ex.printStackTrace(); |
403 | 568 | } | 551 | } |
404 | 569 | } | 552 | } |
411 | 570 | 553 | ||
412 | 571 | int i=0; | 554 | applyMarking(initialMarking); |
413 | 572 | trace = new Trace(); | 555 | mainTrace.clear(); |
414 | 573 | branchTrace = null; | 556 | branchTrace.clear(); |
415 | 574 | traceStep = 0; | 557 | boolean first = true; |
410 | 575 | branchStep = 0; | ||
416 | 576 | for (String s: str.split("\n")) { | 558 | for (String s: str.split("\n")) { |
423 | 577 | if (i==0) { | 559 | if (first) { |
424 | 578 | trace.fromString(s); | 560 | mainTrace.fromString(s); |
425 | 579 | } else if (i==1) { | 561 | int mainTracePosition = mainTrace.getPosition(); |
426 | 580 | traceStep = Integer.valueOf(s); | 562 | mainTrace.setPosition(0); |
427 | 581 | } else if (i==2) { | 563 | boolean work = true; |
428 | 582 | branchTrace = new Trace(); | 564 | while (work && (mainTrace.getPosition() < mainTracePosition)) { |
429 | 565 | work = quietStep(); | ||
430 | 566 | } | ||
431 | 567 | } else { | ||
432 | 583 | branchTrace.fromString(s); | 568 | branchTrace.fromString(s); |
435 | 584 | } else if (i==3) { | 569 | int branchTracePosition = branchTrace.getPosition(); |
436 | 585 | branchStep = Integer.valueOf(s); | 570 | branchTrace.setPosition(0); |
437 | 571 | boolean work = true; | ||
438 | 572 | while (work && (branchTrace.getPosition() < branchTracePosition)) { | ||
439 | 573 | work = quietStep(); | ||
440 | 574 | } | ||
441 | 575 | break; | ||
442 | 586 | } | 576 | } |
474 | 587 | i++; | 577 | first = false; |
475 | 588 | if (i>3) break; | 578 | } |
476 | 589 | } | 579 | updateState(editor); |
477 | 590 | updateState(editor); | 580 | } |
478 | 591 | } | 581 | |
448 | 592 | |||
449 | 593 | private void saveMarking(final GraphEditor editor) { | ||
450 | 594 | savedMarking = readMarking(); | ||
451 | 595 | savedStep = traceStep; | ||
452 | 596 | savedBranchStep = 0; | ||
453 | 597 | savedBranchTrace = null; | ||
454 | 598 | if (branchTrace!=null) { | ||
455 | 599 | savedBranchTrace = (Trace)branchTrace.clone(); | ||
456 | 600 | savedBranchStep = branchStep; | ||
457 | 601 | } | ||
458 | 602 | updateState(editor); | ||
459 | 603 | } | ||
460 | 604 | |||
461 | 605 | private void loadMarking(final GraphEditor editor) { | ||
462 | 606 | applyMarking(savedMarking); | ||
463 | 607 | traceStep = savedStep; | ||
464 | 608 | if (savedBranchTrace != null) { | ||
465 | 609 | branchStep = savedBranchStep; | ||
466 | 610 | branchTrace = (Trace)savedBranchTrace.clone(); | ||
467 | 611 | } else { | ||
468 | 612 | branchStep = 0; | ||
469 | 613 | branchTrace = null; | ||
470 | 614 | } | ||
471 | 615 | updateState(editor); | ||
472 | 616 | } | ||
473 | 617 | |||
479 | 618 | private void mergeTrace(final GraphEditor editor) { | 582 | private void mergeTrace(final GraphEditor editor) { |
494 | 619 | if (branchTrace != null) { | 583 | if (!branchTrace.isEmpty()) { |
495 | 620 | if (trace == null) { | 584 | while (mainTrace.getPosition() < mainTrace.size()) { |
496 | 621 | trace = new Trace(); | 585 | mainTrace.removeCurrent(); |
497 | 622 | } | 586 | } |
498 | 623 | for (String s: branchTrace) { | 587 | mainTrace.addAll(branchTrace); |
499 | 624 | if (s.length() > 0) { | 588 | mainTrace.incPosition(branchTrace.getPosition()); |
500 | 625 | trace.add(s); | 589 | branchTrace.clear(); |
487 | 626 | } | ||
488 | 627 | } | ||
489 | 628 | branchTrace = null; | ||
490 | 629 | if (branchStep > 0) { | ||
491 | 630 | traceStep = branchStep; | ||
492 | 631 | } | ||
493 | 632 | branchStep = 0; | ||
501 | 633 | } | 590 | } |
502 | 634 | updateState(editor); | 591 | updateState(editor); |
503 | 635 | } | 592 | } |
504 | @@ -639,8 +596,7 @@ | |||
505 | 639 | } | 596 | } |
506 | 640 | 597 | ||
507 | 641 | @SuppressWarnings("serial") | 598 | @SuppressWarnings("serial") |
510 | 642 | private final class TraceTableCellRendererImplementation implements | 599 | private final class TraceTableCellRendererImplementation implements TableCellRenderer { |
509 | 643 | TableCellRenderer { | ||
511 | 644 | JLabel label = new JLabel() { | 600 | JLabel label = new JLabel() { |
512 | 645 | @Override | 601 | @Override |
513 | 646 | public void paint( Graphics g ) { | 602 | public void paint( Graphics g ) { |
514 | @@ -652,12 +608,12 @@ | |||
515 | 652 | 608 | ||
516 | 653 | boolean isActive(int row, int column) { | 609 | boolean isActive(int row, int column) { |
517 | 654 | if (column==0) { | 610 | if (column==0) { |
520 | 655 | if ((trace != null) && (branchTrace==null)) { | 611 | if (!mainTrace.isEmpty() && branchTrace.isEmpty()) { |
521 | 656 | return row==traceStep; | 612 | return row == mainTrace.getPosition(); |
522 | 657 | } | 613 | } |
523 | 658 | } else { | 614 | } else { |
526 | 659 | if ((branchTrace != null) && (row >= traceStep) && (row < traceStep+branchTrace.size())) { | 615 | if (!branchTrace.isEmpty() && (row >= mainTrace.getPosition()) && (row < mainTrace.getPosition() + branchTrace.size())) { |
527 | 660 | return (row-traceStep)==branchStep; | 616 | return (row == mainTrace.getPosition() + branchTrace.getPosition()); |
528 | 661 | } | 617 | } |
529 | 662 | } | 618 | } |
530 | 663 | return false; | 619 | return false; |
531 | @@ -686,28 +642,24 @@ | |||
532 | 686 | 642 | ||
533 | 687 | @Override | 643 | @Override |
534 | 688 | public String getColumnName(int column) { | 644 | public String getColumnName(int column) { |
536 | 689 | if (column==0) return "Trace"; | 645 | if (column == 0) return "Trace"; |
537 | 690 | return "Branch"; | 646 | return "Branch"; |
538 | 691 | } | 647 | } |
539 | 692 | 648 | ||
540 | 693 | @Override | 649 | @Override |
541 | 694 | public int getRowCount() { | 650 | public int getRowCount() { |
548 | 695 | int tnum = 0; | 651 | return Math.max(mainTrace.size(), mainTrace.getPosition() + branchTrace.size()); |
543 | 696 | int bnum = 0; | ||
544 | 697 | if (trace!=null) tnum=trace.size(); | ||
545 | 698 | if (branchTrace!=null) bnum=branchTrace.size(); | ||
546 | 699 | |||
547 | 700 | return Math.max(tnum, bnum+traceStep); | ||
549 | 701 | } | 652 | } |
550 | 702 | 653 | ||
551 | 703 | @Override | 654 | @Override |
556 | 704 | public Object getValueAt(int row, int col) { | 655 | public Object getValueAt(int row, int column) { |
557 | 705 | if (col==0) { | 656 | if (column == 0) { |
558 | 706 | if (trace!=null&&row<trace.size()) | 657 | if (!mainTrace.isEmpty() && (row < mainTrace.size())) { |
559 | 707 | return trace.get(row); | 658 | return mainTrace.get(row); |
560 | 659 | } | ||
561 | 708 | } else { | 660 | } else { |
564 | 709 | if (branchTrace!=null&&row>=traceStep&&row<traceStep+branchTrace.size()) { | 661 | if (!branchTrace.isEmpty() && (row >= mainTrace.getPosition()) && (row < mainTrace.getPosition() + branchTrace.size())) { |
565 | 710 | return branchTrace.get(row-traceStep); | 662 | return branchTrace.get(row - mainTrace.getPosition()); |
566 | 711 | } | 663 | } |
567 | 712 | } | 664 | } |
568 | 713 | return ""; | 665 | return ""; |
569 | @@ -734,31 +686,24 @@ | |||
570 | 734 | 686 | ||
571 | 735 | public void executeTransition(final GraphEditor editor, Transition t) { | 687 | public void executeTransition(final GraphEditor editor, Transition t) { |
572 | 736 | if (t == null) return; | 688 | if (t == null) return; |
574 | 737 | 689 | String transitionId = null; | |
575 | 738 | // if clicked on the trace event, do the step forward | 690 | // if clicked on the trace event, do the step forward |
583 | 739 | if ((branchTrace == null) && (trace != null) && (traceStep < trace.size())) { | 691 | if (branchTrace.isEmpty() && !mainTrace.isEmpty() && (mainTrace.getPosition() < mainTrace.size())) { |
584 | 740 | String transitionId = trace.get(traceStep); | 692 | transitionId = mainTrace.get(mainTrace.getPosition()); |
578 | 741 | Node transition = net.getNodeByReference(transitionId); | ||
579 | 742 | if ((transition != null) && (transition == t)) { | ||
580 | 743 | step(editor); | ||
581 | 744 | return; | ||
582 | 745 | } | ||
585 | 746 | } | 693 | } |
586 | 747 | // otherwise form/use the branch trace | 694 | // otherwise form/use the branch trace |
589 | 748 | if ((branchTrace != null) && (branchStep < branchTrace.size())) { | 695 | if (!branchTrace.isEmpty() && (branchTrace.getPosition() < branchTrace.size())) { |
590 | 749 | String transitionId = branchTrace.get(branchStep); | 696 | transitionId = branchTrace.get(branchTrace.getPosition()); |
591 | 697 | } | ||
592 | 698 | if (transitionId != null) { | ||
593 | 750 | Node transition = net.getNodeByReference(transitionId); | 699 | Node transition = net.getNodeByReference(transitionId); |
594 | 751 | if ((transition != null) && (transition == t)) { | 700 | if ((transition != null) && (transition == t)) { |
595 | 752 | step(editor); | 701 | step(editor); |
596 | 753 | return; | 702 | return; |
597 | 754 | } | 703 | } |
598 | 755 | } | 704 | } |
605 | 756 | 705 | while (branchTrace.getPosition() < branchTrace.size()) { | |
606 | 757 | if (branchTrace==null) { | 706 | branchTrace.removeCurrent(); |
601 | 758 | branchTrace = new Trace(); | ||
602 | 759 | } | ||
603 | 760 | while (branchStep < branchTrace.size()) { | ||
604 | 761 | branchTrace.remove(branchStep); | ||
607 | 762 | } | 707 | } |
608 | 763 | branchTrace.add(net.getNodeReference(t)); | 708 | branchTrace.add(net.getNodeReference(t)); |
609 | 764 | step(editor); | 709 | step(editor); |
610 | @@ -805,10 +750,9 @@ | |||
611 | 805 | } | 750 | } |
612 | 806 | 751 | ||
613 | 807 | public void setTrace(Trace t) { | 752 | public void setTrace(Trace t) { |
618 | 808 | this.trace = t; | 753 | mainTrace.clear(); |
619 | 809 | this.traceStep = 0; | 754 | mainTrace.addAll(t); |
620 | 810 | this.branchTrace = null; | 755 | branchTrace.clear(); |
617 | 811 | this.branchStep = 0; | ||
621 | 812 | } | 756 | } |
622 | 813 | 757 | ||
623 | 814 | @Override | 758 | @Override |
624 | @@ -820,11 +764,11 @@ | |||
625 | 820 | Transition transition = ((VisualTransition)node).getReferencedTransition(); | 764 | Transition transition = ((VisualTransition)node).getReferencedTransition(); |
626 | 821 | String transitionId = null; | 765 | String transitionId = null; |
627 | 822 | Node transition2 = null; | 766 | Node transition2 = null; |
630 | 823 | if ((branchTrace != null) && (branchStep < branchTrace.size())) { | 767 | if (branchTrace.canProgress()) { |
631 | 824 | transitionId = branchTrace.get(branchStep); | 768 | transitionId = branchTrace.get(branchTrace.getPosition()); |
632 | 825 | transition2 = net.getNodeByReference(transitionId); | 769 | transition2 = net.getNodeByReference(transitionId); |
635 | 826 | } else if ((branchTrace == null) && (trace != null) && (traceStep < trace.size())) { | 770 | } else if (branchTrace.isEmpty() && mainTrace.canProgress()) { |
636 | 827 | transitionId = trace.get(traceStep); | 771 | transitionId = mainTrace.get(mainTrace.getPosition()); |
637 | 828 | transition2 = net.getNodeByReference(transitionId); | 772 | transition2 = net.getNodeByReference(transitionId); |
638 | 829 | } | 773 | } |
639 | 830 | 774 | ||
640 | 831 | 775 | ||
641 | === modified file 'PolicyNetPlugin/src/org/workcraft/plugins/policy/tools/SimulationTool.java' | |||
642 | --- PolicyNetPlugin/src/org/workcraft/plugins/policy/tools/SimulationTool.java 2014-01-28 17:11:19 +0000 | |||
643 | +++ PolicyNetPlugin/src/org/workcraft/plugins/policy/tools/SimulationTool.java 2014-06-28 22:44:31 +0000 | |||
644 | @@ -68,11 +68,11 @@ | |||
645 | 68 | public Decoration getDecoration(Node node) { | 68 | public Decoration getDecoration(Node node) { |
646 | 69 | String transitionId = null; | 69 | String transitionId = null; |
647 | 70 | Node transition = null; | 70 | Node transition = null; |
650 | 71 | if (branchTrace != null && branchStep < branchTrace.size()) { | 71 | if (branchTrace.canProgress()) { |
651 | 72 | transitionId = branchTrace.get(branchStep); | 72 | transitionId = branchTrace.getCurrent(); |
652 | 73 | transition = net.getNodeByReference(transitionId); | 73 | transition = net.getNodeByReference(transitionId); |
655 | 74 | } else if (branchTrace == null && trace != null && traceStep < trace.size()) { | 74 | } else if (branchTrace.isEmpty() && mainTrace.canProgress()) { |
656 | 75 | transitionId = trace.get(traceStep); | 75 | transitionId = mainTrace.getCurrent(); |
657 | 76 | transition = net.getNodeByReference(transitionId); | 76 | transition = net.getNodeByReference(transitionId); |
658 | 77 | } | 77 | } |
659 | 78 | 78 | ||
660 | 79 | 79 | ||
661 | === modified file 'STGPlugin/src/org/workcraft/plugins/stg/tools/STGSimulationTool.java' | |||
662 | --- STGPlugin/src/org/workcraft/plugins/stg/tools/STGSimulationTool.java 2014-04-03 15:39:57 +0000 | |||
663 | +++ STGPlugin/src/org/workcraft/plugins/stg/tools/STGSimulationTool.java 2014-06-28 22:44:31 +0000 | |||
664 | @@ -118,12 +118,13 @@ | |||
665 | 118 | 118 | ||
666 | 119 | boolean isActive(int row, int column) { | 119 | boolean isActive(int row, int column) { |
667 | 120 | if (column == 0) { | 120 | if (column == 0) { |
670 | 121 | if (trace != null && branchTrace == null) | 121 | if (!mainTrace.isEmpty() && branchTrace.isEmpty()) |
671 | 122 | return row == traceStep; | 122 | return row == mainTrace.getPosition(); |
672 | 123 | } else { | 123 | } else { |
676 | 124 | if (branchTrace != null && row >= traceStep | 124 | int absoluteBranchSize = mainTrace.getPosition() + branchTrace.size(); |
677 | 125 | && row < traceStep + branchTrace.size()) { | 125 | int absoluteBranchPosition = mainTrace.getPosition() + branchTrace.getPosition(); |
678 | 126 | return (row - traceStep) == branchStep; | 126 | if (!branchTrace.isEmpty() && (row >= mainTrace.getPosition()) && (row < absoluteBranchSize)) { |
679 | 127 | return (row == absoluteBranchPosition); | ||
680 | 127 | } | 128 | } |
681 | 128 | } | 129 | } |
682 | 129 | return false; | 130 | return false; |
683 | @@ -191,11 +192,11 @@ | |||
684 | 191 | public void updateState(final GraphEditor editor) { | 192 | public void updateState(final GraphEditor editor) { |
685 | 192 | super.updateState(editor); | 193 | super.updateState(editor); |
686 | 193 | ArrayList<String> combinedTrace = new ArrayList<String>(); | 194 | ArrayList<String> combinedTrace = new ArrayList<String>(); |
689 | 194 | if (trace != null) { | 195 | if (!mainTrace.isEmpty()) { |
690 | 195 | combinedTrace.addAll(trace.subList(0, traceStep)); | 196 | combinedTrace.addAll(mainTrace.subList(0, mainTrace.getPosition())); |
691 | 196 | } | 197 | } |
694 | 197 | if (branchTrace != null) { | 198 | if (!branchTrace.isEmpty()) { |
695 | 198 | combinedTrace.addAll(branchTrace.subList(0, branchStep)); | 199 | combinedTrace.addAll(branchTrace.subList(0, branchTrace.getPosition())); |
696 | 199 | } | 200 | } |
697 | 200 | 201 | ||
698 | 201 | for (String signalName: stateMap.keySet()) { | 202 | for (String signalName: stateMap.keySet()) { |
699 | 202 | 203 | ||
700 | === modified file 'WorkcraftCore/src/org/workcraft/Trace.java' | |||
701 | --- WorkcraftCore/src/org/workcraft/Trace.java 2010-10-25 15:19:08 +0000 | |||
702 | +++ WorkcraftCore/src/org/workcraft/Trace.java 2014-06-28 22:44:31 +0000 | |||
703 | @@ -1,46 +1,93 @@ | |||
704 | 1 | package org.workcraft; | 1 | package org.workcraft; |
705 | 2 | 2 | ||
706 | 3 | import java.io.BufferedReader; | ||
707 | 4 | import java.io.IOException; | ||
708 | 5 | import java.io.InputStream; | ||
709 | 6 | import java.io.InputStreamReader; | ||
710 | 7 | import java.io.OutputStream; | ||
711 | 8 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
712 | 9 | 4 | ||
713 | 10 | @SuppressWarnings("serial") | 5 | @SuppressWarnings("serial") |
715 | 11 | public class Trace extends ArrayList<String>{ | 6 | public class Trace extends ArrayList<String> { |
716 | 7 | |||
717 | 8 | private int position = 0; | ||
718 | 9 | |||
719 | 10 | public int getPosition() { | ||
720 | 11 | return position; | ||
721 | 12 | } | ||
722 | 13 | |||
723 | 14 | public void setPosition(int value) { | ||
724 | 15 | position = Math.min(Math.max(0, value), size()); | ||
725 | 16 | } | ||
726 | 17 | |||
727 | 18 | public void incPosition(int value) { | ||
728 | 19 | setPosition(position + value); | ||
729 | 20 | } | ||
730 | 21 | |||
731 | 22 | public void decPosition(int value) { | ||
732 | 23 | setPosition(position - value); | ||
733 | 24 | } | ||
734 | 25 | |||
735 | 26 | public boolean canProgress() { | ||
736 | 27 | return (!isEmpty() && (position < size())); | ||
737 | 28 | } | ||
738 | 29 | |||
739 | 30 | public String getCurrent() { | ||
740 | 31 | return canProgress() ? get(position) : null; | ||
741 | 32 | } | ||
742 | 33 | |||
743 | 34 | public void removeCurrent() { | ||
744 | 35 | remove(getPosition()); | ||
745 | 36 | } | ||
746 | 37 | |||
747 | 38 | @Override | ||
748 | 39 | public void clear() { | ||
749 | 40 | super.clear(); | ||
750 | 41 | setPosition(0); | ||
751 | 42 | } | ||
752 | 43 | |||
753 | 44 | @Override | ||
754 | 45 | public String remove(int index) { | ||
755 | 46 | if (index < getPosition()) { | ||
756 | 47 | decPosition(1); | ||
757 | 48 | } | ||
758 | 49 | return super.remove(index); | ||
759 | 50 | } | ||
760 | 51 | |||
761 | 12 | public String toString() { | 52 | public String toString() { |
762 | 13 | StringBuffer result = new StringBuffer(""); | 53 | StringBuffer result = new StringBuffer(""); |
764 | 14 | 54 | // position | |
765 | 55 | result.append(String.valueOf(getPosition())); | ||
766 | 56 | result.append(':'); | ||
767 | 57 | // trace | ||
768 | 15 | boolean first = true; | 58 | boolean first = true; |
769 | 16 | |||
770 | 17 | for (String t : this) { | 59 | for (String t : this) { |
774 | 18 | if (first) | 60 | if (!first) { |
772 | 19 | first = false; | ||
773 | 20 | else | ||
775 | 21 | result.append(','); | 61 | result.append(','); |
776 | 62 | } | ||
777 | 63 | result.append(' '); | ||
778 | 22 | result.append(t); | 64 | result.append(t); |
779 | 65 | first = false; | ||
780 | 23 | } | 66 | } |
781 | 24 | |||
782 | 25 | return result.toString(); | 67 | return result.toString(); |
783 | 26 | } | 68 | } |
785 | 27 | 69 | ||
786 | 28 | public void fromString(String str) { | 70 | public void fromString(String str) { |
787 | 29 | clear(); | 71 | clear(); |
791 | 30 | for (String st : str.split("\n")) { | 72 | int tmpPosition = 0; |
792 | 31 | for (String st2 : st.trim().split(",")) | 73 | boolean first = true; |
793 | 32 | add(st2.trim()); | 74 | for (String s : str.split(":")) { |
794 | 75 | if (first) { | ||
795 | 76 | // position | ||
796 | 77 | try { | ||
797 | 78 | tmpPosition = Integer.valueOf(s.trim()); | ||
798 | 79 | } catch (Exception e) { | ||
799 | 80 | |||
800 | 81 | } | ||
801 | 82 | } else { | ||
802 | 83 | // trace | ||
803 | 84 | for (String st : s.trim().split(",")) { | ||
804 | 85 | add(st.trim()); | ||
805 | 86 | } | ||
806 | 87 | } | ||
807 | 88 | first = false; | ||
808 | 33 | } | 89 | } |
821 | 34 | } | 90 | setPosition(tmpPosition); |
822 | 35 | 91 | } | |
823 | 36 | public static void save (OutputStream os, Trace trace) throws IOException { | 92 | |
812 | 37 | os.write(trace.toString().getBytes()); | ||
813 | 38 | } | ||
814 | 39 | |||
815 | 40 | public static Trace load (InputStream is, Trace trace) throws IOException { | ||
816 | 41 | Trace result = new Trace(); | ||
817 | 42 | for (String s : new BufferedReader(new InputStreamReader(is)).readLine().split(",")) | ||
818 | 43 | result.add(s); | ||
819 | 44 | return result; | ||
820 | 45 | } | ||
824 | 46 | } | 93 | } |