Merge lp:~sgaflv/workcraft/trunk-hierarchical into lp:workcraft
- trunk-hierarchical
- Merge into trunk
Proposed by
Stan
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danil Sokolov | Approve | ||
Review via email: mp+226425@code.launchpad.net |
Commit message
Description of the change
- adding pages, hierarchical names and namespaces
- adaptation to all model types, also simulation, verification, and traces
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 '.bzrignore' | |||
2 | --- .bzrignore 2010-10-07 15:30:31 +0000 | |||
3 | +++ .bzrignore 2014-07-11 09:42:10 +0000 | |||
4 | @@ -10,4 +10,8 @@ | |||
5 | 10 | generated | 10 | generated |
6 | 11 | /.metadata | 11 | /.metadata |
7 | 12 | *.jar | 12 | *.jar |
9 | 13 | 13 | *.orig | |
10 | 14 | *.moved | ||
11 | 15 | *.BASE | ||
12 | 16 | *.OTHER | ||
13 | 17 | *.THIS | ||
14 | 14 | \ No newline at end of file | 18 | \ No newline at end of file |
15 | 15 | 19 | ||
16 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/Circuit.java' | |||
17 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/Circuit.java 2010-10-08 15:48:47 +0000 | |||
18 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/Circuit.java 2014-07-11 09:42:10 +0000 | |||
19 | @@ -21,24 +21,79 @@ | |||
20 | 21 | 21 | ||
21 | 22 | package org.workcraft.plugins.circuit; | 22 | package org.workcraft.plugins.circuit; |
22 | 23 | 23 | ||
23 | 24 | import org.workcraft.dom.Connection; | ||
24 | 25 | import org.workcraft.dom.Container; | ||
25 | 24 | import org.workcraft.dom.Node; | 26 | import org.workcraft.dom.Node; |
26 | 27 | import org.workcraft.dom.hierarchy.NamespaceProvider; | ||
27 | 25 | import org.workcraft.dom.math.AbstractMathModel; | 28 | import org.workcraft.dom.math.AbstractMathModel; |
28 | 29 | import org.workcraft.dom.math.CommentNode; | ||
29 | 26 | import org.workcraft.dom.math.MathConnection; | 30 | import org.workcraft.dom.math.MathConnection; |
30 | 27 | import org.workcraft.dom.math.MathGroup; | 31 | import org.workcraft.dom.math.MathGroup; |
31 | 28 | import org.workcraft.dom.math.MathNode; | 32 | import org.workcraft.dom.math.MathNode; |
32 | 33 | import org.workcraft.dom.math.PageNode; | ||
33 | 34 | import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager; | ||
34 | 29 | import org.workcraft.exceptions.InvalidConnectionException; | 35 | import org.workcraft.exceptions.InvalidConnectionException; |
35 | 30 | import org.workcraft.exceptions.ModelValidationException; | 36 | import org.workcraft.exceptions.ModelValidationException; |
36 | 37 | import org.workcraft.gui.propertyeditor.DefaultNamePropertyDescriptor; | ||
37 | 38 | import org.workcraft.gui.propertyeditor.Properties; | ||
38 | 39 | import org.workcraft.plugins.circuit.Contact.IOType; | ||
39 | 40 | import org.workcraft.plugins.circuit.references.CircuitReferenceManager; | ||
40 | 41 | import org.workcraft.serialisation.References; | ||
41 | 42 | import org.workcraft.util.Func; | ||
42 | 31 | import org.workcraft.util.Hierarchy; | 43 | import org.workcraft.util.Hierarchy; |
43 | 44 | import org.workcraft.util.Identifier; | ||
44 | 45 | |||
45 | 32 | 46 | ||
46 | 33 | public class Circuit extends AbstractMathModel { | 47 | public class Circuit extends AbstractMathModel { |
47 | 34 | 48 | ||
48 | 49 | |||
49 | 35 | public Circuit() { | 50 | public Circuit() { |
51 | 36 | this(null); | 51 | this(new MathGroup()); |
52 | 37 | } | 52 | } |
53 | 38 | 53 | ||
54 | 39 | public Circuit(MathGroup root) { | 54 | public Circuit(MathGroup root) { |
57 | 40 | super(root); | 55 | this(root, null); |
58 | 41 | } | 56 | } |
59 | 57 | |||
60 | 58 | |||
61 | 59 | public Circuit(Container root, References refs) { | ||
62 | 60 | |||
63 | 61 | super(root, | ||
64 | 62 | new CircuitReferenceManager((NamespaceProvider)root, refs, new Func<Node, String>() { | ||
65 | 63 | @Override | ||
66 | 64 | public String eval(Node arg) { | ||
67 | 65 | if (arg instanceof CircuitComponent) return "cc"; | ||
68 | 66 | if (arg instanceof Contact) { | ||
69 | 67 | Contact cont = (Contact)arg; | ||
70 | 68 | |||
71 | 69 | if (cont.getParent() instanceof CircuitComponent) | ||
72 | 70 | return "x"; | ||
73 | 71 | |||
74 | 72 | if (cont.getIOType()==IOType.INPUT) | ||
75 | 73 | return "in"; | ||
76 | 74 | else | ||
77 | 75 | return "out"; | ||
78 | 76 | |||
79 | 77 | } | ||
80 | 78 | |||
81 | 79 | if (arg instanceof Connection) return "con"; | ||
82 | 80 | if (arg instanceof PageNode) return "pg"; | ||
83 | 81 | if (arg instanceof CommentNode) return "comment"; | ||
84 | 82 | |||
85 | 83 | if (arg instanceof Container) return "gr"; | ||
86 | 84 | |||
87 | 85 | return "v"; | ||
88 | 86 | } | ||
89 | 87 | } | ||
90 | 88 | |||
91 | 89 | )); | ||
92 | 90 | |||
93 | 91 | if (root==null) { | ||
94 | 92 | Container r = getRoot(); | ||
95 | 93 | getReferenceManager().attach(r); | ||
96 | 94 | } | ||
97 | 95 | } | ||
98 | 96 | |||
99 | 42 | 97 | ||
100 | 43 | public void validate() throws ModelValidationException { | 98 | public void validate() throws ModelValidationException { |
101 | 44 | } | 99 | } |
102 | @@ -51,5 +106,18 @@ | |||
103 | 51 | 106 | ||
104 | 52 | return con; | 107 | return con; |
105 | 53 | } | 108 | } |
106 | 109 | |||
107 | 110 | |||
108 | 111 | @Override | ||
109 | 112 | public Properties getProperties(Node node) { | ||
110 | 113 | if (node != null) { | ||
111 | 114 | if (node instanceof CircuitComponent) | ||
112 | 115 | return Properties.Mix.from(new DefaultNamePropertyDescriptor(this, node)); | ||
113 | 116 | if (node instanceof Contact) | ||
114 | 117 | return Properties.Mix.from(new DefaultNamePropertyDescriptor(this, node)); | ||
115 | 118 | } | ||
116 | 119 | return super.getProperties(node); | ||
117 | 120 | } | ||
118 | 121 | |||
119 | 54 | 122 | ||
120 | 55 | } | 123 | } |
121 | 56 | 124 | ||
122 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java' | |||
123 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java 2013-08-22 18:27:32 +0000 | |||
124 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java 2014-07-11 09:42:10 +0000 | |||
125 | @@ -29,6 +29,7 @@ | |||
126 | 29 | import org.workcraft.dom.Container; | 29 | import org.workcraft.dom.Container; |
127 | 30 | import org.workcraft.dom.DefaultGroupImpl; | 30 | import org.workcraft.dom.DefaultGroupImpl; |
128 | 31 | import org.workcraft.dom.Node; | 31 | import org.workcraft.dom.Node; |
129 | 32 | import org.workcraft.dom.math.MathGroup; | ||
130 | 32 | import org.workcraft.dom.math.MathNode; | 33 | import org.workcraft.dom.math.MathNode; |
131 | 33 | import org.workcraft.observation.HierarchyObserver; | 34 | import org.workcraft.observation.HierarchyObserver; |
132 | 34 | import org.workcraft.observation.ObservableHierarchy; | 35 | import org.workcraft.observation.ObservableHierarchy; |
133 | @@ -39,10 +40,11 @@ | |||
134 | 39 | @DisplayName("Component") | 40 | @DisplayName("Component") |
135 | 40 | @VisualClass(org.workcraft.plugins.circuit.VisualCircuitComponent.class) | 41 | @VisualClass(org.workcraft.plugins.circuit.VisualCircuitComponent.class) |
136 | 41 | 42 | ||
138 | 42 | public class CircuitComponent extends MathNode implements Container, ObservableHierarchy { | 43 | public class CircuitComponent extends MathGroup implements Container, ObservableHierarchy { |
139 | 43 | 44 | ||
140 | 44 | DefaultGroupImpl groupImpl = new DefaultGroupImpl(this); | 45 | DefaultGroupImpl groupImpl = new DefaultGroupImpl(this); |
141 | 45 | private String name = ""; | 46 | private String name = ""; |
142 | 47 | |||
143 | 46 | private boolean isEnvironment; | 48 | private boolean isEnvironment; |
144 | 47 | 49 | ||
145 | 48 | public boolean getIsEnvironment() { | 50 | public boolean getIsEnvironment() { |
146 | @@ -59,7 +61,7 @@ | |||
147 | 59 | 61 | ||
148 | 60 | public void setParent(Node parent) { | 62 | public void setParent(Node parent) { |
149 | 61 | groupImpl.setParent(parent); | 63 | groupImpl.setParent(parent); |
151 | 62 | checkName(parent); | 64 | //checkName(parent); |
152 | 63 | } | 65 | } |
153 | 64 | 66 | ||
154 | 65 | public void addObserver(HierarchyObserver obs) { | 67 | public void addObserver(HierarchyObserver obs) { |
155 | @@ -98,7 +100,7 @@ | |||
156 | 98 | @Override | 100 | @Override |
157 | 99 | public void reparent(Collection<Node> nodes, Container newParent) { | 101 | public void reparent(Collection<Node> nodes, Container newParent) { |
158 | 100 | groupImpl.reparent(nodes, newParent); | 102 | groupImpl.reparent(nodes, newParent); |
160 | 101 | checkName(newParent); | 103 | //checkName(newParent); |
161 | 102 | } | 104 | } |
162 | 103 | 105 | ||
163 | 104 | @Override | 106 | @Override |
164 | @@ -118,35 +120,35 @@ | |||
165 | 118 | return result; | 120 | return result; |
166 | 119 | } | 121 | } |
167 | 120 | 122 | ||
188 | 121 | public String getNewName(Node n, String start) { | 123 | // public String getNewName(Node n, String start) { |
189 | 122 | // iterate through all contacts, check that the name doesn't exist | 124 | // // iterate through all contacts, check that the name doesn't exist |
190 | 123 | int num=0; | 125 | // int num=0; |
191 | 124 | boolean found = true; | 126 | // boolean found = true; |
192 | 125 | 127 | // | |
193 | 126 | while (found) { | 128 | // while (found) { |
194 | 127 | num++; | 129 | // num++; |
195 | 128 | found=false; | 130 | // found=false; |
196 | 129 | 131 | // | |
197 | 130 | for (Node vn : n.getChildren()) { | 132 | // for (Node vn : n.getChildren()) { |
198 | 131 | if (vn instanceof CircuitComponent && vn!=this) { | 133 | // if (vn instanceof CircuitComponent && vn!=this) { |
199 | 132 | if (((CircuitComponent)vn).getName().equals(start+num)) { | 134 | // if (((CircuitComponent)vn).getName().equals(start+num)) { |
200 | 133 | found=true; | 135 | // found=true; |
201 | 134 | break; | 136 | // break; |
202 | 135 | } | 137 | // } |
203 | 136 | } | 138 | // } |
204 | 137 | } | 139 | // } |
205 | 138 | } | 140 | // } |
206 | 139 | return start+num; | 141 | // return start+num; |
207 | 140 | } | 142 | // } |
208 | 141 | 143 | ||
217 | 142 | public void checkName(Node parent) { | 144 | // public void checkName(Node parent) { |
218 | 143 | if (parent==null) return; | 145 | // if (parent==null) return; |
219 | 144 | String start=getName(); | 146 | // String start=getName(); |
220 | 145 | if (start==null||start=="") { | 147 | // if (start==null||start=="") { |
221 | 146 | start="c"; | 148 | // start="c"; |
222 | 147 | setName(getNewName(parent, start)); | 149 | // setName(getNewName(parent, start)); |
223 | 148 | } | 150 | // } |
224 | 149 | } | 151 | // } |
225 | 150 | 152 | ||
226 | 151 | public void setName(String name) { | 153 | public void setName(String name) { |
227 | 152 | this.name = name; | 154 | this.name = name; |
228 | 153 | 155 | ||
229 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitModelDescriptor.java' | |||
230 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitModelDescriptor.java 2010-11-30 01:14:08 +0000 | |||
231 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitModelDescriptor.java 2014-07-11 09:42:10 +0000 | |||
232 | @@ -2,6 +2,7 @@ | |||
233 | 2 | 2 | ||
234 | 3 | import org.workcraft.dom.ModelDescriptor; | 3 | import org.workcraft.dom.ModelDescriptor; |
235 | 4 | import org.workcraft.dom.VisualModelDescriptor; | 4 | import org.workcraft.dom.VisualModelDescriptor; |
236 | 5 | import org.workcraft.dom.math.MathGroup; | ||
237 | 5 | import org.workcraft.dom.math.MathModel; | 6 | import org.workcraft.dom.math.MathModel; |
238 | 6 | import org.workcraft.dom.visual.VisualModel; | 7 | import org.workcraft.dom.visual.VisualModel; |
239 | 7 | import org.workcraft.exceptions.VisualModelInstantiationException; | 8 | import org.workcraft.exceptions.VisualModelInstantiationException; |
240 | 8 | 9 | ||
241 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java' | |||
242 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java 2014-06-27 14:48:42 +0000 | |||
243 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java 2014-07-11 09:42:10 +0000 | |||
244 | @@ -19,8 +19,8 @@ | |||
245 | 19 | * | 19 | * |
246 | 20 | */ | 20 | */ |
247 | 21 | 21 | ||
250 | 22 | package org.workcraft.plugins.circuit; | 22 | package org.workcraft.plugins.circuit; |
251 | 23 | 23 | ||
252 | 24 | import java.util.LinkedHashMap; | 24 | import java.util.LinkedHashMap; |
253 | 25 | import java.util.Map; | 25 | import java.util.Map; |
254 | 26 | 26 | ||
255 | @@ -32,10 +32,10 @@ | |||
256 | 32 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; | 32 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; |
257 | 33 | import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor; | 33 | import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor; |
258 | 34 | 34 | ||
263 | 35 | @DisplayName("Contact") | 35 | @DisplayName("Contact") |
264 | 36 | @VisualClass(org.workcraft.plugins.circuit.VisualContact.class) | 36 | @VisualClass(org.workcraft.plugins.circuit.VisualContact.class) |
265 | 37 | 37 | ||
266 | 38 | public class Contact extends MathNode implements BooleanVariable { | 38 | public class Contact extends MathNode implements BooleanVariable { |
267 | 39 | 39 | ||
268 | 40 | public enum IOType { | 40 | public enum IOType { |
269 | 41 | INPUT("Input"), | 41 | INPUT("Input"), |
270 | @@ -70,82 +70,29 @@ | |||
271 | 70 | sendNotification(new PropertyChangedEvent(this, "initOne")); | 70 | sendNotification(new PropertyChangedEvent(this, "initOne")); |
272 | 71 | } | 71 | } |
273 | 72 | 72 | ||
275 | 73 | public Contact() { | 73 | public Contact() { |
276 | 74 | } | 74 | } |
278 | 75 | 75 | ||
279 | 76 | public Contact(IOType iot) { | 76 | public Contact(IOType iot) { |
280 | 77 | super(); | 77 | super(); |
281 | 78 | setIOType(iot); | 78 | setIOType(iot); |
282 | 79 | } | 79 | } |
283 | 80 | 80 | ||
334 | 81 | static public String getNewName(Node paren, String prefix, Node node, boolean allowShort) { | 81 | public void setIOType(IOType t) { |
285 | 82 | // iterate through all contacts, check that the name doesn't exist | ||
286 | 83 | int index=0; | ||
287 | 84 | boolean found = false; | ||
288 | 85 | if (allowShort) { | ||
289 | 86 | for (Node n : paren.getChildren()) { | ||
290 | 87 | if (n instanceof Contact && n != node) { | ||
291 | 88 | if (((Contact)n).getName().equals(prefix)) { | ||
292 | 89 | found = true; | ||
293 | 90 | break; | ||
294 | 91 | } | ||
295 | 92 | } | ||
296 | 93 | } | ||
297 | 94 | if (!found) return prefix; | ||
298 | 95 | } | ||
299 | 96 | do { | ||
300 | 97 | found = false; | ||
301 | 98 | index++; | ||
302 | 99 | for (Node n : paren.getChildren()) { | ||
303 | 100 | if (n instanceof Contact && n != node) { | ||
304 | 101 | if (((Contact)n).getName().equals(prefix + index)) { | ||
305 | 102 | found = true; | ||
306 | 103 | break; | ||
307 | 104 | } | ||
308 | 105 | } | ||
309 | 106 | } | ||
310 | 107 | } while (found); | ||
311 | 108 | return (prefix + index); | ||
312 | 109 | } | ||
313 | 110 | |||
314 | 111 | public void checkName(Node parent) { | ||
315 | 112 | if (parent == null) return; | ||
316 | 113 | String prefix = getName(); | ||
317 | 114 | if (prefix == null || prefix == "") { | ||
318 | 115 | if (getIOType()==IOType.INPUT) { | ||
319 | 116 | prefix="input"; | ||
320 | 117 | } else { | ||
321 | 118 | prefix="output"; | ||
322 | 119 | } | ||
323 | 120 | setName(getNewName(parent, prefix, this, false)); | ||
324 | 121 | } | ||
325 | 122 | } | ||
326 | 123 | |||
327 | 124 | @Override | ||
328 | 125 | public void setParent(Node parent) { | ||
329 | 126 | super.setParent(parent); | ||
330 | 127 | checkName(parent); | ||
331 | 128 | } | ||
332 | 129 | |||
333 | 130 | public void setIOType(IOType t) { | ||
335 | 131 | this.ioType = t; | 82 | this.ioType = t; |
348 | 132 | if (getName().startsWith("input") && getIOType()==IOType.OUTPUT) { | 83 | sendNotification(new PropertyChangedEvent(this, "ioType")); |
349 | 133 | setName(getNewName(getParent(), "output", this, false)); | 84 | } |
350 | 134 | } else if (getName().startsWith("output") && getIOType()==IOType.INPUT) { | 85 | |
351 | 135 | setName(getNewName(getParent(), "input", this, false)); | 86 | public IOType getIOType() { |
352 | 136 | } | 87 | return ioType; |
353 | 137 | sendNotification(new PropertyChangedEvent(this, "ioType")); | 88 | } |
354 | 138 | } | 89 | |
355 | 139 | 90 | // this is only for information, use Circuit to set component's names | |
344 | 140 | public IOType getIOType() { | ||
345 | 141 | return ioType; | ||
346 | 142 | } | ||
347 | 143 | |||
356 | 144 | public void setName(String name) { | 91 | public void setName(String name) { |
357 | 145 | this.name = name; | 92 | this.name = name; |
358 | 146 | sendNotification(new PropertyChangedEvent(this, "name")); | 93 | sendNotification(new PropertyChangedEvent(this, "name")); |
359 | 147 | } | 94 | } |
361 | 148 | 95 | ||
362 | 149 | public String getName() { | 96 | public String getName() { |
363 | 150 | return name; | 97 | return name; |
364 | 151 | } | 98 | } |
365 | @@ -160,4 +107,4 @@ | |||
366 | 160 | return getName(); | 107 | return getName(); |
367 | 161 | } | 108 | } |
368 | 162 | 109 | ||
370 | 163 | } | 110 | } |
371 | 164 | 111 | ||
372 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java' | |||
373 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java 2014-06-27 14:48:42 +0000 | |||
374 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java 2014-07-11 09:42:10 +0000 | |||
375 | @@ -28,16 +28,22 @@ | |||
376 | 28 | import org.workcraft.annotations.CustomTools; | 28 | import org.workcraft.annotations.CustomTools; |
377 | 29 | import org.workcraft.annotations.DisplayName; | 29 | import org.workcraft.annotations.DisplayName; |
378 | 30 | import org.workcraft.dom.Connection; | 30 | import org.workcraft.dom.Connection; |
379 | 31 | import org.workcraft.dom.Container; | ||
380 | 31 | import org.workcraft.dom.Node; | 32 | import org.workcraft.dom.Node; |
381 | 33 | import org.workcraft.dom.hierarchy.NamespaceProvider; | ||
382 | 32 | import org.workcraft.dom.math.MathConnection; | 34 | import org.workcraft.dom.math.MathConnection; |
383 | 35 | import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager; | ||
384 | 36 | import org.workcraft.dom.references.ReferenceManager; | ||
385 | 33 | import org.workcraft.dom.visual.AbstractVisualModel; | 37 | import org.workcraft.dom.visual.AbstractVisualModel; |
386 | 34 | import org.workcraft.dom.visual.VisualComponent; | 38 | import org.workcraft.dom.visual.VisualComponent; |
387 | 35 | import org.workcraft.dom.visual.VisualGroup; | 39 | import org.workcraft.dom.visual.VisualGroup; |
388 | 40 | import org.workcraft.dom.visual.VisualNode; | ||
389 | 36 | import org.workcraft.exceptions.InvalidConnectionException; | 41 | import org.workcraft.exceptions.InvalidConnectionException; |
390 | 37 | import org.workcraft.exceptions.NodeCreationException; | 42 | import org.workcraft.exceptions.NodeCreationException; |
391 | 38 | import org.workcraft.exceptions.VisualModelInstantiationException; | 43 | import org.workcraft.exceptions.VisualModelInstantiationException; |
392 | 39 | import org.workcraft.gui.propertyeditor.Properties; | 44 | import org.workcraft.gui.propertyeditor.Properties; |
393 | 40 | import org.workcraft.plugins.circuit.Contact.IOType; | 45 | import org.workcraft.plugins.circuit.Contact.IOType; |
394 | 46 | import org.workcraft.plugins.cpog.optimisation.expressions.One; | ||
395 | 41 | import org.workcraft.serialisation.xml.NoAutoSerialisation; | 47 | import org.workcraft.serialisation.xml.NoAutoSerialisation; |
396 | 42 | import org.workcraft.util.Hierarchy; | 48 | import org.workcraft.util.Hierarchy; |
397 | 43 | 49 | ||
398 | @@ -117,15 +123,93 @@ | |||
399 | 117 | } | 123 | } |
400 | 118 | 124 | ||
401 | 119 | public VisualFunctionContact getOrCreateOutput(String name, double x, double y) { | 125 | public VisualFunctionContact getOrCreateOutput(String name, double x, double y) { |
406 | 120 | for(VisualFunctionContact c : getVisualFunctionContacts()) { | 126 | |
407 | 121 | if(c.getName().equals(name)) return c; | 127 | VisualFunctionContact vc = getOrCreateContact(getCurrentLevel(), name, IOType.OUTPUT, x, y); |
408 | 122 | } | 128 | |
409 | 123 | VisualFunctionContact vc = new VisualFunctionContact(new FunctionContact(IOType.OUTPUT)); | 129 | return vc; |
410 | 130 | |||
411 | 131 | } | ||
412 | 132 | |||
413 | 133 | public VisualFunctionContact getOrCreateComponentOutput(VisualFunctionComponent component, String name, double x, double y) { | ||
414 | 134 | |||
415 | 135 | VisualFunctionContact vc = getOrCreateContact(component, name, IOType.OUTPUT, x, y); | ||
416 | 124 | vc.setPosition(new Point2D.Double(x, y)); | 136 | vc.setPosition(new Point2D.Double(x, y)); |
421 | 125 | addFunctionContact(vc); | 137 | |
422 | 126 | vc.setName(name); | 138 | return vc; |
423 | 127 | return vc; | 139 | } |
424 | 128 | } | 140 | |
425 | 141 | public VisualFunctionContact getOrCreateContact(Container container, String name, IOType ioType, double x, double y) { | ||
426 | 142 | // here "parent" is a container of a visual model | ||
427 | 143 | |||
428 | 144 | if (name!=null) { | ||
429 | 145 | |||
430 | 146 | for (Node n: container.getChildren()) { | ||
431 | 147 | if (n instanceof VisualFunctionContact) { | ||
432 | 148 | if (getMathModel().getName(((VisualFunctionContact)n).getReferencedContact()).equals(name)) | ||
433 | 149 | return (VisualFunctionContact)n; | ||
434 | 150 | } // TODO: if found something else with that name, return null? | ||
435 | 151 | } | ||
436 | 152 | |||
437 | 153 | } | ||
438 | 154 | |||
439 | 155 | // the name is available | ||
440 | 156 | // create a new contact if it was not found | ||
441 | 157 | VisualContact.Direction dir=null; | ||
442 | 158 | if (ioType==null) ioType = IOType.OUTPUT; | ||
443 | 159 | dir=VisualContact.Direction.WEST; | ||
444 | 160 | if (ioType==IOType.OUTPUT) | ||
445 | 161 | dir=VisualContact.Direction.EAST; | ||
446 | 162 | |||
447 | 163 | |||
448 | 164 | |||
449 | 165 | |||
450 | 166 | VisualFunctionContact vc = new VisualFunctionContact(new FunctionContact(ioType)); | ||
451 | 167 | vc.setDirection(dir); | ||
452 | 168 | vc.setPosition(new Point2D.Double(x, y)); | ||
453 | 169 | |||
454 | 170 | if (container instanceof VisualFunctionComponent) { | ||
455 | 171 | VisualFunctionComponent component = (VisualFunctionComponent)container; | ||
456 | 172 | |||
457 | 173 | component.addContact(this, vc); | ||
458 | 174 | |||
459 | 175 | if (name!=null) | ||
460 | 176 | circuit.setName(vc.getReferencedComponent(), name); | ||
461 | 177 | |||
462 | 178 | |||
463 | 179 | vc.setSetFunction(One.instance()); | ||
464 | 180 | vc.setResetFunction(One.instance()); | ||
465 | 181 | } else { | ||
466 | 182 | |||
467 | 183 | AbstractVisualModel.getMathContainer(this, getRoot()).add(vc.getReferencedComponent()); | ||
468 | 184 | add(vc); | ||
469 | 185 | |||
470 | 186 | if (name!=null) | ||
471 | 187 | circuit.setName(vc.getReferencedComponent(), name); | ||
472 | 188 | |||
473 | 189 | } | ||
474 | 190 | |||
475 | 191 | return vc; | ||
476 | 192 | } | ||
477 | 193 | |||
478 | 194 | // public VisualFunctionContact addFunction(VisualCircuitComponent component, IOType ioType) { | ||
479 | 195 | // VisualContact.Direction dir=null; | ||
480 | 196 | // if (ioType==null) ioType = IOType.OUTPUT; | ||
481 | 197 | // dir=VisualContact.Direction.WEST; | ||
482 | 198 | // | ||
483 | 199 | // if (ioType==IOType.OUTPUT) { | ||
484 | 200 | // dir=VisualContact.Direction.EAST; | ||
485 | 201 | // } | ||
486 | 202 | // | ||
487 | 203 | // FunctionContact c = new FunctionContact(ioType); | ||
488 | 204 | // VisualFunctionContact vc = new VisualFunctionContact(c); | ||
489 | 205 | // vc.setDirection(dir); | ||
490 | 206 | // | ||
491 | 207 | // //circuit.setName(component.getReferencedComponent(), Contact.getNewName(component.getReferencedComponent(), prefix, null, allowShort)); | ||
492 | 208 | // | ||
493 | 209 | // component.addContact(vc); | ||
494 | 210 | // return vc; | ||
495 | 211 | // } | ||
496 | 212 | |||
497 | 129 | 213 | ||
498 | 130 | public void addFunctionComponent(VisualFunctionComponent component) { | 214 | public void addFunctionComponent(VisualFunctionComponent component) { |
499 | 131 | for (Node node : component.getMathReferences()) { | 215 | for (Node node : component.getMathReferences()) { |
500 | @@ -141,10 +225,10 @@ | |||
501 | 141 | super.add(joint); | 225 | super.add(joint); |
502 | 142 | } | 226 | } |
503 | 143 | 227 | ||
508 | 144 | public void addFunctionContact(VisualFunctionContact contact) { | 228 | // public void addFunctionContact(VisualFunctionComponent component, VisualFunctionContact contact) { |
509 | 145 | circuit.add(contact.getReferencedFunctionContact()); | 229 | // component.add(contact); |
510 | 146 | super.add(contact); | 230 | // component.getReferencedCircuitComponent().add(contact.getReferencedContact()); |
511 | 147 | } | 231 | // } |
512 | 148 | 232 | ||
513 | 149 | @NoAutoSerialisation | 233 | @NoAutoSerialisation |
514 | 150 | public File getEnvironmentFile() { | 234 | public File getEnvironmentFile() { |
515 | @@ -170,14 +254,18 @@ | |||
516 | 170 | Properties properties = super.getProperties(node); | 254 | Properties properties = super.getProperties(node); |
517 | 171 | if (node == null) { | 255 | if (node == null) { |
518 | 172 | properties = Properties.Merge.add(properties, new EnvironmentFilePropertyDescriptor(this)); | 256 | properties = Properties.Merge.add(properties, new EnvironmentFilePropertyDescriptor(this)); |
520 | 173 | } else if(node instanceof VisualFunctionContact) { | 257 | } |
521 | 258 | |||
522 | 259 | if (node instanceof VisualFunctionContact) { | ||
523 | 174 | VisualFunctionContact contact = (VisualFunctionContact)node; | 260 | VisualFunctionContact contact = (VisualFunctionContact)node; |
524 | 175 | VisualContactFormulaProperties props = new VisualContactFormulaProperties(this); | 261 | VisualContactFormulaProperties props = new VisualContactFormulaProperties(this); |
525 | 262 | |||
526 | 176 | properties = Properties.Merge.add(properties, | 263 | properties = Properties.Merge.add(properties, |
527 | 177 | props.getSetProperty(contact), | 264 | props.getSetProperty(contact), |
528 | 178 | props.getResetProperty(contact)); | 265 | props.getResetProperty(contact)); |
529 | 179 | } | 266 | } |
530 | 180 | return properties; | 267 | return properties; |
531 | 181 | } | 268 | } |
532 | 269 | |||
533 | 182 | 270 | ||
534 | 183 | } | 271 | } |
535 | 184 | 272 | ||
536 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java' | |||
537 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java 2014-06-27 14:48:42 +0000 | |||
538 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java 2014-07-11 09:42:10 +0000 | |||
539 | @@ -39,6 +39,7 @@ | |||
540 | 39 | import org.workcraft.dom.Container; | 39 | import org.workcraft.dom.Container; |
541 | 40 | import org.workcraft.dom.DefaultGroupImpl; | 40 | import org.workcraft.dom.DefaultGroupImpl; |
542 | 41 | import org.workcraft.dom.Node; | 41 | import org.workcraft.dom.Node; |
543 | 42 | import org.workcraft.dom.visual.AbstractVisualModel; | ||
544 | 42 | import org.workcraft.dom.visual.BoundingBoxHelper; | 43 | import org.workcraft.dom.visual.BoundingBoxHelper; |
545 | 43 | import org.workcraft.dom.visual.CustomTouchable; | 44 | import org.workcraft.dom.visual.CustomTouchable; |
546 | 44 | import org.workcraft.dom.visual.DrawRequest; | 45 | import org.workcraft.dom.visual.DrawRequest; |
547 | @@ -86,15 +87,16 @@ | |||
548 | 86 | } | 87 | } |
549 | 87 | 88 | ||
550 | 88 | private void addPropertyDeclarations() { | 89 | private void addPropertyDeclarations() { |
560 | 89 | addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, String>( | 90 | // addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, String>( |
561 | 90 | this, "Name", String.class) { | 91 | // this, "Name", String.class) { |
562 | 91 | protected void setter(VisualCircuitComponent object, String value) { | 92 | // protected void setter(VisualCircuitComponent object, String value) { |
563 | 92 | object.getReferencedCircuitComponent().setName(value); | 93 | // get |
564 | 93 | } | 94 | // object.getReferencedCircuitComponent().setName(value); |
565 | 94 | protected String getter(VisualCircuitComponent object) { | 95 | // } |
566 | 95 | return object.getReferencedCircuitComponent().getName(); | 96 | // protected String getter(VisualCircuitComponent object) { |
567 | 96 | } | 97 | // return object.getReferencedCircuitComponent().getName(); |
568 | 97 | }); | 98 | // } |
569 | 99 | // }); | ||
570 | 98 | 100 | ||
571 | 99 | addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, Boolean>( | 101 | addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, Boolean>( |
572 | 100 | this, "Treat as environment", Boolean.class) { | 102 | this, "Treat as environment", Boolean.class) { |
573 | @@ -142,13 +144,13 @@ | |||
574 | 142 | return (CircuitComponent)this.getReferencedComponent(); | 144 | return (CircuitComponent)this.getReferencedComponent(); |
575 | 143 | } | 145 | } |
576 | 144 | 146 | ||
584 | 145 | public String getName() { | 147 | // public String getName() { |
585 | 146 | return getReferencedCircuitComponent().getName(); | 148 | // return getReferencedCircuitComponent().getName(); |
586 | 147 | } | 149 | // } |
587 | 148 | 150 | // | |
588 | 149 | public void setName(String value) { | 151 | // public void setName(String value) { |
589 | 150 | getReferencedCircuitComponent().setName(value); | 152 | // getReferencedCircuitComponent().setName(value); |
590 | 151 | } | 153 | // } |
591 | 152 | 154 | ||
592 | 153 | public boolean getIsEnvironment() { | 155 | public boolean getIsEnvironment() { |
593 | 154 | if (getReferencedCircuitComponent() != null) { | 156 | if (getReferencedCircuitComponent() != null) { |
594 | @@ -241,17 +243,20 @@ | |||
595 | 241 | } | 243 | } |
596 | 242 | } | 244 | } |
597 | 243 | 245 | ||
599 | 244 | public void updateDirection(VisualContact vc, VisualContact.Direction dir) { | 246 | public void updateDirection(VisualCircuit vcircuit, VisualContact vc, VisualContact.Direction dir) { |
600 | 245 | vc.setDirection(dir); | 247 | vc.setDirection(dir); |
601 | 246 | contactLabelBB = null; | 248 | contactLabelBB = null; |
602 | 247 | updateSidePosition(vc); | 249 | updateSidePosition(vc); |
603 | 248 | updateStepPositions(); | 250 | updateStepPositions(); |
604 | 249 | } | 251 | } |
605 | 250 | 252 | ||
607 | 251 | public void addContact(VisualContact vc) { | 253 | public void addContact(VisualCircuit vcircuit, VisualContact vc) { |
608 | 252 | if (!getChildren().contains(vc)) { | 254 | if (!getChildren().contains(vc)) { |
610 | 253 | this.getReferencedCircuitComponent().add(vc.getReferencedComponent()); | 255 | |
611 | 256 | Container container = AbstractVisualModel.getMathContainer(vcircuit, this); | ||
612 | 257 | container.add(vc.getReferencedComponent()); | ||
613 | 254 | add(vc); | 258 | add(vc); |
614 | 259 | |||
615 | 255 | contactLabelBB = null; | 260 | contactLabelBB = null; |
616 | 256 | updateSidePosition(vc); | 261 | updateSidePosition(vc); |
617 | 257 | updateStepPositions(); | 262 | updateStepPositions(); |
618 | @@ -259,7 +264,9 @@ | |||
619 | 259 | } | 264 | } |
620 | 260 | 265 | ||
621 | 261 | protected void updateTotalBB() { | 266 | protected void updateTotalBB() { |
622 | 267 | |||
623 | 262 | totalBB = BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class)); | 268 | totalBB = BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class)); |
624 | 269 | |||
625 | 263 | if (contactLabelBB != null && totalBB != null) { | 270 | if (contactLabelBB != null && totalBB != null) { |
626 | 264 | Rectangle2D.union(totalBB, contactLabelBB, totalBB); | 271 | Rectangle2D.union(totalBB, contactLabelBB, totalBB); |
627 | 265 | } | 272 | } |
628 | @@ -273,7 +280,7 @@ | |||
629 | 273 | return result; | 280 | return result; |
630 | 274 | } | 281 | } |
631 | 275 | 282 | ||
633 | 276 | public void updateContactLabelBB(Graphics2D g) { | 283 | public void updateContactLabelBB(Circuit circuit, Graphics2D g) { |
634 | 277 | int north=0; | 284 | int north=0; |
635 | 278 | int south=0; | 285 | int south=0; |
636 | 279 | int east=0; | 286 | int east=0; |
637 | @@ -295,7 +302,7 @@ | |||
638 | 295 | for (Node vn: getChildren()) { | 302 | for (Node vn: getChildren()) { |
639 | 296 | if (!(vn instanceof VisualContact)) continue; | 303 | if (!(vn instanceof VisualContact)) continue; |
640 | 297 | VisualContact vc = (VisualContact)vn; | 304 | VisualContact vc = (VisualContact)vn; |
642 | 298 | GlyphVector gv = vc.getNameGlyphs(g); | 305 | GlyphVector gv = vc.getNameGlyphs(circuit, g); |
643 | 299 | Rectangle2D cur = gv.getVisualBounds(); | 306 | Rectangle2D cur = gv.getVisualBounds(); |
644 | 300 | double xx = (double)(Math.round(cur.getWidth() * 4))/4; | 307 | double xx = (double)(Math.round(cur.getWidth() * 4))/4; |
645 | 301 | 308 | ||
646 | @@ -358,13 +365,15 @@ | |||
647 | 358 | protected void drawContacts(DrawRequest r) { | 365 | protected void drawContacts(DrawRequest r) { |
648 | 359 | Graphics2D g = r.getGraphics(); | 366 | Graphics2D g = r.getGraphics(); |
649 | 360 | Color colorisation = r.getDecoration().getColorisation(); | 367 | Color colorisation = r.getDecoration().getColorisation(); |
650 | 368 | Circuit circuit = (Circuit)r.getModel().getMathModel(); | ||
651 | 369 | |||
652 | 361 | Rectangle2D bb = getBestBB(); | 370 | Rectangle2D bb = getBestBB(); |
653 | 362 | double step_pos; | 371 | double step_pos; |
654 | 363 | for (Node n: getChildren()) { | 372 | for (Node n: getChildren()) { |
655 | 364 | if (n instanceof VisualContact) { | 373 | if (n instanceof VisualContact) { |
656 | 365 | VisualContact c = (VisualContact)n; | 374 | VisualContact c = (VisualContact)n; |
657 | 366 | if (!c.getDirection().equals(Direction.WEST)) continue; | 375 | if (!c.getDirection().equals(Direction.WEST)) continue; |
659 | 367 | GlyphVector gv = c.getNameGlyphs(g); | 376 | GlyphVector gv = c.getNameGlyphs(circuit, g); |
660 | 368 | Rectangle2D cur = gv.getVisualBounds(); | 377 | Rectangle2D cur = gv.getVisualBounds(); |
661 | 369 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); | 378 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); |
662 | 370 | step_pos = c.getY(); | 379 | step_pos = c.getY(); |
663 | @@ -376,7 +385,7 @@ | |||
664 | 376 | if (n instanceof VisualContact) { | 385 | if (n instanceof VisualContact) { |
665 | 377 | VisualContact c = (VisualContact)n; | 386 | VisualContact c = (VisualContact)n; |
666 | 378 | if (!c.getDirection().equals(Direction.EAST)) continue; | 387 | if (!c.getDirection().equals(Direction.EAST)) continue; |
668 | 379 | GlyphVector gv = c.getNameGlyphs(g); | 388 | GlyphVector gv = c.getNameGlyphs(circuit, g); |
669 | 380 | Rectangle2D cur = gv.getVisualBounds(); | 389 | Rectangle2D cur = gv.getVisualBounds(); |
670 | 381 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); | 390 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); |
671 | 382 | step_pos = c.getY(); | 391 | step_pos = c.getY(); |
672 | @@ -392,7 +401,7 @@ | |||
673 | 392 | if (n instanceof VisualContact) { | 401 | if (n instanceof VisualContact) { |
674 | 393 | VisualContact c = (VisualContact)n; | 402 | VisualContact c = (VisualContact)n; |
675 | 394 | if (!c.getDirection().equals(Direction.NORTH)) continue; | 403 | if (!c.getDirection().equals(Direction.NORTH)) continue; |
677 | 395 | GlyphVector gv = c.getNameGlyphs(g); | 404 | GlyphVector gv = c.getNameGlyphs(circuit, g); |
678 | 396 | Rectangle2D cur = gv.getVisualBounds(); | 405 | Rectangle2D cur = gv.getVisualBounds(); |
679 | 397 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); | 406 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); |
680 | 398 | step_pos = c.getX(); | 407 | step_pos = c.getX(); |
681 | @@ -404,7 +413,7 @@ | |||
682 | 404 | if (n instanceof VisualContact) { | 413 | if (n instanceof VisualContact) { |
683 | 405 | VisualContact c = (VisualContact)n; | 414 | VisualContact c = (VisualContact)n; |
684 | 406 | if (!c.getDirection().equals(Direction.SOUTH)) continue; | 415 | if (!c.getDirection().equals(Direction.SOUTH)) continue; |
686 | 407 | GlyphVector gv = c.getNameGlyphs(g); | 416 | GlyphVector gv = c.getNameGlyphs(circuit, g); |
687 | 408 | Rectangle2D cur = gv.getVisualBounds(); | 417 | Rectangle2D cur = gv.getVisualBounds(); |
688 | 409 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); | 418 | g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation)); |
689 | 410 | step_pos = c.getX(); | 419 | step_pos = c.getX(); |
690 | @@ -413,20 +422,28 @@ | |||
691 | 413 | } | 422 | } |
692 | 414 | } | 423 | } |
693 | 415 | 424 | ||
694 | 425 | |||
695 | 416 | @Override | 426 | @Override |
696 | 417 | public Rectangle2D getInternalBoundingBoxInLocalSpace() { | 427 | public Rectangle2D getInternalBoundingBoxInLocalSpace() { |
697 | 418 | if (groupImpl == null) { | 428 | if (groupImpl == null) { |
698 | 419 | return super.getInternalBoundingBoxInLocalSpace(); | 429 | return super.getInternalBoundingBoxInLocalSpace(); |
699 | 420 | } | 430 | } |
701 | 421 | return BoundingBoxHelper.union(totalBB, BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class))); | 431 | Rectangle2D rect = BoundingBoxHelper.union(totalBB, BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class))); |
702 | 432 | |||
703 | 433 | if (rect==null) | ||
704 | 434 | return super.getInternalBoundingBoxInLocalSpace(); | ||
705 | 435 | |||
706 | 436 | return rect; | ||
707 | 422 | } | 437 | } |
708 | 423 | 438 | ||
709 | 439 | |||
710 | 424 | @Override | 440 | @Override |
711 | 425 | public void draw(DrawRequest r) { | 441 | public void draw(DrawRequest r) { |
712 | 426 | Graphics2D g = r.getGraphics(); | 442 | Graphics2D g = r.getGraphics(); |
714 | 427 | 443 | Circuit circuit = (Circuit)r.getModel().getMathModel(); | |
715 | 444 | |||
716 | 428 | cacheRenderedText(r); // needed to better estimate the bounding box | 445 | cacheRenderedText(r); // needed to better estimate the bounding box |
718 | 429 | updateContactLabelBB(g); | 446 | updateContactLabelBB(circuit, g); |
719 | 430 | drawContactConnections(r); | 447 | drawContactConnections(r); |
720 | 431 | 448 | ||
721 | 432 | Rectangle2D shape = getBestBB(); | 449 | Rectangle2D shape = getBestBB(); |
722 | @@ -580,27 +597,30 @@ | |||
723 | 580 | } | 597 | } |
724 | 581 | } | 598 | } |
725 | 582 | 599 | ||
747 | 583 | public VisualContact addInput(String name, VisualContact.Direction dir) { | 600 | // public VisualContact addInput(Circuit circuit, String name, VisualContact.Direction dir) { |
748 | 584 | VisualContact vc = new VisualContact(new Contact(IOType.INPUT)); | 601 | // VisualContact vc = new VisualContact(new Contact(IOType.INPUT)); |
749 | 585 | if (dir==null) { | 602 | // if (dir==null) { |
750 | 586 | dir=VisualContact.Direction.WEST; | 603 | // dir=VisualContact.Direction.WEST; |
751 | 587 | } | 604 | // } |
752 | 588 | vc.setDirection(dir); | 605 | // vc.setDirection(dir); |
753 | 589 | vc.setName(name); | 606 | // |
754 | 590 | addContact(vc); | 607 | // circuit.setName(vc.getReferencedComponent(), name); |
755 | 591 | return vc; | 608 | // |
756 | 592 | } | 609 | // addContact(vc); |
757 | 593 | 610 | // return vc; | |
758 | 594 | public VisualContact addOutput(String name, VisualContact.Direction dir) { | 611 | // } |
759 | 595 | VisualContact vc = new VisualContact(new Contact(IOType.OUTPUT)); | 612 | // |
760 | 596 | if (dir==null) { | 613 | // public VisualContact addOutput(VisualCircuit vcircuit, String name, VisualContact.Direction dir) { |
761 | 597 | dir=VisualContact.Direction.EAST; | 614 | // VisualContact vc = new VisualContact(new Contact(IOType.OUTPUT)); |
762 | 598 | } | 615 | // if (dir==null) { |
763 | 599 | vc.setDirection(dir); | 616 | // dir=VisualContact.Direction.EAST; |
764 | 600 | vc.setName(name); | 617 | // } |
765 | 601 | addContact(vc); | 618 | // vc.setDirection(dir); |
766 | 602 | return vc; | 619 | // |
767 | 603 | } | 620 | // circuit.setName(vc.getReferencedComponent(), name); |
768 | 621 | // addContact(vc); | ||
769 | 622 | // return vc; | ||
770 | 623 | // } | ||
771 | 604 | 624 | ||
772 | 605 | @Override | 625 | @Override |
773 | 606 | public void addObserver(HierarchyObserver obs) { | 626 | public void addObserver(HierarchyObserver obs) { |
774 | 607 | 627 | ||
775 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java' | |||
776 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-07-07 13:20:59 +0000 | |||
777 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-07-11 09:42:10 +0000 | |||
778 | @@ -167,15 +167,15 @@ | |||
779 | 167 | } | 167 | } |
780 | 168 | }); | 168 | }); |
781 | 169 | 169 | ||
791 | 170 | addPropertyDeclaration(new PropertyDeclaration<VisualContact, String>( | 170 | // addPropertyDeclaration(new PropertyDeclaration<VisualContact, String>( |
792 | 171 | this, "Name", String.class) { | 171 | // this, "Name", String.class) { |
793 | 172 | protected void setter(VisualContact object, String value) { | 172 | // protected void setter(VisualContact object, String value) { |
794 | 173 | object.setName(value); | 173 | // object.setName(value); |
795 | 174 | } | 174 | // } |
796 | 175 | protected String getter(VisualContact object) { | 175 | // protected String getter(VisualContact object) { |
797 | 176 | return object.getName(); | 176 | // return object.getName(); |
798 | 177 | } | 177 | // } |
799 | 178 | }); | 178 | // }); |
800 | 179 | 179 | ||
801 | 180 | 180 | ||
802 | 181 | addPropertyDeclaration(new PropertyDeclaration<VisualContact, Boolean>( | 181 | addPropertyDeclaration(new PropertyDeclaration<VisualContact, Boolean>( |
803 | @@ -203,6 +203,8 @@ | |||
804 | 203 | public void draw(DrawRequest r) { | 203 | public void draw(DrawRequest r) { |
805 | 204 | Graphics2D g = r.getGraphics(); | 204 | Graphics2D g = r.getGraphics(); |
806 | 205 | Decoration d = r.getDecoration(); | 205 | Decoration d = r.getDecoration(); |
807 | 206 | Circuit circuit = (Circuit)r.getModel().getMathModel(); | ||
808 | 207 | |||
809 | 206 | boolean inSimulationMode = ((d.getColorisation() != null) || (d.getBackground() != null)); | 208 | boolean inSimulationMode = ((d.getColorisation() != null) || (d.getBackground() != null)); |
810 | 207 | Color colorisation = d.getColorisation(); | 209 | Color colorisation = d.getColorisation(); |
811 | 208 | Color fillColor = d.getBackground(); | 210 | Color fillColor = d.getBackground(); |
812 | @@ -237,7 +239,7 @@ | |||
813 | 237 | } | 239 | } |
814 | 238 | g.transform(at); | 240 | g.transform(at); |
815 | 239 | 241 | ||
817 | 240 | GlyphVector gv = getNameGlyphs(g); | 242 | GlyphVector gv = getNameGlyphs(circuit, g); |
818 | 241 | Rectangle2D cur = gv.getVisualBounds(); | 243 | Rectangle2D cur = gv.getVisualBounds(); |
819 | 242 | g.setColor(Coloriser.colorise((getIOType()==IOType.INPUT)?inputColor:outputColor, colorisation)); | 244 | g.setColor(Coloriser.colorise((getIOType()==IOType.INPUT)?inputColor:outputColor, colorisation)); |
820 | 243 | 245 | ||
821 | @@ -293,19 +295,19 @@ | |||
822 | 293 | } | 295 | } |
823 | 294 | } | 296 | } |
824 | 295 | 297 | ||
826 | 296 | public GlyphVector getNameGlyphs(Graphics2D g) { | 298 | public GlyphVector getNameGlyphs(Circuit circuit, Graphics2D g) { |
827 | 297 | if (nameGlyph == null) { | 299 | if (nameGlyph == null) { |
828 | 298 | if (getDirection() == VisualContact.Direction.NORTH || getDirection() == VisualContact.Direction.SOUTH) { | 300 | if (getDirection() == VisualContact.Direction.NORTH || getDirection() == VisualContact.Direction.SOUTH) { |
829 | 299 | AffineTransform at = new AffineTransform(); | 301 | AffineTransform at = new AffineTransform(); |
830 | 300 | at.quadrantRotate(1); | 302 | at.quadrantRotate(1); |
831 | 301 | } | 303 | } |
833 | 302 | nameGlyph = nameFont.createGlyphVector(g.getFontRenderContext(), getName()); | 304 | nameGlyph = nameFont.createGlyphVector(g.getFontRenderContext(), circuit.getName(this.getReferencedContact())); |
834 | 303 | } | 305 | } |
835 | 304 | return nameGlyph; | 306 | return nameGlyph; |
836 | 305 | } | 307 | } |
837 | 306 | 308 | ||
840 | 307 | public Rectangle2D getNameBB(Graphics2D g) { | 309 | public Rectangle2D getNameBB(Circuit circuit, Graphics2D g) { |
841 | 308 | return getNameGlyphs(g).getVisualBounds(); | 310 | return getNameGlyphs(circuit, g).getVisualBounds(); |
842 | 309 | } | 311 | } |
843 | 310 | 312 | ||
844 | 311 | public void setDirection(VisualContact.Direction dir) { | 313 | public void setDirection(VisualContact.Direction dir) { |
845 | @@ -336,20 +338,34 @@ | |||
846 | 336 | public String getName() { | 338 | public String getName() { |
847 | 337 | return getReferencedContact().getName(); | 339 | return getReferencedContact().getName(); |
848 | 338 | } | 340 | } |
850 | 339 | 341 | ||
851 | 340 | @NoAutoSerialisation | 342 | @NoAutoSerialisation |
852 | 341 | public void setName(String name) { | 343 | public void setName(String name) { |
853 | 342 | getReferencedContact().setName(name); | 344 | getReferencedContact().setName(name); |
854 | 343 | } | 345 | } |
855 | 346 | |||
856 | 347 | |||
857 | 348 | //// | ||
858 | 349 | // public void updateLocalName(String name) { | ||
859 | 350 | // resetNameGlyph(); | ||
860 | 351 | // getReferencedContact().setName(name); | ||
861 | 352 | // sendNotification(new PropertyChangedEvent(this, "name")); | ||
862 | 353 | // } | ||
863 | 344 | 354 | ||
864 | 345 | public Contact getReferencedContact() { | 355 | public Contact getReferencedContact() { |
865 | 346 | return (Contact)getReferencedComponent(); | 356 | return (Contact)getReferencedComponent(); |
866 | 347 | } | 357 | } |
867 | 348 | 358 | ||
868 | 359 | |||
869 | 360 | /* | ||
870 | 361 | * returns true if | ||
871 | 362 | */ | ||
872 | 349 | public static boolean isDriver(Node node) { | 363 | public static boolean isDriver(Node node) { |
873 | 350 | if (node instanceof VisualContact) { | 364 | if (node instanceof VisualContact) { |
874 | 351 | VisualContact contact = (VisualContact)node; | 365 | VisualContact contact = (VisualContact)node; |
876 | 352 | return (contact.getIOType() == IOType.OUTPUT) || !(contact.getParent() instanceof VisualComponent); | 366 | boolean ret = (contact.getIOType() == IOType.OUTPUT) || |
877 | 367 | !(contact.getParent() instanceof VisualCircuitComponent); | ||
878 | 368 | return ret; | ||
879 | 353 | } | 369 | } |
880 | 354 | return false; | 370 | return false; |
881 | 355 | } | 371 | } |
882 | 356 | 372 | ||
883 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContactFormulaProperties.java' | |||
884 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContactFormulaProperties.java 2014-06-27 14:48:42 +0000 | |||
885 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContactFormulaProperties.java 2014-07-11 09:42:10 +0000 | |||
886 | @@ -3,7 +3,9 @@ | |||
887 | 3 | import java.lang.reflect.InvocationTargetException; | 3 | import java.lang.reflect.InvocationTargetException; |
888 | 4 | import java.util.Map; | 4 | import java.util.Map; |
889 | 5 | 5 | ||
890 | 6 | import org.workcraft.dom.Container; | ||
891 | 6 | import org.workcraft.gui.propertyeditor.PropertyDescriptor; | 7 | import org.workcraft.gui.propertyeditor.PropertyDescriptor; |
892 | 8 | import org.workcraft.plugins.circuit.Contact.IOType; | ||
893 | 7 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | 9 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
894 | 8 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString; | 10 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString; |
895 | 9 | import org.workcraft.plugins.cpog.optimisation.javacc.BooleanParser; | 11 | import org.workcraft.plugins.cpog.optimisation.javacc.BooleanParser; |
896 | @@ -11,10 +13,10 @@ | |||
897 | 11 | import org.workcraft.util.Func; | 13 | import org.workcraft.util.Func; |
898 | 12 | 14 | ||
899 | 13 | public class VisualContactFormulaProperties { | 15 | public class VisualContactFormulaProperties { |
901 | 14 | VisualCircuit circuit; | 16 | VisualCircuit vcircuit; |
902 | 15 | 17 | ||
903 | 16 | public VisualContactFormulaProperties(VisualCircuit circuit) { | 18 | public VisualContactFormulaProperties(VisualCircuit circuit) { |
905 | 17 | this.circuit = circuit; | 19 | this.vcircuit = circuit; |
906 | 18 | } | 20 | } |
907 | 19 | 21 | ||
908 | 20 | private BooleanFormula parseFormula(final VisualFunctionContact contact, String resetFunction) { | 22 | private BooleanFormula parseFormula(final VisualFunctionContact contact, String resetFunction) { |
909 | @@ -23,13 +25,19 @@ | |||
910 | 23 | new Func<String, BooleanFormula>() { | 25 | new Func<String, BooleanFormula>() { |
911 | 24 | @Override | 26 | @Override |
912 | 25 | public BooleanFormula eval(String name) { | 27 | public BooleanFormula eval(String name) { |
913 | 28 | |||
914 | 29 | |||
915 | 26 | if (contact.getParent() instanceof VisualFunctionComponent) { | 30 | if (contact.getParent() instanceof VisualFunctionComponent) { |
922 | 27 | return ((VisualFunctionComponent)contact.getParent()).getOrCreateInput(name) | 31 | return |
923 | 28 | .getReferencedContact(); | 32 | (BooleanFormula) |
924 | 29 | } | 33 | vcircuit.getOrCreateContact( |
925 | 30 | 34 | (Container)contact.getParent(), | |
926 | 31 | else | 35 | name, |
927 | 32 | return circuit.getOrCreateOutput(name, contact.getX()+1, contact.getY()+1).getReferencedContact(); | 36 | IOType.INPUT, 0, 0 |
928 | 37 | ).getReferencedContact(); | ||
929 | 38 | } else | ||
930 | 39 | return (BooleanFormula) | ||
931 | 40 | vcircuit.getOrCreateOutput(name, contact.getX()+1, contact.getY()+1).getReferencedContact(); | ||
932 | 33 | } | 41 | } |
933 | 34 | }); | 42 | }); |
934 | 35 | } catch (ParseException e) { | 43 | } catch (ParseException e) { |
935 | 36 | 44 | ||
936 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionComponent.java' | |||
937 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionComponent.java 2014-06-27 14:48:42 +0000 | |||
938 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionComponent.java 2014-07-11 09:42:10 +0000 | |||
939 | @@ -39,9 +39,9 @@ | |||
940 | 39 | 39 | ||
941 | 40 | public VisualFunctionComponent(CircuitComponent component) { | 40 | public VisualFunctionComponent(CircuitComponent component) { |
942 | 41 | super(component); | 41 | super(component); |
946 | 42 | if (component.getChildren().isEmpty()) { | 42 | // if (component.getChildren().isEmpty()) { |
947 | 43 | this.addFunction("x", null, false); | 43 | // this.addFunction("x", null, false); |
948 | 44 | } | 44 | // } |
949 | 45 | } | 45 | } |
950 | 46 | 46 | ||
951 | 47 | ComponentRenderingResult renderingResult = null; | 47 | ComponentRenderingResult renderingResult = null; |
952 | @@ -100,32 +100,6 @@ | |||
953 | 100 | return super.hitTestInLocalSpace(pointInLocalSpace); | 100 | return super.hitTestInLocalSpace(pointInLocalSpace); |
954 | 101 | } | 101 | } |
955 | 102 | } | 102 | } |
956 | 103 | |||
957 | 104 | public VisualFunctionContact addFunction(String prefix, IOType ioType, boolean allowShort) { | ||
958 | 105 | VisualContact.Direction dir=null; | ||
959 | 106 | if (ioType==null) ioType = IOType.OUTPUT; | ||
960 | 107 | |||
961 | 108 | dir=VisualContact.Direction.WEST; | ||
962 | 109 | if (ioType==IOType.OUTPUT) { | ||
963 | 110 | dir=VisualContact.Direction.EAST; | ||
964 | 111 | } | ||
965 | 112 | FunctionContact c = new FunctionContact(ioType); | ||
966 | 113 | VisualFunctionContact vc = new VisualFunctionContact(c); | ||
967 | 114 | vc.setDirection(dir); | ||
968 | 115 | vc.setName(Contact.getNewName(this.getReferencedComponent(), prefix, null, allowShort)); | ||
969 | 116 | addContact(vc); | ||
970 | 117 | return vc; | ||
971 | 118 | } | ||
972 | 119 | |||
973 | 120 | public VisualFunctionContact getOrCreateInput(String arg) { | ||
974 | 121 | for (VisualFunctionContact c : Hierarchy.filterNodesByType(getChildren(), VisualFunctionContact.class)) { | ||
975 | 122 | if(c.getName().equals(arg)) return c; | ||
976 | 123 | } | ||
977 | 124 | VisualFunctionContact vc = addFunction(arg, IOType.INPUT, true); | ||
978 | 125 | vc.setSetFunction(One.instance()); | ||
979 | 126 | vc.setResetFunction(One.instance()); | ||
980 | 127 | return vc; | ||
981 | 128 | } | ||
982 | 129 | 103 | ||
983 | 130 | @Override | 104 | @Override |
984 | 131 | public void setRenderType(RenderType renderType) { | 105 | public void setRenderType(RenderType renderType) { |
985 | @@ -185,8 +159,11 @@ | |||
986 | 185 | vc.setTransform(ct, !firstUpdate); // suppress notifications at first recalculation of contact coordinates | 159 | vc.setTransform(ct, !firstUpdate); // suppress notifications at first recalculation of contact coordinates |
987 | 186 | continue; | 160 | continue; |
988 | 187 | } | 161 | } |
989 | 162 | |||
990 | 188 | if (vc.getIOType() != IOType.INPUT) continue; | 163 | if (vc.getIOType() != IOType.INPUT) continue; |
992 | 189 | Point2D position = res.contactPositions().get(vc.getName()); | 164 | |
993 | 165 | String vcName = vc.getName(); | ||
994 | 166 | Point2D position = res.contactPositions().get(vcName); | ||
995 | 190 | if (position != null) { | 167 | if (position != null) { |
996 | 191 | bt.translate(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin), position.getY()); | 168 | bt.translate(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin), position.getY()); |
997 | 192 | 169 | ||
998 | @@ -221,6 +198,9 @@ | |||
999 | 221 | GateRenderer.foreground = Coloriser.colorise(getForegroundColor(), r.getDecoration().getColorisation()); | 198 | GateRenderer.foreground = Coloriser.colorise(getForegroundColor(), r.getDecoration().getColorisation()); |
1000 | 222 | GateRenderer.background = Coloriser.colorise(getFillColor(), r.getDecoration().getBackground()); | 199 | GateRenderer.background = Coloriser.colorise(getFillColor(), r.getDecoration().getBackground()); |
1001 | 223 | ComponentRenderingResult res = getRenderingResult(); | 200 | ComponentRenderingResult res = getRenderingResult(); |
1002 | 201 | VisualCircuit vcircuit = (VisualCircuit)r.getModel(); | ||
1003 | 202 | |||
1004 | 203 | |||
1005 | 224 | if (res == null) { | 204 | if (res == null) { |
1006 | 225 | super.draw(r); | 205 | super.draw(r); |
1007 | 226 | } else { | 206 | } else { |
1008 | @@ -290,7 +270,8 @@ | |||
1009 | 290 | 270 | ||
1010 | 291 | if (vc.getIOType() != IOType.INPUT) continue; | 271 | if (vc.getIOType() != IOType.INPUT) continue; |
1011 | 292 | 272 | ||
1013 | 293 | Point2D position = res.contactPositions().get(vc.getName()); | 273 | String cname = vc.getReferencedContact().getName(); |
1014 | 274 | Point2D position = res.contactPositions().get(cname); | ||
1015 | 294 | if (position != null) { | 275 | if (position != null) { |
1016 | 295 | line = new Line2D.Double(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin), | 276 | line = new Line2D.Double(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin), |
1017 | 296 | position.getY(), position.getX(), position.getY()); | 277 | position.getY(), position.getX(), position.getY()); |
1018 | 297 | 278 | ||
1019 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java' | |||
1020 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java 2014-06-27 14:48:42 +0000 | |||
1021 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java 2014-07-11 09:42:10 +0000 | |||
1022 | @@ -19,7 +19,7 @@ | |||
1023 | 19 | * | 19 | * |
1024 | 20 | */ | 20 | */ |
1025 | 21 | 21 | ||
1027 | 22 | package org.workcraft.plugins.circuit; | 22 | package org.workcraft.plugins.circuit; |
1028 | 23 | 23 | ||
1029 | 24 | import java.awt.BasicStroke; | 24 | import java.awt.BasicStroke; |
1030 | 25 | import java.awt.Color; | 25 | import java.awt.Color; |
1031 | @@ -87,7 +87,7 @@ | |||
1032 | 87 | public BooleanFormula getSetFunction() { | 87 | public BooleanFormula getSetFunction() { |
1033 | 88 | return getReferencedFunctionContact().getSetFunction(); | 88 | return getReferencedFunctionContact().getSetFunction(); |
1034 | 89 | } | 89 | } |
1036 | 90 | 90 | ||
1037 | 91 | @NoAutoSerialisation | 91 | @NoAutoSerialisation |
1038 | 92 | public void setSetFunction(BooleanFormula setFunction) { | 92 | public void setSetFunction(BooleanFormula setFunction) { |
1039 | 93 | if (getParent() instanceof VisualFunctionComponent) { | 93 | if (getParent() instanceof VisualFunctionComponent) { |
1040 | @@ -126,7 +126,7 @@ | |||
1041 | 126 | } | 126 | } |
1042 | 127 | return renderedSetFormula; | 127 | return renderedSetFormula; |
1043 | 128 | } | 128 | } |
1045 | 129 | 129 | ||
1046 | 130 | FormulaRenderingResult getRenderedResetFormula(FontRenderContext fcon) { | 130 | FormulaRenderingResult getRenderedResetFormula(FontRenderContext fcon) { |
1047 | 131 | if (((FunctionContact)getReferencedContact()).getResetFunction() == null) { | 131 | if (((FunctionContact)getReferencedContact()).getResetFunction() == null) { |
1048 | 132 | return null; | 132 | return null; |
1049 | @@ -255,5 +255,5 @@ | |||
1050 | 255 | } | 255 | } |
1051 | 256 | super.notify(e); | 256 | super.notify(e); |
1052 | 257 | } | 257 | } |
1055 | 258 | 258 | ||
1056 | 259 | } | 259 | } |
1057 | 260 | 260 | ||
1058 | === added directory 'CircuitPlugin/src/org/workcraft/plugins/circuit/references' | |||
1059 | === added file 'CircuitPlugin/src/org/workcraft/plugins/circuit/references/CircuitReferenceManager.java' | |||
1060 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/references/CircuitReferenceManager.java 1970-01-01 00:00:00 +0000 | |||
1061 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/references/CircuitReferenceManager.java 2014-07-11 09:42:10 +0000 | |||
1062 | @@ -0,0 +1,72 @@ | |||
1063 | 1 | package org.workcraft.plugins.circuit.references; | ||
1064 | 2 | |||
1065 | 3 | import org.workcraft.dom.Node; | ||
1066 | 4 | import org.workcraft.dom.hierarchy.NamespaceHelper; | ||
1067 | 5 | import org.workcraft.dom.hierarchy.NamespaceProvider; | ||
1068 | 6 | import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager; | ||
1069 | 7 | import org.workcraft.dom.references.NameManager; | ||
1070 | 8 | import org.workcraft.plugins.circuit.CircuitComponent; | ||
1071 | 9 | import org.workcraft.plugins.circuit.Contact; | ||
1072 | 10 | import org.workcraft.plugins.circuit.FunctionComponent; | ||
1073 | 11 | import org.workcraft.serialisation.References; | ||
1074 | 12 | import org.workcraft.util.Func; | ||
1075 | 13 | import org.workcraft.util.Identifier; | ||
1076 | 14 | |||
1077 | 15 | |||
1078 | 16 | public class CircuitReferenceManager extends HierarchicalUniqueNameReferenceManager { | ||
1079 | 17 | |||
1080 | 18 | public CircuitReferenceManager(NamespaceProvider provider, | ||
1081 | 19 | References existing, Func<Node, String> defaultName) { | ||
1082 | 20 | super(existing, defaultName); | ||
1083 | 21 | } | ||
1084 | 22 | |||
1085 | 23 | @Override | ||
1086 | 24 | public String getName(Node node) { | ||
1087 | 25 | |||
1088 | 26 | NameManager<Node> man = getNameManager(getNamespaceProvider(node)); | ||
1089 | 27 | |||
1090 | 28 | if (node instanceof Contact && !man.isNamed(node)) { | ||
1091 | 29 | return ((Contact)node).getName(); | ||
1092 | 30 | } | ||
1093 | 31 | |||
1094 | 32 | if (node instanceof FunctionComponent && (!man.isNamed(node))) { | ||
1095 | 33 | return ((FunctionComponent)node).getName(); | ||
1096 | 34 | } | ||
1097 | 35 | |||
1098 | 36 | if (!man.isNamed(node)) return null; | ||
1099 | 37 | |||
1100 | 38 | return super.getName(node); | ||
1101 | 39 | } | ||
1102 | 40 | |||
1103 | 41 | @Override | ||
1104 | 42 | public void setName(Node node, String name) { | ||
1105 | 43 | |||
1106 | 44 | // support for the older models | ||
1107 | 45 | if (Identifier.isNumber(name) && node instanceof Contact) { | ||
1108 | 46 | |||
1109 | 47 | String n = ((Contact)node).getName(); | ||
1110 | 48 | |||
1111 | 49 | if (n!=null&&!n.equals("")) name=n; | ||
1112 | 50 | } else if (Identifier.isNumber(name) && node instanceof CircuitComponent) { | ||
1113 | 51 | |||
1114 | 52 | String n = ((CircuitComponent)node).getName(); | ||
1115 | 53 | if (n!=null&&!n.equals("")) name=n; | ||
1116 | 54 | |||
1117 | 55 | } else if (Identifier.isNumber(name)) { | ||
1118 | 56 | // name="_"+name; | ||
1119 | 57 | name=defaultName.eval(node)+name; | ||
1120 | 58 | } | ||
1121 | 59 | |||
1122 | 60 | if (node instanceof Contact) { | ||
1123 | 61 | // propagate info to the node itself | ||
1124 | 62 | ((Contact)node).setName(name); | ||
1125 | 63 | } | ||
1126 | 64 | if (node instanceof CircuitComponent) { | ||
1127 | 65 | // propagate info to the node itself | ||
1128 | 66 | ((CircuitComponent)node).setName(name); | ||
1129 | 67 | } | ||
1130 | 68 | |||
1131 | 69 | super.setName(node, name); | ||
1132 | 70 | } | ||
1133 | 71 | |||
1134 | 72 | } | ||
1135 | 0 | 73 | ||
1136 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSelectionTool.java' | |||
1137 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSelectionTool.java 2013-07-25 12:29:40 +0000 | |||
1138 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSelectionTool.java 2014-07-11 09:42:10 +0000 | |||
1139 | @@ -15,8 +15,13 @@ | |||
1140 | 15 | import org.workcraft.gui.events.GraphEditorMouseEvent; | 15 | import org.workcraft.gui.events.GraphEditorMouseEvent; |
1141 | 16 | import org.workcraft.gui.graph.tools.GraphEditor; | 16 | import org.workcraft.gui.graph.tools.GraphEditor; |
1142 | 17 | import org.workcraft.gui.graph.tools.SelectionTool; | 17 | import org.workcraft.gui.graph.tools.SelectionTool; |
1143 | 18 | import org.workcraft.plugins.circuit.Circuit; | ||
1144 | 19 | import org.workcraft.plugins.circuit.FunctionContact; | ||
1145 | 20 | import org.workcraft.plugins.circuit.VisualCircuit; | ||
1146 | 18 | import org.workcraft.plugins.circuit.VisualCircuitComponent; | 21 | import org.workcraft.plugins.circuit.VisualCircuitComponent; |
1147 | 19 | import org.workcraft.plugins.circuit.VisualFunctionComponent; | 22 | import org.workcraft.plugins.circuit.VisualFunctionComponent; |
1148 | 23 | import org.workcraft.plugins.circuit.VisualFunctionContact; | ||
1149 | 24 | import org.workcraft.plugins.circuit.Contact.IOType; | ||
1150 | 20 | 25 | ||
1151 | 21 | public class CircuitSelectionTool extends SelectionTool { | 26 | public class CircuitSelectionTool extends SelectionTool { |
1152 | 22 | 27 | ||
1153 | @@ -52,11 +57,15 @@ | |||
1154 | 52 | popup.addSeparator(); | 57 | popup.addSeparator(); |
1155 | 53 | 58 | ||
1156 | 54 | JMenuItem addFunction = new JMenuItem("Add function"); | 59 | JMenuItem addFunction = new JMenuItem("Add function"); |
1157 | 60 | |||
1158 | 55 | addFunction.addActionListener(new ActionListener() { | 61 | addFunction.addActionListener(new ActionListener() { |
1159 | 56 | @Override | 62 | @Override |
1160 | 57 | public void actionPerformed(ActionEvent e) { | 63 | public void actionPerformed(ActionEvent e) { |
1161 | 58 | editor.getWorkspaceEntry().saveMemento(); | 64 | editor.getWorkspaceEntry().saveMemento(); |
1163 | 59 | comp.addFunction("x", null, false); | 65 | VisualCircuit vcircuit = (VisualCircuit)editor.getModel(); |
1164 | 66 | |||
1165 | 67 | vcircuit.getOrCreateContact(comp, null, IOType.OUTPUT, 0, 0); | ||
1166 | 68 | // comp.addFunction("x", null, false); | ||
1167 | 60 | } | 69 | } |
1168 | 61 | }); | 70 | }); |
1169 | 62 | 71 | ||
1170 | @@ -76,7 +85,10 @@ | |||
1171 | 76 | @Override | 85 | @Override |
1172 | 77 | public void actionPerformed(ActionEvent e) { | 86 | public void actionPerformed(ActionEvent e) { |
1173 | 78 | editor.getWorkspaceEntry().saveMemento(); | 87 | editor.getWorkspaceEntry().saveMemento(); |
1175 | 79 | comp.addInput("", null); | 88 | VisualCircuit vcircuit = (VisualCircuit)editor.getModel(); |
1176 | 89 | |||
1177 | 90 | vcircuit.getOrCreateContact(comp, null, IOType.INPUT, 0, 0); | ||
1178 | 91 | // comp.addInput((Circuit)vcircuit.getMathModel(), "", null); | ||
1179 | 80 | } | 92 | } |
1180 | 81 | }); | 93 | }); |
1181 | 82 | 94 | ||
1182 | @@ -85,7 +97,10 @@ | |||
1183 | 85 | @Override | 97 | @Override |
1184 | 86 | public void actionPerformed(ActionEvent e) { | 98 | public void actionPerformed(ActionEvent e) { |
1185 | 87 | editor.getWorkspaceEntry().saveMemento(); | 99 | editor.getWorkspaceEntry().saveMemento(); |
1187 | 88 | comp.addOutput("", null); | 100 | VisualCircuit vcircuit = (VisualCircuit)editor.getModel(); |
1188 | 101 | |||
1189 | 102 | vcircuit.getOrCreateContact(comp, null, IOType.OUTPUT, 0, 0); | ||
1190 | 103 | // comp.addOutput((Circuit)vcircuit.getMathModel(), "", null); | ||
1191 | 89 | } | 104 | } |
1192 | 90 | }); | 105 | }); |
1193 | 91 | 106 | ||
1194 | 92 | 107 | ||
1195 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java' | |||
1196 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-07-07 13:20:59 +0000 | |||
1197 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-07-11 09:42:10 +0000 | |||
1198 | @@ -15,7 +15,9 @@ | |||
1199 | 15 | import java.util.TreeSet; | 15 | import java.util.TreeSet; |
1200 | 16 | 16 | ||
1201 | 17 | import org.workcraft.dom.Connection; | 17 | import org.workcraft.dom.Connection; |
1202 | 18 | import org.workcraft.dom.Container; | ||
1203 | 18 | import org.workcraft.dom.Node; | 19 | import org.workcraft.dom.Node; |
1204 | 20 | import org.workcraft.dom.hierarchy.NamespaceHelper; | ||
1205 | 19 | import org.workcraft.dom.visual.Movable; | 21 | import org.workcraft.dom.visual.Movable; |
1206 | 20 | import org.workcraft.dom.visual.TransformHelper; | 22 | import org.workcraft.dom.visual.TransformHelper; |
1207 | 21 | import org.workcraft.dom.visual.VisualComponent; | 23 | import org.workcraft.dom.visual.VisualComponent; |
1208 | @@ -31,7 +33,6 @@ | |||
1209 | 31 | import org.workcraft.plugins.circuit.VisualFunctionContact; | 33 | import org.workcraft.plugins.circuit.VisualFunctionContact; |
1210 | 32 | import org.workcraft.plugins.circuit.VisualJoint; | 34 | import org.workcraft.plugins.circuit.VisualJoint; |
1211 | 33 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | 35 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
1212 | 34 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; | ||
1213 | 35 | import org.workcraft.plugins.cpog.optimisation.Literal; | 36 | import org.workcraft.plugins.cpog.optimisation.Literal; |
1214 | 36 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString; | 37 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString; |
1215 | 37 | import org.workcraft.plugins.cpog.optimisation.dnf.Dnf; | 38 | import org.workcraft.plugins.cpog.optimisation.dnf.Dnf; |
1216 | @@ -87,14 +88,23 @@ | |||
1217 | 87 | 88 | ||
1218 | 88 | private static ContactSTG generatePlaces(VisualCircuit circuit, VisualSTG stg, VisualContact contact) { | 89 | private static ContactSTG generatePlaces(VisualCircuit circuit, VisualSTG stg, VisualContact contact) { |
1219 | 89 | String contactName = getContactName(circuit, contact); | 90 | String contactName = getContactName(circuit, contact); |
1221 | 90 | VisualPlace zeroPlace = stg.createPlace(contactName+"_0"); | 91 | |
1222 | 92 | String path = NamespaceHelper.getParentReference(circuit.getMathModel().getNodeReference(contact.getReferencedComponent())); | ||
1223 | 93 | Container curContainer = (Container)createdContainers.get(path); | ||
1224 | 94 | while (curContainer==null) { | ||
1225 | 95 | path = NamespaceHelper.getParentReference(path); | ||
1226 | 96 | curContainer = (Container)createdContainers.get(path); | ||
1227 | 97 | } | ||
1228 | 98 | |||
1229 | 99 | |||
1230 | 100 | VisualPlace zeroPlace = stg.createPlace(contactName+"_0", curContainer); | ||
1231 | 91 | zeroPlace.setLabel(contactName+"=0"); | 101 | zeroPlace.setLabel(contactName+"=0"); |
1232 | 92 | 102 | ||
1233 | 93 | if (!contact.getInitOne()) { | 103 | if (!contact.getInitOne()) { |
1234 | 94 | zeroPlace.getReferencedPlace().setTokens(1); | 104 | zeroPlace.getReferencedPlace().setTokens(1); |
1235 | 95 | } | 105 | } |
1236 | 96 | 106 | ||
1238 | 97 | VisualPlace onePlace = stg.createPlace(contactName+"_1"); | 107 | VisualPlace onePlace = stg.createPlace(contactName+"_1", curContainer); |
1239 | 98 | onePlace.setLabel(contactName+"=1"); | 108 | onePlace.setLabel(contactName+"=1"); |
1240 | 99 | if (contact.getInitOne()) { | 109 | if (contact.getInitOne()) { |
1241 | 100 | onePlace.getReferencedPlace().setTokens(1); | 110 | onePlace.getReferencedPlace().setTokens(1); |
1242 | @@ -131,15 +141,23 @@ | |||
1243 | 131 | } | 141 | } |
1244 | 132 | } | 142 | } |
1245 | 133 | 143 | ||
1247 | 134 | public static VisualSTG generate(VisualCircuit circuit) { | 144 | |
1248 | 145 | |||
1249 | 146 | // store created containers in a separate map | ||
1250 | 147 | private static HashMap<String, Node> createdContainers = null; | ||
1251 | 148 | |||
1252 | 149 | public synchronized static VisualSTG generate(VisualCircuit circuit) { | ||
1253 | 135 | try { | 150 | try { |
1254 | 136 | VisualSTG stg = new VisualSTG(new STG()); | 151 | VisualSTG stg = new VisualSTG(new STG()); |
1255 | 137 | 152 | ||
1256 | 153 | // first, create the same page structure | ||
1257 | 154 | createdContainers = NamespaceHelper.copyPageStructure(stg, stg.getRoot(), circuit, circuit.getRoot(), null); | ||
1258 | 155 | |||
1259 | 138 | Map<Contact, VisualContact> targetDrivers = new HashMap<Contact, VisualContact>(); | 156 | Map<Contact, VisualContact> targetDrivers = new HashMap<Contact, VisualContact>(); |
1260 | 139 | Map<VisualContact, ContactSTG> drivers = new HashMap<VisualContact, ContactSTG>(); | 157 | Map<VisualContact, ContactSTG> drivers = new HashMap<VisualContact, ContactSTG>(); |
1261 | 140 | 158 | ||
1262 | 141 | // generate all possible drivers and fill out the targets | 159 | // generate all possible drivers and fill out the targets |
1264 | 142 | for(VisualContact contact : Hierarchy.getDescendantsOfType(circuit.getRoot(), VisualContact.class)) { | 160 | for (VisualContact contact : Hierarchy.getDescendantsOfType(circuit.getRoot(), VisualContact.class)) { |
1265 | 143 | ContactSTG cstg; | 161 | ContactSTG cstg; |
1266 | 144 | 162 | ||
1267 | 145 | if(VisualContact.isDriver(contact)) { | 163 | if(VisualContact.isDriver(contact)) { |
1268 | @@ -171,10 +189,10 @@ | |||
1269 | 171 | BooleanFormula resetFunc = null; | 189 | BooleanFormula resetFunc = null; |
1270 | 172 | Type signalType = Type.INPUT; | 190 | Type signalType = Type.INPUT; |
1271 | 173 | if (driver instanceof VisualFunctionContact) { | 191 | if (driver instanceof VisualFunctionContact) { |
1272 | 192 | // Determine signal type | ||
1273 | 174 | VisualFunctionContact contact = (VisualFunctionContact)driver; | 193 | VisualFunctionContact contact = (VisualFunctionContact)driver; |
1277 | 175 | if ((contact.getIOType() == IOType.OUTPUT) && !isFromEnvironment(contact)) { | 194 | signalType = getSignalType(contact); |
1278 | 176 | signalType = Type.OUTPUT; | 195 | |
1276 | 177 | } | ||
1279 | 178 | if ((contact.getIOType() == IOType.OUTPUT) && !(contact.getParent() instanceof VisualCircuitComponent)) { | 196 | if ((contact.getIOType() == IOType.OUTPUT) && !(contact.getParent() instanceof VisualCircuitComponent)) { |
1280 | 179 | // Driver of the primary output port | 197 | // Driver of the primary output port |
1281 | 180 | VisualContact outputDriver = findDriver(circuit, contact); | 198 | VisualContact outputDriver = findDriver(circuit, contact); |
1282 | @@ -203,11 +221,19 @@ | |||
1283 | 203 | } | 221 | } |
1284 | 204 | } | 222 | } |
1285 | 205 | 223 | ||
1291 | 206 | private static boolean isFromEnvironment(VisualContact contact) { | 224 | private static Type getSignalType(VisualFunctionContact contact) { |
1292 | 207 | if (contact.getParent() instanceof VisualCircuitComponent) { | 225 | Type result = Type.INPUT; |
1293 | 208 | return ((VisualCircuitComponent)contact.getParent()).getIsEnvironment(); | 226 | if (contact.getIOType() == IOType.OUTPUT) { |
1294 | 209 | } | 227 | if (contact.getParent() instanceof VisualCircuitComponent) { |
1295 | 210 | return false; | 228 | VisualCircuitComponent component = (VisualCircuitComponent)contact.getParent(); |
1296 | 229 | if (!component.getIsEnvironment()) { | ||
1297 | 230 | result = Type.INTERNAL; | ||
1298 | 231 | } | ||
1299 | 232 | } else { | ||
1300 | 233 | result = Type.OUTPUT; | ||
1301 | 234 | } | ||
1302 | 235 | } | ||
1303 | 236 | return result; | ||
1304 | 211 | } | 237 | } |
1305 | 212 | 238 | ||
1306 | 213 | private static void implementDriver(VisualCircuit circuit, VisualSTG stg, | 239 | private static void implementDriver(VisualCircuit circuit, VisualSTG stg, |
1307 | @@ -284,8 +310,22 @@ | |||
1308 | 284 | reset, subtract(add(center, direction), pOffset), minusDirection, | 310 | reset, subtract(add(center, direction), pOffset), minusDirection, |
1309 | 285 | signalName, ttype, SignalTransition.Direction.MINUS, p.p1, p.p0)); | 311 | signalName, ttype, SignalTransition.Direction.MINUS, p.p1, p.p0)); |
1310 | 286 | 312 | ||
1311 | 313 | Container currentLevel = null; | ||
1312 | 314 | Container oldLevel = stg.getCurrentLevel(); | ||
1313 | 315 | |||
1314 | 316 | for (Node node:nodes) { | ||
1315 | 317 | if (currentLevel==null) | ||
1316 | 318 | currentLevel = (Container)node.getParent(); | ||
1317 | 319 | |||
1318 | 320 | if (currentLevel!=node.getParent()) | ||
1319 | 321 | throw new RuntimeException("Current level is not the same among the processed nodes"); | ||
1320 | 322 | } | ||
1321 | 323 | |||
1322 | 324 | |||
1323 | 325 | stg.setCurrentLevel(currentLevel); | ||
1324 | 287 | stg.select(nodes); | 326 | stg.select(nodes); |
1325 | 288 | stg.groupSelection(); | 327 | stg.groupSelection(); |
1326 | 328 | stg.setCurrentLevel(oldLevel); | ||
1327 | 289 | } | 329 | } |
1328 | 290 | 330 | ||
1329 | 291 | private static LinkedList<VisualNode> buildTransitions(VisualContact parentContact, | 331 | private static LinkedList<VisualNode> buildTransitions(VisualContact parentContact, |
1330 | @@ -296,6 +336,15 @@ | |||
1331 | 296 | 336 | ||
1332 | 297 | LinkedList<VisualNode> nodes = new LinkedList<VisualNode>(); | 337 | LinkedList<VisualNode> nodes = new LinkedList<VisualNode>(); |
1333 | 298 | 338 | ||
1334 | 339 | |||
1335 | 340 | String path = NamespaceHelper.getParentReference(circuit.getMathModel().getNodeReference(parentContact.getReferencedComponent())); | ||
1336 | 341 | Container curContainer = (Container)createdContainers.get(path); | ||
1337 | 342 | while (curContainer==null) { | ||
1338 | 343 | path = NamespaceHelper.getParentReference(path); | ||
1339 | 344 | curContainer = (Container)createdContainers.get(path); | ||
1340 | 345 | } | ||
1341 | 346 | |||
1342 | 347 | |||
1343 | 299 | TreeSet<DnfClause> clauses = new TreeSet<DnfClause>( | 348 | TreeSet<DnfClause> clauses = new TreeSet<DnfClause>( |
1344 | 300 | new Comparator<DnfClause>() { | 349 | new Comparator<DnfClause>() { |
1345 | 301 | @Override | 350 | @Override |
1346 | @@ -311,7 +360,7 @@ | |||
1347 | 311 | 360 | ||
1348 | 312 | for(DnfClause clause : clauses) | 361 | for(DnfClause clause : clauses) |
1349 | 313 | { | 362 | { |
1351 | 314 | VisualSignalTransition transition = stg.createSignalTransition(signalName, type, transitionDirection); | 363 | VisualSignalTransition transition = stg.createSignalTransition(signalName, type, transitionDirection, curContainer); |
1352 | 315 | nodes.add(transition); | 364 | nodes.add(transition); |
1353 | 316 | parentContact.getReferencedTransitions().add(transition.getReferencedTransition()); | 365 | parentContact.getReferencedTransitions().add(transition.getReferencedTransition()); |
1354 | 317 | 366 | ||
1355 | @@ -333,7 +382,7 @@ | |||
1356 | 333 | ContactSTG source = drivers.get(driverContact); | 382 | ContactSTG source = drivers.get(driverContact); |
1357 | 334 | 383 | ||
1358 | 335 | if(source == null) | 384 | if(source == null) |
1360 | 336 | throw new RuntimeException("No source for " + targetContact.getName() + " while generating " + signalName); | 385 | throw new RuntimeException("No source for " + circuit.getMathModel().getName(targetContact) + " while generating " + signalName); |
1361 | 337 | 386 | ||
1362 | 338 | VisualPlace p = literal.getNegation() ? source.p0 : source.p1; | 387 | VisualPlace p = literal.getNegation() ? source.p0 : source.p1; |
1363 | 339 | 388 | ||
1364 | @@ -365,12 +414,19 @@ | |||
1365 | 365 | } | 414 | } |
1366 | 366 | } | 415 | } |
1367 | 367 | 416 | ||
1369 | 368 | result = ((VisualFunctionComponent)parent).getName(); | 417 | result = NamespaceHelper.getFlatName( |
1370 | 418 | circuit.getMathModel().getName(vc.getReferencedComponent()) | ||
1371 | 419 | ); | ||
1372 | 420 | |||
1373 | 421 | // result = HierarchicalNames.getFlatName( | ||
1374 | 422 | // circuit.getMathModel().getNodeReference(vc.getReferencedComponent()) | ||
1375 | 423 | // ); | ||
1376 | 424 | |||
1377 | 369 | if (contact.getIOType() == IOType.INPUT || output_cnt > 1) { | 425 | if (contact.getIOType() == IOType.INPUT || output_cnt > 1) { |
1379 | 370 | result += "_" + contact.getName(); | 426 | result += "_" + circuit.getMathModel().getName(contact.getReferencedContact()); |
1380 | 371 | } | 427 | } |
1381 | 372 | } else { | 428 | } else { |
1383 | 373 | result = contact.getName(); | 429 | result = circuit.getMathModel().getName(contact.getReferencedContact()); |
1384 | 374 | } | 430 | } |
1385 | 375 | return result; | 431 | return result; |
1386 | 376 | } | 432 | } |
1387 | 377 | 433 | ||
1388 | === modified file 'CpogsPlugin/.classpath' | |||
1389 | --- CpogsPlugin/.classpath 2014-01-29 19:00:22 +0000 | |||
1390 | +++ CpogsPlugin/.classpath 2014-07-11 09:42:10 +0000 | |||
1391 | @@ -5,5 +5,6 @@ | |||
1392 | 5 | <classpathentry combineaccessrules="false" kind="src" path="/WorkcraftCore"/> | 5 | <classpathentry combineaccessrules="false" kind="src" path="/WorkcraftCore"/> |
1393 | 6 | <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | 6 | <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> |
1394 | 7 | <classpathentry combineaccessrules="false" kind="src" path="/STGPlugin"/> | 7 | <classpathentry combineaccessrules="false" kind="src" path="/STGPlugin"/> |
1395 | 8 | <classpathentry kind="lib" path="/ThirdParty/TableLayout-bin-jdk1.5-2009-08-26.jar"/> | ||
1396 | 8 | <classpathentry kind="output" path="bin"/> | 9 | <classpathentry kind="output" path="bin"/> |
1397 | 9 | </classpath> | 10 | </classpath> |
1398 | 10 | 11 | ||
1399 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CPOG.java' | |||
1400 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/CPOG.java 2014-04-07 16:35:42 +0000 | |||
1401 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/CPOG.java 2014-07-11 09:42:10 +0000 | |||
1402 | @@ -27,7 +27,10 @@ | |||
1403 | 27 | import org.workcraft.dom.Connection; | 27 | import org.workcraft.dom.Connection; |
1404 | 28 | import org.workcraft.dom.Container; | 28 | import org.workcraft.dom.Container; |
1405 | 29 | import org.workcraft.dom.Node; | 29 | import org.workcraft.dom.Node; |
1406 | 30 | import org.workcraft.dom.hierarchy.NamespaceProvider; | ||
1407 | 30 | import org.workcraft.dom.math.AbstractMathModel; | 31 | import org.workcraft.dom.math.AbstractMathModel; |
1408 | 32 | import org.workcraft.dom.math.MathGroup; | ||
1409 | 33 | import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager; | ||
1410 | 31 | import org.workcraft.dom.references.UniqueNameReferenceManager; | 34 | import org.workcraft.dom.references.UniqueNameReferenceManager; |
1411 | 32 | import org.workcraft.exceptions.InvalidConnectionException; | 35 | import org.workcraft.exceptions.InvalidConnectionException; |
1412 | 33 | import org.workcraft.observation.HierarchyEvent; | 36 | import org.workcraft.observation.HierarchyEvent; |
1413 | @@ -42,11 +45,11 @@ | |||
1414 | 42 | public class CPOG extends AbstractMathModel { | 45 | public class CPOG extends AbstractMathModel { |
1415 | 43 | 46 | ||
1416 | 44 | public CPOG() { | 47 | public CPOG() { |
1418 | 45 | this(null, null); | 48 | this(new MathGroup(), null); |
1419 | 46 | } | 49 | } |
1420 | 47 | 50 | ||
1421 | 48 | public CPOG(Container root, References refs) { | 51 | public CPOG(Container root, References refs) { |
1423 | 49 | super(root, new UniqueNameReferenceManager(refs, new Func<Node, String>() { | 52 | super(root, new HierarchicalUniqueNameReferenceManager(refs, new Func<Node, String>() { |
1424 | 50 | @Override | 53 | @Override |
1425 | 51 | public String eval(Node arg) { | 54 | public String eval(Node arg) { |
1426 | 52 | if (arg instanceof Vertex) | 55 | if (arg instanceof Vertex) |
1427 | 53 | 56 | ||
1428 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ConsistencyEnforcer.java' | |||
1429 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/ConsistencyEnforcer.java 2010-05-01 15:12:53 +0000 | |||
1430 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/ConsistencyEnforcer.java 2014-07-11 09:42:10 +0000 | |||
1431 | @@ -5,6 +5,7 @@ | |||
1432 | 5 | import org.workcraft.observation.HierarchySupervisor; | 5 | import org.workcraft.observation.HierarchySupervisor; |
1433 | 6 | import org.workcraft.observation.NodesAddedEvent; | 6 | import org.workcraft.observation.NodesAddedEvent; |
1434 | 7 | import org.workcraft.observation.NodesDeletedEvent; | 7 | import org.workcraft.observation.NodesDeletedEvent; |
1435 | 8 | import org.workcraft.observation.NodesReparentedEvent; | ||
1436 | 8 | 9 | ||
1437 | 9 | public class ConsistencyEnforcer extends HierarchySupervisor { | 10 | public class ConsistencyEnforcer extends HierarchySupervisor { |
1438 | 10 | 11 | ||
1439 | @@ -20,7 +21,7 @@ | |||
1440 | 20 | @Override | 21 | @Override |
1441 | 21 | public void handleEvent(HierarchyEvent e) | 22 | public void handleEvent(HierarchyEvent e) |
1442 | 22 | { | 23 | { |
1444 | 23 | if (e instanceof NodesAddedEvent) | 24 | if (e instanceof NodesAddedEvent || e instanceof NodesReparentedEvent) |
1445 | 24 | { | 25 | { |
1446 | 25 | updateEncoding(); | 26 | updateEncoding(); |
1447 | 26 | createDefaultLabels(e); | 27 | createDefaultLabels(e); |
1448 | 27 | 28 | ||
1449 | === removed file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogEncoder.java' | |||
1450 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogEncoder.java 2013-10-21 17:36:57 +0000 | |||
1451 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogEncoder.java 1970-01-01 00:00:00 +0000 | |||
1452 | @@ -1,311 +0,0 @@ | |||
1453 | 1 | package org.workcraft.plugins.cpog; | ||
1454 | 2 | |||
1455 | 3 | import java.awt.geom.Point2D; | ||
1456 | 4 | import java.util.ArrayList; | ||
1457 | 5 | import java.util.HashMap; | ||
1458 | 6 | import javax.swing.JOptionPane; | ||
1459 | 7 | |||
1460 | 8 | import org.workcraft.Tool; | ||
1461 | 9 | import org.workcraft.dom.visual.VisualComponent; | ||
1462 | 10 | import org.workcraft.dom.visual.connections.VisualConnection; | ||
1463 | 11 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | ||
1464 | 12 | import org.workcraft.plugins.cpog.optimisation.CleverCnfGenerator; | ||
1465 | 13 | import org.workcraft.plugins.cpog.optimisation.CpogEncoding; | ||
1466 | 14 | import org.workcraft.plugins.cpog.optimisation.DefaultCpogSolver; | ||
1467 | 15 | import org.workcraft.plugins.cpog.optimisation.OneHotIntBooleanFormula; | ||
1468 | 16 | import org.workcraft.plugins.cpog.optimisation.OneHotNumberProvider; | ||
1469 | 17 | import org.workcraft.plugins.cpog.optimisation.Optimiser; | ||
1470 | 18 | import org.workcraft.plugins.cpog.optimisation.expressions.One; | ||
1471 | 19 | import org.workcraft.util.Geometry; | ||
1472 | 20 | import org.workcraft.workspace.WorkspaceEntry; | ||
1473 | 21 | |||
1474 | 22 | public class CpogEncoder implements Tool { | ||
1475 | 23 | |||
1476 | 24 | @Override | ||
1477 | 25 | public String getDisplayName() { | ||
1478 | 26 | return "CPOG Encoding"; | ||
1479 | 27 | } | ||
1480 | 28 | |||
1481 | 29 | @Override | ||
1482 | 30 | public String getSection() { | ||
1483 | 31 | return "Encoding"; | ||
1484 | 32 | } | ||
1485 | 33 | |||
1486 | 34 | @Override | ||
1487 | 35 | public boolean isApplicableTo(WorkspaceEntry we) | ||
1488 | 36 | { | ||
1489 | 37 | if (we.getModelEntry() == null) return false; | ||
1490 | 38 | if (we.getModelEntry().getVisualModel() instanceof VisualCPOG) return true; | ||
1491 | 39 | return false; | ||
1492 | 40 | } | ||
1493 | 41 | |||
1494 | 42 | |||
1495 | 43 | private String generateConstraint(char [][][] constraints, int numScenarios, int event1, int event2) | ||
1496 | 44 | { | ||
1497 | 45 | StringBuilder s = new StringBuilder(); | ||
1498 | 46 | for(int k = 0; k < numScenarios; k++) s.append(constraints[k][event1][event2]); | ||
1499 | 47 | return s.toString(); | ||
1500 | 48 | } | ||
1501 | 49 | |||
1502 | 50 | private char trivialEncoding(char [][][] constraints, int numScenarios, int event1, int event2) | ||
1503 | 51 | { | ||
1504 | 52 | char trivial = '-'; | ||
1505 | 53 | |||
1506 | 54 | for(int k = 0; k < numScenarios; k++) | ||
1507 | 55 | { | ||
1508 | 56 | if (constraints[k][event1][event2] == '0') | ||
1509 | 57 | { | ||
1510 | 58 | if (trivial == '1') return '?'; | ||
1511 | 59 | trivial = '0'; | ||
1512 | 60 | } | ||
1513 | 61 | |||
1514 | 62 | if (constraints[k][event1][event2] == '1') | ||
1515 | 63 | { | ||
1516 | 64 | if (trivial == '0') return '?'; | ||
1517 | 65 | trivial = '1'; | ||
1518 | 66 | } | ||
1519 | 67 | } | ||
1520 | 68 | |||
1521 | 69 | return trivial; | ||
1522 | 70 | } | ||
1523 | 71 | |||
1524 | 72 | @Override | ||
1525 | 73 | public void run(WorkspaceEntry we) | ||
1526 | 74 | { | ||
1527 | 75 | VisualCPOG cpog = (VisualCPOG)(we.getModelEntry().getVisualModel()); | ||
1528 | 76 | |||
1529 | 77 | we.captureMemento(); | ||
1530 | 78 | |||
1531 | 79 | HashMap<String, Integer> events = new HashMap<String, Integer>(); | ||
1532 | 80 | int n = 0; | ||
1533 | 81 | ArrayList<Point2D> positions = new ArrayList<Point2D>(); | ||
1534 | 82 | ArrayList<Integer> count = new ArrayList<Integer>(); | ||
1535 | 83 | |||
1536 | 84 | // TODO: remove deprecated method | ||
1537 | 85 | ArrayList<VisualScenario> scenarios = new ArrayList<VisualScenario>(cpog.getGroups()); | ||
1538 | 86 | |||
1539 | 87 | int m = scenarios.size(); | ||
1540 | 88 | |||
1541 | 89 | if (m < 2) | ||
1542 | 90 | { | ||
1543 | 91 | JOptionPane.showMessageDialog(null, | ||
1544 | 92 | "At least two scenarios are expected.", | ||
1545 | 93 | "Not enough scenarios", | ||
1546 | 94 | JOptionPane.ERROR_MESSAGE); | ||
1547 | 95 | we.cancelMemento(); | ||
1548 | 96 | return; | ||
1549 | 97 | } | ||
1550 | 98 | |||
1551 | 99 | // find all events | ||
1552 | 100 | for(int k = 0; k < m; k++) | ||
1553 | 101 | { | ||
1554 | 102 | for(VisualComponent component : scenarios.get(k).getComponents()) | ||
1555 | 103 | if (component instanceof VisualVertex) | ||
1556 | 104 | { | ||
1557 | 105 | VisualVertex vertex = (VisualVertex)component; | ||
1558 | 106 | |||
1559 | 107 | if (!events.containsKey(vertex.getLabel())) | ||
1560 | 108 | { | ||
1561 | 109 | events.put(vertex.getLabel(), n); | ||
1562 | 110 | count.add(1); | ||
1563 | 111 | Point2D p = vertex.getCenter(); | ||
1564 | 112 | p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY()); | ||
1565 | 113 | positions.add(p); | ||
1566 | 114 | n++; | ||
1567 | 115 | } | ||
1568 | 116 | else | ||
1569 | 117 | { | ||
1570 | 118 | int id = events.get(vertex.getLabel()); | ||
1571 | 119 | count.set(id, count.get(id) + 1); | ||
1572 | 120 | Point2D p = vertex.getCenter(); | ||
1573 | 121 | p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY()); | ||
1574 | 122 | positions.set(id, Geometry.add(positions.get(id), p)); | ||
1575 | 123 | } | ||
1576 | 124 | } | ||
1577 | 125 | } | ||
1578 | 126 | |||
1579 | 127 | // construct constraints | ||
1580 | 128 | |||
1581 | 129 | char [][][] constraints = new char[m][n][n]; | ||
1582 | 130 | int [][] graph = new int[n][n]; | ||
1583 | 131 | |||
1584 | 132 | for(int k = 0; k < m; k++) | ||
1585 | 133 | { | ||
1586 | 134 | for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) constraints[k][i][j] = '0'; | ||
1587 | 135 | |||
1588 | 136 | for(VisualComponent component : scenarios.get(k).getComponents()) | ||
1589 | 137 | if (component instanceof VisualVertex) | ||
1590 | 138 | { | ||
1591 | 139 | VisualVertex vertex = (VisualVertex)component; | ||
1592 | 140 | int id = events.get(vertex.getLabel()); | ||
1593 | 141 | constraints[k][id][id] = '1'; | ||
1594 | 142 | } | ||
1595 | 143 | |||
1596 | 144 | for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) graph[i][j] = 0; | ||
1597 | 145 | |||
1598 | 146 | for(VisualConnection c : scenarios.get(k).getConnections()) | ||
1599 | 147 | if (c instanceof VisualArc) | ||
1600 | 148 | { | ||
1601 | 149 | VisualArc arc = (VisualArc)c; | ||
1602 | 150 | VisualComponent c1 = arc.getFirst(), c2 = arc.getSecond(); | ||
1603 | 151 | if (c1 instanceof VisualVertex && c2 instanceof VisualVertex) | ||
1604 | 152 | { | ||
1605 | 153 | int id1 = events.get(((VisualVertex)c1).getLabel()); | ||
1606 | 154 | int id2 = events.get(((VisualVertex)c2).getLabel()); | ||
1607 | 155 | graph[id1][id2] = 1; | ||
1608 | 156 | } | ||
1609 | 157 | } | ||
1610 | 158 | |||
1611 | 159 | // compute transitive closure | ||
1612 | 160 | |||
1613 | 161 | for(int t = 0; t < n; t++) | ||
1614 | 162 | for(int i = 0; i < n; i++) | ||
1615 | 163 | if (graph[i][t] > 0) | ||
1616 | 164 | for(int j = 0; j < n; j++) | ||
1617 | 165 | if (graph[t][j] > 0) graph[i][j] = 1; | ||
1618 | 166 | |||
1619 | 167 | // detect transitive arcs | ||
1620 | 168 | |||
1621 | 169 | for(int t = 0; t < n; t++) | ||
1622 | 170 | for(int i = 0; i < n; i++) | ||
1623 | 171 | if (graph[i][t] > 0) | ||
1624 | 172 | for(int j = 0; j < n; j++) | ||
1625 | 173 | if (graph[t][j] > 0) graph[i][j] = 2; | ||
1626 | 174 | |||
1627 | 175 | // report cyclic scenario | ||
1628 | 176 | |||
1629 | 177 | for(int i = 0; i < n; i++) | ||
1630 | 178 | if (graph[i][i] > 0) | ||
1631 | 179 | { | ||
1632 | 180 | JOptionPane.showMessageDialog(null, | ||
1633 | 181 | "Scenario '" + scenarios.get(k).getLabel() + "' is cyclic.", | ||
1634 | 182 | "Invalid scenario", | ||
1635 | 183 | JOptionPane.ERROR_MESSAGE); | ||
1636 | 184 | we.cancelMemento(); | ||
1637 | 185 | return; | ||
1638 | 186 | } | ||
1639 | 187 | |||
1640 | 188 | for(int i = 0; i < n; i++) | ||
1641 | 189 | for(int j = 0; j < n; j++) | ||
1642 | 190 | if (i != j) | ||
1643 | 191 | { | ||
1644 | 192 | char ch = '0'; | ||
1645 | 193 | |||
1646 | 194 | if (graph[i][j] > 0) ch = '1'; | ||
1647 | 195 | if (graph[i][j] > 1) ch = '-'; | ||
1648 | 196 | if (constraints[k][i][i] == '0' || constraints[k][j][j] == '0') ch = '-'; | ||
1649 | 197 | |||
1650 | 198 | constraints[k][i][j] = ch; | ||
1651 | 199 | } | ||
1652 | 200 | } | ||
1653 | 201 | |||
1654 | 202 | // group similar constraints | ||
1655 | 203 | |||
1656 | 204 | HashMap<String, Integer> task = new HashMap<String, Integer>(); | ||
1657 | 205 | |||
1658 | 206 | for(int i = 0; i < n; i++) | ||
1659 | 207 | for(int j = 0; j < n; j++) | ||
1660 | 208 | if (trivialEncoding(constraints, m, i, j) == '?') | ||
1661 | 209 | { | ||
1662 | 210 | String constraint = generateConstraint(constraints, m, i, j); | ||
1663 | 211 | if (!task.containsKey(constraint)) task.put(constraint, task.size()); | ||
1664 | 212 | } | ||
1665 | 213 | |||
1666 | 214 | // call CPOG encoder | ||
1667 | 215 | |||
1668 | 216 | char [][] matrix = new char[m][task.size()]; | ||
1669 | 217 | |||
1670 | 218 | String [] instance = new String[m]; | ||
1671 | 219 | for(String s : task.keySet()) | ||
1672 | 220 | for(int i = 0; i < m; i++) matrix[i][task.get(s)] = s.charAt(i); | ||
1673 | 221 | |||
1674 | 222 | for(int i = 0; i < m; i++) instance[i] = new String(matrix[i]); | ||
1675 | 223 | |||
1676 | 224 | int freeVariables = CpogSettings.getEncodingWidth(); | ||
1677 | 225 | int derivedVariables = CpogSettings.getCircuitSize(); | ||
1678 | 226 | |||
1679 | 227 | Optimiser<OneHotIntBooleanFormula> oneHot = new Optimiser<OneHotIntBooleanFormula>(new OneHotNumberProvider()); | ||
1680 | 228 | |||
1681 | 229 | DefaultCpogSolver<BooleanFormula> solverCnf = new DefaultCpogSolver<BooleanFormula>(oneHot, new CleverCnfGenerator()); | ||
1682 | 230 | |||
1683 | 231 | Variable [] vars = new Variable[freeVariables]; | ||
1684 | 232 | for(int i = 0; i < freeVariables; i++) vars[i] = cpog.createVisualVariable().getMathVariable(); | ||
1685 | 233 | |||
1686 | 234 | CpogEncoding solution = null; | ||
1687 | 235 | try | ||
1688 | 236 | { | ||
1689 | 237 | solution = solverCnf.solve(instance, vars, derivedVariables); | ||
1690 | 238 | if (solution == null) | ||
1691 | 239 | { | ||
1692 | 240 | we.cancelMemento(); | ||
1693 | 241 | JOptionPane.showMessageDialog(null, "No solution.", "Encoding result", JOptionPane.INFORMATION_MESSAGE); | ||
1694 | 242 | } | ||
1695 | 243 | |||
1696 | 244 | } | ||
1697 | 245 | catch(Exception e) | ||
1698 | 246 | { | ||
1699 | 247 | we.cancelMemento(); | ||
1700 | 248 | JOptionPane.showMessageDialog(null, e.getMessage(), "Encoding result", JOptionPane.ERROR_MESSAGE); | ||
1701 | 249 | } | ||
1702 | 250 | |||
1703 | 251 | if(solution == null) return; | ||
1704 | 252 | |||
1705 | 253 | // create result | ||
1706 | 254 | |||
1707 | 255 | boolean[][] encoding = solution.getEncoding(); | ||
1708 | 256 | |||
1709 | 257 | for(int k = 0; k < m; k++) | ||
1710 | 258 | { | ||
1711 | 259 | for(int i = 0; i < freeVariables; i++) | ||
1712 | 260 | scenarios.get(k).getEncoding().setState(vars[i], VariableState.fromBoolean(encoding[k][i])); | ||
1713 | 261 | } | ||
1714 | 262 | |||
1715 | 263 | VisualScenario result = cpog.createVisualScenario(); | ||
1716 | 264 | result.setLabel("Composition"); | ||
1717 | 265 | VisualVertex [] vertices = new VisualVertex[n]; | ||
1718 | 266 | for(String eventName : events.keySet()) | ||
1719 | 267 | { | ||
1720 | 268 | int id = events.get(eventName); | ||
1721 | 269 | vertices[id] = cpog.createVisualVertex(result); | ||
1722 | 270 | vertices[id].setLabel(eventName); | ||
1723 | 271 | vertices[id].setPosition(Geometry.multiply(positions.get(id), 1.0/count.get(id))); | ||
1724 | 272 | } | ||
1725 | 273 | |||
1726 | 274 | BooleanFormula[] functions = solution.getFunctions(); | ||
1727 | 275 | for(int i = 0; i < n; i++) | ||
1728 | 276 | for(int j = 0; j < n; j++) | ||
1729 | 277 | { | ||
1730 | 278 | BooleanFormula condition; | ||
1731 | 279 | |||
1732 | 280 | char trivial = trivialEncoding(constraints, m, i, j); | ||
1733 | 281 | if (trivial != '?') | ||
1734 | 282 | { | ||
1735 | 283 | if (trivial == '1') | ||
1736 | 284 | { | ||
1737 | 285 | condition = One.instance(); | ||
1738 | 286 | } | ||
1739 | 287 | else | ||
1740 | 288 | { | ||
1741 | 289 | continue; | ||
1742 | 290 | } | ||
1743 | 291 | } | ||
1744 | 292 | else | ||
1745 | 293 | { | ||
1746 | 294 | String constraint = generateConstraint(constraints, m, i, j); | ||
1747 | 295 | condition = functions[task.get(constraint)]; | ||
1748 | 296 | } | ||
1749 | 297 | |||
1750 | 298 | if (i == j) | ||
1751 | 299 | { | ||
1752 | 300 | vertices[i].setCondition(condition); | ||
1753 | 301 | } | ||
1754 | 302 | else | ||
1755 | 303 | { | ||
1756 | 304 | VisualArc arc = cpog.connect(vertices[i], vertices[j]); | ||
1757 | 305 | arc.setCondition(condition); | ||
1758 | 306 | } | ||
1759 | 307 | } | ||
1760 | 308 | we.saveMemento(); | ||
1761 | 309 | } | ||
1762 | 310 | |||
1763 | 311 | } | ||
1764 | 312 | 0 | ||
1765 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogModule.java' | |||
1766 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogModule.java 2013-12-27 19:04:57 +0000 | |||
1767 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogModule.java 2014-07-11 09:42:10 +0000 | |||
1768 | @@ -16,6 +16,7 @@ | |||
1769 | 16 | import org.workcraft.plugins.cpog.serialisation.VertexSerialiser; | 16 | import org.workcraft.plugins.cpog.serialisation.VertexSerialiser; |
1770 | 17 | import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupDeserialiser; | 17 | import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupDeserialiser; |
1771 | 18 | import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupSerialiser; | 18 | import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupSerialiser; |
1772 | 19 | import org.workcraft.plugins.cpog.tools.EncoderPreferencesTool; | ||
1773 | 19 | import org.workcraft.plugins.cpog.tools.GraphStatisticsTool; | 20 | import org.workcraft.plugins.cpog.tools.GraphStatisticsTool; |
1774 | 20 | import org.workcraft.serialisation.xml.XMLDeserialiser; | 21 | import org.workcraft.serialisation.xml.XMLDeserialiser; |
1775 | 21 | import org.workcraft.serialisation.xml.XMLSerialiser; | 22 | import org.workcraft.serialisation.xml.XMLSerialiser; |
1776 | @@ -40,7 +41,9 @@ | |||
1777 | 40 | p.registerClass(XMLDeserialiser.class, ArcDeserialiser.class); | 41 | p.registerClass(XMLDeserialiser.class, ArcDeserialiser.class); |
1778 | 41 | p.registerClass(SettingsPage.class, CpogSettings.class); | 42 | p.registerClass(SettingsPage.class, CpogSettings.class); |
1779 | 42 | 43 | ||
1781 | 43 | p.registerClass(Tool.class, CpogEncoder.class); | 44 | //p.registerClass(Tool.class, CpogEncoder.class); |
1782 | 45 | |||
1783 | 46 | p.registerClass(Tool.class, EncoderPreferencesTool.class, framework); | ||
1784 | 44 | 47 | ||
1785 | 45 | p.registerClass(Tool.class, new Initialiser<Tool>() { | 48 | p.registerClass(Tool.class, new Initialiser<Tool>() { |
1786 | 46 | @Override | 49 | @Override |
1787 | 47 | 50 | ||
1788 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogProgrammer.java' | |||
1789 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogProgrammer.java 1970-01-01 00:00:00 +0000 | |||
1790 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogProgrammer.java 2014-07-11 09:42:10 +0000 | |||
1791 | @@ -0,0 +1,1023 @@ | |||
1792 | 1 | package org.workcraft.plugins.cpog; | ||
1793 | 2 | |||
1794 | 3 | import java.awt.geom.Point2D; | ||
1795 | 4 | import java.io.BufferedReader; | ||
1796 | 5 | import java.io.DataInputStream; | ||
1797 | 6 | import java.io.File; | ||
1798 | 7 | import java.io.FileInputStream; | ||
1799 | 8 | import java.io.FileOutputStream; | ||
1800 | 9 | import java.io.IOException; | ||
1801 | 10 | import java.io.InputStream; | ||
1802 | 11 | import java.io.InputStreamReader; | ||
1803 | 12 | import java.io.PrintStream; | ||
1804 | 13 | import java.util.ArrayList; | ||
1805 | 14 | import java.util.HashMap; | ||
1806 | 15 | import java.util.Map; | ||
1807 | 16 | import java.util.StringTokenizer; | ||
1808 | 17 | |||
1809 | 18 | import javax.swing.JOptionPane; | ||
1810 | 19 | |||
1811 | 20 | import org.workcraft.dom.visual.RemovedNodeDeselector; | ||
1812 | 21 | import org.workcraft.dom.visual.VisualComponent; | ||
1813 | 22 | import org.workcraft.dom.visual.connections.VisualConnection; | ||
1814 | 23 | import org.workcraft.plugins.cpog.EncoderSettings.generationMode; | ||
1815 | 24 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | ||
1816 | 25 | import org.workcraft.plugins.cpog.optimisation.CleverCnfGenerator; | ||
1817 | 26 | import org.workcraft.plugins.cpog.optimisation.CpogEncoding; | ||
1818 | 27 | import org.workcraft.plugins.cpog.optimisation.CpogOptimisationTask; | ||
1819 | 28 | import org.workcraft.plugins.cpog.optimisation.DefaultCpogSolver; | ||
1820 | 29 | import org.workcraft.plugins.cpog.optimisation.OneHotIntBooleanFormula; | ||
1821 | 30 | import org.workcraft.plugins.cpog.optimisation.OneHotNumberProvider; | ||
1822 | 31 | import org.workcraft.plugins.cpog.optimisation.Optimiser; | ||
1823 | 32 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString; | ||
1824 | 33 | import org.workcraft.plugins.cpog.optimisation.expressions.One; | ||
1825 | 34 | import org.workcraft.plugins.cpog.optimisation.expressions.Zero; | ||
1826 | 35 | import org.workcraft.plugins.cpog.optimisation.javacc.BooleanParser; | ||
1827 | 36 | import org.workcraft.util.Func; | ||
1828 | 37 | import org.workcraft.util.Geometry; | ||
1829 | 38 | import org.workcraft.workspace.WorkspaceEntry; | ||
1830 | 39 | |||
1831 | 40 | import com.sun.org.apache.regexp.internal.RE; | ||
1832 | 41 | |||
1833 | 42 | public class CpogProgrammer { | ||
1834 | 43 | |||
1835 | 44 | private EncoderSettings settings; | ||
1836 | 45 | private File scenarioFile, encodingFile ; | ||
1837 | 46 | private String toolPath = "../tools/"; | ||
1838 | 47 | private int bits = 1; | ||
1839 | 48 | private Double minArea; | ||
1840 | 49 | |||
1841 | 50 | // SETTING PARAMETERS FOR CALLING PROGRAMMER.X | ||
1842 | 51 | private String espressoCommand, abcFolder , gatesLibrary , | ||
1843 | 52 | verbose = "", genMode= "", numSol= "", customFlag= "", customPath= "", effort= "", espressoFlag= "", abcFlag= "", gateLibFlag= "", cpogSize= "", disableFunction= "", | ||
1844 | 53 | oldSynt= ""; | ||
1845 | 54 | // Allocation data structures | ||
1846 | 55 | private Process process; | ||
1847 | 56 | private String[] opt_enc, opt_formulaeVertices,truthTableVertices, opt_vertices, opt_sources, opt_dests, | ||
1848 | 57 | opt_formulaeArcs, truthTableArcs, arcNames; | ||
1849 | 58 | private int v,a,n; | ||
1850 | 59 | |||
1851 | 60 | public CpogProgrammer(EncoderSettings settings){ | ||
1852 | 61 | this.setSettings(settings); | ||
1853 | 62 | } | ||
1854 | 63 | |||
1855 | 64 | private String binaryToInt(String string) { | ||
1856 | 65 | int value = 0, wg = 1; | ||
1857 | 66 | if(string != null){ | ||
1858 | 67 | for(int i = string.length()-1; i>=0; i--){ | ||
1859 | 68 | if(string.charAt(i) == '1'){ | ||
1860 | 69 | value += wg; | ||
1861 | 70 | } | ||
1862 | 71 | wg *= 2; | ||
1863 | 72 | } | ||
1864 | 73 | |||
1865 | 74 | return String.valueOf(value); | ||
1866 | 75 | } | ||
1867 | 76 | return "0"; | ||
1868 | 77 | } | ||
1869 | 78 | |||
1870 | 79 | private static boolean deleteDir(File dir) { | ||
1871 | 80 | if (dir.isDirectory()) { | ||
1872 | 81 | String[] children = dir.list(); | ||
1873 | 82 | for (int i = 0; i < children.length; i++) { | ||
1874 | 83 | boolean success = deleteDir(new File(dir, children[i])); | ||
1875 | 84 | if (!success) { | ||
1876 | 85 | return false; | ||
1877 | 86 | } | ||
1878 | 87 | } | ||
1879 | 88 | } | ||
1880 | 89 | |||
1881 | 90 | return dir.delete(); // The directory is empty now and can be deleted. | ||
1882 | 91 | } | ||
1883 | 92 | |||
1884 | 93 | private String generateConstraint(char [][][] constraints, int numScenarios, int event1, int event2) | ||
1885 | 94 | { | ||
1886 | 95 | StringBuilder s = new StringBuilder(); | ||
1887 | 96 | for(int k = 0; k < numScenarios; k++) s.append(constraints[k][event1][event2]); | ||
1888 | 97 | return s.toString(); | ||
1889 | 98 | } | ||
1890 | 99 | |||
1891 | 100 | private char trivialEncoding(char [][][] constraints, int numScenarios, int event1, int event2) | ||
1892 | 101 | { | ||
1893 | 102 | char trivial = '-'; | ||
1894 | 103 | |||
1895 | 104 | for(int k = 0; k < numScenarios; k++) | ||
1896 | 105 | { | ||
1897 | 106 | if (constraints[k][event1][event2] == '0') | ||
1898 | 107 | { | ||
1899 | 108 | if (trivial == '1') return '?'; | ||
1900 | 109 | trivial = '0'; | ||
1901 | 110 | } | ||
1902 | 111 | |||
1903 | 112 | if (constraints[k][event1][event2] == '1') | ||
1904 | 113 | { | ||
1905 | 114 | if (trivial == '0') return '?'; | ||
1906 | 115 | trivial = '1'; | ||
1907 | 116 | } | ||
1908 | 117 | } | ||
1909 | 118 | |||
1910 | 119 | return trivial; | ||
1911 | 120 | } | ||
1912 | 121 | |||
1913 | 122 | private int WriteCpogIntoFile(int m, ArrayList<VisualScenario> scenarios) | ||
1914 | 123 | { | ||
1915 | 124 | try{ | ||
1916 | 125 | scenarioFile = File.createTempFile("scenarios", "cpog"); | ||
1917 | 126 | |||
1918 | 127 | PrintStream Output = new PrintStream(scenarioFile); | ||
1919 | 128 | |||
1920 | 129 | |||
1921 | 130 | for(int k = 0; k < m; k++) | ||
1922 | 131 | { | ||
1923 | 132 | Map<String, Integer> nodes = new HashMap<String, Integer>(); | ||
1924 | 133 | // Print arcs | ||
1925 | 134 | Output.println(".scenario CPOG_" + k); | ||
1926 | 135 | for(VisualConnection c : scenarios.get(k).getConnections()){ | ||
1927 | 136 | if (c instanceof VisualArc) | ||
1928 | 137 | { | ||
1929 | 138 | VisualArc arc = (VisualArc)c; | ||
1930 | 139 | VisualComponent c1 = arc.getFirst(), c2 = arc.getSecond(); | ||
1931 | 140 | if (c1 instanceof VisualVertex && c2 instanceof VisualVertex) | ||
1932 | 141 | { | ||
1933 | 142 | nodes.put(c1.getLabel(), 0); | ||
1934 | 143 | nodes.put(c2.getLabel(), 0); | ||
1935 | 144 | Output.println(c1.getLabel() + " " + c2.getLabel()); | ||
1936 | 145 | } | ||
1937 | 146 | } | ||
1938 | 147 | } | ||
1939 | 148 | |||
1940 | 149 | // Print conditions on vertices | ||
1941 | 150 | for(VisualComponent component : scenarios.get(k).getComponents()){ | ||
1942 | 151 | if(component instanceof VisualVertex){ | ||
1943 | 152 | VisualVertex vertex = (VisualVertex)component; | ||
1944 | 153 | BooleanFormula condition = vertex.getCondition(); | ||
1945 | 154 | if (condition != One.instance() && condition != Zero.instance()){ | ||
1946 | 155 | |||
1947 | 156 | // Format output by substituting ' with ! | ||
1948 | 157 | String cond = FormulaToString.toString(condition).replaceAll("'", "!"); | ||
1949 | 158 | String result = ""; | ||
1950 | 159 | String tmp = ""; | ||
1951 | 160 | for(int i=0; i<cond.length(); i++){ | ||
1952 | 161 | if(cond.charAt(i) != '(' && cond.charAt(i) != ')' && cond.charAt(i) != '+' && | ||
1953 | 162 | cond.charAt(i) != '*' && cond.charAt(i) != '!' && cond.charAt(i) != ' '){ | ||
1954 | 163 | tmp = ""; | ||
1955 | 164 | while(i < cond.length() && cond.charAt(i) != '(' && cond.charAt(i) != ')' && cond.charAt(i) != '+' && | ||
1956 | 165 | cond.charAt(i) != '*' && cond.charAt(i) != '!' && cond.charAt(i) != ' '){ | ||
1957 | 166 | tmp += cond.charAt(i); | ||
1958 | 167 | i++; | ||
1959 | 168 | } | ||
1960 | 169 | //System.out.println("TMP: " + tmp); | ||
1961 | 170 | for(int j= tmp.length()-1; j >= 0; j--){ | ||
1962 | 171 | //System.out.println(j + ") " + tmp.charAt(j)); | ||
1963 | 172 | result += tmp.charAt(j); | ||
1964 | 173 | } | ||
1965 | 174 | if(i < cond.length()){ | ||
1966 | 175 | result += cond.charAt(i); | ||
1967 | 176 | } | ||
1968 | 177 | } | ||
1969 | 178 | else{ | ||
1970 | 179 | result += cond.charAt(i);; | ||
1971 | 180 | } | ||
1972 | 181 | } | ||
1973 | 182 | |||
1974 | 183 | String end = ""; | ||
1975 | 184 | for(int i = 0; i<result.length(); i++){ | ||
1976 | 185 | if(result.charAt(i) == '(') end += ')'; | ||
1977 | 186 | else if (result.charAt(i) == ')') end += '('; | ||
1978 | 187 | else end += result.charAt(i); | ||
1979 | 188 | } | ||
1980 | 189 | |||
1981 | 190 | // Print conditions on each vertices | ||
1982 | 191 | Output.print(":"); | ||
1983 | 192 | for(int i=end.length()-1; i>=0; i--){ | ||
1984 | 193 | Output.print(end.charAt(i)); | ||
1985 | 194 | } | ||
1986 | 195 | Output.println(" " + vertex.getLabel()); | ||
1987 | 196 | } | ||
1988 | 197 | |||
1989 | 198 | //VisualVertex vertex = (VisualVertex)component; | ||
1990 | 199 | if(!nodes.containsKey(vertex.getLabel())){ | ||
1991 | 200 | Output.println(vertex.getLabel()); | ||
1992 | 201 | } | ||
1993 | 202 | } | ||
1994 | 203 | |||
1995 | 204 | } | ||
1996 | 205 | Output.println(".end"); | ||
1997 | 206 | if(k != m-1){ | ||
1998 | 207 | Output.println(); | ||
1999 | 208 | } | ||
2000 | 209 | } | ||
2001 | 210 | Output.close(); | ||
2002 | 211 | |||
2003 | 212 | // WRITING CUSTOM ENCODING FILE | ||
2004 | 213 | if(settings.getGenMode() != generationMode.SCENCO){ | ||
2005 | 214 | encodingFile = File.createTempFile("custom", "enc"); | ||
2006 | 215 | if(settings.isCustomEncMode()){ | ||
2007 | 216 | PrintStream Output1 = new PrintStream(encodingFile); | ||
2008 | 217 | |||
2009 | 218 | String [] enc = settings.getCustomEnc(); | ||
2010 | 219 | for(int k = 0; k < m; k++) | ||
2011 | 220 | { | ||
2012 | 221 | if(enc[k].contains("2") || enc[k].contains("3") || enc[k].contains("4") || | ||
2013 | 222 | enc[k].contains("5") || enc[k].contains("6") || enc[k].contains("7") || | ||
2014 | 223 | enc[k].contains("8") || enc[k].contains("9")){ | ||
2015 | 224 | JOptionPane.showMessageDialog(null, | ||
2016 | 225 | "Op-code " + enc[k] + " not allowed.", | ||
2017 | 226 | "Custom encoding error", | ||
2018 | 227 | JOptionPane.ERROR_MESSAGE); | ||
2019 | 228 | return -1; | ||
2020 | 229 | |||
2021 | 230 | } | ||
2022 | 231 | String empty = ""; | ||
2023 | 232 | for(int i=0; i<settings.getBits(); i++) empty += 'X'; | ||
2024 | 233 | if(enc[k].equals("") || enc[k].equals(empty)){ | ||
2025 | 234 | Output1.println("/"); | ||
2026 | 235 | } | ||
2027 | 236 | else{ | ||
2028 | 237 | Output1.println(enc[k]); | ||
2029 | 238 | } | ||
2030 | 239 | } | ||
2031 | 240 | Output1.println(settings.getBits()); | ||
2032 | 241 | Output1.close(); | ||
2033 | 242 | } | ||
2034 | 243 | } | ||
2035 | 244 | }catch (IOException e) { | ||
2036 | 245 | System.out.println("Error: " + e); | ||
2037 | 246 | } | ||
2038 | 247 | |||
2039 | 248 | return 0; | ||
2040 | 249 | } | ||
2041 | 250 | |||
2042 | 251 | private void printController(int m){ | ||
2043 | 252 | System.out.println(); | ||
2044 | 253 | String fileName = toolPath + "results/generated_encoding/"; | ||
2045 | 254 | for(int i=0; i<m; i++) fileName = fileName.concat(binaryToInt(opt_enc[i]) + "_"); | ||
2046 | 255 | fileName = fileName.concat(".prg"); | ||
2047 | 256 | File f = new File(fileName); | ||
2048 | 257 | if(f.exists() && !f.isDirectory()){ | ||
2049 | 258 | System.out.println("Boolean controller:"); | ||
2050 | 259 | try{ | ||
2051 | 260 | FileInputStream fstream = new FileInputStream(fileName); | ||
2052 | 261 | DataInputStream in = new DataInputStream(fstream); | ||
2053 | 262 | BufferedReader bre = new BufferedReader(new InputStreamReader(in)); | ||
2054 | 263 | String strLine; | ||
2055 | 264 | bre.readLine(); | ||
2056 | 265 | bre.readLine(); | ||
2057 | 266 | while ((strLine = bre.readLine()) != null) { | ||
2058 | 267 | System.out.println (strLine); | ||
2059 | 268 | } | ||
2060 | 269 | in.close(); | ||
2061 | 270 | }catch (Exception e){ //Catch exception if any | ||
2062 | 271 | System.err.println("Error: " + e.getMessage()); | ||
2063 | 272 | } | ||
2064 | 273 | System.out.println(); | ||
2065 | 274 | } | ||
2066 | 275 | return; | ||
2067 | 276 | } | ||
2068 | 277 | |||
2069 | 278 | private void deleteTempFiles(){ | ||
2070 | 279 | if(scenarioFile.exists()) scenarioFile.delete(); | ||
2071 | 280 | if(encodingFile.exists()) encodingFile.delete(); | ||
2072 | 281 | return; | ||
2073 | 282 | } | ||
2074 | 283 | |||
2075 | 284 | private int callingProgrammer(Double currArea, WorkspaceEntry we, int it, boolean continuous) throws IOException{ | ||
2076 | 285 | //Debug Printing: launching executable | ||
2077 | 286 | /*System.out.println(toolPath + "programmer.x" + " " + scenarioFile.getAbsolutePath() + " " + | ||
2078 | 287 | "-m" + " " + effort + " " + genMode + " " + numSol + " " + customFlag + " " + customPath + " " + | ||
2079 | 288 | verbose + " " + cpogSize + " " + disableFunction + " " + oldSynt + " " + | ||
2080 | 289 | espressoFlag + " " + espressoCommand + " " + abcFlag + " " + abcFolder + " " + gateLibFlag + " " + | ||
2081 | 290 | gatesLibrary);*/ | ||
2082 | 291 | process = new ProcessBuilder(toolPath + "programmer.x", scenarioFile.getAbsolutePath(), | ||
2083 | 292 | "-m",effort,genMode, numSol,customFlag,customPath,verbose,cpogSize,disableFunction,oldSynt, | ||
2084 | 293 | espressoFlag,espressoCommand, abcFlag, abcFolder, gateLibFlag, gatesLibrary).start(); | ||
2085 | 294 | InputStream is = process.getInputStream(); | ||
2086 | 295 | InputStreamReader isr = new InputStreamReader(is); | ||
2087 | 296 | BufferedReader br = new BufferedReader(isr); | ||
2088 | 297 | String line; | ||
2089 | 298 | boolean finish = false; | ||
2090 | 299 | if(continuous){ | ||
2091 | 300 | while ( (line = br.readLine()) != null && finish == false) { | ||
2092 | 301 | // Read Area | ||
2093 | 302 | if(line.contains(".area")){ | ||
2094 | 303 | line = br.readLine(); | ||
2095 | 304 | currArea = Double.valueOf(line); | ||
2096 | 305 | line = br.readLine(); | ||
2097 | 306 | if(currArea < minArea){ | ||
2098 | 307 | v = 0; a = 0; | ||
2099 | 308 | minArea = currArea; | ||
2100 | 309 | System.out.println(it + ") " + "Area of current circuit: " + minArea); | ||
2101 | 310 | while((line = br.readLine()) != null){ | ||
2102 | 311 | // Read Optimal Encoding | ||
2103 | 312 | if(line.contains("MIN: ")){ | ||
2104 | 313 | StringTokenizer st2 = new StringTokenizer(line, " "); | ||
2105 | 314 | int j = 0; | ||
2106 | 315 | st2.nextElement(); | ||
2107 | 316 | while (st2.hasMoreElements()) { | ||
2108 | 317 | opt_enc[j++] = (String) st2.nextElement(); | ||
2109 | 318 | } | ||
2110 | 319 | } | ||
2111 | 320 | |||
2112 | 321 | // Read Optimal Formulae | ||
2113 | 322 | if(line.contains(".start_formulae")){ | ||
2114 | 323 | line = br.readLine(); | ||
2115 | 324 | while(line.contains(".end_formulae") == false){ | ||
2116 | 325 | StringTokenizer st2 = new StringTokenizer(line, ","); | ||
2117 | 326 | String el = (String)st2.nextElement(); | ||
2118 | 327 | if(el.equals("V")){ //formula of a vertex | ||
2119 | 328 | opt_vertices[v] = (String) st2.nextElement(); | ||
2120 | 329 | truthTableVertices[v] = (String) st2.nextElement(); | ||
2121 | 330 | opt_formulaeVertices[v++] = (String) st2.nextElement(); | ||
2122 | 331 | }else{ | ||
2123 | 332 | opt_sources[a] = (String) st2.nextElement(); | ||
2124 | 333 | opt_dests[a] = (String) st2.nextElement(); | ||
2125 | 334 | arcNames[a] = opt_sources[a] + "->" + opt_dests[a]; | ||
2126 | 335 | truthTableArcs[a] = (String) st2.nextElement(); | ||
2127 | 336 | opt_formulaeArcs[a++] = (String) st2.nextElement(); | ||
2128 | 337 | } | ||
2129 | 338 | line = br.readLine(); | ||
2130 | 339 | } | ||
2131 | 340 | |||
2132 | 341 | } | ||
2133 | 342 | |||
2134 | 343 | // Read statistics | ||
2135 | 344 | if(line.contains(".statistics")){ | ||
2136 | 345 | line = br.readLine(); | ||
2137 | 346 | while(line.contains(".end_statistics") == false){ | ||
2138 | 347 | line = br.readLine(); | ||
2139 | 348 | } | ||
2140 | 349 | } | ||
2141 | 350 | |||
2142 | 351 | // Read errors | ||
2143 | 352 | if(line.contains(".error")){ | ||
2144 | 353 | line = br.readLine(); | ||
2145 | 354 | while(line.contains(".end_error") == false){ | ||
2146 | 355 | JOptionPane.showMessageDialog(null, | ||
2147 | 356 | line, | ||
2148 | 357 | "Programmer.x error", | ||
2149 | 358 | JOptionPane.ERROR_MESSAGE); | ||
2150 | 359 | line = br.readLine(); | ||
2151 | 360 | } | ||
2152 | 361 | return -1; | ||
2153 | 362 | |||
2154 | 363 | } | ||
2155 | 364 | } | ||
2156 | 365 | }else{ | ||
2157 | 366 | finish = true; | ||
2158 | 367 | } | ||
2159 | 368 | } | ||
2160 | 369 | |||
2161 | 370 | } | ||
2162 | 371 | }else{ | ||
2163 | 372 | while ( (line = br.readLine()) != null){ | ||
2164 | 373 | if(settings.isVerboseMode()) | ||
2165 | 374 | System.out.println(line); | ||
2166 | 375 | |||
2167 | 376 | // Read Optimal Encoding | ||
2168 | 377 | if(line.contains("MIN: ")){ | ||
2169 | 378 | StringTokenizer st2 = new StringTokenizer(line, " "); | ||
2170 | 379 | int j = 0; | ||
2171 | 380 | st2.nextElement(); | ||
2172 | 381 | while (st2.hasMoreElements()) { | ||
2173 | 382 | opt_enc[j++] = (String) st2.nextElement(); | ||
2174 | 383 | } | ||
2175 | 384 | } | ||
2176 | 385 | |||
2177 | 386 | // Read Optimal Formulae | ||
2178 | 387 | if(line.contains(".start_formulae")){ | ||
2179 | 388 | line = br.readLine(); | ||
2180 | 389 | while(line.contains(".end_formulae") == false){ | ||
2181 | 390 | if(settings.isVerboseMode()) | ||
2182 | 391 | System.out.println(line); | ||
2183 | 392 | StringTokenizer st2 = new StringTokenizer(line, ","); | ||
2184 | 393 | String el = (String)st2.nextElement(); | ||
2185 | 394 | if(el.equals("V")){ //formula of a vertex | ||
2186 | 395 | opt_vertices[v] = (String) st2.nextElement(); | ||
2187 | 396 | truthTableVertices[v] = (String) st2.nextElement(); | ||
2188 | 397 | opt_formulaeVertices[v++] = (String) st2.nextElement(); | ||
2189 | 398 | }else{ | ||
2190 | 399 | opt_sources[a] = (String) st2.nextElement(); | ||
2191 | 400 | opt_dests[a] = (String) st2.nextElement(); | ||
2192 | 401 | arcNames[a] = opt_sources[a] + "->" + opt_dests[a]; | ||
2193 | 402 | truthTableArcs[a] = (String) st2.nextElement(); | ||
2194 | 403 | opt_formulaeArcs[a++] = (String) st2.nextElement(); | ||
2195 | 404 | } | ||
2196 | 405 | line = br.readLine(); | ||
2197 | 406 | } | ||
2198 | 407 | |||
2199 | 408 | } | ||
2200 | 409 | |||
2201 | 410 | // Read statistics | ||
2202 | 411 | if(line.contains(".statistics")){ | ||
2203 | 412 | line = br.readLine(); | ||
2204 | 413 | while(line.contains(".end_statistics") == false){ | ||
2205 | 414 | System.out.println(line); | ||
2206 | 415 | line = br.readLine(); | ||
2207 | 416 | } | ||
2208 | 417 | } | ||
2209 | 418 | |||
2210 | 419 | // Read errors | ||
2211 | 420 | if(line.contains(".error")){ | ||
2212 | 421 | line = br.readLine(); | ||
2213 | 422 | while(line.contains(".end_error") == false){ | ||
2214 | 423 | JOptionPane.showMessageDialog(null, | ||
2215 | 424 | line, | ||
2216 | 425 | "Programmer.x error", | ||
2217 | 426 | JOptionPane.ERROR_MESSAGE); | ||
2218 | 427 | line = br.readLine(); | ||
2219 | 428 | } | ||
2220 | 429 | return -1; | ||
2221 | 430 | |||
2222 | 431 | } | ||
2223 | 432 | } | ||
2224 | 433 | } | ||
2225 | 434 | |||
2226 | 435 | process.destroy(); | ||
2227 | 436 | is.close(); | ||
2228 | 437 | isr.close(); | ||
2229 | 438 | br.close(); | ||
2230 | 439 | return 0; | ||
2231 | 440 | } | ||
2232 | 441 | |||
2233 | 442 | private void reset_vars(){ | ||
2234 | 443 | verbose = ""; genMode= ""; numSol= ""; customFlag= ""; customPath= ""; effort= ""; espressoFlag= ""; | ||
2235 | 444 | abcFlag= ""; gateLibFlag= ""; cpogSize= ""; disableFunction= ""; oldSynt= ""; | ||
2236 | 445 | |||
2237 | 446 | return; | ||
2238 | 447 | } | ||
2239 | 448 | |||
2240 | 449 | public void run(WorkspaceEntry we) | ||
2241 | 450 | { | ||
2242 | 451 | VisualCPOG cpog = (VisualCPOG)(we.getModelEntry().getVisualModel()); | ||
2243 | 452 | |||
2244 | 453 | we.captureMemento(); | ||
2245 | 454 | |||
2246 | 455 | reset_vars(); | ||
2247 | 456 | |||
2248 | 457 | HashMap<String, Integer> events = new HashMap<String, Integer>(); | ||
2249 | 458 | n = 0; | ||
2250 | 459 | ArrayList<Point2D> positions = new ArrayList<Point2D>(); | ||
2251 | 460 | ArrayList<Integer> count = new ArrayList<Integer>(); | ||
2252 | 461 | |||
2253 | 462 | // TODO: remove deprecated method | ||
2254 | 463 | ArrayList<VisualScenario> scenarios = new ArrayList<VisualScenario>(cpog.getGroups()); | ||
2255 | 464 | |||
2256 | 465 | // Scenario contains single graphs compose CPOG | ||
2257 | 466 | int m = scenarios.size(); | ||
2258 | 467 | |||
2259 | 468 | // If less than two, do not encode scenarios | ||
2260 | 469 | if (m < 2) | ||
2261 | 470 | { | ||
2262 | 471 | JOptionPane.showMessageDialog(null, | ||
2263 | 472 | "At least two scenarios are expected.", | ||
2264 | 473 | "Not enough scenarios", | ||
2265 | 474 | JOptionPane.ERROR_MESSAGE); | ||
2266 | 475 | we.cancelMemento(); | ||
2267 | 476 | deleteTempFiles(); | ||
2268 | 477 | return; | ||
2269 | 478 | } | ||
2270 | 479 | |||
2271 | 480 | // Scan every scenarios | ||
2272 | 481 | for(int k = 0; k < m; k++) | ||
2273 | 482 | { | ||
2274 | 483 | // Scan every elements of each scenario | ||
2275 | 484 | for(VisualComponent component : scenarios.get(k).getComponents()) | ||
2276 | 485 | if (component instanceof VisualVertex) // If element is a vertex | ||
2277 | 486 | { | ||
2278 | 487 | VisualVertex vertex = (VisualVertex)component; | ||
2279 | 488 | |||
2280 | 489 | if (!events.containsKey(vertex.getLabel())) // Check if a condition is present on vertex | ||
2281 | 490 | { | ||
2282 | 491 | events.put(vertex.getLabel(), n); | ||
2283 | 492 | count.add(1); | ||
2284 | 493 | Point2D p = vertex.getCenter(); | ||
2285 | 494 | p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY()); | ||
2286 | 495 | positions.add(p); | ||
2287 | 496 | n++; | ||
2288 | 497 | } | ||
2289 | 498 | else | ||
2290 | 499 | { | ||
2291 | 500 | int id = events.get(vertex.getLabel()); | ||
2292 | 501 | count.set(id, count.get(id) + 1); | ||
2293 | 502 | Point2D p = vertex.getCenter(); | ||
2294 | 503 | p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY()); | ||
2295 | 504 | positions.set(id, Geometry.add(positions.get(id), p)); | ||
2296 | 505 | } | ||
2297 | 506 | } | ||
2298 | 507 | } | ||
2299 | 508 | |||
2300 | 509 | // construct constraints | ||
2301 | 510 | |||
2302 | 511 | char [][][] constraints = new char[m][n][n]; | ||
2303 | 512 | int [][] graph = new int[n][n]; | ||
2304 | 513 | |||
2305 | 514 | for(int k = 0; k < m; k++) | ||
2306 | 515 | { | ||
2307 | 516 | for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { | ||
2308 | 517 | constraints[k][i][j] = '0'; | ||
2309 | 518 | } | ||
2310 | 519 | |||
2311 | 520 | for(VisualComponent component : scenarios.get(k).getComponents()) | ||
2312 | 521 | if (component instanceof VisualVertex) | ||
2313 | 522 | { | ||
2314 | 523 | VisualVertex vertex = (VisualVertex)component; | ||
2315 | 524 | int id = events.get(vertex.getLabel()); | ||
2316 | 525 | constraints[k][id][id] = '1'; | ||
2317 | 526 | } | ||
2318 | 527 | |||
2319 | 528 | for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) graph[i][j] = 0; | ||
2320 | 529 | |||
2321 | 530 | for(VisualConnection c : scenarios.get(k).getConnections()) | ||
2322 | 531 | if (c instanceof VisualArc) | ||
2323 | 532 | { | ||
2324 | 533 | VisualArc arc = (VisualArc)c; | ||
2325 | 534 | VisualComponent c1 = arc.getFirst(), c2 = arc.getSecond(); | ||
2326 | 535 | if (c1 instanceof VisualVertex && c2 instanceof VisualVertex) | ||
2327 | 536 | { | ||
2328 | 537 | int id1 = events.get(((VisualVertex)c1).getLabel()); | ||
2329 | 538 | int id2 = events.get(((VisualVertex)c2).getLabel()); | ||
2330 | 539 | graph[id1][id2] = 1; | ||
2331 | 540 | } | ||
2332 | 541 | } | ||
2333 | 542 | |||
2334 | 543 | // compute transitive closure | ||
2335 | 544 | |||
2336 | 545 | for(int t = 0; t < n; t++) | ||
2337 | 546 | for(int i = 0; i < n; i++) | ||
2338 | 547 | if (graph[i][t] > 0) | ||
2339 | 548 | for(int j = 0; j < n; j++) | ||
2340 | 549 | if (graph[t][j] > 0) graph[i][j] = 1; | ||
2341 | 550 | |||
2342 | 551 | // detect transitive arcs | ||
2343 | 552 | |||
2344 | 553 | for(int t = 0; t < n; t++) | ||
2345 | 554 | for(int i = 0; i < n; i++) | ||
2346 | 555 | if (graph[i][t] > 0) | ||
2347 | 556 | for(int j = 0; j < n; j++) | ||
2348 | 557 | if (graph[t][j] > 0) graph[i][j] = 2; | ||
2349 | 558 | |||
2350 | 559 | // report cyclic scenario | ||
2351 | 560 | |||
2352 | 561 | for(int i = 0; i < n; i++) | ||
2353 | 562 | if (graph[i][i] > 0) | ||
2354 | 563 | { | ||
2355 | 564 | deleteTempFiles(); | ||
2356 | 565 | JOptionPane.showMessageDialog(null, | ||
2357 | 566 | "Scenario '" + scenarios.get(k).getLabel() + "' is cyclic.", | ||
2358 | 567 | "Invalid scenario", | ||
2359 | 568 | JOptionPane.ERROR_MESSAGE); | ||
2360 | 569 | we.cancelMemento(); | ||
2361 | 570 | return; | ||
2362 | 571 | } | ||
2363 | 572 | |||
2364 | 573 | for(int i = 0; i < n; i++) | ||
2365 | 574 | for(int j = 0; j < n; j++) | ||
2366 | 575 | if (i != j) | ||
2367 | 576 | { | ||
2368 | 577 | char ch = '0'; | ||
2369 | 578 | |||
2370 | 579 | if (graph[i][j] > 0) ch = '1'; | ||
2371 | 580 | if (graph[i][j] > 1) ch = '-'; | ||
2372 | 581 | if ( constraints[k][i][i] == '0' || constraints[k][j][j] == '0' ) ch = '-'; | ||
2373 | 582 | |||
2374 | 583 | constraints[k][i][j] = ch; | ||
2375 | 584 | } | ||
2376 | 585 | } | ||
2377 | 586 | |||
2378 | 587 | // Write scenarios into file. | ||
2379 | 588 | int res; | ||
2380 | 589 | if((res = WriteCpogIntoFile(m, scenarios)) != 0){ | ||
2381 | 590 | deleteTempFiles(); | ||
2382 | 591 | if(res != -1){ | ||
2383 | 592 | JOptionPane.showMessageDialog(null, | ||
2384 | 593 | "Error on writing scenario file.", | ||
2385 | 594 | "Workcraft error", | ||
2386 | 595 | JOptionPane.ERROR_MESSAGE); | ||
2387 | 596 | } | ||
2388 | 597 | we.cancelMemento(); | ||
2389 | 598 | return; | ||
2390 | 599 | } | ||
2391 | 600 | |||
2392 | 601 | espressoCommand = CpogSettings.getEspressoCommand(); | ||
2393 | 602 | abcFolder = CpogSettings.getAbcFolder(); | ||
2394 | 603 | gatesLibrary = CpogSettings.getGatesLibrary(); | ||
2395 | 604 | opt_enc = new String[m]; | ||
2396 | 605 | opt_formulaeVertices = new String[n*n]; | ||
2397 | 606 | truthTableVertices = new String[n*n]; | ||
2398 | 607 | opt_vertices = new String[n]; | ||
2399 | 608 | opt_sources = new String[n*n]; | ||
2400 | 609 | opt_dests = new String[n*n]; | ||
2401 | 610 | opt_formulaeArcs = new String[n*n]; | ||
2402 | 611 | truthTableArcs = new String[n*n]; | ||
2403 | 612 | arcNames = new String[n*n]; | ||
2404 | 613 | espressoCommand = CpogSettings.getEspressoCommand(); | ||
2405 | 614 | abcFolder = CpogSettings.getAbcFolder(); | ||
2406 | 615 | gatesLibrary = CpogSettings.getGatesLibrary(); | ||
2407 | 616 | espressoFlag = "-e"; | ||
2408 | 617 | v=0; | ||
2409 | 618 | a=0; | ||
2410 | 619 | |||
2411 | 620 | // CALLING PROGRAMMER.X | ||
2412 | 621 | boolean SCENCO = false; | ||
2413 | 622 | try { | ||
2414 | 623 | File f; | ||
2415 | 624 | f = new File(espressoCommand); | ||
2416 | 625 | if(!f.exists() || f.isDirectory()){ | ||
2417 | 626 | deleteTempFiles(); | ||
2418 | 627 | JOptionPane.showMessageDialog(null, | ||
2419 | 628 | "Espresso tool is needed to programmer to work properly", | ||
2420 | 629 | "Espresso tool not present", | ||
2421 | 630 | JOptionPane.ERROR_MESSAGE); | ||
2422 | 631 | we.cancelMemento(); | ||
2423 | 632 | return; | ||
2424 | 633 | } | ||
2425 | 634 | |||
2426 | 635 | espressoCommand = espressoCommand.replace(" ", "\\ "); | ||
2427 | 636 | |||
2428 | 637 | f = new File(abcFolder); | ||
2429 | 638 | if(!f.exists() || !f.isDirectory()){ | ||
2430 | 639 | JOptionPane.showMessageDialog(null, | ||
2431 | 640 | "You can download it at http://www.eecs.berkeley.edu/~alanmi/abc/", | ||
2432 | 641 | "Abc tool not present", | ||
2433 | 642 | JOptionPane.ERROR_MESSAGE); | ||
2434 | 643 | } | ||
2435 | 644 | else{ | ||
2436 | 645 | abcFlag = "-a"; | ||
2437 | 646 | gateLibFlag = "-lib"; | ||
2438 | 647 | f = new File(abcFolder + gatesLibrary); | ||
2439 | 648 | if(!f.exists() || f.isDirectory()){ | ||
2440 | 649 | deleteTempFiles(); | ||
2441 | 650 | JOptionPane.showMessageDialog(null, | ||
2442 | 651 | "It is needed to compute area of circuit properly", | ||
2443 | 652 | "Gate library not present", | ||
2444 | 653 | JOptionPane.ERROR_MESSAGE); | ||
2445 | 654 | we.cancelMemento(); | ||
2446 | 655 | return; | ||
2447 | 656 | } | ||
2448 | 657 | } | ||
2449 | 658 | |||
2450 | 659 | if(settings.isCpogSize()) cpogSize = "-cs"; | ||
2451 | 660 | if(settings.isCostFunc()) disableFunction = "-d"; | ||
2452 | 661 | if(settings.isVerboseMode()) verbose = "-v"; | ||
2453 | 662 | if(settings.isEffort()) effort = "all"; | ||
2454 | 663 | else effort = "min"; | ||
2455 | 664 | if(settings.isCustomEncMode()){ | ||
2456 | 665 | customFlag = "-set"; | ||
2457 | 666 | customPath = encodingFile.getAbsolutePath(); | ||
2458 | 667 | } | ||
2459 | 668 | switch(settings.getGenMode()){ | ||
2460 | 669 | case OPTIMAL_ENCODING: | ||
2461 | 670 | genMode = "-top"; | ||
2462 | 671 | numSol = String.valueOf(settings.getSolutionNumber()); | ||
2463 | 672 | break; | ||
2464 | 673 | case RECURSIVE: | ||
2465 | 674 | if(settings.isCustomEncMode()){ | ||
2466 | 675 | deleteTempFiles(); | ||
2467 | 676 | JOptionPane.showMessageDialog(null, | ||
2468 | 677 | "Recursive encodings generation combined with custom op-codes is not supported.", | ||
2469 | 678 | "Encodings generation error", | ||
2470 | 679 | JOptionPane.ERROR_MESSAGE); | ||
2471 | 680 | we.cancelMemento(); | ||
2472 | 681 | return; | ||
2473 | 682 | } | ||
2474 | 683 | break; | ||
2475 | 684 | case RANDOM: | ||
2476 | 685 | genMode = "-r"; | ||
2477 | 686 | if(settings.isCustomEncMode()){ | ||
2478 | 687 | deleteTempFiles(); | ||
2479 | 688 | JOptionPane.showMessageDialog(null, | ||
2480 | 689 | "Random encodings generation combined with custom op-codes is not supported.", | ||
2481 | 690 | "Encodings generation error", | ||
2482 | 691 | JOptionPane.ERROR_MESSAGE); | ||
2483 | 692 | we.cancelMemento(); | ||
2484 | 693 | return; | ||
2485 | 694 | } | ||
2486 | 695 | numSol = String.valueOf(settings.getSolutionNumber()); | ||
2487 | 696 | break; | ||
2488 | 697 | case SCENCO: | ||
2489 | 698 | SCENCO = true; | ||
2490 | 699 | customFlag = "-set"; | ||
2491 | 700 | genMode = "-top"; | ||
2492 | 701 | numSol = "1"; | ||
2493 | 702 | break; | ||
2494 | 703 | case OLD_SYNT: | ||
2495 | 704 | customFlag = "-set"; | ||
2496 | 705 | customPath = encodingFile.getAbsolutePath(); | ||
2497 | 706 | oldSynt = "-old"; | ||
2498 | 707 | genMode = "-top"; | ||
2499 | 708 | numSol = "1"; | ||
2500 | 709 | break; | ||
2501 | 710 | default: | ||
2502 | 711 | System.out.println("Error"); | ||
2503 | 712 | } | ||
2504 | 713 | |||
2505 | 714 | deleteDir(new File(toolPath + "results/")); | ||
2506 | 715 | File d = new File("../tools/results/generated_encoding/"); | ||
2507 | 716 | d.mkdirs(); | ||
2508 | 717 | |||
2509 | 718 | if(!SCENCO){ | ||
2510 | 719 | // CALLING PROGRAMMER.X | ||
2511 | 720 | boolean out = false; | ||
2512 | 721 | boolean continuous = false; | ||
2513 | 722 | int limit, it = 0; | ||
2514 | 723 | if(settings.isContMode()){ | ||
2515 | 724 | limit = 100; | ||
2516 | 725 | numSol = "1"; | ||
2517 | 726 | continuous = true; | ||
2518 | 727 | }else{ | ||
2519 | 728 | limit = 1; | ||
2520 | 729 | } | ||
2521 | 730 | minArea = Double.MAX_VALUE; | ||
2522 | 731 | Double currArea = Double.MAX_VALUE; | ||
2523 | 732 | while(!out && it < limit){ | ||
2524 | 733 | if(callingProgrammer(currArea, we,it, continuous) != 0){ | ||
2525 | 734 | deleteTempFiles(); | ||
2526 | 735 | we.cancelMemento(); | ||
2527 | 736 | return; | ||
2528 | 737 | } | ||
2529 | 738 | it++; | ||
2530 | 739 | } | ||
2531 | 740 | // Print controller | ||
2532 | 741 | printController(m); | ||
2533 | 742 | |||
2534 | 743 | } | ||
2535 | 744 | } catch (IOException e1) { | ||
2536 | 745 | System.out.println("Error."); | ||
2537 | 746 | e1.printStackTrace(); | ||
2538 | 747 | } | ||
2539 | 748 | // group similar constraints | ||
2540 | 749 | HashMap<String, BooleanFormula> formulaeName = new HashMap<String, BooleanFormula>(); | ||
2541 | 750 | HashMap<String, Integer> task = new HashMap<String, Integer>(); | ||
2542 | 751 | for(int i = 0; i < n; i++) | ||
2543 | 752 | for(int j = 0; j < n; j++) | ||
2544 | 753 | if (trivialEncoding(constraints, m, i, j) == '?') | ||
2545 | 754 | { | ||
2546 | 755 | String constraint = generateConstraint(constraints, m, i, j); | ||
2547 | 756 | if (!task.containsKey(constraint)){ | ||
2548 | 757 | task.put(constraint, task.size()); | ||
2549 | 758 | } | ||
2550 | 759 | } | ||
2551 | 760 | |||
2552 | 761 | // call CPOG encoder | ||
2553 | 762 | |||
2554 | 763 | char [][] matrix = new char[m][task.size()]; | ||
2555 | 764 | |||
2556 | 765 | String [] instance = new String[m]; | ||
2557 | 766 | for(String s : task.keySet()) | ||
2558 | 767 | for(int i = 0; i < m; i++) matrix[i][task.get(s)] = s.charAt(i); | ||
2559 | 768 | |||
2560 | 769 | for(int i = 0; i < m; i++) instance[i] = new String(matrix[i]); | ||
2561 | 770 | |||
2562 | 771 | int freeVariables; | ||
2563 | 772 | if(settings.getGenMode() != generationMode.SCENCO) | ||
2564 | 773 | freeVariables = opt_enc[0].length(); | ||
2565 | 774 | else | ||
2566 | 775 | freeVariables = settings.getBits(); | ||
2567 | 776 | int derivedVariables = CpogSettings.getCircuitSize(); | ||
2568 | 777 | |||
2569 | 778 | Optimiser<OneHotIntBooleanFormula> oneHot = new Optimiser<OneHotIntBooleanFormula>(new OneHotNumberProvider()); | ||
2570 | 779 | |||
2571 | 780 | DefaultCpogSolver<BooleanFormula> solverCnf = new DefaultCpogSolver<BooleanFormula>(oneHot, new CleverCnfGenerator()); | ||
2572 | 781 | |||
2573 | 782 | VisualVariable predicatives[] = new VisualVariable[n]; | ||
2574 | 783 | int pr = 0; | ||
2575 | 784 | for(int k = 0; k < m; k++) | ||
2576 | 785 | { | ||
2577 | 786 | for(VisualComponent component : scenarios.get(k).getComponents()){ | ||
2578 | 787 | if(component instanceof VisualVariable){ | ||
2579 | 788 | predicatives[pr++] = (VisualVariable) component; | ||
2580 | 789 | } | ||
2581 | 790 | } | ||
2582 | 791 | } | ||
2583 | 792 | |||
2584 | 793 | Variable [] vars = new Variable[freeVariables + pr]; | ||
2585 | 794 | for(int i = 0; i < freeVariables; i++) vars[i] = cpog.createVisualVariable().getMathVariable(); | ||
2586 | 795 | for(int i = 0; i< pr; i++) vars[freeVariables +i] = predicatives[i].getMathVariable(); | ||
2587 | 796 | |||
2588 | 797 | // DEBUG PRINTING: printing variables needed to encode graph. | ||
2589 | 798 | /*System.out.println("PRINTING VARIABLES:"); | ||
2590 | 799 | for(int i = 0; i< freeVariables + pr; i++) | ||
2591 | 800 | System.out.println(vars[i].getLabel());*/ | ||
2592 | 801 | |||
2593 | 802 | CpogEncoding solution = null; | ||
2594 | 803 | try | ||
2595 | 804 | { | ||
2596 | 805 | // SCENCO EXECUTION TO FIND VARIABLES AND FUNCTIONS | ||
2597 | 806 | solution = solverCnf.solve(instance, vars, derivedVariables); | ||
2598 | 807 | CpogOptimisationTask opt_task = (CpogOptimisationTask) solverCnf.getTask(instance, vars, derivedVariables); | ||
2599 | 808 | if (solution == null) | ||
2600 | 809 | { | ||
2601 | 810 | if(SCENCO){ | ||
2602 | 811 | we.cancelMemento(); | ||
2603 | 812 | JOptionPane.showMessageDialog(null, "SCENCO is not able to solve the CPOG, try other options.", | ||
2604 | 813 | "Encoding result", JOptionPane.ERROR_MESSAGE); | ||
2605 | 814 | deleteTempFiles(); | ||
2606 | 815 | return; | ||
2607 | 816 | } | ||
2608 | 817 | System.out.println("INFORMATION: Scenco cannot solve the CPOG."); | ||
2609 | 818 | System.out.println(); | ||
2610 | 819 | } | ||
2611 | 820 | |||
2612 | 821 | System.out.println("Op-code selected for graphs:"); | ||
2613 | 822 | for(int i=0; i<m; i++){ | ||
2614 | 823 | String name; | ||
2615 | 824 | if(scenarios.get(i).getLabel().equals("")){ | ||
2616 | 825 | name = "CPOG " + i; | ||
2617 | 826 | } | ||
2618 | 827 | else{ | ||
2619 | 828 | name = scenarios.get(i).getLabel(); | ||
2620 | 829 | } | ||
2621 | 830 | System.out.println(name + ": " + opt_enc[i]); | ||
2622 | 831 | } | ||
2623 | 832 | solution = new CpogEncoding(null, null); | ||
2624 | 833 | |||
2625 | 834 | if(!SCENCO){ | ||
2626 | 835 | |||
2627 | 836 | solution = new CpogEncoding(null, null); | ||
2628 | 837 | BooleanFormula[][] encodingVars = opt_task.getEncodingVars(); | ||
2629 | 838 | BooleanFormula[] formule = new BooleanFormula[v + a]; | ||
2630 | 839 | // Set optimal formulae to graphs | ||
2631 | 840 | final Variable [] variables = vars; | ||
2632 | 841 | for(int i=0; i<v; i++){ | ||
2633 | 842 | if(opt_formulaeVertices[i].contains("x")){ | ||
2634 | 843 | BooleanFormula formula_opt = null; | ||
2635 | 844 | formula_opt = BooleanParser.parse(opt_formulaeVertices[i], new Func<String, BooleanFormula>() { | ||
2636 | 845 | |||
2637 | 846 | @Override | ||
2638 | 847 | public BooleanFormula eval(String arg) { | ||
2639 | 848 | arg = arg.substring("x_".length()); | ||
2640 | 849 | int id = Integer.parseInt(arg); | ||
2641 | 850 | return variables[id]; | ||
2642 | 851 | } | ||
2643 | 852 | }); | ||
2644 | 853 | |||
2645 | 854 | formulaeName.put(opt_vertices[i], formula_opt); | ||
2646 | 855 | |||
2647 | 856 | // OLD formulae array | ||
2648 | 857 | /*if(task.containsKey(truthTableVertices[i])){ | ||
2649 | 858 | formule[task.get(truthTableVertices[i])] = formula_opt; | ||
2650 | 859 | }*/ | ||
2651 | 860 | } | ||
2652 | 861 | } | ||
2653 | 862 | for(int i=0; i<a; i++){ | ||
2654 | 863 | if(opt_formulaeArcs[i].contains("x")){ | ||
2655 | 864 | BooleanFormula formula_opt = null; | ||
2656 | 865 | formula_opt = BooleanParser.parse(opt_formulaeArcs[i], new Func<String, BooleanFormula>() { | ||
2657 | 866 | @Override | ||
2658 | 867 | public BooleanFormula eval(String arg) { | ||
2659 | 868 | arg = arg.substring("x_".length()); | ||
2660 | 869 | int id = Integer.parseInt(arg); | ||
2661 | 870 | return variables[id]; | ||
2662 | 871 | } | ||
2663 | 872 | }); | ||
2664 | 873 | |||
2665 | 874 | formulaeName.put(arcNames[i], formula_opt); | ||
2666 | 875 | |||
2667 | 876 | /*if(task.containsKey(truthTableArcs[i])){ | ||
2668 | 877 | formule[task.get(truthTableArcs[i])] = formula_opt; | ||
2669 | 878 | }*/ | ||
2670 | 879 | } | ||
2671 | 880 | } | ||
2672 | 881 | solution.setFormule(formule); | ||
2673 | 882 | //TODO | ||
2674 | 883 | // Set optimal encoding to graphs | ||
2675 | 884 | boolean[][] opt_encoding = new boolean[m][]; | ||
2676 | 885 | for(int i=0;i<m;i++) | ||
2677 | 886 | { | ||
2678 | 887 | opt_encoding[i] = new boolean[freeVariables + pr]; | ||
2679 | 888 | for(int j=0;j<freeVariables;j++){ | ||
2680 | 889 | if(opt_enc[i].charAt(j) == '0' || opt_enc[i].charAt(j) == '-') opt_encoding[i][j] = false; | ||
2681 | 890 | else opt_encoding[i][j] = true; | ||
2682 | 891 | } | ||
2683 | 892 | for(int j=freeVariables;j<freeVariables + pr;j++){ | ||
2684 | 893 | opt_encoding[i][j] = false; | ||
2685 | 894 | } | ||
2686 | 895 | |||
2687 | 896 | } | ||
2688 | 897 | solution.setEncoding(opt_encoding); | ||
2689 | 898 | } | ||
2690 | 899 | } | ||
2691 | 900 | catch(Exception e) | ||
2692 | 901 | { | ||
2693 | 902 | we.cancelMemento(); | ||
2694 | 903 | JOptionPane.showMessageDialog(null, e.getMessage(), "Encoding result", JOptionPane.ERROR_MESSAGE); | ||
2695 | 904 | } | ||
2696 | 905 | |||
2697 | 906 | if(solution == null){ | ||
2698 | 907 | return; | ||
2699 | 908 | } | ||
2700 | 909 | |||
2701 | 910 | // create result | ||
2702 | 911 | |||
2703 | 912 | boolean[][] encoding = solution.getEncoding(); | ||
2704 | 913 | |||
2705 | 914 | if(settings.getGenMode() == generationMode.SCENCO){ | ||
2706 | 915 | |||
2707 | 916 | try{ | ||
2708 | 917 | encodingFile = File.createTempFile("encoding", "cpog"); | ||
2709 | 918 | PrintStream Output = new PrintStream(encodingFile); | ||
2710 | 919 | |||
2711 | 920 | for(int i=0; i<m; i++){ | ||
2712 | 921 | for(int j=0; j<settings.getBits(); j++){ | ||
2713 | 922 | if(encoding[i][j]){ | ||
2714 | 923 | Output.print("1"); | ||
2715 | 924 | } | ||
2716 | 925 | else{ | ||
2717 | 926 | Output.print("0"); | ||
2718 | 927 | } | ||
2719 | 928 | } | ||
2720 | 929 | Output.println(); | ||
2721 | 930 | } | ||
2722 | 931 | Output.close(); | ||
2723 | 932 | |||
2724 | 933 | customPath = encodingFile.getAbsolutePath(); | ||
2725 | 934 | if(callingProgrammer(Double.MAX_VALUE, we, 0, false) != 0){ | ||
2726 | 935 | deleteTempFiles(); | ||
2727 | 936 | we.cancelMemento(); | ||
2728 | 937 | return; | ||
2729 | 938 | } | ||
2730 | 939 | |||
2731 | 940 | // Print controller | ||
2732 | 941 | printController(m); | ||
2733 | 942 | }catch (IOException e) { | ||
2734 | 943 | System.out.println("Error: " + e); | ||
2735 | 944 | } | ||
2736 | 945 | } | ||
2737 | 946 | |||
2738 | 947 | //TODO | ||
2739 | 948 | for(int k = 0; k < m; k++) | ||
2740 | 949 | { | ||
2741 | 950 | for(int i = 0; i < freeVariables; i++){ | ||
2742 | 951 | scenarios.get(k).getEncoding().setState(vars[i], VariableState.fromBoolean(encoding[k][i])); | ||
2743 | 952 | } | ||
2744 | 953 | for(int i = freeVariables; i < freeVariables + pr; i++){ | ||
2745 | 954 | scenarios.get(k).getEncoding().setState(vars[i], VariableState.fromBoolean(encoding[k][i])); | ||
2746 | 955 | } | ||
2747 | 956 | } | ||
2748 | 957 | |||
2749 | 958 | VisualScenario result = cpog.createVisualScenario(); | ||
2750 | 959 | result.setLabel("Composition"); | ||
2751 | 960 | VisualVertex [] vertices = new VisualVertex[n]; | ||
2752 | 961 | for(String eventName : events.keySet()) | ||
2753 | 962 | { | ||
2754 | 963 | int id = events.get(eventName); | ||
2755 | 964 | vertices[id] = cpog.createVisualVertex(result); | ||
2756 | 965 | vertices[id].setLabel(eventName); | ||
2757 | 966 | vertices[id].setPosition(Geometry.multiply(positions.get(id), 1.0/count.get(id))); | ||
2758 | 967 | if(formulaeName.containsKey(eventName)){ | ||
2759 | 968 | vertices[id].setCondition(formulaeName.get(eventName)); | ||
2760 | 969 | }else | ||
2761 | 970 | vertices[id].setCondition(One.instance()); | ||
2762 | 971 | } | ||
2763 | 972 | |||
2764 | 973 | |||
2765 | 974 | // SET FORMULAE INTO RESULT GRAPH | ||
2766 | 975 | BooleanFormula[] functions = solution.getFunctions(); | ||
2767 | 976 | for(int i = 0; i < n; i++) | ||
2768 | 977 | for(int j = 0; j < n; j++) | ||
2769 | 978 | { | ||
2770 | 979 | BooleanFormula condition; | ||
2771 | 980 | |||
2772 | 981 | char trivial = trivialEncoding(constraints, m, i, j); | ||
2773 | 982 | if (trivial != '?') | ||
2774 | 983 | { | ||
2775 | 984 | if (trivial == '1') | ||
2776 | 985 | { | ||
2777 | 986 | condition = One.instance(); | ||
2778 | 987 | } | ||
2779 | 988 | else | ||
2780 | 989 | { | ||
2781 | 990 | continue; | ||
2782 | 991 | } | ||
2783 | 992 | } | ||
2784 | 993 | /*else | ||
2785 | 994 | { | ||
2786 | 995 | String constraint = generateConstraint(constraints, m, i, j); | ||
2787 | 996 | condition = functions[task.get(constraint)]; | ||
2788 | 997 | }*/ | ||
2789 | 998 | |||
2790 | 999 | /*if (i == j) | ||
2791 | 1000 | { | ||
2792 | 1001 | vertices[i].setCondition(condition); | ||
2793 | 1002 | }*/ | ||
2794 | 1003 | if (i != j) | ||
2795 | 1004 | { | ||
2796 | 1005 | VisualArc arc = cpog.connect(vertices[i], vertices[j]); | ||
2797 | 1006 | String arcName = vertices[i].getLabel() + "->" + vertices[j].getLabel(); | ||
2798 | 1007 | |||
2799 | 1008 | if(formulaeName.containsKey(arcName)){ | ||
2800 | 1009 | condition = formulaeName.get(arcName); | ||
2801 | 1010 | }else | ||
2802 | 1011 | condition = One.instance(); | ||
2803 | 1012 | |||
2804 | 1013 | arc.setCondition(condition); | ||
2805 | 1014 | } | ||
2806 | 1015 | } | ||
2807 | 1016 | |||
2808 | 1017 | we.saveMemento(); | ||
2809 | 1018 | } | ||
2810 | 1019 | |||
2811 | 1020 | public void setSettings(EncoderSettings settings) { | ||
2812 | 1021 | this.settings = settings; | ||
2813 | 1022 | } | ||
2814 | 1023 | } | ||
2815 | 0 | 1024 | ||
2816 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogSettings.java' | |||
2817 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogSettings.java 2014-06-04 13:07:53 +0000 | |||
2818 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogSettings.java 2014-07-11 09:42:10 +0000 | |||
2819 | @@ -12,6 +12,8 @@ | |||
2820 | 12 | 12 | ||
2821 | 13 | public class CpogSettings implements SettingsPage { | 13 | public class CpogSettings implements SettingsPage { |
2822 | 14 | 14 | ||
2823 | 15 | private static LinkedList<PropertyDescriptor> properties; | ||
2824 | 16 | |||
2825 | 15 | public enum SatSolver { | 17 | public enum SatSolver { |
2826 | 16 | MINISAT("MiniSat"), | 18 | MINISAT("MiniSat"), |
2827 | 17 | CLASP("Clasp"); | 19 | CLASP("Clasp"); |
2828 | @@ -30,27 +32,15 @@ | |||
2829 | 30 | return choice; | 32 | return choice; |
2830 | 31 | } | 33 | } |
2831 | 32 | } | 34 | } |
2832 | 33 | |||
2833 | 34 | private static LinkedList<PropertyDescriptor> properties; | ||
2834 | 35 | |||
2835 | 36 | private static final String prefix = "CpogSettings"; | ||
2836 | 37 | private static final String keySatSolver = prefix + ".satSolver"; | ||
2837 | 38 | private static final String keyEncodingWidth = prefix + ".encodingWidth"; | ||
2838 | 39 | private static final String keyCircuitSize = prefix + ".circuitSize"; | ||
2839 | 40 | private static final String keyClaspCommand = prefix + ".claspCommand"; | ||
2840 | 41 | private static final String keyMinisatCommand = prefix + ".minisatCommand"; | ||
2841 | 42 | |||
2842 | 43 | private static final SatSolver defaultSatSolver = SatSolver.CLASP; | ||
2843 | 44 | private static final int defaultEncodingWidth = 2; | ||
2844 | 45 | private static final int defaultCircuitSize = 4; | ||
2845 | 46 | private static final String defaultClaspCommand = "clasp"; | ||
2846 | 47 | private static final String defaultMinisatCommand = "minisat"; | ||
2847 | 48 | 35 | ||
2853 | 49 | private static SatSolver satSolver = defaultSatSolver; | 36 | private static SatSolver satSolver = SatSolver.CLASP; |
2854 | 50 | private static int encodingWidth = defaultEncodingWidth; | 37 | //private static int encodingWidth = 2; |
2855 | 51 | private static int circuitSize = defaultCircuitSize; | 38 | private static int circuitSize = 4; |
2856 | 52 | private static String claspCommand = defaultClaspCommand; | 39 | private static String claspCommand = "clasp"; |
2857 | 53 | private static String minisatCommand = defaultMinisatCommand; | 40 | private static String minisatCommand = "minisat"; |
2858 | 41 | private static String espressoCommand = "espresso"; | ||
2859 | 42 | private static String abcFolder = "abc/"; | ||
2860 | 43 | private static String gatesLibrary = "90nm.genlib"; | ||
2861 | 54 | 44 | ||
2862 | 55 | @Override | 45 | @Override |
2863 | 56 | public Collection<PropertyDescriptor> getDescriptors() { | 46 | public Collection<PropertyDescriptor> getDescriptors() { |
2864 | @@ -71,16 +61,6 @@ | |||
2865 | 71 | }); | 61 | }); |
2866 | 72 | 62 | ||
2867 | 73 | properties.add(new PropertyDeclaration<CpogSettings, Integer>( | 63 | properties.add(new PropertyDeclaration<CpogSettings, Integer>( |
2868 | 74 | this, "Encoding bit-width", Integer.class) { | ||
2869 | 75 | protected void setter(CpogSettings object, Integer value) { | ||
2870 | 76 | CpogSettings.setEncodingWidth(value); | ||
2871 | 77 | } | ||
2872 | 78 | protected Integer getter(CpogSettings object) { | ||
2873 | 79 | return CpogSettings.getEncodingWidth(); | ||
2874 | 80 | } | ||
2875 | 81 | }); | ||
2876 | 82 | |||
2877 | 83 | properties.add(new PropertyDeclaration<CpogSettings, Integer>( | ||
2878 | 84 | this, "Circuit size in 2-input gates", Integer.class) { | 64 | this, "Circuit size in 2-input gates", Integer.class) { |
2879 | 85 | protected void setter(CpogSettings object, Integer value) { | 65 | protected void setter(CpogSettings object, Integer value) { |
2880 | 86 | CpogSettings.setCircuitSize(value); | 66 | CpogSettings.setCircuitSize(value); |
2881 | @@ -109,11 +89,41 @@ | |||
2882 | 109 | return CpogSettings.getMinisatCommand(); | 89 | return CpogSettings.getMinisatCommand(); |
2883 | 110 | } | 90 | } |
2884 | 111 | }); | 91 | }); |
2885 | 92 | |||
2886 | 93 | properties.add(new PropertyDeclaration<CpogSettings, String>( | ||
2887 | 94 | this, "Espresso solver", String.class) { | ||
2888 | 95 | protected void setter(CpogSettings object, String value) { | ||
2889 | 96 | CpogSettings.setEspressoCommand(value); | ||
2890 | 97 | } | ||
2891 | 98 | protected String getter(CpogSettings object) { | ||
2892 | 99 | return CpogSettings.getEspressoCommand(); | ||
2893 | 100 | } | ||
2894 | 101 | }); | ||
2895 | 102 | |||
2896 | 103 | properties.add(new PropertyDeclaration<CpogSettings, String>( | ||
2897 | 104 | this, "Abc folder path", String.class) { | ||
2898 | 105 | protected void setter(CpogSettings object, String value) { | ||
2899 | 106 | CpogSettings.setAbcFolder(value); | ||
2900 | 107 | } | ||
2901 | 108 | protected String getter(CpogSettings object) { | ||
2902 | 109 | return CpogSettings.getAbcFolder(); | ||
2903 | 110 | } | ||
2904 | 111 | }); | ||
2905 | 112 | |||
2906 | 113 | properties.add(new PropertyDeclaration<CpogSettings, String>( | ||
2907 | 114 | this, "Gate library (genlib format) inside abc folder", String.class) { | ||
2908 | 115 | protected void setter(CpogSettings object, String value) { | ||
2909 | 116 | CpogSettings.setGatesLibrary(value); | ||
2910 | 117 | } | ||
2911 | 118 | protected String getter(CpogSettings object) { | ||
2912 | 119 | return CpogSettings.getGatesLibrary(); | ||
2913 | 120 | } | ||
2914 | 121 | }); | ||
2915 | 112 | } | 122 | } |
2916 | 113 | 123 | ||
2917 | 114 | @Override | 124 | @Override |
2918 | 115 | public String getName() { | 125 | public String getName() { |
2920 | 116 | return "Scenco"; // SCENario ENCOder! | 126 | return "SCENCO"; |
2921 | 117 | } | 127 | } |
2922 | 118 | 128 | ||
2923 | 119 | @Override | 129 | @Override |
2924 | @@ -123,59 +133,81 @@ | |||
2925 | 123 | 133 | ||
2926 | 124 | @Override | 134 | @Override |
2927 | 125 | public void load(Config config) { | 135 | public void load(Config config) { |
2933 | 126 | setSatSolver(config.getEnum(keySatSolver, SatSolver.class, defaultSatSolver)); | 136 | satSolver = config.getEnum("CpogSettings.satSolver", SatSolver.class, SatSolver.CLASP); |
2934 | 127 | setEncodingWidth(config.getInt(keyEncodingWidth, defaultEncodingWidth)); | 137 | circuitSize = config.getInt("CpogSettings.circuitSize", 4); |
2935 | 128 | setCircuitSize(config.getInt(keyCircuitSize, defaultCircuitSize)); | 138 | setClaspCommand(config.getString("CpogSettings.claspCommand", "clasp")); |
2936 | 129 | setClaspCommand(config.getString(keyClaspCommand, defaultClaspCommand)); | 139 | setMinisatCommand(config.getString("CpogSettings.minisatCommand", "minisat")); |
2937 | 130 | setMinisatCommand(config.getString(keyMinisatCommand, defaultMinisatCommand)); | 140 | setEspressoCommand(config.getString("CpogSettings.espressoCommand", "espresso")); |
2938 | 141 | setAbcFolder(config.getString("CpogSettings.abcFolder", "abc/")); | ||
2939 | 142 | setGatesLibrary(config.getString("CpogSettings.gatesLibrary", "90nm.genlib")); | ||
2940 | 131 | } | 143 | } |
2941 | 132 | 144 | ||
2942 | 133 | @Override | 145 | @Override |
2943 | 134 | public void save(Config config) { | 146 | public void save(Config config) { |
2949 | 135 | config.setEnum(keySatSolver, SatSolver.class, satSolver); | 147 | config.setEnum("CpogSettings.satSolver", SatSolver.class, satSolver); |
2950 | 136 | config.setInt(keyEncodingWidth, getEncodingWidth()); | 148 | config.setInt("CpogSettings.circuitSize", circuitSize); |
2951 | 137 | config.setInt(keyCircuitSize, getCircuitSize()); | 149 | config.set("CpogSettings.claspCommand", claspCommand); |
2952 | 138 | config.set(keyClaspCommand, getClaspCommand()); | 150 | config.set("CpogSettings.minisatCommand", minisatCommand); |
2953 | 139 | config.set(keyMinisatCommand, getMinisatCommand()); | 151 | config.set("CpogSettings.espressoCommand", espressoCommand); |
2954 | 152 | config.set("CpogSettings.abcFolder", abcFolder); | ||
2955 | 153 | config.set("CpogSettings.gatesLibrary", gatesLibrary); | ||
2956 | 140 | } | 154 | } |
2957 | 141 | 155 | ||
2958 | 142 | public static SatSolver getSatSolver() { | 156 | public static SatSolver getSatSolver() { |
2959 | 143 | return satSolver; | 157 | return satSolver; |
2960 | 144 | } | 158 | } |
2961 | 145 | 159 | ||
2972 | 146 | public static void setSatSolver(SatSolver value) { | 160 | public static void setSatSolver(SatSolver satSolver) { |
2973 | 147 | satSolver = value; | 161 | CpogSettings.satSolver = satSolver; |
2964 | 148 | } | ||
2965 | 149 | |||
2966 | 150 | public static int getEncodingWidth() { | ||
2967 | 151 | return encodingWidth; | ||
2968 | 152 | } | ||
2969 | 153 | |||
2970 | 154 | public static void setEncodingWidth(int value) { | ||
2971 | 155 | encodingWidth = value; | ||
2974 | 156 | } | 162 | } |
2975 | 157 | 163 | ||
2976 | 158 | public static int getCircuitSize() { | 164 | public static int getCircuitSize() { |
2977 | 159 | return circuitSize; | 165 | return circuitSize; |
2978 | 160 | } | 166 | } |
2979 | 161 | 167 | ||
2982 | 162 | public static void setCircuitSize(int value) { | 168 | public static void setCircuitSize(int circuitSize) { |
2983 | 163 | circuitSize = value; | 169 | CpogSettings.circuitSize = circuitSize; |
2984 | 164 | } | 170 | } |
2985 | 165 | 171 | ||
2986 | 166 | public static String getClaspCommand() { | 172 | public static String getClaspCommand() { |
2987 | 167 | return claspCommand; | 173 | return claspCommand; |
2988 | 168 | } | 174 | } |
2989 | 169 | 175 | ||
2992 | 170 | public static void setClaspCommand(String value) { | 176 | public static void setClaspCommand(String claspCommand) { |
2993 | 171 | claspCommand = value; | 177 | CpogSettings.claspCommand = claspCommand; |
2994 | 172 | } | 178 | } |
2995 | 173 | 179 | ||
2996 | 174 | public static String getMinisatCommand() { | 180 | public static String getMinisatCommand() { |
2997 | 175 | return minisatCommand; | 181 | return minisatCommand; |
2998 | 176 | } | 182 | } |
2999 | 177 | 183 | ||
3003 | 178 | public static void setMinisatCommand(String value) { | 184 | public static void setMinisatCommand(String minisatCommand) { |
3004 | 179 | minisatCommand = value; | 185 | CpogSettings.minisatCommand = minisatCommand; |
3005 | 180 | } | 186 | } |
3006 | 187 | |||
3007 | 188 | public static String getEspressoCommand() { | ||
3008 | 189 | return espressoCommand; | ||
3009 | 190 | } | ||
3010 | 191 | |||
3011 | 192 | public static void setEspressoCommand(String espressoCommand) { | ||
3012 | 193 | CpogSettings.espressoCommand = espressoCommand; | ||
3013 | 194 | } | ||
3014 | 195 | |||
3015 | 196 | public static String getAbcFolder() { | ||
3016 | 197 | return abcFolder; | ||
3017 | 198 | } | ||
3018 | 199 | |||
3019 | 200 | public static void setAbcFolder(String abcFolder) { | ||
3020 | 201 | CpogSettings.abcFolder = abcFolder; | ||
3021 | 202 | } | ||
3022 | 203 | |||
3023 | 204 | public static String getGatesLibrary() { | ||
3024 | 205 | return gatesLibrary; | ||
3025 | 206 | } | ||
3026 | 207 | |||
3027 | 208 | public static void setGatesLibrary(String gatesLibrary) { | ||
3028 | 209 | CpogSettings.gatesLibrary = gatesLibrary; | ||
3029 | 210 | } | ||
3030 | 211 | |||
3031 | 212 | |||
3032 | 181 | } | 213 | } |
3033 | 182 | 214 | ||
3034 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettings.java' | |||
3035 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettings.java 1970-01-01 00:00:00 +0000 | |||
3036 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettings.java 2014-07-11 09:42:10 +0000 | |||
3037 | @@ -0,0 +1,208 @@ | |||
3038 | 1 | package org.workcraft.plugins.cpog; | ||
3039 | 2 | |||
3040 | 3 | import java.io.File; | ||
3041 | 4 | import java.io.IOException; | ||
3042 | 5 | import java.util.ArrayList; | ||
3043 | 6 | import java.util.LinkedHashMap; | ||
3044 | 7 | import java.util.Map; | ||
3045 | 8 | |||
3046 | 9 | import org.workcraft.util.FileUtils; | ||
3047 | 10 | |||
3048 | 11 | public class EncoderSettings { | ||
3049 | 12 | |||
3050 | 13 | public enum generationMode{ | ||
3051 | 14 | OPTIMAL_ENCODING("Simulated annealing"), | ||
3052 | 15 | RECURSIVE("Exhaustive search"), | ||
3053 | 16 | RANDOM("Random search"), | ||
3054 | 17 | SCENCO("Old tool SCENCO"), | ||
3055 | 18 | OLD_SYNT("Old synthesise"); | ||
3056 | 19 | |||
3057 | 20 | public final String name; | ||
3058 | 21 | |||
3059 | 22 | public static final generationMode[] modes = | ||
3060 | 23 | { | ||
3061 | 24 | OPTIMAL_ENCODING, | ||
3062 | 25 | RECURSIVE, | ||
3063 | 26 | RANDOM, | ||
3064 | 27 | SCENCO, | ||
3065 | 28 | OLD_SYNT | ||
3066 | 29 | }; | ||
3067 | 30 | |||
3068 | 31 | private generationMode(String name){ | ||
3069 | 32 | this.name = name; | ||
3070 | 33 | } | ||
3071 | 34 | |||
3072 | 35 | static public Map<String, generationMode> getChoice() { | ||
3073 | 36 | LinkedHashMap<String, generationMode> choice = new LinkedHashMap<String, generationMode>(); | ||
3074 | 37 | for (generationMode item : generationMode.values()) { | ||
3075 | 38 | choice.put(item.name, item); | ||
3076 | 39 | } | ||
3077 | 40 | return choice; | ||
3078 | 41 | } | ||
3079 | 42 | } | ||
3080 | 43 | |||
3081 | 44 | public EncoderSettings(String espressoPath, String abcPath, String libPath) { | ||
3082 | 45 | this.espressoPath = espressoPath; | ||
3083 | 46 | this.abcPath = abcPath; | ||
3084 | 47 | this.libPath = libPath; | ||
3085 | 48 | } | ||
3086 | 49 | |||
3087 | 50 | private int solutionNumber = 10, numPO,bits; | ||
3088 | 51 | private generationMode genMode = generationMode.OPTIMAL_ENCODING; | ||
3089 | 52 | private boolean verboseMode, customEncMode, effort, contMode, cpogSize, costFunc; | ||
3090 | 53 | private String[] customEnc; | ||
3091 | 54 | private String espressoPath,abcPath,libPath; | ||
3092 | 55 | |||
3093 | 56 | public boolean isCpogSize() { | ||
3094 | 57 | return cpogSize; | ||
3095 | 58 | } | ||
3096 | 59 | |||
3097 | 60 | public void setCpogSize(boolean cpogSize) { | ||
3098 | 61 | this.cpogSize = cpogSize; | ||
3099 | 62 | } | ||
3100 | 63 | |||
3101 | 64 | public boolean isCostFunc() { | ||
3102 | 65 | return costFunc; | ||
3103 | 66 | } | ||
3104 | 67 | |||
3105 | 68 | public void setCostFunc(boolean costFunc) { | ||
3106 | 69 | this.costFunc = costFunc; | ||
3107 | 70 | } | ||
3108 | 71 | |||
3109 | 72 | public boolean isContMode() { | ||
3110 | 73 | return contMode; | ||
3111 | 74 | } | ||
3112 | 75 | |||
3113 | 76 | public void setContMode(boolean contMode) { | ||
3114 | 77 | this.contMode = contMode; | ||
3115 | 78 | } | ||
3116 | 79 | |||
3117 | 80 | public boolean isEffort() { | ||
3118 | 81 | return effort; | ||
3119 | 82 | } | ||
3120 | 83 | |||
3121 | 84 | public void setEffort(boolean effort) { | ||
3122 | 85 | this.effort = effort; | ||
3123 | 86 | } | ||
3124 | 87 | public int getBits() { | ||
3125 | 88 | return bits; | ||
3126 | 89 | } | ||
3127 | 90 | |||
3128 | 91 | public void setBits(int bits) { | ||
3129 | 92 | this.bits = bits; | ||
3130 | 93 | } | ||
3131 | 94 | |||
3132 | 95 | public String getEspressoPath() { | ||
3133 | 96 | return espressoPath; | ||
3134 | 97 | } | ||
3135 | 98 | |||
3136 | 99 | public void setEspressoPath(String espressoPath) { | ||
3137 | 100 | this.espressoPath = espressoPath; | ||
3138 | 101 | } | ||
3139 | 102 | |||
3140 | 103 | public String getAbcPath() { | ||
3141 | 104 | return abcPath; | ||
3142 | 105 | } | ||
3143 | 106 | |||
3144 | 107 | public void setAbcPath(String abcPath) { | ||
3145 | 108 | this.abcPath = abcPath; | ||
3146 | 109 | } | ||
3147 | 110 | |||
3148 | 111 | public EncoderSettings(int solutionNumber, generationMode genMode, boolean verboseMode, | ||
3149 | 112 | boolean customEncMode, String[] customEnc, int numPO) { | ||
3150 | 113 | this.solutionNumber = solutionNumber; | ||
3151 | 114 | this.genMode = genMode; | ||
3152 | 115 | this.verboseMode = verboseMode; | ||
3153 | 116 | this.customEncMode = customEncMode; | ||
3154 | 117 | this.numPO = numPO; | ||
3155 | 118 | this.customEnc = customEnc; | ||
3156 | 119 | } | ||
3157 | 120 | |||
3158 | 121 | public EncoderSettings(int solutionNumber, generationMode genMode, boolean verboseMode, | ||
3159 | 122 | boolean customEncMode) { | ||
3160 | 123 | this.solutionNumber = solutionNumber; | ||
3161 | 124 | this.genMode = genMode; | ||
3162 | 125 | this.verboseMode = verboseMode; | ||
3163 | 126 | this.customEncMode = customEncMode; | ||
3164 | 127 | } | ||
3165 | 128 | |||
3166 | 129 | public int getSolutionNumber() { | ||
3167 | 130 | return solutionNumber; | ||
3168 | 131 | } | ||
3169 | 132 | |||
3170 | 133 | public void setSolutionNumber(int number){ | ||
3171 | 134 | solutionNumber = number; | ||
3172 | 135 | } | ||
3173 | 136 | |||
3174 | 137 | public void setGenerationModeInt(int index){ | ||
3175 | 138 | switch(index){ | ||
3176 | 139 | case 0: | ||
3177 | 140 | genMode = generationMode.OPTIMAL_ENCODING; | ||
3178 | 141 | break; | ||
3179 | 142 | case 1: | ||
3180 | 143 | genMode = generationMode.RECURSIVE; | ||
3181 | 144 | break; | ||
3182 | 145 | case 2: | ||
3183 | 146 | genMode = generationMode.RANDOM; | ||
3184 | 147 | break; | ||
3185 | 148 | case 3: | ||
3186 | 149 | genMode = generationMode.SCENCO; | ||
3187 | 150 | break; | ||
3188 | 151 | case 4: | ||
3189 | 152 | genMode = generationMode.OLD_SYNT; | ||
3190 | 153 | break; | ||
3191 | 154 | default: | ||
3192 | 155 | System.out.println("Error."); | ||
3193 | 156 | } | ||
3194 | 157 | } | ||
3195 | 158 | |||
3196 | 159 | public int getNumPO() { | ||
3197 | 160 | return numPO; | ||
3198 | 161 | } | ||
3199 | 162 | |||
3200 | 163 | public void setNumPO(int numPO) { | ||
3201 | 164 | this.numPO = numPO; | ||
3202 | 165 | } | ||
3203 | 166 | |||
3204 | 167 | public generationMode getGenMode() { | ||
3205 | 168 | return genMode; | ||
3206 | 169 | } | ||
3207 | 170 | |||
3208 | 171 | public void setGenMode(generationMode genMode) { | ||
3209 | 172 | this.genMode = genMode; | ||
3210 | 173 | } | ||
3211 | 174 | |||
3212 | 175 | public boolean isVerboseMode() { | ||
3213 | 176 | return verboseMode; | ||
3214 | 177 | } | ||
3215 | 178 | |||
3216 | 179 | public void setVerboseMode(boolean verboseMode) { | ||
3217 | 180 | this.verboseMode = verboseMode; | ||
3218 | 181 | } | ||
3219 | 182 | |||
3220 | 183 | public boolean isCustomEncMode() { | ||
3221 | 184 | return customEncMode; | ||
3222 | 185 | } | ||
3223 | 186 | |||
3224 | 187 | public void setCustomEncMode(boolean customEncMode) { | ||
3225 | 188 | this.customEncMode = customEncMode; | ||
3226 | 189 | } | ||
3227 | 190 | |||
3228 | 191 | public String[] getCustomEnc() { | ||
3229 | 192 | return customEnc; | ||
3230 | 193 | } | ||
3231 | 194 | |||
3232 | 195 | public void setCustomEnc(String[] customEnc) { | ||
3233 | 196 | this.customEnc = customEnc; | ||
3234 | 197 | } | ||
3235 | 198 | |||
3236 | 199 | public String getLibPath() { | ||
3237 | 200 | return libPath; | ||
3238 | 201 | } | ||
3239 | 202 | |||
3240 | 203 | public void setLibPath(String libPath) { | ||
3241 | 204 | this.libPath = libPath; | ||
3242 | 205 | } | ||
3243 | 206 | |||
3244 | 207 | |||
3245 | 208 | } | ||
3246 | 0 | 209 | ||
3247 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettingsSerialiser.java' | |||
3248 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettingsSerialiser.java 1970-01-01 00:00:00 +0000 | |||
3249 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettingsSerialiser.java 2014-07-11 09:42:10 +0000 | |||
3250 | @@ -0,0 +1,29 @@ | |||
3251 | 1 | package org.workcraft.plugins.cpog; | ||
3252 | 2 | |||
3253 | 3 | import org.w3c.dom.Element; | ||
3254 | 4 | import org.workcraft.plugins.shared.presets.SettingsSerialiser; | ||
3255 | 5 | import org.workcraft.util.XmlUtil; | ||
3256 | 6 | |||
3257 | 7 | public class EncoderSettingsSerialiser implements SettingsSerialiser<EncoderSettings> { | ||
3258 | 8 | |||
3259 | 9 | @Override | ||
3260 | 10 | public EncoderSettings fromXML(Element e) { | ||
3261 | 11 | String espressoPath = XmlUtil.readStringAttr(e, "Espresso"); | ||
3262 | 12 | String abcPath = XmlUtil.readStringAttr(e, "Abc"); | ||
3263 | 13 | String libraryPath = XmlUtil.readStringAttr(e, "Library"); | ||
3264 | 14 | |||
3265 | 15 | return new EncoderSettings(espressoPath,abcPath,libraryPath); | ||
3266 | 16 | } | ||
3267 | 17 | |||
3268 | 18 | @Override | ||
3269 | 19 | public void toXML(EncoderSettings settings, Element parent) { | ||
3270 | 20 | Element e = parent.getOwnerDocument().createElement("settings"); | ||
3271 | 21 | e.setAttribute("Espresso", settings.getEspressoPath()); | ||
3272 | 22 | e.setAttribute("Abc", settings.getAbcPath()); | ||
3273 | 23 | e.setAttribute("Library", settings.getLibPath()); | ||
3274 | 24 | |||
3275 | 25 | parent.appendChild(e); | ||
3276 | 26 | |||
3277 | 27 | } | ||
3278 | 28 | |||
3279 | 29 | } | ||
3280 | 0 | 30 | ||
3281 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerChainResultHandler.java' | |||
3282 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerChainResultHandler.java 1970-01-01 00:00:00 +0000 | |||
3283 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerChainResultHandler.java 2014-07-11 09:42:10 +0000 | |||
3284 | @@ -0,0 +1,95 @@ | |||
3285 | 1 | package org.workcraft.plugins.cpog; | ||
3286 | 2 | |||
3287 | 3 | import javax.swing.JOptionPane; | ||
3288 | 4 | import javax.swing.SwingUtilities; | ||
3289 | 5 | |||
3290 | 6 | import org.workcraft.plugins.cpog.EncoderSettings.generationMode; | ||
3291 | 7 | import org.workcraft.plugins.cpog.tasks.ProgrammerChainResult; | ||
3292 | 8 | import org.workcraft.plugins.cpog.tasks.ProgrammerChainTask; | ||
3293 | 9 | import org.workcraft.plugins.shared.tasks.ExternalProcessResult; | ||
3294 | 10 | import org.workcraft.tasks.DummyProgressMonitor; | ||
3295 | 11 | import org.workcraft.tasks.Result; | ||
3296 | 12 | import org.workcraft.tasks.Result.Outcome; | ||
3297 | 13 | |||
3298 | 14 | public class ProgrammerChainResultHandler extends DummyProgressMonitor<ProgrammerChainResult> { | ||
3299 | 15 | private String errorMessage; | ||
3300 | 16 | private final ProgrammerChainTask task; | ||
3301 | 17 | |||
3302 | 18 | public ProgrammerChainResultHandler(ProgrammerChainTask task) { | ||
3303 | 19 | this.task = task; | ||
3304 | 20 | } | ||
3305 | 21 | |||
3306 | 22 | @Override | ||
3307 | 23 | public void finished(final Result<? extends ProgrammerChainResult> result, String description) { | ||
3308 | 24 | if (result.getOutcome() == Outcome.FINISHED) { | ||
3309 | 25 | final generationMode programmerMode = result.getReturnValue().getProgrammerSettings().getGenMode(); | ||
3310 | 26 | switch (programmerMode) { | ||
3311 | 27 | case OPTIMAL_ENCODING: | ||
3312 | 28 | case RECURSIVE: | ||
3313 | 29 | //SwingUtilities.invokeLater(new MpsatStgReachabilityResultHandler(task, result)); | ||
3314 | 30 | break; | ||
3315 | 31 | default: | ||
3316 | 32 | SwingUtilities.invokeLater(new Runnable() { | ||
3317 | 33 | @Override | ||
3318 | 34 | public void run() { | ||
3319 | 35 | JOptionPane.showMessageDialog(null, | ||
3320 | 36 | "Scenco mode \"" + programmerMode + "\" is not (yet) supported." , | ||
3321 | 37 | "Sorry..", JOptionPane.WARNING_MESSAGE); | ||
3322 | 38 | } | ||
3323 | 39 | }); | ||
3324 | 40 | break; | ||
3325 | 41 | } | ||
3326 | 42 | } | ||
3327 | 43 | else if (result.getOutcome() != Outcome.CANCELLED) { | ||
3328 | 44 | errorMessage = "Scenco tool chain execution failed :-("; | ||
3329 | 45 | |||
3330 | 46 | Throwable cause1 = result.getCause(); | ||
3331 | 47 | |||
3332 | 48 | if (cause1 != null) { | ||
3333 | 49 | // Exception was thrown somewhere in the chain task run() method (not in any of the subtasks) | ||
3334 | 50 | errorMessage += "\n\nFailure caused by: " + cause1.toString() + "\nPlease see the \"Problems\" tab for more details."; | ||
3335 | 51 | } else | ||
3336 | 52 | { | ||
3337 | 53 | Result<? extends Object> exportResult = result.getReturnValue().getExportResult(); | ||
3338 | 54 | if (exportResult.getOutcome() == Outcome.FAILED) { | ||
3339 | 55 | errorMessage += "\n\nFailed to export the model as a .g file."; | ||
3340 | 56 | Throwable cause = exportResult.getCause(); | ||
3341 | 57 | if (cause != null) | ||
3342 | 58 | errorMessage += "\n\nFailure caused by: " + cause.toString() + "\nPlease see the \"Problems\" tab for more details."; | ||
3343 | 59 | else | ||
3344 | 60 | errorMessage += "\n\nThe exporter class did not offer further explanation."; | ||
3345 | 61 | } else { | ||
3346 | 62 | Result<? extends ExternalProcessResult> punfResult = result.getReturnValue().getPunfResult(); | ||
3347 | 63 | |||
3348 | 64 | if (punfResult.getOutcome() == Outcome.FAILED) { | ||
3349 | 65 | errorMessage += "\n\nPunf could not build the unfolding prefix."; | ||
3350 | 66 | Throwable cause = punfResult.getCause(); | ||
3351 | 67 | if (cause != null) | ||
3352 | 68 | errorMessage += "\n\nFailure caused by: " + cause.toString() + "\nPlease see the \"Problems\" tab for more details."; | ||
3353 | 69 | else | ||
3354 | 70 | errorMessage += "\n\nFailure caused by the following errors:\n" + new String(punfResult.getReturnValue().getErrors()); | ||
3355 | 71 | } else { | ||
3356 | 72 | Result<? extends ExternalProcessResult> encoderResult = result.getReturnValue().getEncoderResult(); | ||
3357 | 73 | |||
3358 | 74 | if (encoderResult.getOutcome() == Outcome.FAILED) { | ||
3359 | 75 | errorMessage += "\n\nEncoder failed to execute as expected."; | ||
3360 | 76 | Throwable cause = encoderResult.getCause(); | ||
3361 | 77 | if (cause != null) | ||
3362 | 78 | errorMessage += "\n\nFailure caused by: " + cause.toString() + "\nPlease see the \"Problems\" tab for more details."; | ||
3363 | 79 | else | ||
3364 | 80 | errorMessage += "\n\nFailure caused by the following errors:\n" + new String(encoderResult.getReturnValue().getErrors()); | ||
3365 | 81 | } | ||
3366 | 82 | else { | ||
3367 | 83 | errorMessage += "\n\nEncoder chain task returned failure status without further explanation. This should not have happened -_-a."; | ||
3368 | 84 | } | ||
3369 | 85 | } | ||
3370 | 86 | } | ||
3371 | 87 | } | ||
3372 | 88 | SwingUtilities.invokeLater(new Runnable() { | ||
3373 | 89 | @Override | ||
3374 | 90 | public void run() { | ||
3375 | 91 | JOptionPane.showMessageDialog(null, errorMessage, "Oops..", JOptionPane.ERROR_MESSAGE); } | ||
3376 | 92 | }); | ||
3377 | 93 | } | ||
3378 | 94 | } | ||
3379 | 95 | } | ||
3380 | 0 | \ No newline at end of file | 96 | \ No newline at end of file |
3381 | 1 | 97 | ||
3382 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerMode.java' | |||
3383 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerMode.java 1970-01-01 00:00:00 +0000 | |||
3384 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerMode.java 2014-07-11 09:42:10 +0000 | |||
3385 | @@ -0,0 +1,41 @@ | |||
3386 | 1 | package org.workcraft.plugins.cpog; | ||
3387 | 2 | |||
3388 | 3 | public enum ProgrammerMode { | ||
3389 | 4 | MICROCONTROLLER("-M", "Microcontroller synthesising", false), | ||
3390 | 5 | CPOG_SIZE("-C", "Element controller synthesising", false); | ||
3391 | 6 | |||
3392 | 7 | private String argument; | ||
3393 | 8 | private String description; | ||
3394 | 9 | private boolean reach; | ||
3395 | 10 | |||
3396 | 11 | public static final ProgrammerMode[] modes = | ||
3397 | 12 | { | ||
3398 | 13 | MICROCONTROLLER, | ||
3399 | 14 | CPOG_SIZE | ||
3400 | 15 | }; | ||
3401 | 16 | |||
3402 | 17 | public static ProgrammerMode getMode (String arg) { | ||
3403 | 18 | for (int i=0; i<modes.length; i++) | ||
3404 | 19 | if (modes[i].getArgument().equals(arg)) | ||
3405 | 20 | return modes[i]; | ||
3406 | 21 | return null; | ||
3407 | 22 | } | ||
3408 | 23 | |||
3409 | 24 | ProgrammerMode(String argument, String description, boolean reach) { | ||
3410 | 25 | this.argument = argument; | ||
3411 | 26 | this.description = description; | ||
3412 | 27 | this.reach = reach; | ||
3413 | 28 | } | ||
3414 | 29 | |||
3415 | 30 | public String toString() { | ||
3416 | 31 | return description; | ||
3417 | 32 | } | ||
3418 | 33 | |||
3419 | 34 | public String getArgument() { | ||
3420 | 35 | return argument; | ||
3421 | 36 | } | ||
3422 | 37 | |||
3423 | 38 | public boolean isReach() { | ||
3424 | 39 | return reach; | ||
3425 | 40 | } | ||
3426 | 41 | } | ||
3427 | 0 | \ No newline at end of file | 42 | \ No newline at end of file |
3428 | 1 | 43 | ||
3429 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerUtilitySettings.java' | |||
3430 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerUtilitySettings.java 1970-01-01 00:00:00 +0000 | |||
3431 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerUtilitySettings.java 2014-07-11 09:42:10 +0000 | |||
3432 | @@ -0,0 +1,110 @@ | |||
3433 | 1 | package org.workcraft.plugins.cpog; | ||
3434 | 2 | |||
3435 | 3 | import java.util.Collection; | ||
3436 | 4 | import java.util.LinkedList; | ||
3437 | 5 | import java.util.List; | ||
3438 | 6 | |||
3439 | 7 | import org.workcraft.Config; | ||
3440 | 8 | import org.workcraft.gui.propertyeditor.PropertyDeclaration; | ||
3441 | 9 | import org.workcraft.gui.propertyeditor.PropertyDescriptor; | ||
3442 | 10 | import org.workcraft.gui.propertyeditor.SettingsPage; | ||
3443 | 11 | import org.workcraft.plugins.cpog.EncoderSettings.generationMode; | ||
3444 | 12 | |||
3445 | 13 | public class ProgrammerUtilitySettings implements SettingsPage { | ||
3446 | 14 | private static LinkedList<PropertyDescriptor> properties; | ||
3447 | 15 | |||
3448 | 16 | private static final String commandKey = "Tools.encoder.command"; | ||
3449 | 17 | private static final String solutionModeKey = "Tools.encoder.solutionMode"; | ||
3450 | 18 | private static final String extraArgsKey = "Tools.encoder.args"; | ||
3451 | 19 | |||
3452 | 20 | private static String command = "scenco"; | ||
3453 | 21 | private static generationMode genMode = generationMode.OPTIMAL_ENCODING; | ||
3454 | 22 | private static String extraArgs = ""; | ||
3455 | 23 | |||
3456 | 24 | public ProgrammerUtilitySettings() { | ||
3457 | 25 | properties = new LinkedList<PropertyDescriptor>(); | ||
3458 | 26 | |||
3459 | 27 | properties.add(new PropertyDeclaration<ProgrammerUtilitySettings, String>( | ||
3460 | 28 | this, "Scenco command", String.class) { | ||
3461 | 29 | protected void setter(ProgrammerUtilitySettings object, String value) { | ||
3462 | 30 | ProgrammerUtilitySettings.setCommand(value); | ||
3463 | 31 | } | ||
3464 | 32 | protected String getter(ProgrammerUtilitySettings object) { | ||
3465 | 33 | return ProgrammerUtilitySettings.getCommand(); | ||
3466 | 34 | } | ||
3467 | 35 | }); | ||
3468 | 36 | |||
3469 | 37 | properties.add(new PropertyDeclaration<ProgrammerUtilitySettings, generationMode>( | ||
3470 | 38 | this, "Check mode", generationMode.class, generationMode.getChoice()) { | ||
3471 | 39 | protected void setter(ProgrammerUtilitySettings object, generationMode value) { | ||
3472 | 40 | ProgrammerUtilitySettings.setGenerationMode(value); | ||
3473 | 41 | } | ||
3474 | 42 | protected generationMode getter(ProgrammerUtilitySettings object) { | ||
3475 | 43 | return ProgrammerUtilitySettings.getGenerationMode(); | ||
3476 | 44 | } | ||
3477 | 45 | }); | ||
3478 | 46 | |||
3479 | 47 | properties.add(new PropertyDeclaration<ProgrammerUtilitySettings, String>( | ||
3480 | 48 | this, "Scenco additional arguments", String.class) { | ||
3481 | 49 | protected void setter(ProgrammerUtilitySettings object, String value) { | ||
3482 | 50 | ProgrammerUtilitySettings.setExtraArgs(value); | ||
3483 | 51 | } | ||
3484 | 52 | protected String getter(ProgrammerUtilitySettings object) { | ||
3485 | 53 | return ProgrammerUtilitySettings.getExtraArgs(); | ||
3486 | 54 | } | ||
3487 | 55 | }); | ||
3488 | 56 | } | ||
3489 | 57 | |||
3490 | 58 | @Override | ||
3491 | 59 | public List<PropertyDescriptor> getDescriptors() { | ||
3492 | 60 | return properties; | ||
3493 | 61 | } | ||
3494 | 62 | |||
3495 | 63 | @Override | ||
3496 | 64 | public void load(Config config) { | ||
3497 | 65 | command = config.getString(commandKey, "scenco"); | ||
3498 | 66 | genMode = config.getEnum(solutionModeKey, generationMode.class, generationMode.OPTIMAL_ENCODING); | ||
3499 | 67 | extraArgs = config.getString(extraArgsKey, ""); | ||
3500 | 68 | } | ||
3501 | 69 | |||
3502 | 70 | @Override | ||
3503 | 71 | public void save(Config config) { | ||
3504 | 72 | config.set(commandKey, command); | ||
3505 | 73 | config.setEnum(solutionModeKey, generationMode.class, genMode); | ||
3506 | 74 | config.set(extraArgsKey, extraArgs); | ||
3507 | 75 | } | ||
3508 | 76 | |||
3509 | 77 | @Override | ||
3510 | 78 | public String getSection() { | ||
3511 | 79 | return "External tools"; | ||
3512 | 80 | } | ||
3513 | 81 | |||
3514 | 82 | @Override | ||
3515 | 83 | public String getName() { | ||
3516 | 84 | return "Scenco"; | ||
3517 | 85 | } | ||
3518 | 86 | |||
3519 | 87 | public static String getCommand() { | ||
3520 | 88 | return command; | ||
3521 | 89 | } | ||
3522 | 90 | |||
3523 | 91 | public static void setCommand(String value) { | ||
3524 | 92 | ProgrammerUtilitySettings.command = value; | ||
3525 | 93 | } | ||
3526 | 94 | |||
3527 | 95 | public static String getExtraArgs() { | ||
3528 | 96 | return extraArgs; | ||
3529 | 97 | } | ||
3530 | 98 | |||
3531 | 99 | public static void setExtraArgs(String value) { | ||
3532 | 100 | ProgrammerUtilitySettings.extraArgs = value; | ||
3533 | 101 | } | ||
3534 | 102 | |||
3535 | 103 | public static void setGenerationMode(generationMode value) { | ||
3536 | 104 | ProgrammerUtilitySettings.genMode = value; | ||
3537 | 105 | } | ||
3538 | 106 | |||
3539 | 107 | public static generationMode getGenerationMode() { | ||
3540 | 108 | return genMode; | ||
3541 | 109 | } | ||
3542 | 110 | } | ||
3543 | 0 | 111 | ||
3544 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/Variable.java' | |||
3545 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/Variable.java 2014-04-07 16:35:42 +0000 | |||
3546 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/Variable.java 2014-07-11 09:42:10 +0000 | |||
3547 | @@ -31,7 +31,8 @@ | |||
3548 | 31 | @DisplayName("Variable") | 31 | @DisplayName("Variable") |
3549 | 32 | @VisualClass(org.workcraft.plugins.cpog.VisualVariable.class) | 32 | @VisualClass(org.workcraft.plugins.cpog.VisualVariable.class) |
3550 | 33 | public class Variable extends MathNode implements Comparable<Variable>, BooleanVariable | 33 | public class Variable extends MathNode implements Comparable<Variable>, BooleanVariable |
3552 | 34 | { | 34 | { |
3553 | 35 | |||
3554 | 35 | private VariableState state = VariableState.UNDEFINED; | 36 | private VariableState state = VariableState.UNDEFINED; |
3555 | 36 | 37 | ||
3556 | 37 | private String label = ""; | 38 | private String label = ""; |
3557 | 38 | 39 | ||
3558 | === added directory 'CpogsPlugin/src/org/workcraft/plugins/cpog/gui' | |||
3559 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/gui/EncoderConfigurationDialog.java' | |||
3560 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/gui/EncoderConfigurationDialog.java 1970-01-01 00:00:00 +0000 | |||
3561 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/gui/EncoderConfigurationDialog.java 2014-07-11 09:42:10 +0000 | |||
3562 | @@ -0,0 +1,451 @@ | |||
3563 | 1 | package org.workcraft.plugins.cpog.gui; | ||
3564 | 2 | |||
3565 | 3 | import info.clearthought.layout.TableLayout; | ||
3566 | 4 | |||
3567 | 5 | import java.awt.Color; | ||
3568 | 6 | import java.awt.Dimension; | ||
3569 | 7 | import java.awt.FlowLayout; | ||
3570 | 8 | import java.awt.Window; | ||
3571 | 9 | import java.awt.event.ActionEvent; | ||
3572 | 10 | import java.awt.event.ActionListener; | ||
3573 | 11 | import java.awt.event.KeyEvent; | ||
3574 | 12 | import java.util.ArrayList; | ||
3575 | 13 | |||
3576 | 14 | import javax.swing.BorderFactory; | ||
3577 | 15 | import javax.swing.JButton; | ||
3578 | 16 | import javax.swing.JCheckBox; | ||
3579 | 17 | import javax.swing.JComboBox; | ||
3580 | 18 | import javax.swing.JComponent; | ||
3581 | 19 | import javax.swing.JDialog; | ||
3582 | 20 | import javax.swing.JLabel; | ||
3583 | 21 | import javax.swing.JPanel; | ||
3584 | 22 | import javax.swing.JScrollPane; | ||
3585 | 23 | import javax.swing.JTable; | ||
3586 | 24 | import javax.swing.JTextField; | ||
3587 | 25 | import javax.swing.KeyStroke; | ||
3588 | 26 | |||
3589 | 27 | import org.workcraft.gui.SimpleFlowLayout; | ||
3590 | 28 | import org.workcraft.plugins.cpog.CpogProgrammer; | ||
3591 | 29 | import org.workcraft.plugins.cpog.EncoderSettings; | ||
3592 | 30 | import org.workcraft.plugins.cpog.EncoderSettings.generationMode; | ||
3593 | 31 | import org.workcraft.plugins.cpog.VisualCPOG; | ||
3594 | 32 | import org.workcraft.plugins.cpog.VisualScenario; | ||
3595 | 33 | import org.workcraft.plugins.shared.presets.PresetManager; | ||
3596 | 34 | import org.workcraft.workspace.WorkspaceEntry; | ||
3597 | 35 | |||
3598 | 36 | public class EncoderConfigurationDialog extends JDialog { | ||
3599 | 37 | |||
3600 | 38 | private JLabel numberOfSolutionsLabel, contLabel, | ||
3601 | 39 | verboseModeLabel,exampleLabel,exampleLabel2,exampleLabel3,exampleLabel4, | ||
3602 | 40 | exampleLabel5,customEncLabel,bitsLabel,effortLabel,genLabel, | ||
3603 | 41 | optimiseLabel, disableLabel; | ||
3604 | 42 | private JCheckBox verboseModeCheck, customEncodings, effortCheck, | ||
3605 | 43 | disableCheck, contCheck; | ||
3606 | 44 | private JComboBox generationModeBox,OptimiseBox; | ||
3607 | 45 | private JPanel generationPanel, buttonsPanel, content; | ||
3608 | 46 | private JButton saveButton, closeButton; | ||
3609 | 47 | private JTextField numberOfSolutionsText, bitsText; | ||
3610 | 48 | private PresetManager<EncoderSettings> presetManager; | ||
3611 | 49 | private JTable encodingTable; | ||
3612 | 50 | JScrollPane scrollPane; | ||
3613 | 51 | private TableLayout layout; | ||
3614 | 52 | private int m,bits; | ||
3615 | 53 | |||
3616 | 54 | // Core variables | ||
3617 | 55 | private CpogProgrammer encoder; | ||
3618 | 56 | private EncoderSettings settings; | ||
3619 | 57 | private WorkspaceEntry we; | ||
3620 | 58 | private static boolean settingsPresent = false; | ||
3621 | 59 | |||
3622 | 60 | Dimension dimensionLabel = new Dimension(270, 22); | ||
3623 | 61 | Dimension dimensionBox = new Dimension(270, 22); | ||
3624 | 62 | Dimension dimensionText = new Dimension(585,22); | ||
3625 | 63 | Dimension dimensionTable = new Dimension(942,100); | ||
3626 | 64 | Dimension dimensionWindow = new Dimension(100,400); | ||
3627 | 65 | |||
3628 | 66 | //generationPanel.getPreferredSize().height | ||
3629 | 67 | |||
3630 | 68 | public EncoderSettings getSettings() { | ||
3631 | 69 | return settings; | ||
3632 | 70 | } | ||
3633 | 71 | |||
3634 | 72 | public EncoderConfigurationDialog(Window owner, PresetManager<EncoderSettings> presetManager, EncoderSettings settings,WorkspaceEntry we) { | ||
3635 | 73 | super(owner, "SCENCO configuration", ModalityType.APPLICATION_MODAL); | ||
3636 | 74 | this.presetManager = presetManager; | ||
3637 | 75 | this.settings = settings; | ||
3638 | 76 | this.we = we; | ||
3639 | 77 | |||
3640 | 78 | createGenerationPanel(); | ||
3641 | 79 | createButtonPanel(); | ||
3642 | 80 | |||
3643 | 81 | /*double size[][] = new double[][] { | ||
3644 | 82 | {TableLayout.FILL}, | ||
3645 | 83 | {TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL, dimensionWindow.height } | ||
3646 | 84 | };*/ | ||
3647 | 85 | double size[][] = new double[][] { | ||
3648 | 86 | {946}, | ||
3649 | 87 | {430,100} | ||
3650 | 88 | }; | ||
3651 | 89 | |||
3652 | 90 | layout = new TableLayout(size); | ||
3653 | 91 | //layout.setHGap(3); | ||
3654 | 92 | //layout.setVGap(3); | ||
3655 | 93 | |||
3656 | 94 | content = new JPanel(layout); | ||
3657 | 95 | content.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); | ||
3658 | 96 | |||
3659 | 97 | content.add(generationPanel, "0 0"); | ||
3660 | 98 | content.add(buttonsPanel, "0 1"); | ||
3661 | 99 | setContentPane(content); | ||
3662 | 100 | |||
3663 | 101 | |||
3664 | 102 | |||
3665 | 103 | getRootPane().registerKeyboardAction(new ActionListener() { | ||
3666 | 104 | @Override | ||
3667 | 105 | public void actionPerformed(ActionEvent e) { | ||
3668 | 106 | setVisible(false); | ||
3669 | 107 | } | ||
3670 | 108 | }, | ||
3671 | 109 | KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), | ||
3672 | 110 | JComponent.WHEN_IN_FOCUSED_WINDOW); | ||
3673 | 111 | |||
3674 | 112 | } | ||
3675 | 113 | |||
3676 | 114 | private void createButtonPanel() { | ||
3677 | 115 | buttonsPanel = new JPanel (new FlowLayout(FlowLayout.RIGHT)); | ||
3678 | 116 | |||
3679 | 117 | saveButton = new JButton ("Run"); | ||
3680 | 118 | saveButton.addActionListener(new ActionListener() { | ||
3681 | 119 | @Override | ||
3682 | 120 | public void actionPerformed(ActionEvent e) { | ||
3683 | 121 | setVisible(false); | ||
3684 | 122 | |||
3685 | 123 | |||
3686 | 124 | // ENCODER EXECUTION | ||
3687 | 125 | |||
3688 | 126 | // Read parameters | ||
3689 | 127 | if (effortCheck.isSelected()) | ||
3690 | 128 | settings.setEffort(false); | ||
3691 | 129 | else | ||
3692 | 130 | settings.setEffort(true); | ||
3693 | 131 | settings.setBits(Integer.valueOf(bitsText.getText())); | ||
3694 | 132 | settings.setCpogSize(OptimiseBox.getSelectedIndex() == 0 ? false : true); | ||
3695 | 133 | settings.setCostFunc(disableCheck.isSelected()); | ||
3696 | 134 | settings.setVerboseMode(verboseModeCheck.isSelected()); | ||
3697 | 135 | settings.setContMode(contCheck.isSelected()); | ||
3698 | 136 | settings.setGenerationModeInt(generationModeBox.getSelectedIndex()); | ||
3699 | 137 | settings.setSolutionNumber(Integer.parseInt(numberOfSolutionsText.getText())); | ||
3700 | 138 | settings.setNumPO(m); | ||
3701 | 139 | if(customEncodings.isSelected()){ | ||
3702 | 140 | settings.setCustomEncMode(true); | ||
3703 | 141 | String encodings[] = new String[m]; | ||
3704 | 142 | for(int i = 0; i<m; i++){ | ||
3705 | 143 | encodings[i] = (String) encodingTable.getModel().getValueAt(i, 1); | ||
3706 | 144 | } | ||
3707 | 145 | settings.setCustomEnc(encodings); | ||
3708 | 146 | }else{ | ||
3709 | 147 | settings.setBits(bits+1); | ||
3710 | 148 | settings.setCustomEncMode(false); | ||
3711 | 149 | } | ||
3712 | 150 | |||
3713 | 151 | // Set them on encoder | ||
3714 | 152 | if(settingsPresent == false){ | ||
3715 | 153 | settingsPresent = true; | ||
3716 | 154 | encoder = new CpogProgrammer(settings); | ||
3717 | 155 | }else{ | ||
3718 | 156 | encoder.setSettings(settings); | ||
3719 | 157 | } | ||
3720 | 158 | |||
3721 | 159 | // Execute programmer.x | ||
3722 | 160 | encoder.run(we); | ||
3723 | 161 | } | ||
3724 | 162 | }); | ||
3725 | 163 | |||
3726 | 164 | closeButton = new JButton ("Close"); | ||
3727 | 165 | closeButton.addActionListener(new ActionListener() { | ||
3728 | 166 | @Override | ||
3729 | 167 | public void actionPerformed(ActionEvent e) { | ||
3730 | 168 | setVisible(false); | ||
3731 | 169 | } | ||
3732 | 170 | }); | ||
3733 | 171 | |||
3734 | 172 | buttonsPanel.add(saveButton); | ||
3735 | 173 | buttonsPanel.add(closeButton); | ||
3736 | 174 | |||
3737 | 175 | } | ||
3738 | 176 | |||
3739 | 177 | private void createGenerationPanel() { | ||
3740 | 178 | setMinimumSize(new Dimension(600, 400)); | ||
3741 | 179 | generationPanel = new JPanel(new SimpleFlowLayout()); | ||
3742 | 180 | JPanel numberOfSolutionsPanel = new JPanel (new FlowLayout(FlowLayout.LEFT, 3, 0)); | ||
3743 | 181 | VisualCPOG cpog = (VisualCPOG)(we.getModelEntry().getVisualModel()); | ||
3744 | 182 | ArrayList<VisualScenario> scenarios = new ArrayList<VisualScenario>(cpog.getGroups()); | ||
3745 | 183 | m = scenarios.size(); | ||
3746 | 184 | |||
3747 | 185 | // GENERATION MODE COMBOBOX | ||
3748 | 186 | genLabel = new JLabel("Mode:"); | ||
3749 | 187 | genLabel.setPreferredSize(dimensionLabel); | ||
3750 | 188 | generationModeBox = new JComboBox(); | ||
3751 | 189 | generationModeBox.setEditable(false); | ||
3752 | 190 | generationModeBox.setPreferredSize(dimensionBox); | ||
3753 | 191 | for (generationMode mode : generationMode.modes) { | ||
3754 | 192 | generationModeBox.addItem(mode.name); | ||
3755 | 193 | } | ||
3756 | 194 | generationModeBox.setSelectedIndex(settings.getGenMode().ordinal()); | ||
3757 | 195 | generationModeBox.setBackground(Color.WHITE); | ||
3758 | 196 | generationModeBox.addActionListener(new ActionListener() { | ||
3759 | 197 | |||
3760 | 198 | @Override | ||
3761 | 199 | public void actionPerformed(ActionEvent e) { | ||
3762 | 200 | switch(generationModeBox.getSelectedIndex()){ | ||
3763 | 201 | // SIMULATED ANNEALING | ||
3764 | 202 | case 0: | ||
3765 | 203 | numberOfSolutionsText.setBackground(Color.WHITE); | ||
3766 | 204 | numberOfSolutionsText.setEnabled(true); | ||
3767 | 205 | contCheck.setEnabled(true); | ||
3768 | 206 | customEncodings.setEnabled(true); | ||
3769 | 207 | disableCheck.setSelected(false); | ||
3770 | 208 | disableCheck.setEnabled(true); | ||
3771 | 209 | break; | ||
3772 | 210 | // EXHAUSTIVE SEARCH | ||
3773 | 211 | case 1: | ||
3774 | 212 | numberOfSolutionsText.setBackground(Color.LIGHT_GRAY); | ||
3775 | 213 | numberOfSolutionsText.setEnabled(false); | ||
3776 | 214 | contCheck.setEnabled(false); | ||
3777 | 215 | contCheck.setSelected(false); | ||
3778 | 216 | customEncodings.setEnabled(false); | ||
3779 | 217 | customEncodings.setSelected(false); | ||
3780 | 218 | encodingTable.setEnabled(false); | ||
3781 | 219 | encodingTable.setBackground(Color.LIGHT_GRAY); | ||
3782 | 220 | bitsText.setBackground(Color.LIGHT_GRAY); | ||
3783 | 221 | bitsText.setEnabled(false); | ||
3784 | 222 | disableCheck.setSelected(false); | ||
3785 | 223 | disableCheck.setEnabled(false); | ||
3786 | 224 | break; | ||
3787 | 225 | // RANDOM SEARCH | ||
3788 | 226 | case 2: | ||
3789 | 227 | numberOfSolutionsText.setBackground(Color.WHITE); | ||
3790 | 228 | numberOfSolutionsText.setEnabled(true); | ||
3791 | 229 | contCheck.setEnabled(true); | ||
3792 | 230 | customEncodings.setEnabled(false); | ||
3793 | 231 | customEncodings.setSelected(false); | ||
3794 | 232 | encodingTable.setEnabled(false); | ||
3795 | 233 | encodingTable.setBackground(Color.LIGHT_GRAY); | ||
3796 | 234 | bitsText.setBackground(Color.LIGHT_GRAY); | ||
3797 | 235 | bitsText.setEnabled(false); | ||
3798 | 236 | disableCheck.setSelected(false); | ||
3799 | 237 | disableCheck.setEnabled(false); | ||
3800 | 238 | break; | ||
3801 | 239 | // OLD SCENCO | ||
3802 | 240 | case 3: | ||
3803 | 241 | numberOfSolutionsText.setBackground(Color.LIGHT_GRAY); | ||
3804 | 242 | numberOfSolutionsText.setEnabled(false); | ||
3805 | 243 | contCheck.setEnabled(false); | ||
3806 | 244 | contCheck.setSelected(false); | ||
3807 | 245 | customEncodings.setSelected(false); | ||
3808 | 246 | customEncodings.setEnabled(false); | ||
3809 | 247 | encodingTable.setEnabled(false); | ||
3810 | 248 | encodingTable.setBackground(Color.LIGHT_GRAY); | ||
3811 | 249 | bitsText.setBackground(Color.LIGHT_GRAY); | ||
3812 | 250 | bitsText.setEnabled(false); | ||
3813 | 251 | disableCheck.setSelected(false); | ||
3814 | 252 | disableCheck.setEnabled(false); | ||
3815 | 253 | break; | ||
3816 | 254 | // OLD SYNTHESISE | ||
3817 | 255 | case 4: | ||
3818 | 256 | numberOfSolutionsText.setBackground(Color.LIGHT_GRAY); | ||
3819 | 257 | numberOfSolutionsText.setEnabled(false); | ||
3820 | 258 | contCheck.setEnabled(false); | ||
3821 | 259 | contCheck.setSelected(false); | ||
3822 | 260 | customEncodings.setSelected(false); | ||
3823 | 261 | customEncodings.setEnabled(false); | ||
3824 | 262 | encodingTable.setEnabled(false); | ||
3825 | 263 | encodingTable.setBackground(Color.LIGHT_GRAY); | ||
3826 | 264 | bitsText.setBackground(Color.LIGHT_GRAY); | ||
3827 | 265 | bitsText.setEnabled(false); | ||
3828 | 266 | disableCheck.setSelected(false); | ||
3829 | 267 | disableCheck.setEnabled(false); | ||
3830 | 268 | break; | ||
3831 | 269 | default: | ||
3832 | 270 | } | ||
3833 | 271 | } | ||
3834 | 272 | }); | ||
3835 | 273 | |||
3836 | 274 | // OPTIMISE FOR MICROCONTROLLER/CPOG SIZE | ||
3837 | 275 | optimiseLabel = new JLabel("Optimise for:"); | ||
3838 | 276 | optimiseLabel.setPreferredSize(dimensionLabel); | ||
3839 | 277 | OptimiseBox = new JComboBox(); | ||
3840 | 278 | OptimiseBox.setEditable(false); | ||
3841 | 279 | OptimiseBox.setPreferredSize(dimensionBox); | ||
3842 | 280 | OptimiseBox.addItem("microcontroller"); | ||
3843 | 281 | OptimiseBox.addItem("CPOG size"); | ||
3844 | 282 | OptimiseBox.setSelectedIndex(settings.isCpogSize() ? 1 : 0); | ||
3845 | 283 | OptimiseBox.setBackground(Color.WHITE); | ||
3846 | 284 | |||
3847 | 285 | // DISABLE COST FUNCTION | ||
3848 | 286 | disableLabel = new JLabel("Disable cost function approximation: "); | ||
3849 | 287 | disableLabel.setPreferredSize(dimensionLabel); | ||
3850 | 288 | disableCheck = new JCheckBox("",settings.isCostFunc()); | ||
3851 | 289 | disableCheck.setToolTipText("Requires a big amount of time"); | ||
3852 | 290 | |||
3853 | 291 | |||
3854 | 292 | // Speed-up | ||
3855 | 293 | effortLabel = new JLabel("Using heuristic for speed-up:"); | ||
3856 | 294 | effortLabel.setPreferredSize(dimensionLabel); | ||
3857 | 295 | effortCheck = new JCheckBox("",settings.isEffort()); | ||
3858 | 296 | |||
3859 | 297 | // NUMBER OF SOLUTIONS TO GENERATE | ||
3860 | 298 | numberOfSolutionsLabel = new JLabel("Number of encodings to generate: "); | ||
3861 | 299 | numberOfSolutionsLabel.setPreferredSize(dimensionLabel); | ||
3862 | 300 | numberOfSolutionsText = new JTextField(); | ||
3863 | 301 | numberOfSolutionsText.setText(String.valueOf(settings.getSolutionNumber())); | ||
3864 | 302 | numberOfSolutionsText.setPreferredSize(new Dimension(70, 15)); | ||
3865 | 303 | |||
3866 | 304 | // CONTINUOUS MODE | ||
3867 | 305 | contCheck = new JCheckBox("",settings.isContMode()); | ||
3868 | 306 | contLabel = new JLabel("Continuous mode"); | ||
3869 | 307 | contLabel.setPreferredSize(new Dimension(150, 15)); | ||
3870 | 308 | contCheck.addActionListener(new ActionListener() { | ||
3871 | 309 | |||
3872 | 310 | @Override | ||
3873 | 311 | public void actionPerformed(ActionEvent e) { | ||
3874 | 312 | if(contCheck.isSelected()){ | ||
3875 | 313 | numberOfSolutionsText.setBackground(Color.LIGHT_GRAY); | ||
3876 | 314 | numberOfSolutionsText.setEnabled(false); | ||
3877 | 315 | }else{ | ||
3878 | 316 | numberOfSolutionsText.setBackground(Color.WHITE); | ||
3879 | 317 | numberOfSolutionsText.setEnabled(true); | ||
3880 | 318 | } | ||
3881 | 319 | } | ||
3882 | 320 | }); | ||
3883 | 321 | |||
3884 | 322 | // TABLE OF ENCODINGS | ||
3885 | 323 | exampleLabel = new JLabel("Fill in the table below if you want to set a custom op-code to a whichever Partial Order Graph. Below symbols allowed:"); | ||
3886 | 324 | exampleLabel2 = new JLabel("- 0 1 assign a specific bit 0 or 1;"); | ||
3887 | 325 | exampleLabel3 = new JLabel("- X find the best bit assignment;"); | ||
3888 | 326 | exampleLabel4 = new JLabel("- - a Don't Care bit."); | ||
3889 | 327 | exampleLabel5 = new JLabel("You have to take care of selecting an enough number of bits for encoding all Partial Order."); | ||
3890 | 328 | exampleLabel.setPreferredSize(new Dimension(942,15)); | ||
3891 | 329 | exampleLabel2.setPreferredSize(new Dimension(800,15)); | ||
3892 | 330 | exampleLabel3.setPreferredSize(new Dimension(800,15)); | ||
3893 | 331 | exampleLabel4.setPreferredSize(new Dimension(800,15)); | ||
3894 | 332 | exampleLabel5.setPreferredSize(new Dimension(800,15)); | ||
3895 | 333 | customEncLabel = new JLabel("Custom encodings: "); | ||
3896 | 334 | customEncLabel.setPreferredSize(dimensionLabel); | ||
3897 | 335 | customEncodings = new JCheckBox("", false); | ||
3898 | 336 | customEncodings.addActionListener(new ActionListener() { | ||
3899 | 337 | |||
3900 | 338 | @Override | ||
3901 | 339 | public void actionPerformed(ActionEvent e) { | ||
3902 | 340 | if(customEncodings.isSelected()){ | ||
3903 | 341 | encodingTable.setEnabled(true); | ||
3904 | 342 | encodingTable.setBackground(Color.WHITE); | ||
3905 | 343 | bitsText.setBackground(Color.WHITE); | ||
3906 | 344 | bitsText.setEnabled(true); | ||
3907 | 345 | } | ||
3908 | 346 | else{ | ||
3909 | 347 | encodingTable.setEnabled(false); | ||
3910 | 348 | encodingTable.setBackground(Color.LIGHT_GRAY); | ||
3911 | 349 | bitsText.setBackground(Color.LIGHT_GRAY); | ||
3912 | 350 | bitsText.setEnabled(false); | ||
3913 | 351 | } | ||
3914 | 352 | } | ||
3915 | 353 | }); | ||
3916 | 354 | |||
3917 | 355 | bitsLabel = new JLabel("Number of bits to use: "); | ||
3918 | 356 | bitsLabel.setPreferredSize(dimensionLabel); | ||
3919 | 357 | int value = 2; | ||
3920 | 358 | while(value < m){ | ||
3921 | 359 | value *=2; | ||
3922 | 360 | bits++; | ||
3923 | 361 | } | ||
3924 | 362 | |||
3925 | 363 | bitsText = new JTextField(); | ||
3926 | 364 | bitsText.setText(String.valueOf(bits + 1)); | ||
3927 | 365 | bitsText.setPreferredSize(new Dimension(70, 15)); | ||
3928 | 366 | bitsText.setBackground(Color.LIGHT_GRAY); | ||
3929 | 367 | bitsText.setEnabled(false); | ||
3930 | 368 | bitsText.addActionListener(new ActionListener() { | ||
3931 | 369 | |||
3932 | 370 | @Override | ||
3933 | 371 | public void actionPerformed(ActionEvent e) { | ||
3934 | 372 | if(Integer.parseInt(bitsText.getText()) < bits +1) | ||
3935 | 373 | bitsText.setText(String.valueOf(bits + 1)); | ||
3936 | 374 | for(int i=0;i<m;i++){ | ||
3937 | 375 | String data = ""; | ||
3938 | 376 | for(int j=0; j < Integer.valueOf(bitsText.getText()); j++) data = data + "X"; | ||
3939 | 377 | encodingTable.getModel().setValueAt(data, i, 1); | ||
3940 | 378 | } | ||
3941 | 379 | } | ||
3942 | 380 | }); | ||
3943 | 381 | |||
3944 | 382 | String[] columnNames = {"Partial Order Name","Encoding"}; | ||
3945 | 383 | Object[][] data = new Object[m][3]; | ||
3946 | 384 | for(int i=0; i<m; i++){ | ||
3947 | 385 | String name; | ||
3948 | 386 | if(scenarios.get(i).getLabel().equals("")){ | ||
3949 | 387 | name = "CPOG " + i; | ||
3950 | 388 | } | ||
3951 | 389 | else{ | ||
3952 | 390 | name = scenarios.get(i).getLabel(); | ||
3953 | 391 | } | ||
3954 | 392 | data[i][0] = name; | ||
3955 | 393 | data[i][1] = ""; | ||
3956 | 394 | for(int j=0; j < Integer.valueOf(bitsText.getText()); j++) data[i][1] = data[i][1] + "X"; | ||
3957 | 395 | } | ||
3958 | 396 | encodingTable = new JTable(data, columnNames); | ||
3959 | 397 | MyTableCellRenderer renderer = new MyTableCellRenderer(); | ||
3960 | 398 | encodingTable.setDefaultRenderer(Object.class, renderer); | ||
3961 | 399 | scrollPane = new JScrollPane(encodingTable); | ||
3962 | 400 | scrollPane.setPreferredSize(dimensionTable); | ||
3963 | 401 | encodingTable.setFillsViewportHeight(false); | ||
3964 | 402 | encodingTable.setEnabled(false); | ||
3965 | 403 | encodingTable.setBackground(Color.LIGHT_GRAY); | ||
3966 | 404 | |||
3967 | 405 | |||
3968 | 406 | // VERBOSE MODE INSTANTIATION | ||
3969 | 407 | verboseModeLabel = new JLabel("Activate verbose mode:"); | ||
3970 | 408 | verboseModeLabel.setPreferredSize(dimensionLabel); | ||
3971 | 409 | verboseModeCheck = new JCheckBox("",false); | ||
3972 | 410 | |||
3973 | 411 | // INSTANTATING PANEL | ||
3974 | 412 | generationPanel.add(genLabel); | ||
3975 | 413 | generationPanel.add(generationModeBox); | ||
3976 | 414 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3977 | 415 | generationPanel.add(optimiseLabel); | ||
3978 | 416 | generationPanel.add(OptimiseBox); | ||
3979 | 417 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3980 | 418 | generationPanel.add(disableLabel); | ||
3981 | 419 | generationPanel.add(disableCheck); | ||
3982 | 420 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3983 | 421 | generationPanel.add(effortLabel); | ||
3984 | 422 | generationPanel.add(effortCheck); | ||
3985 | 423 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3986 | 424 | generationPanel.add(numberOfSolutionsLabel); | ||
3987 | 425 | generationPanel.add(numberOfSolutionsText); | ||
3988 | 426 | generationPanel.add(contCheck); | ||
3989 | 427 | generationPanel.add(contLabel); | ||
3990 | 428 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3991 | 429 | generationPanel.add(verboseModeLabel); | ||
3992 | 430 | generationPanel.add(verboseModeCheck); | ||
3993 | 431 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3994 | 432 | generationPanel.add(exampleLabel); | ||
3995 | 433 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3996 | 434 | generationPanel.add(exampleLabel2); | ||
3997 | 435 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
3998 | 436 | generationPanel.add(exampleLabel3); | ||
3999 | 437 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
4000 | 438 | generationPanel.add(exampleLabel4); | ||
4001 | 439 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
4002 | 440 | generationPanel.add(exampleLabel5); | ||
4003 | 441 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
4004 | 442 | generationPanel.add(customEncLabel); | ||
4005 | 443 | generationPanel.add(customEncodings); | ||
4006 | 444 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
4007 | 445 | generationPanel.add(bitsLabel); | ||
4008 | 446 | generationPanel.add(bitsText); | ||
4009 | 447 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
4010 | 448 | generationPanel.add(scrollPane); | ||
4011 | 449 | generationPanel.add(new SimpleFlowLayout.LineBreak()); | ||
4012 | 450 | } | ||
4013 | 451 | } | ||
4014 | 0 | 452 | ||
4015 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/gui/MyTableCellRenderer.java' | |||
4016 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/gui/MyTableCellRenderer.java 1970-01-01 00:00:00 +0000 | |||
4017 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/gui/MyTableCellRenderer.java 2014-07-11 09:42:10 +0000 | |||
4018 | @@ -0,0 +1,15 @@ | |||
4019 | 1 | package org.workcraft.plugins.cpog.gui; | ||
4020 | 2 | |||
4021 | 3 | import java.awt.Component; | ||
4022 | 4 | |||
4023 | 5 | import javax.swing.JTable; | ||
4024 | 6 | import javax.swing.table.DefaultTableCellRenderer; | ||
4025 | 7 | |||
4026 | 8 | public class MyTableCellRenderer extends DefaultTableCellRenderer{ | ||
4027 | 9 | public Component getTableCellRendererComponent(JTable table,Object value, | ||
4028 | 10 | boolean isSelected, boolean hasFocus, int row, int column){ | ||
4029 | 11 | super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); | ||
4030 | 12 | setHorizontalAlignment( CENTER ); | ||
4031 | 13 | return this; | ||
4032 | 14 | } | ||
4033 | 15 | } | ||
4034 | 0 | \ No newline at end of file | 16 | \ No newline at end of file |
4035 | 1 | 17 | ||
4036 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/CpogEncoding.java' | |||
4037 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/CpogEncoding.java 2010-04-09 17:40:12 +0000 | |||
4038 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/CpogEncoding.java 2014-07-11 09:42:10 +0000 | |||
4039 | @@ -31,6 +31,15 @@ | |||
4040 | 31 | public boolean[][] getEncoding() { | 31 | public boolean[][] getEncoding() { |
4041 | 32 | return encoding; | 32 | return encoding; |
4042 | 33 | } | 33 | } |
4045 | 34 | private final BooleanFormula[] functions; | 34 | public void setEncoding(boolean[][] encoding){ |
4046 | 35 | private final boolean[][] encoding; | 35 | this.encoding = encoding; |
4047 | 36 | } | ||
4048 | 37 | public void setFormula(BooleanFormula formula,int index){ | ||
4049 | 38 | this.functions[index] = formula; | ||
4050 | 39 | } | ||
4051 | 40 | public void setFormule(BooleanFormula[] formula){ | ||
4052 | 41 | this.functions = formula; | ||
4053 | 42 | } | ||
4054 | 43 | private BooleanFormula[] functions; | ||
4055 | 44 | private boolean[][] encoding; | ||
4056 | 36 | } | 45 | } |
4057 | 37 | 46 | ||
4058 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/DefaultCpogSolver.java' | |||
4059 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/DefaultCpogSolver.java 2010-12-03 20:17:13 +0000 | |||
4060 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/DefaultCpogSolver.java 2014-07-11 09:42:10 +0000 | |||
4061 | @@ -11,6 +11,12 @@ | |||
4062 | 11 | this.cnfConverter = simpleCnfTaskProvider; | 11 | this.cnfConverter = simpleCnfTaskProvider; |
4063 | 12 | } | 12 | } |
4064 | 13 | 13 | ||
4065 | 14 | public CpogOptimisationTask<? extends T> getTask(String[] scenarios, BooleanVariable [] variables, int derivedVars) | ||
4066 | 15 | { | ||
4067 | 16 | CpogOptimisationTask<? extends T> task = problemGenerator.getFormula(scenarios, variables, derivedVars); | ||
4068 | 17 | return task; | ||
4069 | 18 | } | ||
4070 | 19 | |||
4071 | 14 | public CpogEncoding solve(String[] scenarios, BooleanVariable [] variables, int derivedVars) | 20 | public CpogEncoding solve(String[] scenarios, BooleanVariable [] variables, int derivedVars) |
4072 | 15 | { | 21 | { |
4073 | 16 | CpogOptimisationTask<? extends T> task = problemGenerator.getFormula(scenarios, variables, derivedVars); | 22 | CpogOptimisationTask<? extends T> task = problemGenerator.getFormula(scenarios, variables, derivedVars); |
4074 | 17 | 23 | ||
4075 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/FreeVariable.java' | |||
4076 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/FreeVariable.java 2010-04-13 15:52:01 +0000 | |||
4077 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/FreeVariable.java 2014-07-11 09:42:10 +0000 | |||
4078 | @@ -3,7 +3,7 @@ | |||
4079 | 3 | import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor; | 3 | import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor; |
4080 | 4 | 4 | ||
4081 | 5 | public class FreeVariable implements BooleanVariable, Comparable<FreeVariable> { | 5 | public class FreeVariable implements BooleanVariable, Comparable<FreeVariable> { |
4083 | 6 | 6 | ||
4084 | 7 | private final String label; | 7 | private final String label; |
4085 | 8 | 8 | ||
4086 | 9 | public FreeVariable(String label) { | 9 | public FreeVariable(String label) { |
4087 | 10 | 10 | ||
4088 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFormulaSerialiser.java' | |||
4089 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFormulaSerialiser.java 2010-10-22 14:07:56 +0000 | |||
4090 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFormulaSerialiser.java 2014-07-11 09:42:10 +0000 | |||
4091 | @@ -22,6 +22,8 @@ | |||
4092 | 22 | package org.workcraft.plugins.cpog.serialisation; | 22 | package org.workcraft.plugins.cpog.serialisation; |
4093 | 23 | 23 | ||
4094 | 24 | import org.w3c.dom.Element; | 24 | import org.w3c.dom.Element; |
4095 | 25 | import org.workcraft.dom.hierarchy.NamespaceHelper; | ||
4096 | 26 | import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager; | ||
4097 | 25 | import org.workcraft.exceptions.SerialisationException; | 27 | import org.workcraft.exceptions.SerialisationException; |
4098 | 26 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | 28 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
4099 | 27 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; | 29 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; |
4100 | @@ -31,6 +33,7 @@ | |||
4101 | 31 | import org.workcraft.serialisation.ReferenceProducer; | 33 | import org.workcraft.serialisation.ReferenceProducer; |
4102 | 32 | import org.workcraft.serialisation.xml.CustomXMLSerialiser; | 34 | import org.workcraft.serialisation.xml.CustomXMLSerialiser; |
4103 | 33 | import org.workcraft.serialisation.xml.NodeSerialiser; | 35 | import org.workcraft.serialisation.xml.NodeSerialiser; |
4104 | 36 | import org.workcraft.util.Identifier; | ||
4105 | 34 | 37 | ||
4106 | 35 | public abstract class BooleanFormulaSerialiser implements CustomXMLSerialiser | 38 | public abstract class BooleanFormulaSerialiser implements CustomXMLSerialiser |
4107 | 36 | { | 39 | { |
4108 | @@ -52,10 +55,21 @@ | |||
4109 | 52 | } | 55 | } |
4110 | 53 | 56 | ||
4111 | 54 | PrinterSuite printers = new FormulaToString.PrinterSuite(); | 57 | PrinterSuite printers = new FormulaToString.PrinterSuite(); |
4113 | 55 | printers.vars = new FormulaToString.VariablePrinter(){ | 58 | printers.vars = new FormulaToString.VariablePrinter() { |
4114 | 56 | @Override | 59 | @Override |
4115 | 57 | public Void visit(BooleanVariable node) { | 60 | public Void visit(BooleanVariable node) { |
4117 | 58 | append("var_"+internalReferences.getReference(node)); | 61 | |
4118 | 62 | String ref = internalReferences.getReference(node); | ||
4119 | 63 | // use full path to a flattened name | ||
4120 | 64 | String flat = NamespaceHelper.getFlatName(ref); | ||
4121 | 65 | |||
4122 | 66 | // old style naming, if number is used as an ID for a contact | ||
4123 | 67 | if (Identifier.isNumber(ref)) { | ||
4124 | 68 | append("var_"+ref); | ||
4125 | 69 | } else | ||
4126 | 70 | append(flat); | ||
4127 | 71 | |||
4128 | 72 | |||
4129 | 59 | return null; | 73 | return null; |
4130 | 60 | } | 74 | } |
4131 | 61 | }; | 75 | }; |
4132 | 62 | 76 | ||
4133 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFunctionDeserialiser.java' | |||
4134 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFunctionDeserialiser.java 2010-10-22 14:07:56 +0000 | |||
4135 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFunctionDeserialiser.java 2014-07-11 09:42:10 +0000 | |||
4136 | @@ -22,6 +22,7 @@ | |||
4137 | 22 | package org.workcraft.plugins.cpog.serialisation; | 22 | package org.workcraft.plugins.cpog.serialisation; |
4138 | 23 | 23 | ||
4139 | 24 | import org.w3c.dom.Element; | 24 | import org.w3c.dom.Element; |
4140 | 25 | import org.workcraft.dom.hierarchy.NamespaceHelper; | ||
4141 | 25 | import org.workcraft.exceptions.DeserialisationException; | 26 | import org.workcraft.exceptions.DeserialisationException; |
4142 | 26 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | 27 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
4143 | 27 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; | 28 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; |
4144 | @@ -43,7 +44,30 @@ | |||
4145 | 43 | this.internalReferenceResolver = internalReferenceResolver; | 44 | this.internalReferenceResolver = internalReferenceResolver; |
4146 | 44 | } | 45 | } |
4147 | 45 | 46 | ||
4149 | 46 | public BooleanVariable eval(String ref){ return (BooleanVariable) internalReferenceResolver.getObject(ref.substring("var_".length())); } | 47 | public BooleanVariable eval(String ref){ |
4150 | 48 | |||
4151 | 49 | if (ref.startsWith("var_")) { | ||
4152 | 50 | ref = ref.substring("var_".length()); | ||
4153 | 51 | |||
4154 | 52 | BooleanVariable bv = (BooleanVariable)internalReferenceResolver.getObject(ref); | ||
4155 | 53 | if (bv!=null) | ||
4156 | 54 | return bv; | ||
4157 | 55 | |||
4158 | 56 | // for (Object o: internalReferenceResolver.getObjects()) { | ||
4159 | 57 | // if (o instanceof BooleanVariable) { | ||
4160 | 58 | // bv = (BooleanVariable)o; | ||
4161 | 59 | // if (bv.getLegacyID().equals(Integer.valueOf(ref))) | ||
4162 | 60 | // return bv; | ||
4163 | 61 | // | ||
4164 | 62 | // return null; | ||
4165 | 63 | // } | ||
4166 | 64 | // } | ||
4167 | 65 | } | ||
4168 | 66 | |||
4169 | 67 | String hier = NamespaceHelper.flatToHierarchicalName(ref); | ||
4170 | 68 | |||
4171 | 69 | return (BooleanVariable) internalReferenceResolver.getObject(hier); | ||
4172 | 70 | } | ||
4173 | 47 | } | 71 | } |
4174 | 48 | 72 | ||
4175 | 49 | @Override | 73 | @Override |
4176 | 50 | 74 | ||
4177 | === added directory 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks' | |||
4178 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainResult.java' | |||
4179 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainResult.java 1970-01-01 00:00:00 +0000 | |||
4180 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainResult.java 2014-07-11 09:42:10 +0000 | |||
4181 | @@ -0,0 +1,56 @@ | |||
4182 | 1 | package org.workcraft.plugins.cpog.tasks; | ||
4183 | 2 | |||
4184 | 3 | import org.workcraft.plugins.cpog.EncoderSettings; | ||
4185 | 4 | import org.workcraft.plugins.shared.tasks.ExternalProcessResult; | ||
4186 | 5 | import org.workcraft.tasks.Result; | ||
4187 | 6 | |||
4188 | 7 | public class ProgrammerChainResult { | ||
4189 | 8 | private Result<? extends ExternalProcessResult> punfResult; | ||
4190 | 9 | private Result<? extends ExternalProcessResult> encoderResult; | ||
4191 | 10 | private Result<? extends Object> exportResult; | ||
4192 | 11 | private EncoderSettings encoderSettings; | ||
4193 | 12 | private String message; | ||
4194 | 13 | |||
4195 | 14 | public ProgrammerChainResult(Result<? extends Object> exportResult, | ||
4196 | 15 | Result<? extends ExternalProcessResult> punfResult, | ||
4197 | 16 | Result<? extends ExternalProcessResult> encoderResult, | ||
4198 | 17 | EncoderSettings encoderSettings) { | ||
4199 | 18 | this.punfResult = punfResult; | ||
4200 | 19 | this.encoderResult = encoderResult; | ||
4201 | 20 | this.exportResult = exportResult; | ||
4202 | 21 | this.encoderSettings = encoderSettings; | ||
4203 | 22 | } | ||
4204 | 23 | |||
4205 | 24 | public ProgrammerChainResult(Result<? extends Object> exportResult, | ||
4206 | 25 | Result<? extends ExternalProcessResult> punfResult, | ||
4207 | 26 | Result<? extends ExternalProcessResult> encoderResult, | ||
4208 | 27 | EncoderSettings encoderSettings, String message) { | ||
4209 | 28 | |||
4210 | 29 | this.punfResult = punfResult; | ||
4211 | 30 | this.encoderResult = encoderResult; | ||
4212 | 31 | this.exportResult = exportResult; | ||
4213 | 32 | this.encoderSettings = encoderSettings; | ||
4214 | 33 | |||
4215 | 34 | this.message = message; | ||
4216 | 35 | } | ||
4217 | 36 | |||
4218 | 37 | public EncoderSettings getProgrammerSettings() { | ||
4219 | 38 | return encoderSettings; | ||
4220 | 39 | } | ||
4221 | 40 | |||
4222 | 41 | public Result<? extends ExternalProcessResult> getPunfResult() { | ||
4223 | 42 | return punfResult; | ||
4224 | 43 | } | ||
4225 | 44 | |||
4226 | 45 | public Result<? extends ExternalProcessResult> getEncoderResult() { | ||
4227 | 46 | return encoderResult; | ||
4228 | 47 | } | ||
4229 | 48 | |||
4230 | 49 | public String getMessage() { | ||
4231 | 50 | return message; | ||
4232 | 51 | } | ||
4233 | 52 | |||
4234 | 53 | public Result<? extends Object> getExportResult() { | ||
4235 | 54 | return exportResult; | ||
4236 | 55 | } | ||
4237 | 56 | } | ||
4238 | 0 | 57 | ||
4239 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainTask.java' | |||
4240 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainTask.java 1970-01-01 00:00:00 +0000 | |||
4241 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainTask.java 2014-07-11 09:42:10 +0000 | |||
4242 | @@ -0,0 +1,103 @@ | |||
4243 | 1 | package org.workcraft.plugins.cpog.tasks; | ||
4244 | 2 | |||
4245 | 3 | import java.io.File; | ||
4246 | 4 | |||
4247 | 5 | import org.workcraft.Framework; | ||
4248 | 6 | import org.workcraft.dom.visual.VisualModel; | ||
4249 | 7 | import org.workcraft.interop.Exporter; | ||
4250 | 8 | import org.workcraft.plugins.cpog.EncoderSettings; | ||
4251 | 9 | import org.workcraft.plugins.shared.tasks.ExternalProcessResult; | ||
4252 | 10 | import org.workcraft.serialisation.Format; | ||
4253 | 11 | import org.workcraft.tasks.ProgressMonitor; | ||
4254 | 12 | import org.workcraft.tasks.Result; | ||
4255 | 13 | import org.workcraft.tasks.SubtaskMonitor; | ||
4256 | 14 | import org.workcraft.tasks.Task; | ||
4257 | 15 | import org.workcraft.tasks.Result.Outcome; | ||
4258 | 16 | import org.workcraft.util.Export; | ||
4259 | 17 | import org.workcraft.util.WorkspaceUtils; | ||
4260 | 18 | import org.workcraft.util.Export.ExportTask; | ||
4261 | 19 | import org.workcraft.workspace.WorkspaceEntry; | ||
4262 | 20 | |||
4263 | 21 | public class ProgrammerChainTask implements Task<ProgrammerChainResult> { | ||
4264 | 22 | |||
4265 | 23 | private final WorkspaceEntry we; | ||
4266 | 24 | private final EncoderSettings settings; | ||
4267 | 25 | private final Framework framework; | ||
4268 | 26 | private VisualModel model; | ||
4269 | 27 | |||
4270 | 28 | public ProgrammerChainTask(WorkspaceEntry we, EncoderSettings settings, Framework framework) { | ||
4271 | 29 | this.we = we; | ||
4272 | 30 | this.settings = settings; | ||
4273 | 31 | this.framework = framework; | ||
4274 | 32 | this.model = null; | ||
4275 | 33 | } | ||
4276 | 34 | |||
4277 | 35 | @Override | ||
4278 | 36 | public Result<? extends ProgrammerChainResult> run(ProgressMonitor<? super ProgrammerChainResult> monitor) { | ||
4279 | 37 | try { | ||
4280 | 38 | if(model == null) { | ||
4281 | 39 | model = WorkspaceUtils.getAs(getWorkspaceEntry(), VisualModel.class); | ||
4282 | 40 | } | ||
4283 | 41 | Exporter exporter = Export.chooseBestExporter(framework.getPluginManager(), model, Format.DOT); | ||
4284 | 42 | if (exporter == null) { | ||
4285 | 43 | throw new RuntimeException ("Exporter not available: model class " + model.getClass().getName() + " to format STG."); | ||
4286 | 44 | } | ||
4287 | 45 | File netFile = File.createTempFile("net", exporter.getExtenstion()); | ||
4288 | 46 | ExportTask exportTask; | ||
4289 | 47 | exportTask = new ExportTask(exporter, model, netFile.getCanonicalPath()); | ||
4290 | 48 | SubtaskMonitor<Object> mon = new SubtaskMonitor<Object>(monitor); | ||
4291 | 49 | Result<? extends Object> exportResult = framework.getTaskManager().execute(exportTask, "Exporting .g", mon); | ||
4292 | 50 | if (exportResult.getOutcome() != Outcome.FINISHED) { | ||
4293 | 51 | netFile.delete(); | ||
4294 | 52 | if (exportResult.getOutcome() == Outcome.CANCELLED) | ||
4295 | 53 | return new Result<ProgrammerChainResult>(Outcome.CANCELLED); | ||
4296 | 54 | return new Result<ProgrammerChainResult>(Outcome.FAILED, new ProgrammerChainResult(exportResult, null, null, settings)); | ||
4297 | 55 | } | ||
4298 | 56 | monitor.progressUpdate(0.33); | ||
4299 | 57 | |||
4300 | 58 | // File mciFile = File.createTempFile("unfolding", ".mci"); | ||
4301 | 59 | // PunfTask punfTask = new PunfTask(netFile.getCanonicalPath(), mciFile.getCanonicalPath()); | ||
4302 | 60 | // Result<? extends ExternalProcessResult> punfResult = framework.getTaskManager().execute(punfTask, "Unfolding .g", mon); | ||
4303 | 61 | // netFile.delete(); | ||
4304 | 62 | // | ||
4305 | 63 | // if (punfResult.getOutcome() != Outcome.FINISHED) { | ||
4306 | 64 | // mciFile.delete(); | ||
4307 | 65 | // if (punfResult.getOutcome() == Outcome.CANCELLED) | ||
4308 | 66 | // return new Result<ProgrammerChainResult>(Outcome.CANCELLED); | ||
4309 | 67 | // return new Result<ProgrammerChainResult>(Outcome.FAILED, new ProgrammerChainResult(exportResult, punfResult, null, settings)); | ||
4310 | 68 | // } | ||
4311 | 69 | // | ||
4312 | 70 | // monitor.progressUpdate(0.66); | ||
4313 | 71 | // | ||
4314 | 72 | // ProgrammerTask programmerTask = new ProgrammerTask(null, mciFile.getCanonicalPath()); | ||
4315 | 73 | // Result<? extends ExternalProcessResult> encoderResult = framework.getTaskManager().execute(programmerTask, "Running scenco model-checking", mon); | ||
4316 | 74 | // mciFile.delete(); | ||
4317 | 75 | // | ||
4318 | 76 | // if (encoderResult.getOutcome() != Outcome.FINISHED) { | ||
4319 | 77 | // if (encoderResult.getOutcome() == Outcome.CANCELLED) | ||
4320 | 78 | // return new Result<ProgrammerChainResult>(Outcome.CANCELLED); | ||
4321 | 79 | // return new Result<ProgrammerChainResult>(Outcome.FAILED, new ProgrammerChainResult(exportResult, punfResult, encoderResult, settings )); | ||
4322 | 80 | // } | ||
4323 | 81 | |||
4324 | 82 | monitor.progressUpdate(1.0); | ||
4325 | 83 | |||
4326 | 84 | // return new Result<ProgrammerChainResult>(Outcome.FINISHED, new ProgrammerChainResult(exportResult, punfResult, encoderResult, settings)); | ||
4327 | 85 | return new Result<ProgrammerChainResult>(Outcome.FINISHED, null); | ||
4328 | 86 | } catch (Throwable e) { | ||
4329 | 87 | return new Result<ProgrammerChainResult>(e); | ||
4330 | 88 | } | ||
4331 | 89 | } | ||
4332 | 90 | |||
4333 | 91 | public EncoderSettings getSettings() { | ||
4334 | 92 | return settings; | ||
4335 | 93 | } | ||
4336 | 94 | |||
4337 | 95 | public Framework getFramework() { | ||
4338 | 96 | return framework; | ||
4339 | 97 | } | ||
4340 | 98 | |||
4341 | 99 | public WorkspaceEntry getWorkspaceEntry() { | ||
4342 | 100 | return we; | ||
4343 | 101 | } | ||
4344 | 102 | |||
4345 | 103 | } | ||
4346 | 0 | 104 | ||
4347 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerTask.java' | |||
4348 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerTask.java 1970-01-01 00:00:00 +0000 | |||
4349 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerTask.java 2014-07-11 09:42:10 +0000 | |||
4350 | @@ -0,0 +1,73 @@ | |||
4351 | 1 | package org.workcraft.plugins.cpog.tasks; | ||
4352 | 2 | |||
4353 | 3 | import java.io.File; | ||
4354 | 4 | import java.io.IOException; | ||
4355 | 5 | import java.util.ArrayList; | ||
4356 | 6 | import java.util.HashMap; | ||
4357 | 7 | import java.util.Map; | ||
4358 | 8 | |||
4359 | 9 | import org.workcraft.plugins.cpog.ProgrammerUtilitySettings; | ||
4360 | 10 | import org.workcraft.plugins.shared.tasks.ExternalProcessResult; | ||
4361 | 11 | import org.workcraft.plugins.shared.tasks.ExternalProcessTask; | ||
4362 | 12 | import org.workcraft.tasks.ProgressMonitor; | ||
4363 | 13 | import org.workcraft.tasks.Result; | ||
4364 | 14 | import org.workcraft.tasks.Task; | ||
4365 | 15 | import org.workcraft.tasks.Result.Outcome; | ||
4366 | 16 | import org.workcraft.util.FileUtils; | ||
4367 | 17 | |||
4368 | 18 | public class ProgrammerTask implements Task<ExternalProcessResult> { | ||
4369 | 19 | private String[] args; | ||
4370 | 20 | private String inputFileName; | ||
4371 | 21 | |||
4372 | 22 | public ProgrammerTask(String[] args, String inputFileName) { | ||
4373 | 23 | this.args = args; | ||
4374 | 24 | this.inputFileName = inputFileName; | ||
4375 | 25 | } | ||
4376 | 26 | |||
4377 | 27 | @Override | ||
4378 | 28 | public Result<? extends ExternalProcessResult> run(ProgressMonitor<? super ExternalProcessResult> monitor) { | ||
4379 | 29 | |||
4380 | 30 | ArrayList<String> command = new ArrayList<String>(); | ||
4381 | 31 | command.add(ProgrammerUtilitySettings.getCommand()); | ||
4382 | 32 | |||
4383 | 33 | for (String arg : ProgrammerUtilitySettings.getExtraArgs().split(" ")) | ||
4384 | 34 | if (!arg.isEmpty()) | ||
4385 | 35 | command.add(arg); | ||
4386 | 36 | |||
4387 | 37 | for (String arg : args) | ||
4388 | 38 | command.add(arg); | ||
4389 | 39 | |||
4390 | 40 | command.add(inputFileName); | ||
4391 | 41 | |||
4392 | 42 | File workingDir = FileUtils.createTempDirectory("scenco"); | ||
4393 | 43 | |||
4394 | 44 | ExternalProcessTask externalProcessTask = new ExternalProcessTask(command, workingDir); | ||
4395 | 45 | |||
4396 | 46 | Result<? extends ExternalProcessResult> res = externalProcessTask.run(monitor); | ||
4397 | 47 | |||
4398 | 48 | if(res.getOutcome() == Outcome.CANCELLED) | ||
4399 | 49 | return res; | ||
4400 | 50 | |||
4401 | 51 | Map<String, byte[]> outputFiles = new HashMap<String, byte[]>(); | ||
4402 | 52 | |||
4403 | 53 | try { | ||
4404 | 54 | File mci = new File(workingDir, "scenco.mci"); | ||
4405 | 55 | if(mci.exists()) | ||
4406 | 56 | outputFiles.put("scenco.mci", FileUtils.readAllBytes(mci)); | ||
4407 | 57 | |||
4408 | 58 | File g = new File(workingDir, "scenco.g"); | ||
4409 | 59 | if(g.exists()) | ||
4410 | 60 | outputFiles.put("scenco.g", FileUtils.readAllBytes(g)); | ||
4411 | 61 | } catch (IOException e) { | ||
4412 | 62 | return new Result<ExternalProcessResult>(e); | ||
4413 | 63 | } | ||
4414 | 64 | |||
4415 | 65 | ExternalProcessResult retVal = res.getReturnValue(); | ||
4416 | 66 | ExternalProcessResult result = new ExternalProcessResult(retVal.getReturnCode(), retVal.getOutput(), retVal.getErrors(), outputFiles); | ||
4417 | 67 | |||
4418 | 68 | if (retVal.getReturnCode() < 2) | ||
4419 | 69 | return Result.finished(result); | ||
4420 | 70 | else | ||
4421 | 71 | return Result.failed(result); | ||
4422 | 72 | } | ||
4423 | 73 | } | ||
4424 | 0 | 74 | ||
4425 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tools/EncoderPreferencesTool.java' | |||
4426 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/tools/EncoderPreferencesTool.java 1970-01-01 00:00:00 +0000 | |||
4427 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/tools/EncoderPreferencesTool.java 2014-07-11 09:42:10 +0000 | |||
4428 | @@ -0,0 +1,65 @@ | |||
4429 | 1 | package org.workcraft.plugins.cpog.tools; | ||
4430 | 2 | |||
4431 | 3 | import java.io.File; | ||
4432 | 4 | |||
4433 | 5 | import org.workcraft.Framework; | ||
4434 | 6 | import org.workcraft.Tool; | ||
4435 | 7 | import org.workcraft.plugins.cpog.CpogProgrammer; | ||
4436 | 8 | import org.workcraft.plugins.cpog.EncoderSettings; | ||
4437 | 9 | import org.workcraft.plugins.cpog.EncoderSettings.generationMode; | ||
4438 | 10 | import org.workcraft.plugins.cpog.EncoderSettingsSerialiser; | ||
4439 | 11 | import org.workcraft.plugins.cpog.ProgrammerChainResultHandler; | ||
4440 | 12 | import org.workcraft.plugins.cpog.VisualCPOG; | ||
4441 | 13 | import org.workcraft.plugins.cpog.gui.EncoderConfigurationDialog; | ||
4442 | 14 | import org.workcraft.plugins.cpog.tasks.ProgrammerChainTask; | ||
4443 | 15 | import org.workcraft.plugins.shared.presets.PresetManager; | ||
4444 | 16 | import org.workcraft.util.GUI; | ||
4445 | 17 | import org.workcraft.workspace.WorkspaceEntry; | ||
4446 | 18 | |||
4447 | 19 | public class EncoderPreferencesTool implements Tool { | ||
4448 | 20 | |||
4449 | 21 | private final Framework framework; | ||
4450 | 22 | private static boolean settingPresent = false; | ||
4451 | 23 | private EncoderSettings settings; | ||
4452 | 24 | private EncoderConfigurationDialog dialog; | ||
4453 | 25 | PresetManager<EncoderSettings> pmgr; | ||
4454 | 26 | |||
4455 | 27 | public EncoderPreferencesTool(Framework framework) { | ||
4456 | 28 | this.framework = framework; | ||
4457 | 29 | } | ||
4458 | 30 | |||
4459 | 31 | @Override | ||
4460 | 32 | public boolean isApplicableTo(WorkspaceEntry we) { | ||
4461 | 33 | if (we.getModelEntry() == null) return false; | ||
4462 | 34 | if (we.getModelEntry().getVisualModel() instanceof VisualCPOG) return true; | ||
4463 | 35 | return false; | ||
4464 | 36 | } | ||
4465 | 37 | |||
4466 | 38 | @Override | ||
4467 | 39 | public String getSection() { | ||
4468 | 40 | return "Encoding"; | ||
4469 | 41 | } | ||
4470 | 42 | |||
4471 | 43 | @Override | ||
4472 | 44 | public String getDisplayName() { | ||
4473 | 45 | return "Cpog Programmer"; | ||
4474 | 46 | } | ||
4475 | 47 | |||
4476 | 48 | @Override | ||
4477 | 49 | public void run(WorkspaceEntry we) { | ||
4478 | 50 | if(settingPresent == false){ | ||
4479 | 51 | settingPresent = true; | ||
4480 | 52 | settings = new EncoderSettings(10,generationMode.OPTIMAL_ENCODING,false, false); | ||
4481 | 53 | pmgr = new PresetManager<EncoderSettings>(new File("config/cpog_presets.xml"), new EncoderSettingsSerialiser()); | ||
4482 | 54 | dialog = new EncoderConfigurationDialog(framework.getMainWindow(), pmgr, settings, we); | ||
4483 | 55 | } | ||
4484 | 56 | |||
4485 | 57 | GUI.centerAndSizeToParent(dialog, framework.getMainWindow()); | ||
4486 | 58 | dialog.setVisible(true); | ||
4487 | 59 | // TASK INSERTION | ||
4488 | 60 | /*final ProgrammerChainTask programmerTask = new ProgrammerChainTask(we, dialog.getSettings(), framework); | ||
4489 | 61 | framework.getTaskManager().queue(programmerTask, "Scenco tool chain", | ||
4490 | 62 | new ProgrammerChainResultHandler(programmerTask));*/ | ||
4491 | 63 | } | ||
4492 | 64 | |||
4493 | 65 | } | ||
4494 | 0 | 66 | ||
4495 | === modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/Dfs.java' | |||
4496 | --- DfsPlugin/src/org/workcraft/plugins/dfs/Dfs.java 2013-11-11 18:10:34 +0000 | |||
4497 | +++ DfsPlugin/src/org/workcraft/plugins/dfs/Dfs.java 2014-07-11 09:42:10 +0000 | |||
4498 | @@ -26,10 +26,12 @@ | |||
4499 | 26 | import org.workcraft.dom.Connection; | 26 | import org.workcraft.dom.Connection; |
4500 | 27 | import org.workcraft.dom.Container; | 27 | import org.workcraft.dom.Container; |
4501 | 28 | import org.workcraft.dom.Node; | 28 | import org.workcraft.dom.Node; |
4502 | 29 | import org.workcraft.dom.hierarchy.NamespaceProvider; | ||
4503 | 29 | import org.workcraft.dom.math.AbstractMathModel; | 30 | import org.workcraft.dom.math.AbstractMathModel; |
4504 | 30 | import org.workcraft.dom.math.MathConnection; | 31 | import org.workcraft.dom.math.MathConnection; |
4505 | 32 | import org.workcraft.dom.math.MathGroup; | ||
4506 | 31 | import org.workcraft.dom.math.MathNode; | 33 | import org.workcraft.dom.math.MathNode; |
4508 | 32 | import org.workcraft.dom.references.UniqueNameReferenceManager; | 34 | import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager; |
4509 | 33 | import org.workcraft.gui.propertyeditor.Properties; | 35 | import org.workcraft.gui.propertyeditor.Properties; |
4510 | 34 | import org.workcraft.serialisation.References; | 36 | import org.workcraft.serialisation.References; |
4511 | 35 | import org.workcraft.util.Func; | 37 | import org.workcraft.util.Func; |
4512 | @@ -40,11 +42,12 @@ | |||
4513 | 40 | public class Dfs extends AbstractMathModel { | 42 | public class Dfs extends AbstractMathModel { |
4514 | 41 | 43 | ||
4515 | 42 | public Dfs() { | 44 | public Dfs() { |
4517 | 43 | this(null, null); | 45 | this(new MathGroup(), null); |
4518 | 44 | } | 46 | } |
4519 | 45 | 47 | ||
4520 | 46 | public Dfs(Container root, References refs) { | 48 | public Dfs(Container root, References refs) { |
4522 | 47 | super(root, new UniqueNameReferenceManager(refs, new Func<Node, String>() { | 49 | |
4523 | 50 | super(root, new HierarchicalUniqueNameReferenceManager(refs, new Func<Node, String>() { | ||
4524 | 48 | @Override | 51 | @Override |
4525 | 49 | public String eval(Node arg) { | 52 | public String eval(Node arg) { |
4526 | 50 | if ((arg instanceof Logic) || (arg instanceof CounterflowLogic)) | 53 | if ((arg instanceof Logic) || (arg instanceof CounterflowLogic)) |
4527 | @@ -82,11 +85,4 @@ | |||
4528 | 82 | return null; | 85 | return null; |
4529 | 83 | } | 86 | } |
4530 | 84 | 87 | ||
4531 | 85 | public String getName(Node node) { | ||
4532 | 86 | return ((UniqueNameReferenceManager)getReferenceManager()).getName(node); | ||
4533 | 87 | } | ||
4534 | 88 | |||
4535 | 89 | public void setName(Node node, String name) { | ||
4536 | 90 | ((UniqueNameReferenceManager)getReferenceManager()).setName(node, name); | ||
4537 | 91 | } | ||
4538 | 92 | } | 88 | } |
4539 | 93 | 89 | ||
4540 | === modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/stg/StgGenerator.java' | |||
4541 | --- DfsPlugin/src/org/workcraft/plugins/dfs/stg/StgGenerator.java 2014-01-29 19:00:22 +0000 | |||
4542 | +++ DfsPlugin/src/org/workcraft/plugins/dfs/stg/StgGenerator.java 2014-07-11 09:42:10 +0000 | |||
4543 | @@ -10,6 +10,7 @@ | |||
4544 | 10 | import java.util.Set; | 10 | import java.util.Set; |
4545 | 11 | 11 | ||
4546 | 12 | import org.workcraft.dom.Connection; | 12 | import org.workcraft.dom.Connection; |
4547 | 13 | import org.workcraft.dom.Container; | ||
4548 | 13 | import org.workcraft.dom.Node; | 14 | import org.workcraft.dom.Node; |
4549 | 14 | import org.workcraft.dom.visual.Movable; | 15 | import org.workcraft.dom.visual.Movable; |
4550 | 15 | import org.workcraft.dom.visual.Positioning; | 16 | import org.workcraft.dom.visual.Positioning; |
4551 | @@ -197,7 +198,10 @@ | |||
4552 | 197 | SignalTransition.Type type = SignalTransition.Type.INTERNAL; | 198 | SignalTransition.Type type = SignalTransition.Type.INTERNAL; |
4553 | 198 | ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0); | 199 | ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0); |
4554 | 199 | 200 | ||
4556 | 200 | VisualPlace C0 = stg.createPlace(nameC + name + name0); | 201 | |
4557 | 202 | Container curContainer = null; | ||
4558 | 203 | |||
4559 | 204 | VisualPlace C0 = stg.createPlace(nameC + name + name0, curContainer); | ||
4560 | 201 | C0.setLabel(labelC + name + label0); | 205 | C0.setLabel(labelC + name + label0); |
4561 | 202 | C0.setLabelPositioning(Positioning.BOTTOM); | 206 | C0.setLabelPositioning(Positioning.BOTTOM); |
4562 | 203 | if (!l.getReferencedLogic().isComputed()) { | 207 | if (!l.getReferencedLogic().isComputed()) { |
4563 | @@ -208,7 +212,7 @@ | |||
4564 | 208 | setPosition(C0, x + 2.0, y + 1.0); | 212 | setPosition(C0, x + 2.0, y + 1.0); |
4565 | 209 | nodes.add(C0); | 213 | nodes.add(C0); |
4566 | 210 | 214 | ||
4568 | 211 | VisualPlace C1 = stg.createPlace(nameC + name + name1); | 215 | VisualPlace C1 = stg.createPlace(nameC + name + name1, curContainer); |
4569 | 212 | C1.setLabel(labelC + name + label1); | 216 | C1.setLabel(labelC + name + label1); |
4570 | 213 | C1.setLabelPositioning(Positioning.TOP); | 217 | C1.setLabelPositioning(Positioning.TOP); |
4571 | 214 | if (l.getReferencedLogic().isComputed()) { | 218 | if (l.getReferencedLogic().isComputed()) { |
4572 | @@ -235,7 +239,7 @@ | |||
4573 | 235 | double dy = 0.0; | 239 | double dy = 0.0; |
4574 | 236 | for (Node n: preset) { | 240 | for (Node n: preset) { |
4575 | 237 | if (CR == null || l.getReferencedLogic().isEarlyEvaluation()) { | 241 | if (CR == null || l.getReferencedLogic().isEarlyEvaluation()) { |
4577 | 238 | CR = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.PLUS); | 242 | CR = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.PLUS, curContainer); |
4578 | 239 | CR.setTokenColorGenerator(tokenColorGenerator); | 243 | CR.setTokenColorGenerator(tokenColorGenerator); |
4579 | 240 | createConsumingArc(C0, CR, false); | 244 | createConsumingArc(C0, CR, false); |
4580 | 241 | createProducingArc(CR, C1, true); | 245 | createProducingArc(CR, C1, true); |
4581 | @@ -244,7 +248,7 @@ | |||
4582 | 244 | } | 248 | } |
4583 | 245 | CRs.put(n, CR); | 249 | CRs.put(n, CR); |
4584 | 246 | if (CF == null) { | 250 | if (CF == null) { |
4586 | 247 | CF = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.MINUS); | 251 | CF = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.MINUS, curContainer); |
4587 | 248 | createConsumingArc(C1, CF, false); | 252 | createConsumingArc(C1, CF, false); |
4588 | 249 | createProducingArc(CF, C0, false); | 253 | createProducingArc(CF, C0, false); |
4589 | 250 | setPosition(CF, x - 2.0, y - 1.0 - dy); | 254 | setPosition(CF, x - 2.0, y - 1.0 - dy); |
4590 | @@ -305,8 +309,9 @@ | |||
4591 | 305 | type = SignalTransition.Type.OUTPUT; | 309 | type = SignalTransition.Type.OUTPUT; |
4592 | 306 | } | 310 | } |
4593 | 307 | ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0); | 311 | ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0); |
4594 | 312 | Container curContainer = null; | ||
4595 | 308 | 313 | ||
4597 | 309 | VisualPlace M0 = stg.createPlace(nameM + name + name0); | 314 | VisualPlace M0 = stg.createPlace(nameM + name + name0, curContainer); |
4598 | 310 | M0.setLabel(labelM + name + label0); | 315 | M0.setLabel(labelM + name + label0); |
4599 | 311 | M0.setLabelPositioning(Positioning.BOTTOM); | 316 | M0.setLabelPositioning(Positioning.BOTTOM); |
4600 | 312 | if (!r.getReferencedRegister().isMarked()) { | 317 | if (!r.getReferencedRegister().isMarked()) { |
4601 | @@ -317,7 +322,7 @@ | |||
4602 | 317 | setPosition(M0, x + 2.0, y + 1.0); | 322 | setPosition(M0, x + 2.0, y + 1.0); |
4603 | 318 | nodes.add(M0); | 323 | nodes.add(M0); |
4604 | 319 | 324 | ||
4606 | 320 | VisualPlace M1 = stg.createPlace(nameM + name + name1); | 325 | VisualPlace M1 = stg.createPlace(nameM + name + name1, curContainer); |
4607 | 321 | M1.setLabel(labelM + name + label1); | 326 | M1.setLabel(labelM + name + label1); |
4608 | 322 | M1.setLabelPositioning(Positioning.TOP); | 327 | M1.setLabelPositioning(Positioning.TOP); |
4609 | 323 | if (r.getReferencedRegister().isMarked()) { | 328 | if (r.getReferencedRegister().isMarked()) { |
4610 | @@ -327,14 +332,14 @@ | |||
4611 | 327 | setPosition(M1, x + 2.0, y - 1.0); | 332 | setPosition(M1, x + 2.0, y - 1.0); |
4612 | 328 | nodes.add(M1); | 333 | nodes.add(M1); |
4613 | 329 | 334 | ||
4615 | 330 | VisualSignalTransition MR = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.PLUS); | 335 | VisualSignalTransition MR = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.PLUS, curContainer); |
4616 | 331 | MR.setTokenColorGenerator(tokenColorGenerator); | 336 | MR.setTokenColorGenerator(tokenColorGenerator); |
4617 | 332 | createConsumingArc(M0, MR, false); | 337 | createConsumingArc(M0, MR, false); |
4618 | 333 | createProducingArc(MR, M1, true); | 338 | createProducingArc(MR, M1, true); |
4619 | 334 | setPosition(MR, x - 2.0, y + 1.0); | 339 | setPosition(MR, x - 2.0, y + 1.0); |
4620 | 335 | nodes.add(MR); | 340 | nodes.add(MR); |
4621 | 336 | 341 | ||
4623 | 337 | VisualSignalTransition MF = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.MINUS); | 342 | VisualSignalTransition MF = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.MINUS, curContainer); |
4624 | 338 | createConsumingArc(M1, MF, false); | 343 | createConsumingArc(M1, MF, false); |
4625 | 339 | createProducingArc(MF, M0, false); | 344 | createProducingArc(MF, M0, false); |
4626 | 340 | setPosition(MF, x - 2.0, y - 1.0); | 345 | setPosition(MF, x - 2.0, y - 1.0); |
4627 | @@ -423,7 +428,9 @@ | |||
4628 | 423 | ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0); | 428 | ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0); |
4629 | 424 | ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(l).size() == 0); | 429 | ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(l).size() == 0); |
4630 | 425 | 430 | ||
4632 | 426 | VisualPlace fwC0 = stg.createPlace(nameFwC + name + name0); | 431 | Container curContainer = null; |
4633 | 432 | |||
4634 | 433 | VisualPlace fwC0 = stg.createPlace(nameFwC + name + name0, curContainer); | ||
4635 | 427 | fwC0.setLabel(labelFwC + name + label0); | 434 | fwC0.setLabel(labelFwC + name + label0); |
4636 | 428 | fwC0.setLabelPositioning(Positioning.BOTTOM); | 435 | fwC0.setLabelPositioning(Positioning.BOTTOM); |
4637 | 429 | if (!l.getReferencedCounterflowLogic().isForwardComputed()) { | 436 | if (!l.getReferencedCounterflowLogic().isForwardComputed()) { |
4638 | @@ -434,7 +441,7 @@ | |||
4639 | 434 | setPosition(fwC0, x + 2.0, y - 2.0); | 441 | setPosition(fwC0, x + 2.0, y - 2.0); |
4640 | 435 | nodes.add(fwC0); | 442 | nodes.add(fwC0); |
4641 | 436 | 443 | ||
4643 | 437 | VisualPlace fwC1 = stg.createPlace(nameFwC + name + name1); | 444 | VisualPlace fwC1 = stg.createPlace(nameFwC + name + name1, curContainer); |
4644 | 438 | fwC1.setLabel(labelFwC + name + label1); | 445 | fwC1.setLabel(labelFwC + name + label1); |
4645 | 439 | fwC1.setLabelPositioning(Positioning.TOP); | 446 | fwC1.setLabelPositioning(Positioning.TOP); |
4646 | 440 | if (l.getReferencedCounterflowLogic().isForwardComputed()) { | 447 | if (l.getReferencedCounterflowLogic().isForwardComputed()) { |
4647 | @@ -459,7 +466,7 @@ | |||
4648 | 459 | double dy = 0.0; | 466 | double dy = 0.0; |
4649 | 460 | for (Node n: preset) { | 467 | for (Node n: preset) { |
4650 | 461 | if (fwCR == null || l.getReferencedCounterflowLogic().isForwardEarlyEvaluation()) { | 468 | if (fwCR == null || l.getReferencedCounterflowLogic().isForwardEarlyEvaluation()) { |
4652 | 462 | fwCR = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.PLUS); | 469 | fwCR = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.PLUS, curContainer); |
4653 | 463 | fwCR.setTokenColorGenerator(presetTokenColorGenerator); | 470 | fwCR.setTokenColorGenerator(presetTokenColorGenerator); |
4654 | 464 | createConsumingArc(fwC0, fwCR, false); | 471 | createConsumingArc(fwC0, fwCR, false); |
4655 | 465 | createProducingArc(fwCR, fwC1, true); | 472 | createProducingArc(fwCR, fwC1, true); |
4656 | @@ -468,7 +475,7 @@ | |||
4657 | 468 | } | 475 | } |
4658 | 469 | fwCRs.put(n, fwCR); | 476 | fwCRs.put(n, fwCR); |
4659 | 470 | if (fwCF == null) { | 477 | if (fwCF == null) { |
4661 | 471 | fwCF = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.MINUS); | 478 | fwCF = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.MINUS, curContainer); |
4662 | 472 | createConsumingArc(fwC1, fwCF, false); | 479 | createConsumingArc(fwC1, fwCF, false); |
4663 | 473 | createProducingArc(fwCF, fwC0, false); | 480 | createProducingArc(fwCF, fwC0, false); |
4664 | 474 | stg.connect(fwC1, fwCF); | 481 | stg.connect(fwC1, fwCF); |
4665 | @@ -481,7 +488,7 @@ | |||
4666 | 481 | } | 488 | } |
4667 | 482 | } | 489 | } |
4668 | 483 | 490 | ||
4670 | 484 | VisualPlace bwC0 = stg.createPlace(nameBwC + name + name0); | 491 | VisualPlace bwC0 = stg.createPlace(nameBwC + name + name0, curContainer); |
4671 | 485 | bwC0.setLabel(labelBwC + name + label0); | 492 | bwC0.setLabel(labelBwC + name + label0); |
4672 | 486 | bwC0.setLabelPositioning(Positioning.BOTTOM); | 493 | bwC0.setLabelPositioning(Positioning.BOTTOM); |
4673 | 487 | if (!l.getReferencedCounterflowLogic().isBackwardComputed()) { | 494 | if (!l.getReferencedCounterflowLogic().isBackwardComputed()) { |
4674 | @@ -492,7 +499,7 @@ | |||
4675 | 492 | setPosition(bwC0, x + 2.0, y + 4.0); | 499 | setPosition(bwC0, x + 2.0, y + 4.0); |
4676 | 493 | nodes.add(bwC0); | 500 | nodes.add(bwC0); |
4677 | 494 | 501 | ||
4679 | 495 | VisualPlace bwC1 = stg.createPlace(nameBwC + name + name1); | 502 | VisualPlace bwC1 = stg.createPlace(nameBwC + name + name1, curContainer); |
4680 | 496 | bwC1.setLabel(labelBwC + name + label1); | 503 | bwC1.setLabel(labelBwC + name + label1); |
4681 | 497 | bwC1.setLabelPositioning(Positioning.TOP); | 504 | bwC1.setLabelPositioning(Positioning.TOP); |
4682 | 498 | if (l.getReferencedCounterflowLogic().isBackwardComputed()) { | 505 | if (l.getReferencedCounterflowLogic().isBackwardComputed()) { |
4683 | @@ -517,7 +524,7 @@ | |||
4684 | 517 | double dy = 0.0; | 524 | double dy = 0.0; |
4685 | 518 | for (Node n: postset) { | 525 | for (Node n: postset) { |
4686 | 519 | if (bwCR == null || l.getReferencedCounterflowLogic().isBackwardEarlyEvaluation()) { | 526 | if (bwCR == null || l.getReferencedCounterflowLogic().isBackwardEarlyEvaluation()) { |
4688 | 520 | bwCR = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.PLUS); | 527 | bwCR = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.PLUS, curContainer); |
4689 | 521 | bwCR.setTokenColorGenerator(postsetTokenColorGenerator); | 528 | bwCR.setTokenColorGenerator(postsetTokenColorGenerator); |
4690 | 522 | stg.connect(bwC0, bwCR); | 529 | stg.connect(bwC0, bwCR); |
4691 | 523 | stg.connect(bwCR, bwC1); | 530 | stg.connect(bwCR, bwC1); |
4692 | @@ -526,7 +533,7 @@ | |||
4693 | 526 | } | 533 | } |
4694 | 527 | bwCRs.put(n, bwCR); | 534 | bwCRs.put(n, bwCR); |
4695 | 528 | if (bwCF == null) { | 535 | if (bwCF == null) { |
4697 | 529 | bwCF = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.MINUS); | 536 | bwCF = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.MINUS, curContainer); |
4698 | 530 | stg.connect(bwC1, bwCF); | 537 | stg.connect(bwC1, bwCF); |
4699 | 531 | stg.connect(bwCF, bwC0); | 538 | stg.connect(bwCF, bwC0); |
4700 | 532 | setPosition(bwCF, x - 2.0, y + 2.0 - dy); | 539 | setPosition(bwCF, x - 2.0, y + 2.0 - dy); |
4701 | @@ -585,7 +592,9 @@ | |||
4702 | 585 | ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0); | 592 | ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0); |
4703 | 586 | ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(r).size() == 0); | 593 | ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(r).size() == 0); |
4704 | 587 | 594 | ||
4706 | 588 | VisualPlace orM0 = stg.createPlace(nameOrM + name + name0); | 595 | Container curContainer = null; |
4707 | 596 | |||
4708 | 597 | VisualPlace orM0 = stg.createPlace(nameOrM + name + name0, curContainer); | ||
4709 | 589 | orM0.setLabel(labelOrM + name + label0); | 598 | orM0.setLabel(labelOrM + name + label0); |
4710 | 590 | orM0.setLabelPositioning(Positioning.BOTTOM); | 599 | orM0.setLabelPositioning(Positioning.BOTTOM); |
4711 | 591 | if (!r.getReferencedCounterflowRegister().isOrMarked()) { | 600 | if (!r.getReferencedCounterflowRegister().isOrMarked()) { |
4712 | @@ -596,7 +605,7 @@ | |||
4713 | 596 | setPosition(orM0, x + 2.0, y - 2.0); | 605 | setPosition(orM0, x + 2.0, y - 2.0); |
4714 | 597 | nodes.add(orM0); | 606 | nodes.add(orM0); |
4715 | 598 | 607 | ||
4717 | 599 | VisualPlace orM1 = stg.createPlace(nameOrM + name + name1); | 608 | VisualPlace orM1 = stg.createPlace(nameOrM + name + name1, curContainer); |
4718 | 600 | orM1.setLabel(labelOrM + name + label1); | 609 | orM1.setLabel(labelOrM + name + label1); |
4719 | 601 | orM1.setLabelPositioning(Positioning.TOP); | 610 | orM1.setLabelPositioning(Positioning.TOP); |
4720 | 602 | if (r.getReferencedCounterflowRegister().isOrMarked()) { | 611 | if (r.getReferencedCounterflowRegister().isOrMarked()) { |
4721 | @@ -607,33 +616,33 @@ | |||
4722 | 607 | setPosition(orM1, x + 2.0, y - 4.0); | 616 | setPosition(orM1, x + 2.0, y - 4.0); |
4723 | 608 | nodes.add(orM1); | 617 | nodes.add(orM1); |
4724 | 609 | 618 | ||
4726 | 610 | VisualSignalTransition orMRfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS); | 619 | VisualSignalTransition orMRfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS, curContainer); |
4727 | 611 | orMRfw.setTokenColorGenerator(presetTokenColorGenerator); | 620 | orMRfw.setTokenColorGenerator(presetTokenColorGenerator); |
4728 | 612 | createConsumingArc(orM0, orMRfw, false); | 621 | createConsumingArc(orM0, orMRfw, false); |
4729 | 613 | createProducingArc(orMRfw, orM1, true); | 622 | createProducingArc(orMRfw, orM1, true); |
4730 | 614 | setPosition(orMRfw, x - 2.0, y - 2.5); | 623 | setPosition(orMRfw, x - 2.0, y - 2.5); |
4731 | 615 | nodes.add(orMRfw); | 624 | nodes.add(orMRfw); |
4732 | 616 | 625 | ||
4734 | 617 | VisualSignalTransition orMRbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS); | 626 | VisualSignalTransition orMRbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS, curContainer); |
4735 | 618 | orMRbw.setTokenColorGenerator(postsetTokenColorGenerator); | 627 | orMRbw.setTokenColorGenerator(postsetTokenColorGenerator); |
4736 | 619 | createConsumingArc(orM0, orMRbw, false); | 628 | createConsumingArc(orM0, orMRbw, false); |
4737 | 620 | createProducingArc(orMRbw, orM1, true); | 629 | createProducingArc(orMRbw, orM1, true); |
4738 | 621 | setPosition(orMRbw, x - 2.0, y - 1.5); | 630 | setPosition(orMRbw, x - 2.0, y - 1.5); |
4739 | 622 | nodes.add(orMRbw); | 631 | nodes.add(orMRbw); |
4740 | 623 | 632 | ||
4742 | 624 | VisualSignalTransition orMFfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS); | 633 | VisualSignalTransition orMFfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS, curContainer); |
4743 | 625 | createConsumingArc(orM1, orMFfw, false); | 634 | createConsumingArc(orM1, orMFfw, false); |
4744 | 626 | createProducingArc(orMFfw, orM0, false); | 635 | createProducingArc(orMFfw, orM0, false); |
4745 | 627 | setPosition(orMFfw, x - 2.0, y - 4.5); | 636 | setPosition(orMFfw, x - 2.0, y - 4.5); |
4746 | 628 | nodes.add(orMFfw); | 637 | nodes.add(orMFfw); |
4747 | 629 | 638 | ||
4749 | 630 | VisualSignalTransition orMFbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS); | 639 | VisualSignalTransition orMFbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS, curContainer); |
4750 | 631 | createConsumingArc(orM1, orMFbw, false); | 640 | createConsumingArc(orM1, orMFbw, false); |
4751 | 632 | createProducingArc(orMFbw, orM0, false); | 641 | createProducingArc(orMFbw, orM0, false); |
4752 | 633 | setPosition(orMFbw, x - 2.0, y - 3.5); | 642 | setPosition(orMFbw, x - 2.0, y - 3.5); |
4753 | 634 | nodes.add(orMFbw); | 643 | nodes.add(orMFbw); |
4754 | 635 | 644 | ||
4756 | 636 | VisualPlace andM0 = stg.createPlace(nameAndM + name + name0); | 645 | VisualPlace andM0 = stg.createPlace(nameAndM + name + name0, curContainer); |
4757 | 637 | andM0.setLabel(labelAndM + name + label0); | 646 | andM0.setLabel(labelAndM + name + label0); |
4758 | 638 | andM0.setLabelPositioning(Positioning.BOTTOM); | 647 | andM0.setLabelPositioning(Positioning.BOTTOM); |
4759 | 639 | if (!r.getReferencedCounterflowRegister().isAndMarked()) { | 648 | if (!r.getReferencedCounterflowRegister().isAndMarked()) { |
4760 | @@ -644,7 +653,7 @@ | |||
4761 | 644 | setPosition(andM0, x + 2.0, y + 4.0); | 653 | setPosition(andM0, x + 2.0, y + 4.0); |
4762 | 645 | nodes.add(andM0); | 654 | nodes.add(andM0); |
4763 | 646 | 655 | ||
4765 | 647 | VisualPlace andM1 = stg.createPlace(nameAndM + name + name1); | 656 | VisualPlace andM1 = stg.createPlace(nameAndM + name + name1, curContainer); |
4766 | 648 | andM1.setLabel(labelAndM + name + label1); | 657 | andM1.setLabel(labelAndM + name + label1); |
4767 | 649 | andM1.setLabelPositioning(Positioning.TOP); | 658 | andM1.setLabelPositioning(Positioning.TOP); |
4768 | 650 | if (r.getReferencedCounterflowRegister().isAndMarked()) { | 659 | if (r.getReferencedCounterflowRegister().isAndMarked()) { |
4769 | @@ -655,13 +664,13 @@ | |||
4770 | 655 | setPosition(andM1, x + 2.0, y + 2.0); | 664 | setPosition(andM1, x + 2.0, y + 2.0); |
4771 | 656 | nodes.add(andM1); | 665 | nodes.add(andM1); |
4772 | 657 | 666 | ||
4774 | 658 | VisualSignalTransition andMR = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.PLUS); | 667 | VisualSignalTransition andMR = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.PLUS, curContainer); |
4775 | 659 | createConsumingArc(andM0, andMR, false); | 668 | createConsumingArc(andM0, andMR, false); |
4776 | 660 | createProducingArc(andMR, andM1, false); | 669 | createProducingArc(andMR, andM1, false); |
4777 | 661 | setPosition(andMR, x - 2.0, y + 4.0); | 670 | setPosition(andMR, x - 2.0, y + 4.0); |
4778 | 662 | nodes.add(andMR); | 671 | nodes.add(andMR); |
4779 | 663 | 672 | ||
4781 | 664 | VisualSignalTransition andMF = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.MINUS); | 673 | VisualSignalTransition andMF = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.MINUS, curContainer); |
4782 | 665 | createConsumingArc(andM1, andMF, false); | 674 | createConsumingArc(andM1, andMF, false); |
4783 | 666 | createProducingArc(andMF, andM0, false); | 675 | createProducingArc(andMF, andM0, false); |
4784 | 667 | setPosition(andMF, x - 2.0, y + 2.0); | 676 | setPosition(andMF, x - 2.0, y + 2.0); |
4785 | @@ -749,8 +758,9 @@ | |||
4786 | 749 | type = SignalTransition.Type.OUTPUT; | 758 | type = SignalTransition.Type.OUTPUT; |
4787 | 750 | } | 759 | } |
4788 | 751 | ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0); | 760 | ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0); |
4789 | 761 | Container curContainer = null; | ||
4790 | 752 | 762 | ||
4792 | 753 | VisualPlace M0 = stg.createPlace(nameM + name + name0); | 763 | VisualPlace M0 = stg.createPlace(nameM + name + name0, curContainer); |
4793 | 754 | M0.setLabel(labelM + name + label0); | 764 | M0.setLabel(labelM + name + label0); |
4794 | 755 | M0.setLabelPositioning(Positioning.BOTTOM); | 765 | M0.setLabelPositioning(Positioning.BOTTOM); |
4795 | 756 | if (!r.getReferencedBinaryRegister().isTrueMarked() && !r.getReferencedBinaryRegister().isFalseMarked()) { | 766 | if (!r.getReferencedBinaryRegister().isTrueMarked() && !r.getReferencedBinaryRegister().isFalseMarked()) { |
4796 | @@ -761,7 +771,7 @@ | |||
4797 | 761 | setPosition(M0, x - 4.0, y + 1.0); | 771 | setPosition(M0, x - 4.0, y + 1.0); |
4798 | 762 | nodes.add(M0); | 772 | nodes.add(M0); |
4799 | 763 | 773 | ||
4801 | 764 | VisualPlace M1 = stg.createPlace(nameM + name + name1); | 774 | VisualPlace M1 = stg.createPlace(nameM + name + name1, curContainer); |
4802 | 765 | M1.setLabel(labelM + name + label1); | 775 | M1.setLabel(labelM + name + label1); |
4803 | 766 | M1.setLabelPositioning(Positioning.TOP); | 776 | M1.setLabelPositioning(Positioning.TOP); |
4804 | 767 | if (r.getReferencedBinaryRegister().isTrueMarked() || r.getReferencedBinaryRegister().isFalseMarked()) { | 777 | if (r.getReferencedBinaryRegister().isTrueMarked() || r.getReferencedBinaryRegister().isFalseMarked()) { |
4805 | @@ -772,7 +782,7 @@ | |||
4806 | 772 | setPosition(M1, x - 4.0, y - 1.0); | 782 | setPosition(M1, x - 4.0, y - 1.0); |
4807 | 773 | nodes.add(M1); | 783 | nodes.add(M1); |
4808 | 774 | 784 | ||
4810 | 775 | VisualPlace tM0 = stg.createPlace(nameTrueM + name + name0); | 785 | VisualPlace tM0 = stg.createPlace(nameTrueM + name + name0, curContainer); |
4811 | 776 | tM0.setLabel(labelTrueM + name + label0); | 786 | tM0.setLabel(labelTrueM + name + label0); |
4812 | 777 | tM0.setLabelPositioning(Positioning.BOTTOM); | 787 | tM0.setLabelPositioning(Positioning.BOTTOM); |
4813 | 778 | if (!r.getReferencedBinaryRegister().isTrueMarked()) { | 788 | if (!r.getReferencedBinaryRegister().isTrueMarked()) { |
4814 | @@ -783,7 +793,7 @@ | |||
4815 | 783 | setPosition(tM0, x + 4.0, y - 2.0); | 793 | setPosition(tM0, x + 4.0, y - 2.0); |
4816 | 784 | nodes.add(tM0); | 794 | nodes.add(tM0); |
4817 | 785 | 795 | ||
4819 | 786 | VisualPlace tM1 = stg.createPlace(nameTrueM + name + name1); | 796 | VisualPlace tM1 = stg.createPlace(nameTrueM + name + name1, curContainer); |
4820 | 787 | tM1.setLabel(labelTrueM + name + label1); | 797 | tM1.setLabel(labelTrueM + name + label1); |
4821 | 788 | tM1.setLabelPositioning(Positioning.TOP); | 798 | tM1.setLabelPositioning(Positioning.TOP); |
4822 | 789 | if (r.getReferencedBinaryRegister().isTrueMarked()) { | 799 | if (r.getReferencedBinaryRegister().isTrueMarked()) { |
4823 | @@ -805,7 +815,7 @@ | |||
4824 | 805 | double dy = 0.0; | 815 | double dy = 0.0; |
4825 | 806 | for (Node n: preset) { | 816 | for (Node n: preset) { |
4826 | 807 | if (tMR == null || orSync) { | 817 | if (tMR == null || orSync) { |
4828 | 808 | tMR = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.PLUS); | 818 | tMR = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.PLUS, curContainer); |
4829 | 809 | tMR.setTokenColorGenerator(tokenColorGenerator); | 819 | tMR.setTokenColorGenerator(tokenColorGenerator); |
4830 | 810 | createConsumingArc(tM0, tMR, false); | 820 | createConsumingArc(tM0, tMR, false); |
4831 | 811 | createProducingArc(tMR, tM1, true); | 821 | createProducingArc(tMR, tM1, true); |
4832 | @@ -817,7 +827,7 @@ | |||
4833 | 817 | tMRs.put(n, tMR); | 827 | tMRs.put(n, tMR); |
4834 | 818 | dy += 1.0; | 828 | dy += 1.0; |
4835 | 819 | } | 829 | } |
4837 | 820 | VisualSignalTransition tMF = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.MINUS); | 830 | VisualSignalTransition tMF = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.MINUS, curContainer); |
4838 | 821 | createConsumingArc(tM1, tMF, false); | 831 | createConsumingArc(tM1, tMF, false); |
4839 | 822 | createProducingArc(tMF, tM0, false); | 832 | createProducingArc(tMF, tM0, false); |
4840 | 823 | createConsumingArc(M1, tMF, false); | 833 | createConsumingArc(M1, tMF, false); |
4841 | @@ -825,7 +835,8 @@ | |||
4842 | 825 | setPosition(tMF, x, y - 4.0 - dy); | 835 | setPosition(tMF, x, y - 4.0 - dy); |
4843 | 826 | nodes.add(tMF); | 836 | nodes.add(tMF); |
4844 | 827 | 837 | ||
4846 | 828 | VisualPlace fM0 = stg.createPlace(nameFalseM + name + name0); | 838 | |
4847 | 839 | VisualPlace fM0 = stg.createPlace(nameFalseM + name + name0, curContainer); | ||
4848 | 829 | fM0.setLabel(labelFalseM + name + label0); | 840 | fM0.setLabel(labelFalseM + name + label0); |
4849 | 830 | fM0.setLabelPositioning(Positioning.BOTTOM); | 841 | fM0.setLabelPositioning(Positioning.BOTTOM); |
4850 | 831 | if (!r.getReferencedBinaryRegister().isFalseMarked()) { | 842 | if (!r.getReferencedBinaryRegister().isFalseMarked()) { |
4851 | @@ -836,7 +847,7 @@ | |||
4852 | 836 | setPosition(fM0, x + 4.0, y + 4.0); | 847 | setPosition(fM0, x + 4.0, y + 4.0); |
4853 | 837 | nodes.add(fM0); | 848 | nodes.add(fM0); |
4854 | 838 | 849 | ||
4856 | 839 | VisualPlace fM1 = stg.createPlace(nameFalseM + name + name1); | 850 | VisualPlace fM1 = stg.createPlace(nameFalseM + name + name1, curContainer); |
4857 | 840 | fM1.setLabel(labelFalseM + name + label1); | 851 | fM1.setLabel(labelFalseM + name + label1); |
4858 | 841 | fM1.setLabelPositioning(Positioning.TOP); | 852 | fM1.setLabelPositioning(Positioning.TOP); |
4859 | 842 | if (r.getReferencedBinaryRegister().isFalseMarked()) { | 853 | if (r.getReferencedBinaryRegister().isFalseMarked()) { |
4860 | @@ -852,7 +863,7 @@ | |||
4861 | 852 | dy = 0.0; | 863 | dy = 0.0; |
4862 | 853 | for (Node n: preset) { | 864 | for (Node n: preset) { |
4863 | 854 | if (fMR == null || andSync) { | 865 | if (fMR == null || andSync) { |
4865 | 855 | fMR = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.PLUS); | 866 | fMR = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.PLUS, curContainer); |
4866 | 856 | fMR.setTokenColorGenerator(tokenColorGenerator); | 867 | fMR.setTokenColorGenerator(tokenColorGenerator); |
4867 | 857 | createConsumingArc(fM0, fMR, false); | 868 | createConsumingArc(fM0, fMR, false); |
4868 | 858 | createProducingArc(fMR, fM1, true); | 869 | createProducingArc(fMR, fM1, true); |
4869 | @@ -864,7 +875,7 @@ | |||
4870 | 864 | fMRs.put(n, fMR); | 875 | fMRs.put(n, fMR); |
4871 | 865 | dy += 1.0; | 876 | dy += 1.0; |
4872 | 866 | } | 877 | } |
4874 | 867 | VisualSignalTransition fMF = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.MINUS); | 878 | VisualSignalTransition fMF = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.MINUS, curContainer); |
4875 | 868 | createConsumingArc(fM1, fMF, false); | 879 | createConsumingArc(fM1, fMF, false); |
4876 | 869 | createProducingArc(fMF, fM0, false); | 880 | createProducingArc(fMF, fM0, false); |
4877 | 870 | createConsumingArc(M1, fMF, false); | 881 | createConsumingArc(M1, fMF, false); |
4878 | 871 | 882 | ||
4879 | === modified file 'GraphPlugin/src/org/workcraft/plugins/graph/ToolsProvider.java' | |||
4880 | --- GraphPlugin/src/org/workcraft/plugins/graph/ToolsProvider.java 2013-11-08 13:40:13 +0000 | |||
4881 | +++ GraphPlugin/src/org/workcraft/plugins/graph/ToolsProvider.java 2014-07-11 09:42:10 +0000 | |||
4882 | @@ -2,12 +2,14 @@ | |||
4883 | 2 | 2 | ||
4884 | 3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4885 | 4 | 4 | ||
4886 | 5 | import org.workcraft.dom.math.PageNode; | ||
4887 | 5 | import org.workcraft.gui.graph.tools.CommentGeneratorTool; | 6 | import org.workcraft.gui.graph.tools.CommentGeneratorTool; |
4888 | 6 | import org.workcraft.gui.graph.tools.ConnectionTool; | 7 | import org.workcraft.gui.graph.tools.ConnectionTool; |
4889 | 7 | import org.workcraft.gui.graph.tools.CustomToolsProvider; | 8 | import org.workcraft.gui.graph.tools.CustomToolsProvider; |
4890 | 8 | import org.workcraft.gui.graph.tools.DefaultNodeGenerator; | 9 | import org.workcraft.gui.graph.tools.DefaultNodeGenerator; |
4891 | 9 | import org.workcraft.gui.graph.tools.GraphEditorTool; | 10 | import org.workcraft.gui.graph.tools.GraphEditorTool; |
4892 | 10 | import org.workcraft.gui.graph.tools.NodeGeneratorTool; | 11 | import org.workcraft.gui.graph.tools.NodeGeneratorTool; |
4893 | 12 | import org.workcraft.gui.graph.tools.PageGeneratorTool; | ||
4894 | 11 | import org.workcraft.gui.graph.tools.SelectionTool; | 13 | import org.workcraft.gui.graph.tools.SelectionTool; |
4895 | 12 | 14 | ||
4896 | 13 | public class ToolsProvider implements CustomToolsProvider { | 15 | public class ToolsProvider implements CustomToolsProvider { |
4897 | @@ -18,6 +20,7 @@ | |||
4898 | 18 | 20 | ||
4899 | 19 | result.add(new SelectionTool()); | 21 | result.add(new SelectionTool()); |
4900 | 20 | result.add(new CommentGeneratorTool()); | 22 | result.add(new CommentGeneratorTool()); |
4901 | 23 | result.add(new PageGeneratorTool(new DefaultNodeGenerator(PageNode.class))); | ||
4902 | 21 | result.add(new ConnectionTool(true, false)); | 24 | result.add(new ConnectionTool(true, false)); |
4903 | 22 | result.add(new NodeGeneratorTool(new DefaultNodeGenerator(Vertex.class))); | 25 | result.add(new NodeGeneratorTool(new DefaultNodeGenerator(Vertex.class))); |
4904 | 23 | return result; | 26 | return result; |
4905 | 24 | 27 | ||
4906 | === modified file 'GraphPlugin/src/org/workcraft/plugins/graph/VisualGraph.java' | |||
4907 | --- GraphPlugin/src/org/workcraft/plugins/graph/VisualGraph.java 2013-11-08 13:40:13 +0000 | |||
4908 | +++ GraphPlugin/src/org/workcraft/plugins/graph/VisualGraph.java 2014-07-11 09:42:10 +0000 | |||
4909 | @@ -65,6 +65,7 @@ | |||
4910 | 65 | public void connect(Node first, Node second) throws InvalidConnectionException { | 65 | public void connect(Node first, Node second) throws InvalidConnectionException { |
4911 | 66 | validateConnection(first, second); | 66 | validateConnection(first, second); |
4912 | 67 | 67 | ||
4913 | 68 | |||
4914 | 68 | VisualComponent c1 = (VisualComponent) first; | 69 | VisualComponent c1 = (VisualComponent) first; |
4915 | 69 | VisualComponent c2 = (VisualComponent) second; | 70 | VisualComponent c2 = (VisualComponent) second; |
4916 | 70 | 71 | ||
4917 | 71 | 72 | ||
4918 | === modified file 'MpsatPlugin/src/org/workcraft/plugins/mpsat/MpsatResultParser.java' | |||
4919 | --- MpsatPlugin/src/org/workcraft/plugins/mpsat/MpsatResultParser.java 2010-10-06 15:51:01 +0000 | |||
4920 | +++ MpsatPlugin/src/org/workcraft/plugins/mpsat/MpsatResultParser.java 2014-07-11 09:42:10 +0000 | |||
4921 | @@ -8,6 +8,7 @@ | |||
4922 | 8 | import java.util.regex.Pattern; | 8 | import java.util.regex.Pattern; |
4923 | 9 | 9 | ||
4924 | 10 | import org.workcraft.Trace; | 10 | import org.workcraft.Trace; |
4925 | 11 | import org.workcraft.dom.hierarchy.NamespaceHelper; | ||
4926 | 11 | import org.workcraft.plugins.shared.tasks.ExternalProcessResult; | 12 | import org.workcraft.plugins.shared.tasks.ExternalProcessResult; |
4927 | 12 | 13 | ||
4928 | 13 | public class MpsatResultParser { | 14 | public class MpsatResultParser { |
4929 | @@ -34,6 +35,8 @@ | |||
4930 | 34 | String[] ss = mpsatTrace.split(","); | 35 | String[] ss = mpsatTrace.split(","); |
4931 | 35 | 36 | ||
4932 | 36 | for (String k: ss) { | 37 | for (String k: ss) { |
4933 | 38 | k=k.replace(NamespaceHelper.flatNameSeparator, NamespaceHelper.hierarchySeparator); | ||
4934 | 39 | |||
4935 | 37 | if (k.charAt(1) == '.') | 40 | if (k.charAt(1) == '.') |
4936 | 38 | trace.add(k.substring(2).trim()); | 41 | trace.add(k.substring(2).trim()); |
4937 | 39 | else | 42 | else |
4938 | 40 | 43 | ||
4939 | === modified file 'PetriNetPlugin/src/org/workcraft/plugins/petri/PetriNet.java' | |||
4940 | --- PetriNetPlugin/src/org/workcraft/plugins/petri/PetriNet.java 2013-10-07 09:51:12 +0000 | |||
4941 | +++ PetriNetPlugin/src/org/workcraft/plugins/petri/PetriNet.java 2014-07-11 09:42:10 +0000 | |||
4942 | @@ -29,10 +29,12 @@ | |||
4943 | 29 | import org.workcraft.dom.Connection; | 29 | import org.workcraft.dom.Connection; |
4944 | 30 | import org.workcraft.dom.Container; | 30 | import org.workcraft.dom.Container; |
4945 | 31 | import org.workcraft.dom.Node; | 31 | import org.workcraft.dom.Node; |
4946 | 32 | import org.workcraft.dom.hierarchy.NamespaceProvider; | ||
4947 | 32 | import org.workcraft.dom.math.AbstractMathModel; | 33 | import org.workcraft.dom.math.AbstractMathModel; |
4948 | 33 | import org.workcraft.dom.math.MathConnection; | 34 | import org.workcraft.dom.math.MathConnection; |
4949 | 35 | import org.workcraft.dom.math.MathGroup; | ||
4950 | 34 | import org.workcraft.dom.math.MathNode; | 36 | import org.workcraft.dom.math.MathNode; |
4952 | 35 | import org.workcraft.dom.references.UniqueNameReferenceManager; | 37 | import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager; |
4953 | 36 | import org.workcraft.exceptions.InvalidConnectionException; | 38 | import org.workcraft.exceptions.InvalidConnectionException; |
4954 | 37 | import org.workcraft.exceptions.ModelValidationException; | 39 | import org.workcraft.exceptions.ModelValidationException; |
4955 | 38 | import org.workcraft.gui.propertyeditor.Properties; | 40 | import org.workcraft.gui.propertyeditor.Properties; |
4956 | @@ -44,7 +46,7 @@ | |||
4957 | 44 | public class PetriNet extends AbstractMathModel implements PetriNetModel { | 46 | public class PetriNet extends AbstractMathModel implements PetriNetModel { |
4958 | 45 | 47 | ||
4959 | 46 | public PetriNet() { | 48 | public PetriNet() { |
4961 | 47 | this(null, null); | 49 | this(new MathGroup(), null); |
4962 | 48 | } | 50 | } |
4963 | 49 | 51 | ||
4964 | 50 | public PetriNet(Container root) { | 52 | public PetriNet(Container root) { |
4965 | @@ -61,7 +63,7 @@ | |||
4966 | 61 | } | 63 | } |
4967 | 62 | 64 | ||
4968 | 63 | public PetriNet(Container root, References refs, final Func<Node, String> nodePrefixFunc) { | 65 | public PetriNet(Container root, References refs, final Func<Node, String> nodePrefixFunc) { |
4970 | 64 | super(root, new UniqueNameReferenceManager(refs, new Func<Node, String>() { | 66 | super(root, new HierarchicalUniqueNameReferenceManager(refs, new Func<Node, String>() { |
4971 | 65 | @Override | 67 | @Override |
4972 | 66 | public String eval(Node arg) { | 68 | public String eval(Node arg) { |
4973 | 67 | String result = nodePrefixFunc.eval(arg); | 69 | String result = nodePrefixFunc.eval(arg); |
4974 | @@ -79,15 +81,9 @@ | |||
4975 | 79 | return result; | 81 | return result; |
4976 | 80 | } | 82 | } |
4977 | 81 | })); | 83 | })); |
4987 | 82 | } | 84 | |
4988 | 83 | 85 | } | |
4989 | 84 | public void setName(Node node, String name) { | 86 | |
4981 | 85 | ((UniqueNameReferenceManager)getReferenceManager()).setName(node, name); | ||
4982 | 86 | } | ||
4983 | 87 | |||
4984 | 88 | public String getName(Node node) { | ||
4985 | 89 | return ((UniqueNameReferenceManager)getReferenceManager()).getName(node); | ||
4986 | 90 | } | ||
4990 | 91 | 87 | ||
4991 | 92 | final public Place createPlace(String name) { | 88 | final public Place createPlace(String name) { |
4992 | 93 | Place newPlace = new Place(); | 89 | Place newPlace = new Place(); |
4993 | @@ -125,7 +121,6 @@ | |||
4994 | 125 | final public Collection<Transition> getTransitions() { | 121 | final public Collection<Transition> getTransitions() { |
4995 | 126 | return Hierarchy.getDescendantsOfType(getRoot(), Transition.class); | 122 | return Hierarchy.getDescendantsOfType(getRoot(), Transition.class); |
4996 | 127 | } | 123 | } |
4997 | 128 | |||
4998 | 129 | 124 | ||
4999 | 130 | public boolean isUnfireEnabled(Transition t) { | 125 | public boolean isUnfireEnabled(Transition t) { |
5000 | 131 | return isUnfireEnabled (this, t); | 126 | return isUnfireEnabled (this, t); |
The diff has been truncated for viewing.