~danilovesky/workcraft/trunk-menu-tools

« back to all changes in this revision

Viewing changes to DfsPlugin/src/org/workcraft/plugins/dfs/tools/DfsSimulationTool.java

  • Committer: Danil Sokolov
  • Date: 2015-05-27 12:17:26 UTC
  • mfrom: (616.1.1 workcraft-trunk)
  • Revision ID: danilovesky@gmail.com-20150527121726-cbu8w2hc3jf9d8g8
Merge proposal for bug #1459158 approved.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import org.workcraft.gui.graph.tools.Decorator;
17
17
import org.workcraft.gui.graph.tools.GraphEditor;
18
18
import org.workcraft.plugins.dfs.BinaryRegister.Marking;
 
19
import org.workcraft.plugins.dfs.VisualAbstractRegister;
19
20
import org.workcraft.plugins.dfs.VisualBinaryRegister;
20
21
import org.workcraft.plugins.dfs.VisualControlRegister;
21
22
import org.workcraft.plugins.dfs.VisualCounterflowLogic;
38
39
import org.workcraft.plugins.dfs.stg.StgGenerator;
39
40
import org.workcraft.plugins.petri.Place;
40
41
import org.workcraft.plugins.petri.Transition;
 
42
import org.workcraft.plugins.petri.VisualPlace;
41
43
import org.workcraft.plugins.shared.CommonSimulationSettings;
42
44
import org.workcraft.plugins.stg.VisualSignalTransition;
43
45
import org.workcraft.plugins.stg.tools.StgSimulationTool;
64
66
                generator = new StgGenerator((VisualDfs)model);
65
67
                return generator.getStg();
66
68
        }
 
69
        
 
70
        private VisualPlace getVisualPlace(Place place) {
 
71
                VisualPlace result = null;
 
72
                for (VisualPlace vp: Hierarchy.getDescendantsOfType(visualNet.getRoot(), VisualPlace.class)) {
 
73
                        if (vp.getReferencedPlace() == place) {
 
74
                                result = vp;
 
75
                                break;
 
76
                        }
 
77
                }
 
78
                return result;
 
79
        }
 
80
 
 
81
        private void copyTokenColor(VisualAbstractRegister r, Node nodeM) {
 
82
                VisualPlace vp = getVisualPlace((Place)nodeM);
 
83
                if (vp != null) {
 
84
                        r.setTokenColor(vp.getTokenColor());
 
85
                }
 
86
        }
67
87
 
68
88
        @Override
69
89
        public void applyInitState(final GraphEditor editor) {
70
90
                if ((savedState == null) || savedState.isEmpty()) {
71
91
                        return;
72
92
                }
 
93
                editor.getWorkspaceEntry().saveMemento();
73
94
                VisualDfs dfs = (VisualDfs)editor.getModel();
74
95
                for(VisualLogic l : Hierarchy.getDescendantsOfType(dfs.getRoot(), VisualLogic.class)) {
75
96
                        String refC = StgGenerator.nameC + dfs.getNodeMathReference(l) + StgGenerator.name1;
85
106
                        if ((nodeM instanceof Place) && savedState.containsKey(nodeM)) {
86
107
                                boolean marked = (savedState.get(nodeM) > 0);
87
108
                                r.getReferencedRegister().setMarked(marked);
 
109
                                copyTokenColor(r, nodeM);
88
110
                        }
89
111
                }
90
112
                for(VisualCounterflowLogic l : Hierarchy.getDescendantsOfType(dfs.getRoot(), VisualCounterflowLogic.class)) {
107
129
                        if ((nodeOrM instanceof Place) && savedState.containsKey(nodeOrM)) {
108
130
                                boolean orMarked = (savedState.get(nodeOrM) > 0);
109
131
                                r.getReferencedCounterflowRegister().setOrMarked(orMarked);
 
132
                                copyTokenColor(r, nodeOrM);
110
133
                        }
111
134
                        String refAndM = StgGenerator.nameAndM + dfs.getNodeMathReference(r) + StgGenerator.name1;
112
135
                        Node nodeAndM = net.getNodeByReference(refAndM);
113
136
                        if ((nodeAndM instanceof Place) && savedState.containsKey(nodeAndM)) {
114
137
                                boolean andMarked = (savedState.get(nodeAndM) > 0);
115
138
                                r.getReferencedCounterflowRegister().setAndMarked(andMarked);
 
139
                                copyTokenColor(r, nodeAndM);
116
140
                        }
117
141
                }
118
142
                for(VisualBinaryRegister r : Hierarchy.getDescendantsOfType(dfs.getRoot(), VisualBinaryRegister.class)) {
123
147
                                if (savedState.get(nodeTrueM) > 0) {
124
148
                                        r.getReferencedBinaryRegister().setMarking(Marking.TRUE_TOKEN);
125
149
                                }
 
150
                                copyTokenColor(r, nodeTrueM);
126
151
                        }
127
152
                        String refFalseM = StgGenerator.nameFalseM + dfs.getNodeMathReference(r) + StgGenerator.name1;
128
153
                        Node nodeFalseM = net.getNodeByReference(refFalseM);
130
155
                                if (savedState.get(nodeFalseM) > 0) {
131
156
                                        r.getReferencedBinaryRegister().setMarking(Marking.FALSE_TOKEN);
132
157
                                }
 
158
                                copyTokenColor(r, nodeFalseM);
133
159
                        }
134
160
                }
135
161
        }