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
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSimulationTool.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSimulationTool.java 2014-06-04 13:07:53 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSimulationTool.java 2014-06-28 22:44:31 +0000
@@ -106,12 +106,11 @@
106 VisualContact contact = (VisualContact) node;106 VisualContact contact = (VisualContact) node;
107 String transitionId = null;107 String transitionId = null;
108 Node transition2 = null;108 Node transition2 = null;
109 if (branchTrace != null && branchStep < branchTrace.size()) {109 if (branchTrace.canProgress()) {
110 transitionId = branchTrace.get(branchStep);110 transitionId = branchTrace.getCurrent();
111 transition2 = net.getNodeByReference(transitionId);111 transition2 = net.getNodeByReference(transitionId);
112 } else if (branchTrace == null && trace != null112 } else if (branchTrace.isEmpty() && mainTrace.canProgress()) {
113 && traceStep < trace.size()) {113 transitionId = mainTrace.getCurrent();
114 transitionId = trace.get(traceStep);
115 transition2 = net.getNodeByReference(transitionId);114 transition2 = net.getNodeByReference(transitionId);
116 }115 }
117116
118117
=== modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/tools/SimulationTool.java'
--- DfsPlugin/src/org/workcraft/plugins/dfs/tools/SimulationTool.java 2014-01-28 17:11:19 +0000
+++ DfsPlugin/src/org/workcraft/plugins/dfs/tools/SimulationTool.java 2014-06-28 22:44:31 +0000
@@ -131,11 +131,11 @@
131 public Decoration getDecoration(Node node) {131 public Decoration getDecoration(Node node) {
132 String transitionId = null;132 String transitionId = null;
133 Node transition = null;133 Node transition = null;
134 if (branchTrace != null && branchStep < branchTrace.size()) {134 if (branchTrace.canProgress()) {
135 transitionId = branchTrace.get(branchStep);135 transitionId = branchTrace.getCurrent();
136 transition = net.getNodeByReference(transitionId);136 transition = net.getNodeByReference(transitionId);
137 } else if (branchTrace == null && trace != null && traceStep < trace.size()) {137 } else if (branchTrace.isEmpty() && mainTrace.canProgress()) {
138 transitionId = trace.get(traceStep);138 transitionId = mainTrace.getCurrent();
139 transition = net.getNodeByReference(transitionId);139 transition = net.getNodeByReference(transitionId);
140 }140 }
141 141
142142
=== modified file 'MpsatPlugin/src/org/workcraft/plugins/mpsat/gui/SolutionPanel.java'
--- MpsatPlugin/src/org/workcraft/plugins/mpsat/gui/SolutionPanel.java 2014-04-29 16:23:15 +0000
+++ MpsatPlugin/src/org/workcraft/plugins/mpsat/gui/SolutionPanel.java 2014-06-28 22:44:31 +0000
@@ -26,14 +26,14 @@
26 private JPanel buttonsPanel;26 private JPanel buttonsPanel;
27 private JTextArea traceText;27 private JTextArea traceText;
28 28
29 public SolutionPanel(final MpsatChainTask task, final Trace t, final ActionListener closeAction) {29 public SolutionPanel(final MpsatChainTask task, final Trace trace, final ActionListener closeAction) {
30 super (new TableLayout(new double[][]30 super (new TableLayout(new double[][]
31 { { TableLayout.FILL, TableLayout.PREFERRED },31 { { TableLayout.FILL, TableLayout.PREFERRED },
32 {TableLayout.FILL} }32 {TableLayout.FILL} }
33 ));33 ));
34 34
35 traceText = new JTextArea();35 traceText = new JTextArea();
36 traceText.setText(t.toString());36 traceText.setText(trace.toString());
37 37
38 final JScrollPane scrollPane = new JScrollPane();38 final JScrollPane scrollPane = new JScrollPane();
39 scrollPane.setViewportView(traceText);39 scrollPane.setViewportView(traceText);
@@ -63,7 +63,7 @@
63 }63 }
64 final ToolboxPanel toolbox = currentEditor.getToolBox();64 final ToolboxPanel toolbox = currentEditor.getToolBox();
65 final PetriNetSimulationTool tool = toolbox.getToolInstance(PetriNetSimulationTool.class);65 final PetriNetSimulationTool tool = toolbox.getToolInstance(PetriNetSimulationTool.class);
66 tool.setTrace(t);66 tool.setTrace(trace);
67 toolbox.selectTool(tool);67 toolbox.selectTool(tool);
68 closeAction.actionPerformed(null);68 closeAction.actionPerformed(null);
69 }69 }
7070
=== modified file 'PetriNetPlugin/src/org/workcraft/plugins/petri/tools/PetriNetSimulationTool.java'
--- PetriNetPlugin/src/org/workcraft/plugins/petri/tools/PetriNetSimulationTool.java 2014-01-28 17:11:19 +0000
+++ PetriNetPlugin/src/org/workcraft/plugins/petri/tools/PetriNetSimulationTool.java 2014-06-28 22:44:31 +0000
@@ -68,6 +68,7 @@
68import org.workcraft.dom.visual.VisualModel;68import org.workcraft.dom.visual.VisualModel;
69import org.workcraft.dom.visual.connections.VisualConnection;69import org.workcraft.dom.visual.connections.VisualConnection;
70import org.workcraft.gui.Coloriser;70import org.workcraft.gui.Coloriser;
71import org.workcraft.gui.ExceptionDialog;
71import org.workcraft.gui.events.GraphEditorKeyEvent;72import org.workcraft.gui.events.GraphEditorKeyEvent;
72import org.workcraft.gui.events.GraphEditorMouseEvent;73import org.workcraft.gui.events.GraphEditorMouseEvent;
73import org.workcraft.gui.graph.tools.AbstractTool;74import org.workcraft.gui.graph.tools.AbstractTool;
@@ -97,21 +98,14 @@
97 98
98 private JSlider speedSlider;99 private JSlider speedSlider;
99 private JButton randomButton, playButton, stopButton, backwardButton, forwardButton;100 private JButton randomButton, playButton, stopButton, backwardButton, forwardButton;
100 private JButton copyStateButton, pasteStateButton, saveMarkingButton, loadMarkingButton, mergeTraceButton;101 private JButton copyStateButton, pasteStateButton, mergeTraceButton;
101 102
102 final double DEFAULT_SIMULATION_DELAY = 0.3;103 final double DEFAULT_SIMULATION_DELAY = 0.3;
103 final double EDGE_SPEED_MULTIPLIER = 10;104 final double EDGE_SPEED_MULTIPLIER = 10;
104 105
105 protected Map<Place, Integer> initialMarking;106 protected Map<Place, Integer> initialMarking;
106 Map<Place, Integer> savedMarking = null;107 protected final Trace mainTrace = new Trace();
107 int savedStep = 0;108 protected final Trace branchTrace = new Trace();
108 private Trace savedBranchTrace;
109 private int savedBranchStep = 0;
110
111 protected Trace branchTrace;
112 protected int branchStep = 0;
113 protected Trace trace;
114 protected int traceStep = 0;
115 109
116 private Timer timer = null;110 private Timer timer = null;
117 private boolean random = false;111 private boolean random = false;
@@ -131,8 +125,6 @@
131125
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");
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");
134 saveMarkingButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-marking-save.svg"), "Save marking to memory");
135 loadMarkingButton = GUI.createIconButton(GUI.createIconFromSVG("images/icons/svg/simulation-marking-load.svg"), "Load marking from memory");
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");
137 129
138 int buttonWidth = (int)Math.round(playButton.getPreferredSize().getWidth() + 5);130 int buttonWidth = (int)Math.round(playButton.getPreferredSize().getWidth() + 5);
@@ -161,8 +153,6 @@
161 traceControl.add(new JSeparator());153 traceControl.add(new JSeparator());
162 traceControl.add(copyStateButton);154 traceControl.add(copyStateButton);
163 traceControl.add(pasteStateButton);155 traceControl.add(pasteStateButton);
164 traceControl.add(saveMarkingButton);
165 traceControl.add(loadMarkingButton);
166 traceControl.add(mergeTraceButton);156 traceControl.add(mergeTraceButton);
167157
168 controlPanel = new JPanel();158 controlPanel = new JPanel();
@@ -186,8 +176,7 @@
186 speedSlider.addChangeListener(new ChangeListener() {176 speedSlider.addChangeListener(new ChangeListener() {
187 @Override177 @Override
188 public void stateChanged(ChangeEvent e) {178 public void stateChanged(ChangeEvent e) {
189 if(timer != null)179 if(timer != null) {
190 {
191 timer.stop();180 timer.stop();
192 timer.setInitialDelay(getAnimationDelay());181 timer.setInitialDelay(getAnimationDelay());
193 timer.setDelay(getAnimationDelay());182 timer.setDelay(getAnimationDelay());
@@ -201,7 +190,6 @@
201 @Override190 @Override
202 public void actionPerformed(ActionEvent e) {191 public void actionPerformed(ActionEvent e) {
203 if (timer == null) {192 if (timer == null) {
204 random = true;
205 timer = new Timer(getAnimationDelay(), new ActionListener() {193 timer = new Timer(getAnimationDelay(), new ActionListener() {
206 @Override194 @Override
207 public void actionPerformed(ActionEvent e) {195 public void actionPerformed(ActionEvent e) {
@@ -209,10 +197,13 @@
209 }197 }
210 });198 });
211 timer.start();199 timer.start();
212 } else {200 random = true;
201 } else if (random) {
213 timer.stop();202 timer.stop();
214 timer = null;203 timer = null;
215 random = false;204 random = false;
205 } else {
206 random = true;
216 }207 }
217 updateState(editor);208 updateState(editor);
218 }209 }
@@ -222,7 +213,6 @@
222 @Override213 @Override
223 public void actionPerformed(ActionEvent e) {214 public void actionPerformed(ActionEvent e) {
224 if (timer == null) {215 if (timer == null) {
225 random = false;
226 timer = new Timer(getAnimationDelay(), new ActionListener() {216 timer = new Timer(getAnimationDelay(), new ActionListener() {
227 @Override217 @Override
228 public void actionPerformed(ActionEvent e) {218 public void actionPerformed(ActionEvent e) {
@@ -230,10 +220,13 @@
230 }220 }
231 });221 });
232 timer.start();222 timer.start();
233 } else {223 random = false;
224 } else if (!random) {
234 timer.stop();225 timer.stop();
235 timer = null;226 timer = null;
236 random = false;227 random = false;
228 } else {
229 random = false;
237 }230 }
238 updateState(editor);231 updateState(editor);
239 }232 }
@@ -274,20 +267,6 @@
274 }267 }
275 });268 });
276 269
277 saveMarkingButton.addActionListener(new ActionListener() {
278 @Override
279 public void actionPerformed(ActionEvent e) {
280 saveMarking(editor);
281 }
282 });
283
284 loadMarkingButton.addActionListener(new ActionListener() {
285 @Override
286 public void actionPerformed(ActionEvent e) {
287 loadMarking(editor);
288 }
289 });
290
291 mergeTraceButton.addActionListener(new ActionListener() {270 mergeTraceButton.addActionListener(new ActionListener() {
292 @Override271 @Override
293 public void actionPerformed(ActionEvent e) {272 public void actionPerformed(ActionEvent e) {
@@ -300,18 +279,28 @@
300 public void mouseClicked(MouseEvent e) {279 public void mouseClicked(MouseEvent e) {
301 int column = traceTable.getSelectedColumn();280 int column = traceTable.getSelectedColumn();
302 int row = traceTable.getSelectedRow();281 int row = traceTable.getSelectedRow();
303 if (column==0) {282 if (column == 0) {
304 if ((trace != null) && (row < trace.size())) {283 if (row < mainTrace.size()) {
305 boolean work=true;284 boolean work = true;
306 while (branchStep>0&&work) work=quietStepBack();285 while (work && (branchTrace.getPosition() > 0)) {
307 while (traceStep>row&&work) work=quietStepBack();286 work = quietStepBack();
308 while (traceStep<row&&work) work=quietStep();287 }
288 while (work && (mainTrace.getPosition() > row)) {
289 work = quietStepBack();
290 }
291 while (work && (mainTrace.getPosition() < row)) {
292 work = quietStep();
293 }
309 }294 }
310 } else {295 } else {
311 if ((branchTrace != null) && (row >= traceStep) && (row < traceStep+branchTrace.size())) {296 if ((row >= mainTrace.getPosition()) && (row < mainTrace.getPosition() + branchTrace.size())) {
312 boolean work=true;297 boolean work = true;
313 while (traceStep+branchStep>row&&work) work=quietStepBack();298 while (work && (mainTrace.getPosition() + branchTrace.getPosition() > row)) {
314 while (traceStep+branchStep<row&&work) work=quietStep();299 work = quietStepBack();
300 }
301 while (work && (mainTrace.getPosition() + branchTrace.getPosition() < row)) {
302 work = quietStep();
303 }
315 }304 }
316 }305 }
317 updateState(editor);306 updateState(editor);
@@ -342,9 +331,8 @@
342 visualNet = getUnderlyingModel(editor.getModel());331 visualNet = getUnderlyingModel(editor.getModel());
343 net = (PetriNetModel)visualNet.getMathModel();332 net = (PetriNetModel)visualNet.getMathModel();
344 initialMarking = readMarking();333 initialMarking = readMarking();
345 traceStep = 0;334 mainTrace.clear();
346 branchTrace = null;335 branchTrace.clear();
347 branchStep = 0;
348 if (visualNet == editor.getModel()) {336 if (visualNet == editor.getModel()) {
349 editor.getWorkspaceEntry().captureMemento();337 editor.getWorkspaceEntry().captureMemento();
350 }338 }
@@ -371,7 +359,7 @@
371 if (net.getPlaces().contains(p)) {359 if (net.getPlaces().contains(p)) {
372 p.setTokens(marking.get(p));360 p.setTokens(marking.get(p));
373 } else {361 } else {
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"));
375 }363 }
376 }364 }
377 }365 }
@@ -381,22 +369,25 @@
381 playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg"));369 playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg"));
382 randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg"));370 randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg"));
383 } else {371 } else {
384 if (!random && (trace == null || traceStep == trace.size())) {372 if (random) {
385 playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg"));373 playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg"));
374 randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_pause.svg"));
375 timer.setDelay(getAnimationDelay());
376 } else if (branchTrace.canProgress() || (branchTrace.isEmpty() && mainTrace.canProgress())) {
377 playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-pause.svg"));
378 randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg"));
379 timer.setDelay(getAnimationDelay());
380 } else {
381 playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-play.svg"));
382 randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_play.svg"));
386 timer.stop();383 timer.stop();
387 timer = null;384 timer = null;
388 } else {
389 playButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-pause.svg"));
390 randomButton.setIcon(GUI.createIconFromSVG("images/icons/svg/simulation-random_pause.svg"));
391 timer.setDelay(getAnimationDelay());
392 }385 }
393 }386 }
394 playButton.setEnabled(trace != null && traceStep < trace.size());387 playButton.setEnabled(branchTrace.canProgress() || (branchTrace.isEmpty() && mainTrace.canProgress()));
395 stopButton.setEnabled(trace != null || branchTrace != null);388 stopButton.setEnabled(!mainTrace.isEmpty() || !branchTrace.isEmpty());
396 backwardButton.setEnabled(traceStep > 0 || branchStep > 0);389 backwardButton.setEnabled((mainTrace.getPosition() > 0) || (branchTrace.getPosition() > 0));
397 forwardButton.setEnabled(branchTrace==null && trace != null && traceStep < trace.size() || branchTrace != null && branchStep < branchTrace.size());390 forwardButton.setEnabled(branchTrace.canProgress() || (branchTrace.isEmpty() && mainTrace.canProgress()));
398 saveMarkingButton.setEnabled(true);
399 loadMarkingButton.setEnabled(savedMarking != null);
400 traceTable.tableChanged(new TableModelEvent(traceTable.getModel()));391 traceTable.tableChanged(new TableModelEvent(traceTable.getModel()));
401 editor.requestFocus();392 editor.requestFocus();
402 editor.repaint();393 editor.repaint();
@@ -405,14 +396,14 @@
405 private boolean quietStepBack() {396 private boolean quietStepBack() {
406 boolean result = false;397 boolean result = false;
407 String transitionId = null;398 String transitionId = null;
408 int traceDec = 0;399 int mainDec = 0;
409 int branchDec = 0;400 int branchDec = 0;
410 if (branchTrace != null && branchStep > 0) {401 if (branchTrace.getPosition() > 0) {
411 transitionId = branchTrace.get(branchStep-1);402 transitionId = branchTrace.get(branchTrace.getPosition()-1);
412 branchDec = 1; 403 branchDec = 1;
413 } else if (trace != null && traceStep > 0) {404 } else if (mainTrace.getPosition() > 0) {
414 transitionId = trace.get(traceStep-1);405 transitionId = mainTrace.get(mainTrace.getPosition() - 1);
415 traceDec = 1; 406 mainDec = 1;
416 }407 }
417 Transition transition = null;408 Transition transition = null;
418 if (transitionId != null) {409 if (transitionId != null) {
@@ -423,10 +414,10 @@
423 }414 }
424 if (transition != null && net.isUnfireEnabled(transition)) {415 if (transition != null && net.isUnfireEnabled(transition)) {
425 net.unFire(transition);416 net.unFire(transition);
426 traceStep -= traceDec;417 mainTrace.decPosition(mainDec);
427 branchStep -= branchDec;418 branchTrace.decPosition(branchDec);
428 if (branchStep == 0 && trace != null) {419 if ((branchTrace.getPosition() == 0) && !mainTrace.isEmpty()) {
429 branchTrace=null;420 branchTrace.clear();
430 }421 }
431 result = true;422 result = true;
432 }423 }
@@ -442,14 +433,14 @@
442 private boolean quietStep() {433 private boolean quietStep() {
443 boolean result = false;434 boolean result = false;
444 String transitionId = null;435 String transitionId = null;
445 int traceInc = 0;436 int mainInc = 0;
446 int branchInc = 0;437 int branchInc = 0;
447 if (branchTrace != null && branchStep < branchTrace.size()) {438 if (branchTrace.canProgress()) {
448 transitionId = branchTrace.get(branchStep);439 transitionId = branchTrace.getCurrent();
449 branchInc = 1;440 branchInc = 1;
450 } else if (trace != null && traceStep < trace.size()) {441 } else if (mainTrace.canProgress()) {
451 transitionId = trace.get(traceStep);442 transitionId = mainTrace.getCurrent();
452 traceInc = 1; 443 mainInc = 1;
453 }444 }
454 Transition transition = null;445 Transition transition = null;
455 if (transitionId != null) {446 if (transitionId != null) {
@@ -461,8 +452,8 @@
461 if (transition != null && net.isEnabled(transition)) {452 if (transition != null && net.isEnabled(transition)) {
462 net.fire(transition);453 net.fire(transition);
463 coloriseTokens(transition);454 coloriseTokens(transition);
464 traceStep += traceInc;455 mainTrace.incPosition(mainInc);
465 branchStep += branchInc;456 branchTrace.incPosition(branchInc);
466 result = true;457 result = true;
467 }458 }
468 return result;459 return result;
@@ -523,16 +514,9 @@
523 }514 }
524515
525 private void reset(final GraphEditor editor) {516 private void reset(final GraphEditor editor) {
526 if (traceStep == 0 && branchTrace == null) {517 applyMarking(initialMarking);
527 trace = null;518 mainTrace.clear();
528 traceStep = 0;519 branchTrace.clear();
529 branchStep=0;
530 } else {
531 applyMarking(initialMarking);
532 traceStep = 0;
533 branchStep=0;
534 branchTrace=null;
535 }
536 if (timer != null) {520 if (timer != null) {
537 timer.stop();521 timer.stop();
538 timer = null;522 timer = null;
@@ -542,9 +526,8 @@
542 526
543 private void copyState(final GraphEditor editor) {527 private void copyState(final GraphEditor editor) {
544 Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();528 Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
545 String st = ((trace!=null)?trace.toString():"")+"\n"+traceStep+"\n";529 StringSelection stringSelection = new StringSelection(
546 String st2 = (branchTrace!=null)?branchTrace.toString()+"\n"+branchStep:"";530 mainTrace.toString() + "\n" + branchTrace.toString() + "\n");
547 StringSelection stringSelection = new StringSelection(st+st2);
548 clip.setContents(stringSelection, this);531 clip.setContents(stringSelection, this);
549 updateState(editor);532 updateState(editor);
550 }533 }
@@ -567,69 +550,43 @@
567 ex.printStackTrace();550 ex.printStackTrace();
568 }551 }
569 }552 }
570 553
571 int i=0;554 applyMarking(initialMarking);
572 trace = new Trace();555 mainTrace.clear();
573 branchTrace = null;556 branchTrace.clear();
574 traceStep = 0;557 boolean first = true;
575 branchStep = 0;
576 for (String s: str.split("\n")) {558 for (String s: str.split("\n")) {
577 if (i==0) {559 if (first) {
578 trace.fromString(s);560 mainTrace.fromString(s);
579 } else if (i==1) {561 int mainTracePosition = mainTrace.getPosition();
580 traceStep = Integer.valueOf(s);562 mainTrace.setPosition(0);
581 } else if (i==2) {563 boolean work = true;
582 branchTrace = new Trace();564 while (work && (mainTrace.getPosition() < mainTracePosition)) {
565 work = quietStep();
566 }
567 } else {
583 branchTrace.fromString(s);568 branchTrace.fromString(s);
584 } else if (i==3) {569 int branchTracePosition = branchTrace.getPosition();
585 branchStep = Integer.valueOf(s);570 branchTrace.setPosition(0);
571 boolean work = true;
572 while (work && (branchTrace.getPosition() < branchTracePosition)) {
573 work = quietStep();
574 }
575 break;
586 }576 }
587 i++;577 first = false;
588 if (i>3) break;578 }
589 }579 updateState(editor);
590 updateState(editor);580 }
591 }581
592
593 private void saveMarking(final GraphEditor editor) {
594 savedMarking = readMarking();
595 savedStep = traceStep;
596 savedBranchStep = 0;
597 savedBranchTrace = null;
598 if (branchTrace!=null) {
599 savedBranchTrace = (Trace)branchTrace.clone();
600 savedBranchStep = branchStep;
601 }
602 updateState(editor);
603 }
604
605 private void loadMarking(final GraphEditor editor) {
606 applyMarking(savedMarking);
607 traceStep = savedStep;
608 if (savedBranchTrace != null) {
609 branchStep = savedBranchStep;
610 branchTrace = (Trace)savedBranchTrace.clone();
611 } else {
612 branchStep = 0;
613 branchTrace = null;
614 }
615 updateState(editor);
616 }
617
618 private void mergeTrace(final GraphEditor editor) {582 private void mergeTrace(final GraphEditor editor) {
619 if (branchTrace != null) {583 if (!branchTrace.isEmpty()) {
620 if (trace == null) {584 while (mainTrace.getPosition() < mainTrace.size()) {
621 trace = new Trace();585 mainTrace.removeCurrent();
622 }586 }
623 for (String s: branchTrace) {587 mainTrace.addAll(branchTrace);
624 if (s.length() > 0) {588 mainTrace.incPosition(branchTrace.getPosition());
625 trace.add(s);589 branchTrace.clear();
626 }
627 }
628 branchTrace = null;
629 if (branchStep > 0) {
630 traceStep = branchStep;
631 }
632 branchStep = 0;
633 }590 }
634 updateState(editor);591 updateState(editor);
635 }592 }
@@ -639,8 +596,7 @@
639 }596 }
640597
641 @SuppressWarnings("serial")598 @SuppressWarnings("serial")
642 private final class TraceTableCellRendererImplementation implements599 private final class TraceTableCellRendererImplementation implements TableCellRenderer {
643 TableCellRenderer {
644 JLabel label = new JLabel() {600 JLabel label = new JLabel() {
645 @Override601 @Override
646 public void paint( Graphics g ) {602 public void paint( Graphics g ) {
@@ -652,12 +608,12 @@
652608
653 boolean isActive(int row, int column) {609 boolean isActive(int row, int column) {
654 if (column==0) {610 if (column==0) {
655 if ((trace != null) && (branchTrace==null)) {611 if (!mainTrace.isEmpty() && branchTrace.isEmpty()) {
656 return row==traceStep;612 return row == mainTrace.getPosition();
657 }613 }
658 } else {614 } else {
659 if ((branchTrace != null) && (row >= traceStep) && (row < traceStep+branchTrace.size())) {615 if (!branchTrace.isEmpty() && (row >= mainTrace.getPosition()) && (row < mainTrace.getPosition() + branchTrace.size())) {
660 return (row-traceStep)==branchStep;616 return (row == mainTrace.getPosition() + branchTrace.getPosition());
661 }617 }
662 }618 }
663 return false;619 return false;
@@ -686,28 +642,24 @@
686 642
687 @Override643 @Override
688 public String getColumnName(int column) {644 public String getColumnName(int column) {
689 if (column==0) return "Trace";645 if (column == 0) return "Trace";
690 return "Branch";646 return "Branch";
691 }647 }
692648
693 @Override649 @Override
694 public int getRowCount() {650 public int getRowCount() {
695 int tnum = 0;651 return Math.max(mainTrace.size(), mainTrace.getPosition() + branchTrace.size());
696 int bnum = 0;
697 if (trace!=null) tnum=trace.size();
698 if (branchTrace!=null) bnum=branchTrace.size();
699
700 return Math.max(tnum, bnum+traceStep);
701 }652 }
702 653
703 @Override654 @Override
704 public Object getValueAt(int row, int col) {655 public Object getValueAt(int row, int column) {
705 if (col==0) {656 if (column == 0) {
706 if (trace!=null&&row<trace.size())657 if (!mainTrace.isEmpty() && (row < mainTrace.size())) {
707 return trace.get(row);658 return mainTrace.get(row);
659 }
708 } else {660 } else {
709 if (branchTrace!=null&&row>=traceStep&&row<traceStep+branchTrace.size()) {661 if (!branchTrace.isEmpty() && (row >= mainTrace.getPosition()) && (row < mainTrace.getPosition() + branchTrace.size())) {
710 return branchTrace.get(row-traceStep);662 return branchTrace.get(row - mainTrace.getPosition());
711 }663 }
712 }664 }
713 return "";665 return "";
@@ -734,31 +686,24 @@
734 686
735 public void executeTransition(final GraphEditor editor, Transition t) {687 public void executeTransition(final GraphEditor editor, Transition t) {
736 if (t == null) return;688 if (t == null) return;
737 689 String transitionId = null;
738 // if clicked on the trace event, do the step forward690 // if clicked on the trace event, do the step forward
739 if ((branchTrace == null) && (trace != null) && (traceStep < trace.size())) {691 if (branchTrace.isEmpty() && !mainTrace.isEmpty() && (mainTrace.getPosition() < mainTrace.size())) {
740 String transitionId = trace.get(traceStep);692 transitionId = mainTrace.get(mainTrace.getPosition());
741 Node transition = net.getNodeByReference(transitionId);
742 if ((transition != null) && (transition == t)) {
743 step(editor);
744 return;
745 }
746 }693 }
747 // otherwise form/use the branch trace694 // otherwise form/use the branch trace
748 if ((branchTrace != null) && (branchStep < branchTrace.size())) {695 if (!branchTrace.isEmpty() && (branchTrace.getPosition() < branchTrace.size())) {
749 String transitionId = branchTrace.get(branchStep);696 transitionId = branchTrace.get(branchTrace.getPosition());
697 }
698 if (transitionId != null) {
750 Node transition = net.getNodeByReference(transitionId);699 Node transition = net.getNodeByReference(transitionId);
751 if ((transition != null) && (transition == t)) {700 if ((transition != null) && (transition == t)) {
752 step(editor);701 step(editor);
753 return;702 return;
754 }703 }
755 }704 }
756 705 while (branchTrace.getPosition() < branchTrace.size()) {
757 if (branchTrace==null) {706 branchTrace.removeCurrent();
758 branchTrace = new Trace();
759 }
760 while (branchStep < branchTrace.size()) {
761 branchTrace.remove(branchStep);
762 }707 }
763 branchTrace.add(net.getNodeReference(t));708 branchTrace.add(net.getNodeReference(t));
764 step(editor);709 step(editor);
@@ -805,10 +750,9 @@
805 }750 }
806751
807 public void setTrace(Trace t) {752 public void setTrace(Trace t) {
808 this.trace = t;753 mainTrace.clear();
809 this.traceStep = 0;754 mainTrace.addAll(t);
810 this.branchTrace = null;755 branchTrace.clear();
811 this.branchStep = 0;
812 }756 }
813757
814 @Override758 @Override
@@ -820,11 +764,11 @@
820 Transition transition = ((VisualTransition)node).getReferencedTransition();764 Transition transition = ((VisualTransition)node).getReferencedTransition();
821 String transitionId = null;765 String transitionId = null;
822 Node transition2 = null;766 Node transition2 = null;
823 if ((branchTrace != null) && (branchStep < branchTrace.size())) {767 if (branchTrace.canProgress()) {
824 transitionId = branchTrace.get(branchStep);768 transitionId = branchTrace.get(branchTrace.getPosition());
825 transition2 = net.getNodeByReference(transitionId);769 transition2 = net.getNodeByReference(transitionId);
826 } else if ((branchTrace == null) && (trace != null) && (traceStep < trace.size())) {770 } else if (branchTrace.isEmpty() && mainTrace.canProgress()) {
827 transitionId = trace.get(traceStep);771 transitionId = mainTrace.get(mainTrace.getPosition());
828 transition2 = net.getNodeByReference(transitionId);772 transition2 = net.getNodeByReference(transitionId);
829 }773 }
830 774
831775
=== modified file 'PolicyNetPlugin/src/org/workcraft/plugins/policy/tools/SimulationTool.java'
--- PolicyNetPlugin/src/org/workcraft/plugins/policy/tools/SimulationTool.java 2014-01-28 17:11:19 +0000
+++ PolicyNetPlugin/src/org/workcraft/plugins/policy/tools/SimulationTool.java 2014-06-28 22:44:31 +0000
@@ -68,11 +68,11 @@
68 public Decoration getDecoration(Node node) {68 public Decoration getDecoration(Node node) {
69 String transitionId = null;69 String transitionId = null;
70 Node transition = null;70 Node transition = null;
71 if (branchTrace != null && branchStep < branchTrace.size()) {71 if (branchTrace.canProgress()) {
72 transitionId = branchTrace.get(branchStep);72 transitionId = branchTrace.getCurrent();
73 transition = net.getNodeByReference(transitionId);73 transition = net.getNodeByReference(transitionId);
74 } else if (branchTrace == null && trace != null && traceStep < trace.size()) {74 } else if (branchTrace.isEmpty() && mainTrace.canProgress()) {
75 transitionId = trace.get(traceStep);75 transitionId = mainTrace.getCurrent();
76 transition = net.getNodeByReference(transitionId);76 transition = net.getNodeByReference(transitionId);
77 }77 }
78 78
7979
=== modified file 'STGPlugin/src/org/workcraft/plugins/stg/tools/STGSimulationTool.java'
--- STGPlugin/src/org/workcraft/plugins/stg/tools/STGSimulationTool.java 2014-04-03 15:39:57 +0000
+++ STGPlugin/src/org/workcraft/plugins/stg/tools/STGSimulationTool.java 2014-06-28 22:44:31 +0000
@@ -118,12 +118,13 @@
118118
119 boolean isActive(int row, int column) {119 boolean isActive(int row, int column) {
120 if (column == 0) {120 if (column == 0) {
121 if (trace != null && branchTrace == null)121 if (!mainTrace.isEmpty() && branchTrace.isEmpty())
122 return row == traceStep;122 return row == mainTrace.getPosition();
123 } else {123 } else {
124 if (branchTrace != null && row >= traceStep124 int absoluteBranchSize = mainTrace.getPosition() + branchTrace.size();
125 && row < traceStep + branchTrace.size()) {125 int absoluteBranchPosition = mainTrace.getPosition() + branchTrace.getPosition();
126 return (row - traceStep) == branchStep;126 if (!branchTrace.isEmpty() && (row >= mainTrace.getPosition()) && (row < absoluteBranchSize)) {
127 return (row == absoluteBranchPosition);
127 }128 }
128 }129 }
129 return false;130 return false;
@@ -191,11 +192,11 @@
191 public void updateState(final GraphEditor editor) {192 public void updateState(final GraphEditor editor) {
192 super.updateState(editor);193 super.updateState(editor);
193 ArrayList<String> combinedTrace = new ArrayList<String>();194 ArrayList<String> combinedTrace = new ArrayList<String>();
194 if (trace != null) {195 if (!mainTrace.isEmpty()) {
195 combinedTrace.addAll(trace.subList(0, traceStep));196 combinedTrace.addAll(mainTrace.subList(0, mainTrace.getPosition()));
196 }197 }
197 if (branchTrace != null) {198 if (!branchTrace.isEmpty()) {
198 combinedTrace.addAll(branchTrace.subList(0, branchStep));199 combinedTrace.addAll(branchTrace.subList(0, branchTrace.getPosition()));
199 }200 }
200 201
201 for (String signalName: stateMap.keySet()) {202 for (String signalName: stateMap.keySet()) {
202203
=== modified file 'WorkcraftCore/src/org/workcraft/Trace.java'
--- WorkcraftCore/src/org/workcraft/Trace.java 2010-10-25 15:19:08 +0000
+++ WorkcraftCore/src/org/workcraft/Trace.java 2014-06-28 22:44:31 +0000
@@ -1,46 +1,93 @@
1package org.workcraft;1package org.workcraft;
22
3import java.io.BufferedReader;
4import java.io.IOException;
5import java.io.InputStream;
6import java.io.InputStreamReader;
7import java.io.OutputStream;
8import java.util.ArrayList;3import java.util.ArrayList;
94
10@SuppressWarnings("serial")5@SuppressWarnings("serial")
11public class Trace extends ArrayList<String>{6public class Trace extends ArrayList<String> {
7
8 private int position = 0;
9
10 public int getPosition() {
11 return position;
12 }
13
14 public void setPosition(int value) {
15 position = Math.min(Math.max(0, value), size());
16 }
17
18 public void incPosition(int value) {
19 setPosition(position + value);
20 }
21
22 public void decPosition(int value) {
23 setPosition(position - value);
24 }
25
26 public boolean canProgress() {
27 return (!isEmpty() && (position < size()));
28 }
29
30 public String getCurrent() {
31 return canProgress() ? get(position) : null;
32 }
33
34 public void removeCurrent() {
35 remove(getPosition());
36 }
37
38 @Override
39 public void clear() {
40 super.clear();
41 setPosition(0);
42 }
43
44 @Override
45 public String remove(int index) {
46 if (index < getPosition()) {
47 decPosition(1);
48 }
49 return super.remove(index);
50 }
51
12 public String toString() {52 public String toString() {
13 StringBuffer result = new StringBuffer("");53 StringBuffer result = new StringBuffer("");
14 54 // position
55 result.append(String.valueOf(getPosition()));
56 result.append(':');
57 // trace
15 boolean first = true;58 boolean first = true;
16
17 for (String t : this) {59 for (String t : this) {
18 if (first)60 if (!first) {
19 first = false;
20 else
21 result.append(',');61 result.append(',');
62 }
63 result.append(' ');
22 result.append(t);64 result.append(t);
65 first = false;
23 }66 }
24
25 return result.toString();67 return result.toString();
26 }68 }
27 69
28 public void fromString(String str) {70 public void fromString(String str) {
29 clear();71 clear();
30 for (String st : str.split("\n")) {72 int tmpPosition = 0;
31 for (String st2 : st.trim().split(","))73 boolean first = true;
32 add(st2.trim());74 for (String s : str.split(":")) {
75 if (first) {
76 // position
77 try {
78 tmpPosition = Integer.valueOf(s.trim());
79 } catch (Exception e) {
80
81 }
82 } else {
83 // trace
84 for (String st : s.trim().split(",")) {
85 add(st.trim());
86 }
87 }
88 first = false;
33 }89 }
34 }90 setPosition(tmpPosition);
35 91 }
36 public static void save (OutputStream os, Trace trace) throws IOException {92
37 os.write(trace.toString().getBytes());
38 }
39
40 public static Trace load (InputStream is, Trace trace) throws IOException {
41 Trace result = new Trace();
42 for (String s : new BufferedReader(new InputStreamReader(is)).readLine().split(","))
43 result.add(s);
44 return result;
45 }
46}93}

Subscribers

People subscribed via source and target branches