Merge lp:~danilovesky/workcraft/trunk-bug-1334772 into lp:workcraft

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

Subscribers

People subscribed via source and target branches