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