Merge lp:~sgaflv/workcraft/trunk-hierarchical into lp:workcraft

Proposed by Stan
Status: Merged
Merged at revision: 516
Proposed branch: lp:~sgaflv/workcraft/trunk-hierarchical
Merge into: lp:workcraft
Diff against target: 21953 lines
To merge this branch: bzr merge lp:~sgaflv/workcraft/trunk-hierarchical
Reviewer Review Type Date Requested Status
Danil Sokolov Approve
Review via email: mp+226425@code.launchpad.net

Description of the change

- adding pages, hierarchical names and namespaces
- adaptation to all model types, also simulation, verification, and traces

To post a comment you must log in.
Revision history for this message
Danil Sokolov (danilovesky) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2010-10-07 15:30:31 +0000
+++ .bzrignore 2014-07-11 09:42:10 +0000
@@ -10,4 +10,8 @@
10generated10generated
11/.metadata11/.metadata
12*.jar12*.jar
1313*.orig
14*.moved
15*.BASE
16*.OTHER
17*.THIS
14\ No newline at end of file18\ No newline at end of file
1519
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/Circuit.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/Circuit.java 2010-10-08 15:48:47 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/Circuit.java 2014-07-11 09:42:10 +0000
@@ -21,24 +21,79 @@
2121
22package org.workcraft.plugins.circuit;22package org.workcraft.plugins.circuit;
2323
24import org.workcraft.dom.Connection;
25import org.workcraft.dom.Container;
24import org.workcraft.dom.Node;26import org.workcraft.dom.Node;
27import org.workcraft.dom.hierarchy.NamespaceProvider;
25import org.workcraft.dom.math.AbstractMathModel;28import org.workcraft.dom.math.AbstractMathModel;
29import org.workcraft.dom.math.CommentNode;
26import org.workcraft.dom.math.MathConnection;30import org.workcraft.dom.math.MathConnection;
27import org.workcraft.dom.math.MathGroup;31import org.workcraft.dom.math.MathGroup;
28import org.workcraft.dom.math.MathNode;32import org.workcraft.dom.math.MathNode;
33import org.workcraft.dom.math.PageNode;
34import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager;
29import org.workcraft.exceptions.InvalidConnectionException;35import org.workcraft.exceptions.InvalidConnectionException;
30import org.workcraft.exceptions.ModelValidationException;36import org.workcraft.exceptions.ModelValidationException;
37import org.workcraft.gui.propertyeditor.DefaultNamePropertyDescriptor;
38import org.workcraft.gui.propertyeditor.Properties;
39import org.workcraft.plugins.circuit.Contact.IOType;
40import org.workcraft.plugins.circuit.references.CircuitReferenceManager;
41import org.workcraft.serialisation.References;
42import org.workcraft.util.Func;
31import org.workcraft.util.Hierarchy;43import org.workcraft.util.Hierarchy;
44import org.workcraft.util.Identifier;
45
3246
33public class Circuit extends AbstractMathModel {47public class Circuit extends AbstractMathModel {
3448
49
35 public Circuit() {50 public Circuit() {
36 this(null);51 this(new MathGroup());
37 }52 }
38 53
39 public Circuit(MathGroup root) {54 public Circuit(MathGroup root) {
40 super(root);55 this(root, null);
41 }56 }
57
58
59 public Circuit(Container root, References refs) {
60
61 super(root,
62 new CircuitReferenceManager((NamespaceProvider)root, refs, new Func<Node, String>() {
63 @Override
64 public String eval(Node arg) {
65 if (arg instanceof CircuitComponent) return "cc";
66 if (arg instanceof Contact) {
67 Contact cont = (Contact)arg;
68
69 if (cont.getParent() instanceof CircuitComponent)
70 return "x";
71
72 if (cont.getIOType()==IOType.INPUT)
73 return "in";
74 else
75 return "out";
76
77 }
78
79 if (arg instanceof Connection) return "con";
80 if (arg instanceof PageNode) return "pg";
81 if (arg instanceof CommentNode) return "comment";
82
83 if (arg instanceof Container) return "gr";
84
85 return "v";
86 }
87 }
88
89 ));
90
91 if (root==null) {
92 Container r = getRoot();
93 getReferenceManager().attach(r);
94 }
95 }
96
4297
43 public void validate() throws ModelValidationException {98 public void validate() throws ModelValidationException {
44 }99 }
@@ -51,5 +106,18 @@
51 106
52 return con;107 return con;
53 }108 }
109
110
111 @Override
112 public Properties getProperties(Node node) {
113 if (node != null) {
114 if (node instanceof CircuitComponent)
115 return Properties.Mix.from(new DefaultNamePropertyDescriptor(this, node));
116 if (node instanceof Contact)
117 return Properties.Mix.from(new DefaultNamePropertyDescriptor(this, node));
118 }
119 return super.getProperties(node);
120 }
121
54122
55}123}
56124
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java 2013-08-22 18:27:32 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java 2014-07-11 09:42:10 +0000
@@ -29,6 +29,7 @@
29import org.workcraft.dom.Container;29import org.workcraft.dom.Container;
30import org.workcraft.dom.DefaultGroupImpl;30import org.workcraft.dom.DefaultGroupImpl;
31import org.workcraft.dom.Node;31import org.workcraft.dom.Node;
32import org.workcraft.dom.math.MathGroup;
32import org.workcraft.dom.math.MathNode;33import org.workcraft.dom.math.MathNode;
33import org.workcraft.observation.HierarchyObserver;34import org.workcraft.observation.HierarchyObserver;
34import org.workcraft.observation.ObservableHierarchy;35import org.workcraft.observation.ObservableHierarchy;
@@ -39,10 +40,11 @@
39@DisplayName("Component")40@DisplayName("Component")
40@VisualClass(org.workcraft.plugins.circuit.VisualCircuitComponent.class)41@VisualClass(org.workcraft.plugins.circuit.VisualCircuitComponent.class)
4142
42public class CircuitComponent extends MathNode implements Container, ObservableHierarchy {43public class CircuitComponent extends MathGroup implements Container, ObservableHierarchy {
43 44
44 DefaultGroupImpl groupImpl = new DefaultGroupImpl(this);45 DefaultGroupImpl groupImpl = new DefaultGroupImpl(this);
45 private String name = "";46 private String name = "";
47
46 private boolean isEnvironment;48 private boolean isEnvironment;
4749
48 public boolean getIsEnvironment() {50 public boolean getIsEnvironment() {
@@ -59,7 +61,7 @@
5961
60 public void setParent(Node parent) {62 public void setParent(Node parent) {
61 groupImpl.setParent(parent);63 groupImpl.setParent(parent);
62 checkName(parent);64 //checkName(parent);
63 }65 }
64 66
65 public void addObserver(HierarchyObserver obs) {67 public void addObserver(HierarchyObserver obs) {
@@ -98,7 +100,7 @@
98 @Override100 @Override
99 public void reparent(Collection<Node> nodes, Container newParent) {101 public void reparent(Collection<Node> nodes, Container newParent) {
100 groupImpl.reparent(nodes, newParent);102 groupImpl.reparent(nodes, newParent);
101 checkName(newParent);103 //checkName(newParent);
102 }104 }
103105
104 @Override106 @Override
@@ -118,35 +120,35 @@
118 return result;120 return result;
119 }121 }
120122
121 public String getNewName(Node n, String start) {123// public String getNewName(Node n, String start) {
122 // iterate through all contacts, check that the name doesn't exist124// // iterate through all contacts, check that the name doesn't exist
123 int num=0;125// int num=0;
124 boolean found = true;126// boolean found = true;
125 127//
126 while (found) {128// while (found) {
127 num++;129// num++;
128 found=false;130// found=false;
129 131//
130 for (Node vn : n.getChildren()) {132// for (Node vn : n.getChildren()) {
131 if (vn instanceof CircuitComponent && vn!=this) {133// if (vn instanceof CircuitComponent && vn!=this) {
132 if (((CircuitComponent)vn).getName().equals(start+num)) {134// if (((CircuitComponent)vn).getName().equals(start+num)) {
133 found=true;135// found=true;
134 break;136// break;
135 }137// }
136 }138// }
137 }139// }
138 }140// }
139 return start+num;141// return start+num;
140 }142// }
141 143
142 public void checkName(Node parent) {144// public void checkName(Node parent) {
143 if (parent==null) return;145// if (parent==null) return;
144 String start=getName();146// String start=getName();
145 if (start==null||start=="") {147// if (start==null||start=="") {
146 start="c";148// start="c";
147 setName(getNewName(parent, start));149// setName(getNewName(parent, start));
148 }150// }
149 }151// }
150152
151 public void setName(String name) {153 public void setName(String name) {
152 this.name = name;154 this.name = name;
153155
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitModelDescriptor.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitModelDescriptor.java 2010-11-30 01:14:08 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitModelDescriptor.java 2014-07-11 09:42:10 +0000
@@ -2,6 +2,7 @@
22
3import org.workcraft.dom.ModelDescriptor;3import org.workcraft.dom.ModelDescriptor;
4import org.workcraft.dom.VisualModelDescriptor;4import org.workcraft.dom.VisualModelDescriptor;
5import org.workcraft.dom.math.MathGroup;
5import org.workcraft.dom.math.MathModel;6import org.workcraft.dom.math.MathModel;
6import org.workcraft.dom.visual.VisualModel;7import org.workcraft.dom.visual.VisualModel;
7import org.workcraft.exceptions.VisualModelInstantiationException;8import org.workcraft.exceptions.VisualModelInstantiationException;
89
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java 2014-06-27 14:48:42 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java 2014-07-11 09:42:10 +0000
@@ -19,8 +19,8 @@
19*19*
20*/20*/
2121
22package org.workcraft.plugins.circuit;22package org.workcraft.plugins.circuit;
2323
24import java.util.LinkedHashMap;24import java.util.LinkedHashMap;
25import java.util.Map;25import java.util.Map;
2626
@@ -32,10 +32,10 @@
32import org.workcraft.plugins.cpog.optimisation.BooleanVariable;32import org.workcraft.plugins.cpog.optimisation.BooleanVariable;
33import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor;33import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor;
3434
35@DisplayName("Contact")35@DisplayName("Contact")
36@VisualClass(org.workcraft.plugins.circuit.VisualContact.class)36@VisualClass(org.workcraft.plugins.circuit.VisualContact.class)
3737
38public class Contact extends MathNode implements BooleanVariable {38public class Contact extends MathNode implements BooleanVariable {
3939
40 public enum IOType {40 public enum IOType {
41 INPUT("Input"),41 INPUT("Input"),
@@ -70,82 +70,29 @@
70 sendNotification(new PropertyChangedEvent(this, "initOne"));70 sendNotification(new PropertyChangedEvent(this, "initOne"));
71 }71 }
7272
73 public Contact() {73 public Contact() {
74 }74 }
75 75
76 public Contact(IOType iot) {76 public Contact(IOType iot) {
77 super();77 super();
78 setIOType(iot);78 setIOType(iot);
79 }79 }
80 80
81 static public String getNewName(Node paren, String prefix, Node node, boolean allowShort) {81 public void setIOType(IOType t) {
82 // iterate through all contacts, check that the name doesn't exist
83 int index=0;
84 boolean found = false;
85 if (allowShort) {
86 for (Node n : paren.getChildren()) {
87 if (n instanceof Contact && n != node) {
88 if (((Contact)n).getName().equals(prefix)) {
89 found = true;
90 break;
91 }
92 }
93 }
94 if (!found) return prefix;
95 }
96 do {
97 found = false;
98 index++;
99 for (Node n : paren.getChildren()) {
100 if (n instanceof Contact && n != node) {
101 if (((Contact)n).getName().equals(prefix + index)) {
102 found = true;
103 break;
104 }
105 }
106 }
107 } while (found);
108 return (prefix + index);
109 }
110
111 public void checkName(Node parent) {
112 if (parent == null) return;
113 String prefix = getName();
114 if (prefix == null || prefix == "") {
115 if (getIOType()==IOType.INPUT) {
116 prefix="input";
117 } else {
118 prefix="output";
119 }
120 setName(getNewName(parent, prefix, this, false));
121 }
122 }
123
124 @Override
125 public void setParent(Node parent) {
126 super.setParent(parent);
127 checkName(parent);
128 }
129
130 public void setIOType(IOType t) {
131 this.ioType = t;82 this.ioType = t;
132 if (getName().startsWith("input") && getIOType()==IOType.OUTPUT) {83 sendNotification(new PropertyChangedEvent(this, "ioType"));
133 setName(getNewName(getParent(), "output", this, false));84 }
134 } else if (getName().startsWith("output") && getIOType()==IOType.INPUT) {85
135 setName(getNewName(getParent(), "input", this, false));86 public IOType getIOType() {
136 }87 return ioType;
137 sendNotification(new PropertyChangedEvent(this, "ioType"));88 }
138 }89
139 90 // this is only for information, use Circuit to set component's names
140 public IOType getIOType() {
141 return ioType;
142 }
143
144 public void setName(String name) {91 public void setName(String name) {
145 this.name = name;92 this.name = name;
146 sendNotification(new PropertyChangedEvent(this, "name"));93 sendNotification(new PropertyChangedEvent(this, "name"));
147 }94 }
14895
149 public String getName() {96 public String getName() {
150 return name;97 return name;
151 }98 }
@@ -160,4 +107,4 @@
160 return getName();107 return getName();
161 }108 }
162109
163}110}
164111
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java 2014-06-27 14:48:42 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java 2014-07-11 09:42:10 +0000
@@ -28,16 +28,22 @@
28import org.workcraft.annotations.CustomTools;28import org.workcraft.annotations.CustomTools;
29import org.workcraft.annotations.DisplayName;29import org.workcraft.annotations.DisplayName;
30import org.workcraft.dom.Connection;30import org.workcraft.dom.Connection;
31import org.workcraft.dom.Container;
31import org.workcraft.dom.Node;32import org.workcraft.dom.Node;
33import org.workcraft.dom.hierarchy.NamespaceProvider;
32import org.workcraft.dom.math.MathConnection;34import org.workcraft.dom.math.MathConnection;
35import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager;
36import org.workcraft.dom.references.ReferenceManager;
33import org.workcraft.dom.visual.AbstractVisualModel;37import org.workcraft.dom.visual.AbstractVisualModel;
34import org.workcraft.dom.visual.VisualComponent;38import org.workcraft.dom.visual.VisualComponent;
35import org.workcraft.dom.visual.VisualGroup;39import org.workcraft.dom.visual.VisualGroup;
40import org.workcraft.dom.visual.VisualNode;
36import org.workcraft.exceptions.InvalidConnectionException;41import org.workcraft.exceptions.InvalidConnectionException;
37import org.workcraft.exceptions.NodeCreationException;42import org.workcraft.exceptions.NodeCreationException;
38import org.workcraft.exceptions.VisualModelInstantiationException;43import org.workcraft.exceptions.VisualModelInstantiationException;
39import org.workcraft.gui.propertyeditor.Properties;44import org.workcraft.gui.propertyeditor.Properties;
40import org.workcraft.plugins.circuit.Contact.IOType;45import org.workcraft.plugins.circuit.Contact.IOType;
46import org.workcraft.plugins.cpog.optimisation.expressions.One;
41import org.workcraft.serialisation.xml.NoAutoSerialisation;47import org.workcraft.serialisation.xml.NoAutoSerialisation;
42import org.workcraft.util.Hierarchy;48import org.workcraft.util.Hierarchy;
4349
@@ -117,15 +123,93 @@
117 }123 }
118124
119 public VisualFunctionContact getOrCreateOutput(String name, double x, double y) {125 public VisualFunctionContact getOrCreateOutput(String name, double x, double y) {
120 for(VisualFunctionContact c : getVisualFunctionContacts()) {126
121 if(c.getName().equals(name)) return c;127 VisualFunctionContact vc = getOrCreateContact(getCurrentLevel(), name, IOType.OUTPUT, x, y);
122 }128
123 VisualFunctionContact vc = new VisualFunctionContact(new FunctionContact(IOType.OUTPUT));129 return vc;
130
131 }
132
133 public VisualFunctionContact getOrCreateComponentOutput(VisualFunctionComponent component, String name, double x, double y) {
134
135 VisualFunctionContact vc = getOrCreateContact(component, name, IOType.OUTPUT, x, y);
124 vc.setPosition(new Point2D.Double(x, y));136 vc.setPosition(new Point2D.Double(x, y));
125 addFunctionContact(vc);137
126 vc.setName(name);138 return vc;
127 return vc;139 }
128 }140
141 public VisualFunctionContact getOrCreateContact(Container container, String name, IOType ioType, double x, double y) {
142 // here "parent" is a container of a visual model
143
144 if (name!=null) {
145
146 for (Node n: container.getChildren()) {
147 if (n instanceof VisualFunctionContact) {
148 if (getMathModel().getName(((VisualFunctionContact)n).getReferencedContact()).equals(name))
149 return (VisualFunctionContact)n;
150 } // TODO: if found something else with that name, return null?
151 }
152
153 }
154
155 // the name is available
156 // create a new contact if it was not found
157 VisualContact.Direction dir=null;
158 if (ioType==null) ioType = IOType.OUTPUT;
159 dir=VisualContact.Direction.WEST;
160 if (ioType==IOType.OUTPUT)
161 dir=VisualContact.Direction.EAST;
162
163
164
165
166 VisualFunctionContact vc = new VisualFunctionContact(new FunctionContact(ioType));
167 vc.setDirection(dir);
168 vc.setPosition(new Point2D.Double(x, y));
169
170 if (container instanceof VisualFunctionComponent) {
171 VisualFunctionComponent component = (VisualFunctionComponent)container;
172
173 component.addContact(this, vc);
174
175 if (name!=null)
176 circuit.setName(vc.getReferencedComponent(), name);
177
178
179 vc.setSetFunction(One.instance());
180 vc.setResetFunction(One.instance());
181 } else {
182
183 AbstractVisualModel.getMathContainer(this, getRoot()).add(vc.getReferencedComponent());
184 add(vc);
185
186 if (name!=null)
187 circuit.setName(vc.getReferencedComponent(), name);
188
189 }
190
191 return vc;
192 }
193
194// public VisualFunctionContact addFunction(VisualCircuitComponent component, IOType ioType) {
195// VisualContact.Direction dir=null;
196// if (ioType==null) ioType = IOType.OUTPUT;
197// dir=VisualContact.Direction.WEST;
198//
199// if (ioType==IOType.OUTPUT) {
200// dir=VisualContact.Direction.EAST;
201// }
202//
203// FunctionContact c = new FunctionContact(ioType);
204// VisualFunctionContact vc = new VisualFunctionContact(c);
205// vc.setDirection(dir);
206//
207// //circuit.setName(component.getReferencedComponent(), Contact.getNewName(component.getReferencedComponent(), prefix, null, allowShort));
208//
209// component.addContact(vc);
210// return vc;
211// }
212
129 213
130 public void addFunctionComponent(VisualFunctionComponent component) {214 public void addFunctionComponent(VisualFunctionComponent component) {
131 for (Node node : component.getMathReferences()) {215 for (Node node : component.getMathReferences()) {
@@ -141,10 +225,10 @@
141 super.add(joint);225 super.add(joint);
142 }226 }
143 227
144 public void addFunctionContact(VisualFunctionContact contact) {228// public void addFunctionContact(VisualFunctionComponent component, VisualFunctionContact contact) {
145 circuit.add(contact.getReferencedFunctionContact());229// component.add(contact);
146 super.add(contact);230// component.getReferencedCircuitComponent().add(contact.getReferencedContact());
147 }231// }
148232
149 @NoAutoSerialisation233 @NoAutoSerialisation
150 public File getEnvironmentFile() {234 public File getEnvironmentFile() {
@@ -170,14 +254,18 @@
170 Properties properties = super.getProperties(node);254 Properties properties = super.getProperties(node);
171 if (node == null) {255 if (node == null) {
172 properties = Properties.Merge.add(properties, new EnvironmentFilePropertyDescriptor(this));256 properties = Properties.Merge.add(properties, new EnvironmentFilePropertyDescriptor(this));
173 } else if(node instanceof VisualFunctionContact) {257 }
258
259 if (node instanceof VisualFunctionContact) {
174 VisualFunctionContact contact = (VisualFunctionContact)node;260 VisualFunctionContact contact = (VisualFunctionContact)node;
175 VisualContactFormulaProperties props = new VisualContactFormulaProperties(this);261 VisualContactFormulaProperties props = new VisualContactFormulaProperties(this);
262
176 properties = Properties.Merge.add(properties,263 properties = Properties.Merge.add(properties,
177 props.getSetProperty(contact),264 props.getSetProperty(contact),
178 props.getResetProperty(contact));265 props.getResetProperty(contact));
179 }266 }
180 return properties;267 return properties;
181 }268 }
269
182 270
183}271}
184272
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java 2014-06-27 14:48:42 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java 2014-07-11 09:42:10 +0000
@@ -39,6 +39,7 @@
39import org.workcraft.dom.Container;39import org.workcraft.dom.Container;
40import org.workcraft.dom.DefaultGroupImpl;40import org.workcraft.dom.DefaultGroupImpl;
41import org.workcraft.dom.Node;41import org.workcraft.dom.Node;
42import org.workcraft.dom.visual.AbstractVisualModel;
42import org.workcraft.dom.visual.BoundingBoxHelper;43import org.workcraft.dom.visual.BoundingBoxHelper;
43import org.workcraft.dom.visual.CustomTouchable;44import org.workcraft.dom.visual.CustomTouchable;
44import org.workcraft.dom.visual.DrawRequest;45import org.workcraft.dom.visual.DrawRequest;
@@ -86,15 +87,16 @@
86 }87 }
8788
88 private void addPropertyDeclarations() {89 private void addPropertyDeclarations() {
89 addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, String>(90// addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, String>(
90 this, "Name", String.class) {91// this, "Name", String.class) {
91 protected void setter(VisualCircuitComponent object, String value) {92// protected void setter(VisualCircuitComponent object, String value) {
92 object.getReferencedCircuitComponent().setName(value);93// get
93 }94// object.getReferencedCircuitComponent().setName(value);
94 protected String getter(VisualCircuitComponent object) {95// }
95 return object.getReferencedCircuitComponent().getName();96// protected String getter(VisualCircuitComponent object) {
96 }97// return object.getReferencedCircuitComponent().getName();
97 });98// }
99// });
98 100
99 addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, Boolean>(101 addPropertyDeclaration(new PropertyDeclaration<VisualCircuitComponent, Boolean>(
100 this, "Treat as environment", Boolean.class) {102 this, "Treat as environment", Boolean.class) {
@@ -142,13 +144,13 @@
142 return (CircuitComponent)this.getReferencedComponent();144 return (CircuitComponent)this.getReferencedComponent();
143 }145 }
144 146
145 public String getName() {147// public String getName() {
146 return getReferencedCircuitComponent().getName();148// return getReferencedCircuitComponent().getName();
147 }149// }
148 150//
149 public void setName(String value) {151// public void setName(String value) {
150 getReferencedCircuitComponent().setName(value);152// getReferencedCircuitComponent().setName(value);
151 }153// }
152 154
153 public boolean getIsEnvironment() {155 public boolean getIsEnvironment() {
154 if (getReferencedCircuitComponent() != null) {156 if (getReferencedCircuitComponent() != null) {
@@ -241,17 +243,20 @@
241 }243 }
242 }244 }
243245
244 public void updateDirection(VisualContact vc, VisualContact.Direction dir) {246 public void updateDirection(VisualCircuit vcircuit, VisualContact vc, VisualContact.Direction dir) {
245 vc.setDirection(dir);247 vc.setDirection(dir);
246 contactLabelBB = null;248 contactLabelBB = null;
247 updateSidePosition(vc);249 updateSidePosition(vc);
248 updateStepPositions();250 updateStepPositions();
249 }251 }
250252
251 public void addContact(VisualContact vc) {253 public void addContact(VisualCircuit vcircuit, VisualContact vc) {
252 if (!getChildren().contains(vc)) {254 if (!getChildren().contains(vc)) {
253 this.getReferencedCircuitComponent().add(vc.getReferencedComponent());255
256 Container container = AbstractVisualModel.getMathContainer(vcircuit, this);
257 container.add(vc.getReferencedComponent());
254 add(vc);258 add(vc);
259
255 contactLabelBB = null;260 contactLabelBB = null;
256 updateSidePosition(vc);261 updateSidePosition(vc);
257 updateStepPositions();262 updateStepPositions();
@@ -259,7 +264,9 @@
259 }264 }
260 265
261 protected void updateTotalBB() {266 protected void updateTotalBB() {
267
262 totalBB = BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class));268 totalBB = BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class));
269
263 if (contactLabelBB != null && totalBB != null) {270 if (contactLabelBB != null && totalBB != null) {
264 Rectangle2D.union(totalBB, contactLabelBB, totalBB);271 Rectangle2D.union(totalBB, contactLabelBB, totalBB);
265 }272 }
@@ -273,7 +280,7 @@
273 return result;280 return result;
274 }281 }
275282
276 public void updateContactLabelBB(Graphics2D g) {283 public void updateContactLabelBB(Circuit circuit, Graphics2D g) {
277 int north=0;284 int north=0;
278 int south=0;285 int south=0;
279 int east=0;286 int east=0;
@@ -295,7 +302,7 @@
295 for (Node vn: getChildren()) {302 for (Node vn: getChildren()) {
296 if (!(vn instanceof VisualContact)) continue;303 if (!(vn instanceof VisualContact)) continue;
297 VisualContact vc = (VisualContact)vn;304 VisualContact vc = (VisualContact)vn;
298 GlyphVector gv = vc.getNameGlyphs(g);305 GlyphVector gv = vc.getNameGlyphs(circuit, g);
299 Rectangle2D cur = gv.getVisualBounds();306 Rectangle2D cur = gv.getVisualBounds();
300 double xx = (double)(Math.round(cur.getWidth() * 4))/4;307 double xx = (double)(Math.round(cur.getWidth() * 4))/4;
301308
@@ -358,13 +365,15 @@
358 protected void drawContacts(DrawRequest r) {365 protected void drawContacts(DrawRequest r) {
359 Graphics2D g = r.getGraphics();366 Graphics2D g = r.getGraphics();
360 Color colorisation = r.getDecoration().getColorisation();367 Color colorisation = r.getDecoration().getColorisation();
368 Circuit circuit = (Circuit)r.getModel().getMathModel();
369
361 Rectangle2D bb = getBestBB();370 Rectangle2D bb = getBestBB();
362 double step_pos;371 double step_pos;
363 for (Node n: getChildren()) {372 for (Node n: getChildren()) {
364 if (n instanceof VisualContact) {373 if (n instanceof VisualContact) {
365 VisualContact c = (VisualContact)n;374 VisualContact c = (VisualContact)n;
366 if (!c.getDirection().equals(Direction.WEST)) continue;375 if (!c.getDirection().equals(Direction.WEST)) continue;
367 GlyphVector gv = c.getNameGlyphs(g);376 GlyphVector gv = c.getNameGlyphs(circuit, g);
368 Rectangle2D cur = gv.getVisualBounds();377 Rectangle2D cur = gv.getVisualBounds();
369 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));378 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));
370 step_pos = c.getY();379 step_pos = c.getY();
@@ -376,7 +385,7 @@
376 if (n instanceof VisualContact) {385 if (n instanceof VisualContact) {
377 VisualContact c = (VisualContact)n;386 VisualContact c = (VisualContact)n;
378 if (!c.getDirection().equals(Direction.EAST)) continue;387 if (!c.getDirection().equals(Direction.EAST)) continue;
379 GlyphVector gv = c.getNameGlyphs(g);388 GlyphVector gv = c.getNameGlyphs(circuit, g);
380 Rectangle2D cur = gv.getVisualBounds();389 Rectangle2D cur = gv.getVisualBounds();
381 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));390 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));
382 step_pos = c.getY();391 step_pos = c.getY();
@@ -392,7 +401,7 @@
392 if (n instanceof VisualContact) {401 if (n instanceof VisualContact) {
393 VisualContact c = (VisualContact)n;402 VisualContact c = (VisualContact)n;
394 if (!c.getDirection().equals(Direction.NORTH)) continue;403 if (!c.getDirection().equals(Direction.NORTH)) continue;
395 GlyphVector gv = c.getNameGlyphs(g);404 GlyphVector gv = c.getNameGlyphs(circuit, g);
396 Rectangle2D cur = gv.getVisualBounds();405 Rectangle2D cur = gv.getVisualBounds();
397 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));406 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));
398 step_pos = c.getX();407 step_pos = c.getX();
@@ -404,7 +413,7 @@
404 if (n instanceof VisualContact) {413 if (n instanceof VisualContact) {
405 VisualContact c = (VisualContact)n;414 VisualContact c = (VisualContact)n;
406 if (!c.getDirection().equals(Direction.SOUTH)) continue;415 if (!c.getDirection().equals(Direction.SOUTH)) continue;
407 GlyphVector gv = c.getNameGlyphs(g);416 GlyphVector gv = c.getNameGlyphs(circuit, g);
408 Rectangle2D cur = gv.getVisualBounds();417 Rectangle2D cur = gv.getVisualBounds();
409 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));418 g.setColor(Coloriser.colorise((c.getIOType()==IOType.INPUT) ? inputColor : outputColor, colorisation));
410 step_pos = c.getX();419 step_pos = c.getX();
@@ -413,20 +422,28 @@
413 }422 }
414 }423 }
415 424
425
416 @Override426 @Override
417 public Rectangle2D getInternalBoundingBoxInLocalSpace() {427 public Rectangle2D getInternalBoundingBoxInLocalSpace() {
418 if (groupImpl == null) {428 if (groupImpl == null) {
419 return super.getInternalBoundingBoxInLocalSpace();429 return super.getInternalBoundingBoxInLocalSpace();
420 }430 }
421 return BoundingBoxHelper.union(totalBB, BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class)));431 Rectangle2D rect = BoundingBoxHelper.union(totalBB, BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class)));
432
433 if (rect==null)
434 return super.getInternalBoundingBoxInLocalSpace();
435
436 return rect;
422 } 437 }
423 438
439
424 @Override440 @Override
425 public void draw(DrawRequest r) {441 public void draw(DrawRequest r) {
426 Graphics2D g = r.getGraphics();442 Graphics2D g = r.getGraphics();
427443 Circuit circuit = (Circuit)r.getModel().getMathModel();
444
428 cacheRenderedText(r); // needed to better estimate the bounding box445 cacheRenderedText(r); // needed to better estimate the bounding box
429 updateContactLabelBB(g);446 updateContactLabelBB(circuit, g);
430 drawContactConnections(r);447 drawContactConnections(r);
431 448
432 Rectangle2D shape = getBestBB();449 Rectangle2D shape = getBestBB();
@@ -580,27 +597,30 @@
580 }597 }
581 }598 }
582599
583 public VisualContact addInput(String name, VisualContact.Direction dir) {600// public VisualContact addInput(Circuit circuit, String name, VisualContact.Direction dir) {
584 VisualContact vc = new VisualContact(new Contact(IOType.INPUT));601// VisualContact vc = new VisualContact(new Contact(IOType.INPUT));
585 if (dir==null) {602// if (dir==null) {
586 dir=VisualContact.Direction.WEST;603// dir=VisualContact.Direction.WEST;
587 }604// }
588 vc.setDirection(dir);605// vc.setDirection(dir);
589 vc.setName(name);606//
590 addContact(vc);607// circuit.setName(vc.getReferencedComponent(), name);
591 return vc;608//
592 }609// addContact(vc);
593 610// return vc;
594 public VisualContact addOutput(String name, VisualContact.Direction dir) {611// }
595 VisualContact vc = new VisualContact(new Contact(IOType.OUTPUT));612//
596 if (dir==null) {613// public VisualContact addOutput(VisualCircuit vcircuit, String name, VisualContact.Direction dir) {
597 dir=VisualContact.Direction.EAST;614// VisualContact vc = new VisualContact(new Contact(IOType.OUTPUT));
598 }615// if (dir==null) {
599 vc.setDirection(dir);616// dir=VisualContact.Direction.EAST;
600 vc.setName(name);617// }
601 addContact(vc);618// vc.setDirection(dir);
602 return vc;619//
603 }620// circuit.setName(vc.getReferencedComponent(), name);
621// addContact(vc);
622// return vc;
623// }
604624
605 @Override625 @Override
606 public void addObserver(HierarchyObserver obs) {626 public void addObserver(HierarchyObserver obs) {
607627
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-07-07 13:20:59 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-07-11 09:42:10 +0000
@@ -167,15 +167,15 @@
167 }167 }
168 });168 });
169169
170 addPropertyDeclaration(new PropertyDeclaration<VisualContact, String>(170// addPropertyDeclaration(new PropertyDeclaration<VisualContact, String>(
171 this, "Name", String.class) {171// this, "Name", String.class) {
172 protected void setter(VisualContact object, String value) {172// protected void setter(VisualContact object, String value) {
173 object.setName(value);173// object.setName(value);
174 }174// }
175 protected String getter(VisualContact object) {175// protected String getter(VisualContact object) {
176 return object.getName();176// return object.getName();
177 }177// }
178 });178// });
179179
180180
181 addPropertyDeclaration(new PropertyDeclaration<VisualContact, Boolean>(181 addPropertyDeclaration(new PropertyDeclaration<VisualContact, Boolean>(
@@ -203,6 +203,8 @@
203 public void draw(DrawRequest r) {203 public void draw(DrawRequest r) {
204 Graphics2D g = r.getGraphics();204 Graphics2D g = r.getGraphics();
205 Decoration d = r.getDecoration();205 Decoration d = r.getDecoration();
206 Circuit circuit = (Circuit)r.getModel().getMathModel();
207
206 boolean inSimulationMode = ((d.getColorisation() != null) || (d.getBackground() != null)); 208 boolean inSimulationMode = ((d.getColorisation() != null) || (d.getBackground() != null));
207 Color colorisation = d.getColorisation();209 Color colorisation = d.getColorisation();
208 Color fillColor = d.getBackground();210 Color fillColor = d.getBackground();
@@ -237,7 +239,7 @@
237 }239 }
238 g.transform(at);240 g.transform(at);
239 241
240 GlyphVector gv = getNameGlyphs(g);242 GlyphVector gv = getNameGlyphs(circuit, g);
241 Rectangle2D cur = gv.getVisualBounds();243 Rectangle2D cur = gv.getVisualBounds();
242 g.setColor(Coloriser.colorise((getIOType()==IOType.INPUT)?inputColor:outputColor, colorisation));244 g.setColor(Coloriser.colorise((getIOType()==IOType.INPUT)?inputColor:outputColor, colorisation));
243 245
@@ -293,19 +295,19 @@
293 }295 }
294 } 296 }
295 297
296 public GlyphVector getNameGlyphs(Graphics2D g) {298 public GlyphVector getNameGlyphs(Circuit circuit, Graphics2D g) {
297 if (nameGlyph == null) {299 if (nameGlyph == null) {
298 if (getDirection() == VisualContact.Direction.NORTH || getDirection() == VisualContact.Direction.SOUTH) {300 if (getDirection() == VisualContact.Direction.NORTH || getDirection() == VisualContact.Direction.SOUTH) {
299 AffineTransform at = new AffineTransform();301 AffineTransform at = new AffineTransform();
300 at.quadrantRotate(1);302 at.quadrantRotate(1);
301 }303 }
302 nameGlyph = nameFont.createGlyphVector(g.getFontRenderContext(), getName());304 nameGlyph = nameFont.createGlyphVector(g.getFontRenderContext(), circuit.getName(this.getReferencedContact()));
303 }305 }
304 return nameGlyph;306 return nameGlyph;
305 }307 }
306 308
307 public Rectangle2D getNameBB(Graphics2D g) {309 public Rectangle2D getNameBB(Circuit circuit, Graphics2D g) {
308 return getNameGlyphs(g).getVisualBounds();310 return getNameGlyphs(circuit, g).getVisualBounds();
309 }311 }
310 312
311 public void setDirection(VisualContact.Direction dir) {313 public void setDirection(VisualContact.Direction dir) {
@@ -336,20 +338,34 @@
336 public String getName() {338 public String getName() {
337 return getReferencedContact().getName();339 return getReferencedContact().getName();
338 }340 }
339341
340 @NoAutoSerialisation342 @NoAutoSerialisation
341 public void setName(String name) {343 public void setName(String name) {
342 getReferencedContact().setName(name);344 getReferencedContact().setName(name);
343 }345 }
346
347
348////
349// public void updateLocalName(String name) {
350// resetNameGlyph();
351// getReferencedContact().setName(name);
352// sendNotification(new PropertyChangedEvent(this, "name"));
353// }
344354
345 public Contact getReferencedContact() {355 public Contact getReferencedContact() {
346 return (Contact)getReferencedComponent();356 return (Contact)getReferencedComponent();
347 }357 }
348358
359
360 /*
361 * returns true if
362 */
349 public static boolean isDriver(Node node) {363 public static boolean isDriver(Node node) {
350 if (node instanceof VisualContact) {364 if (node instanceof VisualContact) {
351 VisualContact contact = (VisualContact)node;365 VisualContact contact = (VisualContact)node;
352 return (contact.getIOType() == IOType.OUTPUT) || !(contact.getParent() instanceof VisualComponent);366 boolean ret = (contact.getIOType() == IOType.OUTPUT) ||
367 !(contact.getParent() instanceof VisualCircuitComponent);
368 return ret;
353 }369 }
354 return false;370 return false;
355 }371 }
356372
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContactFormulaProperties.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContactFormulaProperties.java 2014-06-27 14:48:42 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContactFormulaProperties.java 2014-07-11 09:42:10 +0000
@@ -3,7 +3,9 @@
3import java.lang.reflect.InvocationTargetException;3import java.lang.reflect.InvocationTargetException;
4import java.util.Map;4import java.util.Map;
55
6import org.workcraft.dom.Container;
6import org.workcraft.gui.propertyeditor.PropertyDescriptor;7import org.workcraft.gui.propertyeditor.PropertyDescriptor;
8import org.workcraft.plugins.circuit.Contact.IOType;
7import org.workcraft.plugins.cpog.optimisation.BooleanFormula;9import org.workcraft.plugins.cpog.optimisation.BooleanFormula;
8import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString;10import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString;
9import org.workcraft.plugins.cpog.optimisation.javacc.BooleanParser;11import org.workcraft.plugins.cpog.optimisation.javacc.BooleanParser;
@@ -11,10 +13,10 @@
11import org.workcraft.util.Func;13import org.workcraft.util.Func;
1214
13public class VisualContactFormulaProperties {15public class VisualContactFormulaProperties {
14 VisualCircuit circuit;16 VisualCircuit vcircuit;
15 17
16 public VisualContactFormulaProperties(VisualCircuit circuit) {18 public VisualContactFormulaProperties(VisualCircuit circuit) {
17 this.circuit = circuit;19 this.vcircuit = circuit;
18 }20 }
19 21
20 private BooleanFormula parseFormula(final VisualFunctionContact contact, String resetFunction) {22 private BooleanFormula parseFormula(final VisualFunctionContact contact, String resetFunction) {
@@ -23,13 +25,19 @@
23 new Func<String, BooleanFormula>() {25 new Func<String, BooleanFormula>() {
24 @Override26 @Override
25 public BooleanFormula eval(String name) {27 public BooleanFormula eval(String name) {
28
29
26 if (contact.getParent() instanceof VisualFunctionComponent) {30 if (contact.getParent() instanceof VisualFunctionComponent) {
27 return ((VisualFunctionComponent)contact.getParent()).getOrCreateInput(name)31 return
28 .getReferencedContact();32 (BooleanFormula)
29 }33 vcircuit.getOrCreateContact(
30 34 (Container)contact.getParent(),
31 else35 name,
32 return circuit.getOrCreateOutput(name, contact.getX()+1, contact.getY()+1).getReferencedContact();36 IOType.INPUT, 0, 0
37 ).getReferencedContact();
38 } else
39 return (BooleanFormula)
40 vcircuit.getOrCreateOutput(name, contact.getX()+1, contact.getY()+1).getReferencedContact();
33 }41 }
34 });42 });
35 } catch (ParseException e) {43 } catch (ParseException e) {
3644
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionComponent.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionComponent.java 2014-06-27 14:48:42 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionComponent.java 2014-07-11 09:42:10 +0000
@@ -39,9 +39,9 @@
39 39
40 public VisualFunctionComponent(CircuitComponent component) {40 public VisualFunctionComponent(CircuitComponent component) {
41 super(component);41 super(component);
42 if (component.getChildren().isEmpty()) {42// if (component.getChildren().isEmpty()) {
43 this.addFunction("x", null, false);43// this.addFunction("x", null, false);
44 }44// }
45 }45 }
4646
47 ComponentRenderingResult renderingResult = null;47 ComponentRenderingResult renderingResult = null;
@@ -100,32 +100,6 @@
100 return super.hitTestInLocalSpace(pointInLocalSpace);100 return super.hitTestInLocalSpace(pointInLocalSpace);
101 }101 }
102 }102 }
103
104 public VisualFunctionContact addFunction(String prefix, IOType ioType, boolean allowShort) {
105 VisualContact.Direction dir=null;
106 if (ioType==null) ioType = IOType.OUTPUT;
107
108 dir=VisualContact.Direction.WEST;
109 if (ioType==IOType.OUTPUT) {
110 dir=VisualContact.Direction.EAST;
111 }
112 FunctionContact c = new FunctionContact(ioType);
113 VisualFunctionContact vc = new VisualFunctionContact(c);
114 vc.setDirection(dir);
115 vc.setName(Contact.getNewName(this.getReferencedComponent(), prefix, null, allowShort));
116 addContact(vc);
117 return vc;
118 }
119
120 public VisualFunctionContact getOrCreateInput(String arg) {
121 for (VisualFunctionContact c : Hierarchy.filterNodesByType(getChildren(), VisualFunctionContact.class)) {
122 if(c.getName().equals(arg)) return c;
123 }
124 VisualFunctionContact vc = addFunction(arg, IOType.INPUT, true);
125 vc.setSetFunction(One.instance());
126 vc.setResetFunction(One.instance());
127 return vc;
128 }
129103
130 @Override104 @Override
131 public void setRenderType(RenderType renderType) {105 public void setRenderType(RenderType renderType) {
@@ -185,8 +159,11 @@
185 vc.setTransform(ct, !firstUpdate); // suppress notifications at first recalculation of contact coordinates159 vc.setTransform(ct, !firstUpdate); // suppress notifications at first recalculation of contact coordinates
186 continue;160 continue;
187 }161 }
162
188 if (vc.getIOType() != IOType.INPUT) continue;163 if (vc.getIOType() != IOType.INPUT) continue;
189 Point2D position = res.contactPositions().get(vc.getName());164
165 String vcName = vc.getName();
166 Point2D position = res.contactPositions().get(vcName);
190 if (position != null) {167 if (position != null) {
191 bt.translate(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin), position.getY());168 bt.translate(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin), position.getY());
192 169
@@ -221,6 +198,9 @@
221 GateRenderer.foreground = Coloriser.colorise(getForegroundColor(), r.getDecoration().getColorisation());198 GateRenderer.foreground = Coloriser.colorise(getForegroundColor(), r.getDecoration().getColorisation());
222 GateRenderer.background = Coloriser.colorise(getFillColor(), r.getDecoration().getBackground());199 GateRenderer.background = Coloriser.colorise(getFillColor(), r.getDecoration().getBackground());
223 ComponentRenderingResult res = getRenderingResult();200 ComponentRenderingResult res = getRenderingResult();
201 VisualCircuit vcircuit = (VisualCircuit)r.getModel();
202
203
224 if (res == null) {204 if (res == null) {
225 super.draw(r);205 super.draw(r);
226 } else {206 } else {
@@ -290,7 +270,8 @@
290 270
291 if (vc.getIOType() != IOType.INPUT) continue;271 if (vc.getIOType() != IOType.INPUT) continue;
292 272
293 Point2D position = res.contactPositions().get(vc.getName());273 String cname = vc.getReferencedContact().getName();
274 Point2D position = res.contactPositions().get(cname);
294 if (position != null) {275 if (position != null) {
295 line = new Line2D.Double(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin),276 line = new Line2D.Double(snapP5(res.boundingBox().getMinX() - GateRenderer.contactMargin),
296 position.getY(), position.getX(), position.getY());277 position.getY(), position.getX(), position.getY());
297278
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java 2014-06-27 14:48:42 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java 2014-07-11 09:42:10 +0000
@@ -19,7 +19,7 @@
19*19*
20*/20*/
2121
22package org.workcraft.plugins.circuit;22package org.workcraft.plugins.circuit;
2323
24import java.awt.BasicStroke;24import java.awt.BasicStroke;
25import java.awt.Color;25import java.awt.Color;
@@ -87,7 +87,7 @@
87 public BooleanFormula getSetFunction() {87 public BooleanFormula getSetFunction() {
88 return getReferencedFunctionContact().getSetFunction();88 return getReferencedFunctionContact().getSetFunction();
89 }89 }
9090
91 @NoAutoSerialisation91 @NoAutoSerialisation
92 public void setSetFunction(BooleanFormula setFunction) {92 public void setSetFunction(BooleanFormula setFunction) {
93 if (getParent() instanceof VisualFunctionComponent) {93 if (getParent() instanceof VisualFunctionComponent) {
@@ -126,7 +126,7 @@
126 }126 }
127 return renderedSetFormula;127 return renderedSetFormula;
128 }128 }
129 129
130 FormulaRenderingResult getRenderedResetFormula(FontRenderContext fcon) {130 FormulaRenderingResult getRenderedResetFormula(FontRenderContext fcon) {
131 if (((FunctionContact)getReferencedContact()).getResetFunction() == null) {131 if (((FunctionContact)getReferencedContact()).getResetFunction() == null) {
132 return null;132 return null;
@@ -255,5 +255,5 @@
255 }255 }
256 super.notify(e);256 super.notify(e);
257 }257 }
258 258
259}259}
260260
=== added directory 'CircuitPlugin/src/org/workcraft/plugins/circuit/references'
=== added file 'CircuitPlugin/src/org/workcraft/plugins/circuit/references/CircuitReferenceManager.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/references/CircuitReferenceManager.java 1970-01-01 00:00:00 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/references/CircuitReferenceManager.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,72 @@
1package org.workcraft.plugins.circuit.references;
2
3import org.workcraft.dom.Node;
4import org.workcraft.dom.hierarchy.NamespaceHelper;
5import org.workcraft.dom.hierarchy.NamespaceProvider;
6import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager;
7import org.workcraft.dom.references.NameManager;
8import org.workcraft.plugins.circuit.CircuitComponent;
9import org.workcraft.plugins.circuit.Contact;
10import org.workcraft.plugins.circuit.FunctionComponent;
11import org.workcraft.serialisation.References;
12import org.workcraft.util.Func;
13import org.workcraft.util.Identifier;
14
15
16public class CircuitReferenceManager extends HierarchicalUniqueNameReferenceManager {
17
18 public CircuitReferenceManager(NamespaceProvider provider,
19 References existing, Func<Node, String> defaultName) {
20 super(existing, defaultName);
21 }
22
23 @Override
24 public String getName(Node node) {
25
26 NameManager<Node> man = getNameManager(getNamespaceProvider(node));
27
28 if (node instanceof Contact && !man.isNamed(node)) {
29 return ((Contact)node).getName();
30 }
31
32 if (node instanceof FunctionComponent && (!man.isNamed(node))) {
33 return ((FunctionComponent)node).getName();
34 }
35
36 if (!man.isNamed(node)) return null;
37
38 return super.getName(node);
39 }
40
41 @Override
42 public void setName(Node node, String name) {
43
44 // support for the older models
45 if (Identifier.isNumber(name) && node instanceof Contact) {
46
47 String n = ((Contact)node).getName();
48
49 if (n!=null&&!n.equals("")) name=n;
50 } else if (Identifier.isNumber(name) && node instanceof CircuitComponent) {
51
52 String n = ((CircuitComponent)node).getName();
53 if (n!=null&&!n.equals("")) name=n;
54
55 } else if (Identifier.isNumber(name)) {
56 // name="_"+name;
57 name=defaultName.eval(node)+name;
58 }
59
60 if (node instanceof Contact) {
61 // propagate info to the node itself
62 ((Contact)node).setName(name);
63 }
64 if (node instanceof CircuitComponent) {
65 // propagate info to the node itself
66 ((CircuitComponent)node).setName(name);
67 }
68
69 super.setName(node, name);
70 }
71
72}
073
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSelectionTool.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSelectionTool.java 2013-07-25 12:29:40 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/CircuitSelectionTool.java 2014-07-11 09:42:10 +0000
@@ -15,8 +15,13 @@
15import org.workcraft.gui.events.GraphEditorMouseEvent;15import org.workcraft.gui.events.GraphEditorMouseEvent;
16import org.workcraft.gui.graph.tools.GraphEditor;16import org.workcraft.gui.graph.tools.GraphEditor;
17import org.workcraft.gui.graph.tools.SelectionTool;17import org.workcraft.gui.graph.tools.SelectionTool;
18import org.workcraft.plugins.circuit.Circuit;
19import org.workcraft.plugins.circuit.FunctionContact;
20import org.workcraft.plugins.circuit.VisualCircuit;
18import org.workcraft.plugins.circuit.VisualCircuitComponent;21import org.workcraft.plugins.circuit.VisualCircuitComponent;
19import org.workcraft.plugins.circuit.VisualFunctionComponent;22import org.workcraft.plugins.circuit.VisualFunctionComponent;
23import org.workcraft.plugins.circuit.VisualFunctionContact;
24import org.workcraft.plugins.circuit.Contact.IOType;
2025
21public class CircuitSelectionTool extends SelectionTool {26public class CircuitSelectionTool extends SelectionTool {
2227
@@ -52,11 +57,15 @@
52 popup.addSeparator();57 popup.addSeparator();
53 58
54 JMenuItem addFunction = new JMenuItem("Add function");59 JMenuItem addFunction = new JMenuItem("Add function");
60
55 addFunction.addActionListener(new ActionListener() {61 addFunction.addActionListener(new ActionListener() {
56 @Override62 @Override
57 public void actionPerformed(ActionEvent e) {63 public void actionPerformed(ActionEvent e) {
58 editor.getWorkspaceEntry().saveMemento();64 editor.getWorkspaceEntry().saveMemento();
59 comp.addFunction("x", null, false);65 VisualCircuit vcircuit = (VisualCircuit)editor.getModel();
66
67 vcircuit.getOrCreateContact(comp, null, IOType.OUTPUT, 0, 0);
68// comp.addFunction("x", null, false);
60 }69 }
61 });70 });
62 71
@@ -76,7 +85,10 @@
76 @Override85 @Override
77 public void actionPerformed(ActionEvent e) {86 public void actionPerformed(ActionEvent e) {
78 editor.getWorkspaceEntry().saveMemento();87 editor.getWorkspaceEntry().saveMemento();
79 comp.addInput("", null);88 VisualCircuit vcircuit = (VisualCircuit)editor.getModel();
89
90 vcircuit.getOrCreateContact(comp, null, IOType.INPUT, 0, 0);
91// comp.addInput((Circuit)vcircuit.getMathModel(), "", null);
80 }92 }
81 });93 });
82 94
@@ -85,7 +97,10 @@
85 @Override97 @Override
86 public void actionPerformed(ActionEvent e) {98 public void actionPerformed(ActionEvent e) {
87 editor.getWorkspaceEntry().saveMemento();99 editor.getWorkspaceEntry().saveMemento();
88 comp.addOutput("", null);100 VisualCircuit vcircuit = (VisualCircuit)editor.getModel();
101
102 vcircuit.getOrCreateContact(comp, null, IOType.OUTPUT, 0, 0);
103// comp.addOutput((Circuit)vcircuit.getMathModel(), "", null);
89 }104 }
90 });105 });
91 106
92107
=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java'
--- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-07-07 13:20:59 +0000
+++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-07-11 09:42:10 +0000
@@ -15,7 +15,9 @@
15import java.util.TreeSet;15import java.util.TreeSet;
1616
17import org.workcraft.dom.Connection;17import org.workcraft.dom.Connection;
18import org.workcraft.dom.Container;
18import org.workcraft.dom.Node;19import org.workcraft.dom.Node;
20import org.workcraft.dom.hierarchy.NamespaceHelper;
19import org.workcraft.dom.visual.Movable;21import org.workcraft.dom.visual.Movable;
20import org.workcraft.dom.visual.TransformHelper;22import org.workcraft.dom.visual.TransformHelper;
21import org.workcraft.dom.visual.VisualComponent;23import org.workcraft.dom.visual.VisualComponent;
@@ -31,7 +33,6 @@
31import org.workcraft.plugins.circuit.VisualFunctionContact;33import org.workcraft.plugins.circuit.VisualFunctionContact;
32import org.workcraft.plugins.circuit.VisualJoint;34import org.workcraft.plugins.circuit.VisualJoint;
33import org.workcraft.plugins.cpog.optimisation.BooleanFormula;35import org.workcraft.plugins.cpog.optimisation.BooleanFormula;
34import org.workcraft.plugins.cpog.optimisation.BooleanVariable;
35import org.workcraft.plugins.cpog.optimisation.Literal;36import org.workcraft.plugins.cpog.optimisation.Literal;
36import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString;37import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString;
37import org.workcraft.plugins.cpog.optimisation.dnf.Dnf;38import org.workcraft.plugins.cpog.optimisation.dnf.Dnf;
@@ -87,14 +88,23 @@
87 88
88 private static ContactSTG generatePlaces(VisualCircuit circuit, VisualSTG stg, VisualContact contact) {89 private static ContactSTG generatePlaces(VisualCircuit circuit, VisualSTG stg, VisualContact contact) {
89 String contactName = getContactName(circuit, contact);90 String contactName = getContactName(circuit, contact);
90 VisualPlace zeroPlace = stg.createPlace(contactName+"_0");91
92 String path = NamespaceHelper.getParentReference(circuit.getMathModel().getNodeReference(contact.getReferencedComponent()));
93 Container curContainer = (Container)createdContainers.get(path);
94 while (curContainer==null) {
95 path = NamespaceHelper.getParentReference(path);
96 curContainer = (Container)createdContainers.get(path);
97 }
98
99
100 VisualPlace zeroPlace = stg.createPlace(contactName+"_0", curContainer);
91 zeroPlace.setLabel(contactName+"=0");101 zeroPlace.setLabel(contactName+"=0");
92 102
93 if (!contact.getInitOne()) {103 if (!contact.getInitOne()) {
94 zeroPlace.getReferencedPlace().setTokens(1);104 zeroPlace.getReferencedPlace().setTokens(1);
95 }105 }
96 106
97 VisualPlace onePlace = stg.createPlace(contactName+"_1");107 VisualPlace onePlace = stg.createPlace(contactName+"_1", curContainer);
98 onePlace.setLabel(contactName+"=1");108 onePlace.setLabel(contactName+"=1");
99 if (contact.getInitOne()) {109 if (contact.getInitOne()) {
100 onePlace.getReferencedPlace().setTokens(1);110 onePlace.getReferencedPlace().setTokens(1);
@@ -131,15 +141,23 @@
131 }141 }
132 }142 }
133 143
134 public static VisualSTG generate(VisualCircuit circuit) {144
145
146 // store created containers in a separate map
147 private static HashMap<String, Node> createdContainers = null;
148
149 public synchronized static VisualSTG generate(VisualCircuit circuit) {
135 try {150 try {
136 VisualSTG stg = new VisualSTG(new STG());151 VisualSTG stg = new VisualSTG(new STG());
137 152
153 // first, create the same page structure
154 createdContainers = NamespaceHelper.copyPageStructure(stg, stg.getRoot(), circuit, circuit.getRoot(), null);
155
138 Map<Contact, VisualContact> targetDrivers = new HashMap<Contact, VisualContact>();156 Map<Contact, VisualContact> targetDrivers = new HashMap<Contact, VisualContact>();
139 Map<VisualContact, ContactSTG> drivers = new HashMap<VisualContact, ContactSTG>(); 157 Map<VisualContact, ContactSTG> drivers = new HashMap<VisualContact, ContactSTG>();
140 158
141 // generate all possible drivers and fill out the targets159 // generate all possible drivers and fill out the targets
142 for(VisualContact contact : Hierarchy.getDescendantsOfType(circuit.getRoot(), VisualContact.class)) {160 for (VisualContact contact : Hierarchy.getDescendantsOfType(circuit.getRoot(), VisualContact.class)) {
143 ContactSTG cstg;161 ContactSTG cstg;
144 162
145 if(VisualContact.isDriver(contact)) {163 if(VisualContact.isDriver(contact)) {
@@ -171,10 +189,10 @@
171 BooleanFormula resetFunc = null;189 BooleanFormula resetFunc = null;
172 Type signalType = Type.INPUT;190 Type signalType = Type.INPUT;
173 if (driver instanceof VisualFunctionContact) {191 if (driver instanceof VisualFunctionContact) {
192 // Determine signal type
174 VisualFunctionContact contact = (VisualFunctionContact)driver;193 VisualFunctionContact contact = (VisualFunctionContact)driver;
175 if ((contact.getIOType() == IOType.OUTPUT) && !isFromEnvironment(contact)) {194 signalType = getSignalType(contact);
176 signalType = Type.OUTPUT;195
177 }
178 if ((contact.getIOType() == IOType.OUTPUT) && !(contact.getParent() instanceof VisualCircuitComponent)) {196 if ((contact.getIOType() == IOType.OUTPUT) && !(contact.getParent() instanceof VisualCircuitComponent)) {
179 // Driver of the primary output port197 // Driver of the primary output port
180 VisualContact outputDriver = findDriver(circuit, contact);198 VisualContact outputDriver = findDriver(circuit, contact);
@@ -203,11 +221,19 @@
203 }221 }
204 }222 }
205223
206 private static boolean isFromEnvironment(VisualContact contact) {224 private static Type getSignalType(VisualFunctionContact contact) {
207 if (contact.getParent() instanceof VisualCircuitComponent) {225 Type result = Type.INPUT;
208 return ((VisualCircuitComponent)contact.getParent()).getIsEnvironment();226 if (contact.getIOType() == IOType.OUTPUT) {
209 }227 if (contact.getParent() instanceof VisualCircuitComponent) {
210 return false;228 VisualCircuitComponent component = (VisualCircuitComponent)contact.getParent();
229 if (!component.getIsEnvironment()) {
230 result = Type.INTERNAL;
231 }
232 } else {
233 result = Type.OUTPUT;
234 }
235 }
236 return result;
211 }237 }
212 238
213 private static void implementDriver(VisualCircuit circuit, VisualSTG stg,239 private static void implementDriver(VisualCircuit circuit, VisualSTG stg,
@@ -284,8 +310,22 @@
284 reset, subtract(add(center, direction), pOffset), minusDirection, 310 reset, subtract(add(center, direction), pOffset), minusDirection,
285 signalName, ttype, SignalTransition.Direction.MINUS, p.p1, p.p0));311 signalName, ttype, SignalTransition.Direction.MINUS, p.p1, p.p0));
286 312
313 Container currentLevel = null;
314 Container oldLevel = stg.getCurrentLevel();
315
316 for (Node node:nodes) {
317 if (currentLevel==null)
318 currentLevel = (Container)node.getParent();
319
320 if (currentLevel!=node.getParent())
321 throw new RuntimeException("Current level is not the same among the processed nodes");
322 }
323
324
325 stg.setCurrentLevel(currentLevel);
287 stg.select(nodes);326 stg.select(nodes);
288 stg.groupSelection();327 stg.groupSelection();
328 stg.setCurrentLevel(oldLevel);
289 }329 }
290330
291 private static LinkedList<VisualNode> buildTransitions(VisualContact parentContact,331 private static LinkedList<VisualNode> buildTransitions(VisualContact parentContact,
@@ -296,6 +336,15 @@
296 336
297 LinkedList<VisualNode> nodes = new LinkedList<VisualNode>();337 LinkedList<VisualNode> nodes = new LinkedList<VisualNode>();
298 338
339
340 String path = NamespaceHelper.getParentReference(circuit.getMathModel().getNodeReference(parentContact.getReferencedComponent()));
341 Container curContainer = (Container)createdContainers.get(path);
342 while (curContainer==null) {
343 path = NamespaceHelper.getParentReference(path);
344 curContainer = (Container)createdContainers.get(path);
345 }
346
347
299 TreeSet<DnfClause> clauses = new TreeSet<DnfClause>(348 TreeSet<DnfClause> clauses = new TreeSet<DnfClause>(
300 new Comparator<DnfClause>() {349 new Comparator<DnfClause>() {
301 @Override350 @Override
@@ -311,7 +360,7 @@
311 360
312 for(DnfClause clause : clauses)361 for(DnfClause clause : clauses)
313 { 362 {
314 VisualSignalTransition transition = stg.createSignalTransition(signalName, type, transitionDirection);363 VisualSignalTransition transition = stg.createSignalTransition(signalName, type, transitionDirection, curContainer);
315 nodes.add(transition);364 nodes.add(transition);
316 parentContact.getReferencedTransitions().add(transition.getReferencedTransition());365 parentContact.getReferencedTransitions().add(transition.getReferencedTransition());
317 366
@@ -333,7 +382,7 @@
333 ContactSTG source = drivers.get(driverContact);382 ContactSTG source = drivers.get(driverContact);
334 383
335 if(source == null)384 if(source == null)
336 throw new RuntimeException("No source for " + targetContact.getName() + " while generating " + signalName);385 throw new RuntimeException("No source for " + circuit.getMathModel().getName(targetContact) + " while generating " + signalName);
337 386
338 VisualPlace p = literal.getNegation() ? source.p0 : source.p1;387 VisualPlace p = literal.getNegation() ? source.p0 : source.p1;
339 388
@@ -365,12 +414,19 @@
365 }414 }
366 }415 }
367 416
368 result = ((VisualFunctionComponent)parent).getName();417 result = NamespaceHelper.getFlatName(
418 circuit.getMathModel().getName(vc.getReferencedComponent())
419 );
420
421// result = HierarchicalNames.getFlatName(
422// circuit.getMathModel().getNodeReference(vc.getReferencedComponent())
423// );
424
369 if (contact.getIOType() == IOType.INPUT || output_cnt > 1) {425 if (contact.getIOType() == IOType.INPUT || output_cnt > 1) {
370 result += "_" + contact.getName();426 result += "_" + circuit.getMathModel().getName(contact.getReferencedContact());
371 }427 }
372 } else {428 } else {
373 result = contact.getName();429 result = circuit.getMathModel().getName(contact.getReferencedContact());
374 }430 }
375 return result;431 return result;
376 }432 }
377433
=== modified file 'CpogsPlugin/.classpath'
--- CpogsPlugin/.classpath 2014-01-29 19:00:22 +0000
+++ CpogsPlugin/.classpath 2014-07-11 09:42:10 +0000
@@ -5,5 +5,6 @@
5 <classpathentry combineaccessrules="false" kind="src" path="/WorkcraftCore"/>5 <classpathentry combineaccessrules="false" kind="src" path="/WorkcraftCore"/>
6 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>6 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
7 <classpathentry combineaccessrules="false" kind="src" path="/STGPlugin"/>7 <classpathentry combineaccessrules="false" kind="src" path="/STGPlugin"/>
8 <classpathentry kind="lib" path="/ThirdParty/TableLayout-bin-jdk1.5-2009-08-26.jar"/>
8 <classpathentry kind="output" path="bin"/>9 <classpathentry kind="output" path="bin"/>
9</classpath>10</classpath>
1011
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CPOG.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/CPOG.java 2014-04-07 16:35:42 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/CPOG.java 2014-07-11 09:42:10 +0000
@@ -27,7 +27,10 @@
27import org.workcraft.dom.Connection;27import org.workcraft.dom.Connection;
28import org.workcraft.dom.Container;28import org.workcraft.dom.Container;
29import org.workcraft.dom.Node;29import org.workcraft.dom.Node;
30import org.workcraft.dom.hierarchy.NamespaceProvider;
30import org.workcraft.dom.math.AbstractMathModel;31import org.workcraft.dom.math.AbstractMathModel;
32import org.workcraft.dom.math.MathGroup;
33import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager;
31import org.workcraft.dom.references.UniqueNameReferenceManager;34import org.workcraft.dom.references.UniqueNameReferenceManager;
32import org.workcraft.exceptions.InvalidConnectionException;35import org.workcraft.exceptions.InvalidConnectionException;
33import org.workcraft.observation.HierarchyEvent;36import org.workcraft.observation.HierarchyEvent;
@@ -42,11 +45,11 @@
42public class CPOG extends AbstractMathModel {45public class CPOG extends AbstractMathModel {
4346
44 public CPOG() {47 public CPOG() {
45 this(null, null);48 this(new MathGroup(), null);
46 }49 }
4750
48 public CPOG(Container root, References refs) {51 public CPOG(Container root, References refs) {
49 super(root, new UniqueNameReferenceManager(refs, new Func<Node, String>() {52 super(root, new HierarchicalUniqueNameReferenceManager(refs, new Func<Node, String>() {
50 @Override53 @Override
51 public String eval(Node arg) {54 public String eval(Node arg) {
52 if (arg instanceof Vertex)55 if (arg instanceof Vertex)
5356
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ConsistencyEnforcer.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/ConsistencyEnforcer.java 2010-05-01 15:12:53 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/ConsistencyEnforcer.java 2014-07-11 09:42:10 +0000
@@ -5,6 +5,7 @@
5import org.workcraft.observation.HierarchySupervisor;5import org.workcraft.observation.HierarchySupervisor;
6import org.workcraft.observation.NodesAddedEvent;6import org.workcraft.observation.NodesAddedEvent;
7import org.workcraft.observation.NodesDeletedEvent;7import org.workcraft.observation.NodesDeletedEvent;
8import org.workcraft.observation.NodesReparentedEvent;
89
9public class ConsistencyEnforcer extends HierarchySupervisor {10public class ConsistencyEnforcer extends HierarchySupervisor {
1011
@@ -20,7 +21,7 @@
20 @Override21 @Override
21 public void handleEvent(HierarchyEvent e)22 public void handleEvent(HierarchyEvent e)
22 {23 {
23 if (e instanceof NodesAddedEvent)24 if (e instanceof NodesAddedEvent || e instanceof NodesReparentedEvent)
24 {25 {
25 updateEncoding();26 updateEncoding();
26 createDefaultLabels(e);27 createDefaultLabels(e);
2728
=== removed file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogEncoder.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogEncoder.java 2013-10-21 17:36:57 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogEncoder.java 1970-01-01 00:00:00 +0000
@@ -1,311 +0,0 @@
1package org.workcraft.plugins.cpog;
2
3import java.awt.geom.Point2D;
4import java.util.ArrayList;
5import java.util.HashMap;
6import javax.swing.JOptionPane;
7
8import org.workcraft.Tool;
9import org.workcraft.dom.visual.VisualComponent;
10import org.workcraft.dom.visual.connections.VisualConnection;
11import org.workcraft.plugins.cpog.optimisation.BooleanFormula;
12import org.workcraft.plugins.cpog.optimisation.CleverCnfGenerator;
13import org.workcraft.plugins.cpog.optimisation.CpogEncoding;
14import org.workcraft.plugins.cpog.optimisation.DefaultCpogSolver;
15import org.workcraft.plugins.cpog.optimisation.OneHotIntBooleanFormula;
16import org.workcraft.plugins.cpog.optimisation.OneHotNumberProvider;
17import org.workcraft.plugins.cpog.optimisation.Optimiser;
18import org.workcraft.plugins.cpog.optimisation.expressions.One;
19import org.workcraft.util.Geometry;
20import org.workcraft.workspace.WorkspaceEntry;
21
22public class CpogEncoder implements Tool {
23
24 @Override
25 public String getDisplayName() {
26 return "CPOG Encoding";
27 }
28
29 @Override
30 public String getSection() {
31 return "Encoding";
32 }
33
34 @Override
35 public boolean isApplicableTo(WorkspaceEntry we)
36 {
37 if (we.getModelEntry() == null) return false;
38 if (we.getModelEntry().getVisualModel() instanceof VisualCPOG) return true;
39 return false;
40 }
41
42
43 private String generateConstraint(char [][][] constraints, int numScenarios, int event1, int event2)
44 {
45 StringBuilder s = new StringBuilder();
46 for(int k = 0; k < numScenarios; k++) s.append(constraints[k][event1][event2]);
47 return s.toString();
48 }
49
50 private char trivialEncoding(char [][][] constraints, int numScenarios, int event1, int event2)
51 {
52 char trivial = '-';
53
54 for(int k = 0; k < numScenarios; k++)
55 {
56 if (constraints[k][event1][event2] == '0')
57 {
58 if (trivial == '1') return '?';
59 trivial = '0';
60 }
61
62 if (constraints[k][event1][event2] == '1')
63 {
64 if (trivial == '0') return '?';
65 trivial = '1';
66 }
67 }
68
69 return trivial;
70 }
71
72 @Override
73 public void run(WorkspaceEntry we)
74 {
75 VisualCPOG cpog = (VisualCPOG)(we.getModelEntry().getVisualModel());
76
77 we.captureMemento();
78
79 HashMap<String, Integer> events = new HashMap<String, Integer>();
80 int n = 0;
81 ArrayList<Point2D> positions = new ArrayList<Point2D>();
82 ArrayList<Integer> count = new ArrayList<Integer>();
83
84 // TODO: remove deprecated method
85 ArrayList<VisualScenario> scenarios = new ArrayList<VisualScenario>(cpog.getGroups());
86
87 int m = scenarios.size();
88
89 if (m < 2)
90 {
91 JOptionPane.showMessageDialog(null,
92 "At least two scenarios are expected.",
93 "Not enough scenarios",
94 JOptionPane.ERROR_MESSAGE);
95 we.cancelMemento();
96 return;
97 }
98
99 // find all events
100 for(int k = 0; k < m; k++)
101 {
102 for(VisualComponent component : scenarios.get(k).getComponents())
103 if (component instanceof VisualVertex)
104 {
105 VisualVertex vertex = (VisualVertex)component;
106
107 if (!events.containsKey(vertex.getLabel()))
108 {
109 events.put(vertex.getLabel(), n);
110 count.add(1);
111 Point2D p = vertex.getCenter();
112 p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY());
113 positions.add(p);
114 n++;
115 }
116 else
117 {
118 int id = events.get(vertex.getLabel());
119 count.set(id, count.get(id) + 1);
120 Point2D p = vertex.getCenter();
121 p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY());
122 positions.set(id, Geometry.add(positions.get(id), p));
123 }
124 }
125 }
126
127 // construct constraints
128
129 char [][][] constraints = new char[m][n][n];
130 int [][] graph = new int[n][n];
131
132 for(int k = 0; k < m; k++)
133 {
134 for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) constraints[k][i][j] = '0';
135
136 for(VisualComponent component : scenarios.get(k).getComponents())
137 if (component instanceof VisualVertex)
138 {
139 VisualVertex vertex = (VisualVertex)component;
140 int id = events.get(vertex.getLabel());
141 constraints[k][id][id] = '1';
142 }
143
144 for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) graph[i][j] = 0;
145
146 for(VisualConnection c : scenarios.get(k).getConnections())
147 if (c instanceof VisualArc)
148 {
149 VisualArc arc = (VisualArc)c;
150 VisualComponent c1 = arc.getFirst(), c2 = arc.getSecond();
151 if (c1 instanceof VisualVertex && c2 instanceof VisualVertex)
152 {
153 int id1 = events.get(((VisualVertex)c1).getLabel());
154 int id2 = events.get(((VisualVertex)c2).getLabel());
155 graph[id1][id2] = 1;
156 }
157 }
158
159 // compute transitive closure
160
161 for(int t = 0; t < n; t++)
162 for(int i = 0; i < n; i++)
163 if (graph[i][t] > 0)
164 for(int j = 0; j < n; j++)
165 if (graph[t][j] > 0) graph[i][j] = 1;
166
167 // detect transitive arcs
168
169 for(int t = 0; t < n; t++)
170 for(int i = 0; i < n; i++)
171 if (graph[i][t] > 0)
172 for(int j = 0; j < n; j++)
173 if (graph[t][j] > 0) graph[i][j] = 2;
174
175 // report cyclic scenario
176
177 for(int i = 0; i < n; i++)
178 if (graph[i][i] > 0)
179 {
180 JOptionPane.showMessageDialog(null,
181 "Scenario '" + scenarios.get(k).getLabel() + "' is cyclic.",
182 "Invalid scenario",
183 JOptionPane.ERROR_MESSAGE);
184 we.cancelMemento();
185 return;
186 }
187
188 for(int i = 0; i < n; i++)
189 for(int j = 0; j < n; j++)
190 if (i != j)
191 {
192 char ch = '0';
193
194 if (graph[i][j] > 0) ch = '1';
195 if (graph[i][j] > 1) ch = '-';
196 if (constraints[k][i][i] == '0' || constraints[k][j][j] == '0') ch = '-';
197
198 constraints[k][i][j] = ch;
199 }
200 }
201
202 // group similar constraints
203
204 HashMap<String, Integer> task = new HashMap<String, Integer>();
205
206 for(int i = 0; i < n; i++)
207 for(int j = 0; j < n; j++)
208 if (trivialEncoding(constraints, m, i, j) == '?')
209 {
210 String constraint = generateConstraint(constraints, m, i, j);
211 if (!task.containsKey(constraint)) task.put(constraint, task.size());
212 }
213
214 // call CPOG encoder
215
216 char [][] matrix = new char[m][task.size()];
217
218 String [] instance = new String[m];
219 for(String s : task.keySet())
220 for(int i = 0; i < m; i++) matrix[i][task.get(s)] = s.charAt(i);
221
222 for(int i = 0; i < m; i++) instance[i] = new String(matrix[i]);
223
224 int freeVariables = CpogSettings.getEncodingWidth();
225 int derivedVariables = CpogSettings.getCircuitSize();
226
227 Optimiser<OneHotIntBooleanFormula> oneHot = new Optimiser<OneHotIntBooleanFormula>(new OneHotNumberProvider());
228
229 DefaultCpogSolver<BooleanFormula> solverCnf = new DefaultCpogSolver<BooleanFormula>(oneHot, new CleverCnfGenerator());
230
231 Variable [] vars = new Variable[freeVariables];
232 for(int i = 0; i < freeVariables; i++) vars[i] = cpog.createVisualVariable().getMathVariable();
233
234 CpogEncoding solution = null;
235 try
236 {
237 solution = solverCnf.solve(instance, vars, derivedVariables);
238 if (solution == null)
239 {
240 we.cancelMemento();
241 JOptionPane.showMessageDialog(null, "No solution.", "Encoding result", JOptionPane.INFORMATION_MESSAGE);
242 }
243
244 }
245 catch(Exception e)
246 {
247 we.cancelMemento();
248 JOptionPane.showMessageDialog(null, e.getMessage(), "Encoding result", JOptionPane.ERROR_MESSAGE);
249 }
250
251 if(solution == null) return;
252
253 // create result
254
255 boolean[][] encoding = solution.getEncoding();
256
257 for(int k = 0; k < m; k++)
258 {
259 for(int i = 0; i < freeVariables; i++)
260 scenarios.get(k).getEncoding().setState(vars[i], VariableState.fromBoolean(encoding[k][i]));
261 }
262
263 VisualScenario result = cpog.createVisualScenario();
264 result.setLabel("Composition");
265 VisualVertex [] vertices = new VisualVertex[n];
266 for(String eventName : events.keySet())
267 {
268 int id = events.get(eventName);
269 vertices[id] = cpog.createVisualVertex(result);
270 vertices[id].setLabel(eventName);
271 vertices[id].setPosition(Geometry.multiply(positions.get(id), 1.0/count.get(id)));
272 }
273
274 BooleanFormula[] functions = solution.getFunctions();
275 for(int i = 0; i < n; i++)
276 for(int j = 0; j < n; j++)
277 {
278 BooleanFormula condition;
279
280 char trivial = trivialEncoding(constraints, m, i, j);
281 if (trivial != '?')
282 {
283 if (trivial == '1')
284 {
285 condition = One.instance();
286 }
287 else
288 {
289 continue;
290 }
291 }
292 else
293 {
294 String constraint = generateConstraint(constraints, m, i, j);
295 condition = functions[task.get(constraint)];
296 }
297
298 if (i == j)
299 {
300 vertices[i].setCondition(condition);
301 }
302 else
303 {
304 VisualArc arc = cpog.connect(vertices[i], vertices[j]);
305 arc.setCondition(condition);
306 }
307 }
308 we.saveMemento();
309 }
310
311}
3120
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogModule.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogModule.java 2013-12-27 19:04:57 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogModule.java 2014-07-11 09:42:10 +0000
@@ -16,6 +16,7 @@
16import org.workcraft.plugins.cpog.serialisation.VertexSerialiser;16import org.workcraft.plugins.cpog.serialisation.VertexSerialiser;
17import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupDeserialiser;17import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupDeserialiser;
18import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupSerialiser;18import org.workcraft.plugins.cpog.serialisation.VisualCPOGGroupSerialiser;
19import org.workcraft.plugins.cpog.tools.EncoderPreferencesTool;
19import org.workcraft.plugins.cpog.tools.GraphStatisticsTool;20import org.workcraft.plugins.cpog.tools.GraphStatisticsTool;
20import org.workcraft.serialisation.xml.XMLDeserialiser;21import org.workcraft.serialisation.xml.XMLDeserialiser;
21import org.workcraft.serialisation.xml.XMLSerialiser;22import org.workcraft.serialisation.xml.XMLSerialiser;
@@ -40,7 +41,9 @@
40 p.registerClass(XMLDeserialiser.class, ArcDeserialiser.class);41 p.registerClass(XMLDeserialiser.class, ArcDeserialiser.class);
41 p.registerClass(SettingsPage.class, CpogSettings.class);42 p.registerClass(SettingsPage.class, CpogSettings.class);
42 43
43 p.registerClass(Tool.class, CpogEncoder.class);44 //p.registerClass(Tool.class, CpogEncoder.class);
45
46 p.registerClass(Tool.class, EncoderPreferencesTool.class, framework);
4447
45 p.registerClass(Tool.class, new Initialiser<Tool>() {48 p.registerClass(Tool.class, new Initialiser<Tool>() {
46 @Override49 @Override
4750
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogProgrammer.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogProgrammer.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogProgrammer.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,1023 @@
1package org.workcraft.plugins.cpog;
2
3import java.awt.geom.Point2D;
4import java.io.BufferedReader;
5import java.io.DataInputStream;
6import java.io.File;
7import java.io.FileInputStream;
8import java.io.FileOutputStream;
9import java.io.IOException;
10import java.io.InputStream;
11import java.io.InputStreamReader;
12import java.io.PrintStream;
13import java.util.ArrayList;
14import java.util.HashMap;
15import java.util.Map;
16import java.util.StringTokenizer;
17
18import javax.swing.JOptionPane;
19
20import org.workcraft.dom.visual.RemovedNodeDeselector;
21import org.workcraft.dom.visual.VisualComponent;
22import org.workcraft.dom.visual.connections.VisualConnection;
23import org.workcraft.plugins.cpog.EncoderSettings.generationMode;
24import org.workcraft.plugins.cpog.optimisation.BooleanFormula;
25import org.workcraft.plugins.cpog.optimisation.CleverCnfGenerator;
26import org.workcraft.plugins.cpog.optimisation.CpogEncoding;
27import org.workcraft.plugins.cpog.optimisation.CpogOptimisationTask;
28import org.workcraft.plugins.cpog.optimisation.DefaultCpogSolver;
29import org.workcraft.plugins.cpog.optimisation.OneHotIntBooleanFormula;
30import org.workcraft.plugins.cpog.optimisation.OneHotNumberProvider;
31import org.workcraft.plugins.cpog.optimisation.Optimiser;
32import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString;
33import org.workcraft.plugins.cpog.optimisation.expressions.One;
34import org.workcraft.plugins.cpog.optimisation.expressions.Zero;
35import org.workcraft.plugins.cpog.optimisation.javacc.BooleanParser;
36import org.workcraft.util.Func;
37import org.workcraft.util.Geometry;
38import org.workcraft.workspace.WorkspaceEntry;
39
40import com.sun.org.apache.regexp.internal.RE;
41
42public class CpogProgrammer {
43
44 private EncoderSettings settings;
45 private File scenarioFile, encodingFile ;
46 private String toolPath = "../tools/";
47 private int bits = 1;
48 private Double minArea;
49
50 // SETTING PARAMETERS FOR CALLING PROGRAMMER.X
51 private String espressoCommand, abcFolder , gatesLibrary ,
52 verbose = "", genMode= "", numSol= "", customFlag= "", customPath= "", effort= "", espressoFlag= "", abcFlag= "", gateLibFlag= "", cpogSize= "", disableFunction= "",
53 oldSynt= "";
54 // Allocation data structures
55 private Process process;
56 private String[] opt_enc, opt_formulaeVertices,truthTableVertices, opt_vertices, opt_sources, opt_dests,
57 opt_formulaeArcs, truthTableArcs, arcNames;
58 private int v,a,n;
59
60 public CpogProgrammer(EncoderSettings settings){
61 this.setSettings(settings);
62 }
63
64 private String binaryToInt(String string) {
65 int value = 0, wg = 1;
66 if(string != null){
67 for(int i = string.length()-1; i>=0; i--){
68 if(string.charAt(i) == '1'){
69 value += wg;
70 }
71 wg *= 2;
72 }
73
74 return String.valueOf(value);
75 }
76 return "0";
77 }
78
79 private static boolean deleteDir(File dir) {
80 if (dir.isDirectory()) {
81 String[] children = dir.list();
82 for (int i = 0; i < children.length; i++) {
83 boolean success = deleteDir(new File(dir, children[i]));
84 if (!success) {
85 return false;
86 }
87 }
88 }
89
90 return dir.delete(); // The directory is empty now and can be deleted.
91 }
92
93 private String generateConstraint(char [][][] constraints, int numScenarios, int event1, int event2)
94 {
95 StringBuilder s = new StringBuilder();
96 for(int k = 0; k < numScenarios; k++) s.append(constraints[k][event1][event2]);
97 return s.toString();
98 }
99
100 private char trivialEncoding(char [][][] constraints, int numScenarios, int event1, int event2)
101 {
102 char trivial = '-';
103
104 for(int k = 0; k < numScenarios; k++)
105 {
106 if (constraints[k][event1][event2] == '0')
107 {
108 if (trivial == '1') return '?';
109 trivial = '0';
110 }
111
112 if (constraints[k][event1][event2] == '1')
113 {
114 if (trivial == '0') return '?';
115 trivial = '1';
116 }
117 }
118
119 return trivial;
120 }
121
122 private int WriteCpogIntoFile(int m, ArrayList<VisualScenario> scenarios)
123 {
124 try{
125 scenarioFile = File.createTempFile("scenarios", "cpog");
126
127 PrintStream Output = new PrintStream(scenarioFile);
128
129
130 for(int k = 0; k < m; k++)
131 {
132 Map<String, Integer> nodes = new HashMap<String, Integer>();
133 // Print arcs
134 Output.println(".scenario CPOG_" + k);
135 for(VisualConnection c : scenarios.get(k).getConnections()){
136 if (c instanceof VisualArc)
137 {
138 VisualArc arc = (VisualArc)c;
139 VisualComponent c1 = arc.getFirst(), c2 = arc.getSecond();
140 if (c1 instanceof VisualVertex && c2 instanceof VisualVertex)
141 {
142 nodes.put(c1.getLabel(), 0);
143 nodes.put(c2.getLabel(), 0);
144 Output.println(c1.getLabel() + " " + c2.getLabel());
145 }
146 }
147 }
148
149 // Print conditions on vertices
150 for(VisualComponent component : scenarios.get(k).getComponents()){
151 if(component instanceof VisualVertex){
152 VisualVertex vertex = (VisualVertex)component;
153 BooleanFormula condition = vertex.getCondition();
154 if (condition != One.instance() && condition != Zero.instance()){
155
156 // Format output by substituting ' with !
157 String cond = FormulaToString.toString(condition).replaceAll("'", "!");
158 String result = "";
159 String tmp = "";
160 for(int i=0; i<cond.length(); i++){
161 if(cond.charAt(i) != '(' && cond.charAt(i) != ')' && cond.charAt(i) != '+' &&
162 cond.charAt(i) != '*' && cond.charAt(i) != '!' && cond.charAt(i) != ' '){
163 tmp = "";
164 while(i < cond.length() && cond.charAt(i) != '(' && cond.charAt(i) != ')' && cond.charAt(i) != '+' &&
165 cond.charAt(i) != '*' && cond.charAt(i) != '!' && cond.charAt(i) != ' '){
166 tmp += cond.charAt(i);
167 i++;
168 }
169 //System.out.println("TMP: " + tmp);
170 for(int j= tmp.length()-1; j >= 0; j--){
171 //System.out.println(j + ") " + tmp.charAt(j));
172 result += tmp.charAt(j);
173 }
174 if(i < cond.length()){
175 result += cond.charAt(i);
176 }
177 }
178 else{
179 result += cond.charAt(i);;
180 }
181 }
182
183 String end = "";
184 for(int i = 0; i<result.length(); i++){
185 if(result.charAt(i) == '(') end += ')';
186 else if (result.charAt(i) == ')') end += '(';
187 else end += result.charAt(i);
188 }
189
190 // Print conditions on each vertices
191 Output.print(":");
192 for(int i=end.length()-1; i>=0; i--){
193 Output.print(end.charAt(i));
194 }
195 Output.println(" " + vertex.getLabel());
196 }
197
198 //VisualVertex vertex = (VisualVertex)component;
199 if(!nodes.containsKey(vertex.getLabel())){
200 Output.println(vertex.getLabel());
201 }
202 }
203
204 }
205 Output.println(".end");
206 if(k != m-1){
207 Output.println();
208 }
209 }
210 Output.close();
211
212 // WRITING CUSTOM ENCODING FILE
213 if(settings.getGenMode() != generationMode.SCENCO){
214 encodingFile = File.createTempFile("custom", "enc");
215 if(settings.isCustomEncMode()){
216 PrintStream Output1 = new PrintStream(encodingFile);
217
218 String [] enc = settings.getCustomEnc();
219 for(int k = 0; k < m; k++)
220 {
221 if(enc[k].contains("2") || enc[k].contains("3") || enc[k].contains("4") ||
222 enc[k].contains("5") || enc[k].contains("6") || enc[k].contains("7") ||
223 enc[k].contains("8") || enc[k].contains("9")){
224 JOptionPane.showMessageDialog(null,
225 "Op-code " + enc[k] + " not allowed.",
226 "Custom encoding error",
227 JOptionPane.ERROR_MESSAGE);
228 return -1;
229
230 }
231 String empty = "";
232 for(int i=0; i<settings.getBits(); i++) empty += 'X';
233 if(enc[k].equals("") || enc[k].equals(empty)){
234 Output1.println("/");
235 }
236 else{
237 Output1.println(enc[k]);
238 }
239 }
240 Output1.println(settings.getBits());
241 Output1.close();
242 }
243 }
244 }catch (IOException e) {
245 System.out.println("Error: " + e);
246 }
247
248 return 0;
249 }
250
251 private void printController(int m){
252 System.out.println();
253 String fileName = toolPath + "results/generated_encoding/";
254 for(int i=0; i<m; i++) fileName = fileName.concat(binaryToInt(opt_enc[i]) + "_");
255 fileName = fileName.concat(".prg");
256 File f = new File(fileName);
257 if(f.exists() && !f.isDirectory()){
258 System.out.println("Boolean controller:");
259 try{
260 FileInputStream fstream = new FileInputStream(fileName);
261 DataInputStream in = new DataInputStream(fstream);
262 BufferedReader bre = new BufferedReader(new InputStreamReader(in));
263 String strLine;
264 bre.readLine();
265 bre.readLine();
266 while ((strLine = bre.readLine()) != null) {
267 System.out.println (strLine);
268 }
269 in.close();
270 }catch (Exception e){ //Catch exception if any
271 System.err.println("Error: " + e.getMessage());
272 }
273 System.out.println();
274 }
275 return;
276 }
277
278 private void deleteTempFiles(){
279 if(scenarioFile.exists()) scenarioFile.delete();
280 if(encodingFile.exists()) encodingFile.delete();
281 return;
282 }
283
284 private int callingProgrammer(Double currArea, WorkspaceEntry we, int it, boolean continuous) throws IOException{
285 //Debug Printing: launching executable
286 /*System.out.println(toolPath + "programmer.x" + " " + scenarioFile.getAbsolutePath() + " " +
287 "-m" + " " + effort + " " + genMode + " " + numSol + " " + customFlag + " " + customPath + " " +
288 verbose + " " + cpogSize + " " + disableFunction + " " + oldSynt + " " +
289 espressoFlag + " " + espressoCommand + " " + abcFlag + " " + abcFolder + " " + gateLibFlag + " " +
290 gatesLibrary);*/
291 process = new ProcessBuilder(toolPath + "programmer.x", scenarioFile.getAbsolutePath(),
292 "-m",effort,genMode, numSol,customFlag,customPath,verbose,cpogSize,disableFunction,oldSynt,
293 espressoFlag,espressoCommand, abcFlag, abcFolder, gateLibFlag, gatesLibrary).start();
294 InputStream is = process.getInputStream();
295 InputStreamReader isr = new InputStreamReader(is);
296 BufferedReader br = new BufferedReader(isr);
297 String line;
298 boolean finish = false;
299 if(continuous){
300 while ( (line = br.readLine()) != null && finish == false) {
301 // Read Area
302 if(line.contains(".area")){
303 line = br.readLine();
304 currArea = Double.valueOf(line);
305 line = br.readLine();
306 if(currArea < minArea){
307 v = 0; a = 0;
308 minArea = currArea;
309 System.out.println(it + ") " + "Area of current circuit: " + minArea);
310 while((line = br.readLine()) != null){
311 // Read Optimal Encoding
312 if(line.contains("MIN: ")){
313 StringTokenizer st2 = new StringTokenizer(line, " ");
314 int j = 0;
315 st2.nextElement();
316 while (st2.hasMoreElements()) {
317 opt_enc[j++] = (String) st2.nextElement();
318 }
319 }
320
321 // Read Optimal Formulae
322 if(line.contains(".start_formulae")){
323 line = br.readLine();
324 while(line.contains(".end_formulae") == false){
325 StringTokenizer st2 = new StringTokenizer(line, ",");
326 String el = (String)st2.nextElement();
327 if(el.equals("V")){ //formula of a vertex
328 opt_vertices[v] = (String) st2.nextElement();
329 truthTableVertices[v] = (String) st2.nextElement();
330 opt_formulaeVertices[v++] = (String) st2.nextElement();
331 }else{
332 opt_sources[a] = (String) st2.nextElement();
333 opt_dests[a] = (String) st2.nextElement();
334 arcNames[a] = opt_sources[a] + "->" + opt_dests[a];
335 truthTableArcs[a] = (String) st2.nextElement();
336 opt_formulaeArcs[a++] = (String) st2.nextElement();
337 }
338 line = br.readLine();
339 }
340
341 }
342
343 // Read statistics
344 if(line.contains(".statistics")){
345 line = br.readLine();
346 while(line.contains(".end_statistics") == false){
347 line = br.readLine();
348 }
349 }
350
351 // Read errors
352 if(line.contains(".error")){
353 line = br.readLine();
354 while(line.contains(".end_error") == false){
355 JOptionPane.showMessageDialog(null,
356 line,
357 "Programmer.x error",
358 JOptionPane.ERROR_MESSAGE);
359 line = br.readLine();
360 }
361 return -1;
362
363 }
364 }
365 }else{
366 finish = true;
367 }
368 }
369
370 }
371 }else{
372 while ( (line = br.readLine()) != null){
373 if(settings.isVerboseMode())
374 System.out.println(line);
375
376 // Read Optimal Encoding
377 if(line.contains("MIN: ")){
378 StringTokenizer st2 = new StringTokenizer(line, " ");
379 int j = 0;
380 st2.nextElement();
381 while (st2.hasMoreElements()) {
382 opt_enc[j++] = (String) st2.nextElement();
383 }
384 }
385
386 // Read Optimal Formulae
387 if(line.contains(".start_formulae")){
388 line = br.readLine();
389 while(line.contains(".end_formulae") == false){
390 if(settings.isVerboseMode())
391 System.out.println(line);
392 StringTokenizer st2 = new StringTokenizer(line, ",");
393 String el = (String)st2.nextElement();
394 if(el.equals("V")){ //formula of a vertex
395 opt_vertices[v] = (String) st2.nextElement();
396 truthTableVertices[v] = (String) st2.nextElement();
397 opt_formulaeVertices[v++] = (String) st2.nextElement();
398 }else{
399 opt_sources[a] = (String) st2.nextElement();
400 opt_dests[a] = (String) st2.nextElement();
401 arcNames[a] = opt_sources[a] + "->" + opt_dests[a];
402 truthTableArcs[a] = (String) st2.nextElement();
403 opt_formulaeArcs[a++] = (String) st2.nextElement();
404 }
405 line = br.readLine();
406 }
407
408 }
409
410 // Read statistics
411 if(line.contains(".statistics")){
412 line = br.readLine();
413 while(line.contains(".end_statistics") == false){
414 System.out.println(line);
415 line = br.readLine();
416 }
417 }
418
419 // Read errors
420 if(line.contains(".error")){
421 line = br.readLine();
422 while(line.contains(".end_error") == false){
423 JOptionPane.showMessageDialog(null,
424 line,
425 "Programmer.x error",
426 JOptionPane.ERROR_MESSAGE);
427 line = br.readLine();
428 }
429 return -1;
430
431 }
432 }
433 }
434
435 process.destroy();
436 is.close();
437 isr.close();
438 br.close();
439 return 0;
440 }
441
442 private void reset_vars(){
443 verbose = ""; genMode= ""; numSol= ""; customFlag= ""; customPath= ""; effort= ""; espressoFlag= "";
444 abcFlag= ""; gateLibFlag= ""; cpogSize= ""; disableFunction= ""; oldSynt= "";
445
446 return;
447 }
448
449 public void run(WorkspaceEntry we)
450 {
451 VisualCPOG cpog = (VisualCPOG)(we.getModelEntry().getVisualModel());
452
453 we.captureMemento();
454
455 reset_vars();
456
457 HashMap<String, Integer> events = new HashMap<String, Integer>();
458 n = 0;
459 ArrayList<Point2D> positions = new ArrayList<Point2D>();
460 ArrayList<Integer> count = new ArrayList<Integer>();
461
462 // TODO: remove deprecated method
463 ArrayList<VisualScenario> scenarios = new ArrayList<VisualScenario>(cpog.getGroups());
464
465 // Scenario contains single graphs compose CPOG
466 int m = scenarios.size();
467
468 // If less than two, do not encode scenarios
469 if (m < 2)
470 {
471 JOptionPane.showMessageDialog(null,
472 "At least two scenarios are expected.",
473 "Not enough scenarios",
474 JOptionPane.ERROR_MESSAGE);
475 we.cancelMemento();
476 deleteTempFiles();
477 return;
478 }
479
480 // Scan every scenarios
481 for(int k = 0; k < m; k++)
482 {
483 // Scan every elements of each scenario
484 for(VisualComponent component : scenarios.get(k).getComponents())
485 if (component instanceof VisualVertex) // If element is a vertex
486 {
487 VisualVertex vertex = (VisualVertex)component;
488
489 if (!events.containsKey(vertex.getLabel())) // Check if a condition is present on vertex
490 {
491 events.put(vertex.getLabel(), n);
492 count.add(1);
493 Point2D p = vertex.getCenter();
494 p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY());
495 positions.add(p);
496 n++;
497 }
498 else
499 {
500 int id = events.get(vertex.getLabel());
501 count.set(id, count.get(id) + 1);
502 Point2D p = vertex.getCenter();
503 p.setLocation(p.getX() - scenarios.get(k).getBoundingBox().getMinX(), p.getY() - scenarios.get(k).getBoundingBox().getMinY());
504 positions.set(id, Geometry.add(positions.get(id), p));
505 }
506 }
507 }
508
509 // construct constraints
510
511 char [][][] constraints = new char[m][n][n];
512 int [][] graph = new int[n][n];
513
514 for(int k = 0; k < m; k++)
515 {
516 for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
517 constraints[k][i][j] = '0';
518 }
519
520 for(VisualComponent component : scenarios.get(k).getComponents())
521 if (component instanceof VisualVertex)
522 {
523 VisualVertex vertex = (VisualVertex)component;
524 int id = events.get(vertex.getLabel());
525 constraints[k][id][id] = '1';
526 }
527
528 for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) graph[i][j] = 0;
529
530 for(VisualConnection c : scenarios.get(k).getConnections())
531 if (c instanceof VisualArc)
532 {
533 VisualArc arc = (VisualArc)c;
534 VisualComponent c1 = arc.getFirst(), c2 = arc.getSecond();
535 if (c1 instanceof VisualVertex && c2 instanceof VisualVertex)
536 {
537 int id1 = events.get(((VisualVertex)c1).getLabel());
538 int id2 = events.get(((VisualVertex)c2).getLabel());
539 graph[id1][id2] = 1;
540 }
541 }
542
543 // compute transitive closure
544
545 for(int t = 0; t < n; t++)
546 for(int i = 0; i < n; i++)
547 if (graph[i][t] > 0)
548 for(int j = 0; j < n; j++)
549 if (graph[t][j] > 0) graph[i][j] = 1;
550
551 // detect transitive arcs
552
553 for(int t = 0; t < n; t++)
554 for(int i = 0; i < n; i++)
555 if (graph[i][t] > 0)
556 for(int j = 0; j < n; j++)
557 if (graph[t][j] > 0) graph[i][j] = 2;
558
559 // report cyclic scenario
560
561 for(int i = 0; i < n; i++)
562 if (graph[i][i] > 0)
563 {
564 deleteTempFiles();
565 JOptionPane.showMessageDialog(null,
566 "Scenario '" + scenarios.get(k).getLabel() + "' is cyclic.",
567 "Invalid scenario",
568 JOptionPane.ERROR_MESSAGE);
569 we.cancelMemento();
570 return;
571 }
572
573 for(int i = 0; i < n; i++)
574 for(int j = 0; j < n; j++)
575 if (i != j)
576 {
577 char ch = '0';
578
579 if (graph[i][j] > 0) ch = '1';
580 if (graph[i][j] > 1) ch = '-';
581 if ( constraints[k][i][i] == '0' || constraints[k][j][j] == '0' ) ch = '-';
582
583 constraints[k][i][j] = ch;
584 }
585 }
586
587 // Write scenarios into file.
588 int res;
589 if((res = WriteCpogIntoFile(m, scenarios)) != 0){
590 deleteTempFiles();
591 if(res != -1){
592 JOptionPane.showMessageDialog(null,
593 "Error on writing scenario file.",
594 "Workcraft error",
595 JOptionPane.ERROR_MESSAGE);
596 }
597 we.cancelMemento();
598 return;
599 }
600
601 espressoCommand = CpogSettings.getEspressoCommand();
602 abcFolder = CpogSettings.getAbcFolder();
603 gatesLibrary = CpogSettings.getGatesLibrary();
604 opt_enc = new String[m];
605 opt_formulaeVertices = new String[n*n];
606 truthTableVertices = new String[n*n];
607 opt_vertices = new String[n];
608 opt_sources = new String[n*n];
609 opt_dests = new String[n*n];
610 opt_formulaeArcs = new String[n*n];
611 truthTableArcs = new String[n*n];
612 arcNames = new String[n*n];
613 espressoCommand = CpogSettings.getEspressoCommand();
614 abcFolder = CpogSettings.getAbcFolder();
615 gatesLibrary = CpogSettings.getGatesLibrary();
616 espressoFlag = "-e";
617 v=0;
618 a=0;
619
620 // CALLING PROGRAMMER.X
621 boolean SCENCO = false;
622 try {
623 File f;
624 f = new File(espressoCommand);
625 if(!f.exists() || f.isDirectory()){
626 deleteTempFiles();
627 JOptionPane.showMessageDialog(null,
628 "Espresso tool is needed to programmer to work properly",
629 "Espresso tool not present",
630 JOptionPane.ERROR_MESSAGE);
631 we.cancelMemento();
632 return;
633 }
634
635 espressoCommand = espressoCommand.replace(" ", "\\ ");
636
637 f = new File(abcFolder);
638 if(!f.exists() || !f.isDirectory()){
639 JOptionPane.showMessageDialog(null,
640 "You can download it at http://www.eecs.berkeley.edu/~alanmi/abc/",
641 "Abc tool not present",
642 JOptionPane.ERROR_MESSAGE);
643 }
644 else{
645 abcFlag = "-a";
646 gateLibFlag = "-lib";
647 f = new File(abcFolder + gatesLibrary);
648 if(!f.exists() || f.isDirectory()){
649 deleteTempFiles();
650 JOptionPane.showMessageDialog(null,
651 "It is needed to compute area of circuit properly",
652 "Gate library not present",
653 JOptionPane.ERROR_MESSAGE);
654 we.cancelMemento();
655 return;
656 }
657 }
658
659 if(settings.isCpogSize()) cpogSize = "-cs";
660 if(settings.isCostFunc()) disableFunction = "-d";
661 if(settings.isVerboseMode()) verbose = "-v";
662 if(settings.isEffort()) effort = "all";
663 else effort = "min";
664 if(settings.isCustomEncMode()){
665 customFlag = "-set";
666 customPath = encodingFile.getAbsolutePath();
667 }
668 switch(settings.getGenMode()){
669 case OPTIMAL_ENCODING:
670 genMode = "-top";
671 numSol = String.valueOf(settings.getSolutionNumber());
672 break;
673 case RECURSIVE:
674 if(settings.isCustomEncMode()){
675 deleteTempFiles();
676 JOptionPane.showMessageDialog(null,
677 "Recursive encodings generation combined with custom op-codes is not supported.",
678 "Encodings generation error",
679 JOptionPane.ERROR_MESSAGE);
680 we.cancelMemento();
681 return;
682 }
683 break;
684 case RANDOM:
685 genMode = "-r";
686 if(settings.isCustomEncMode()){
687 deleteTempFiles();
688 JOptionPane.showMessageDialog(null,
689 "Random encodings generation combined with custom op-codes is not supported.",
690 "Encodings generation error",
691 JOptionPane.ERROR_MESSAGE);
692 we.cancelMemento();
693 return;
694 }
695 numSol = String.valueOf(settings.getSolutionNumber());
696 break;
697 case SCENCO:
698 SCENCO = true;
699 customFlag = "-set";
700 genMode = "-top";
701 numSol = "1";
702 break;
703 case OLD_SYNT:
704 customFlag = "-set";
705 customPath = encodingFile.getAbsolutePath();
706 oldSynt = "-old";
707 genMode = "-top";
708 numSol = "1";
709 break;
710 default:
711 System.out.println("Error");
712 }
713
714 deleteDir(new File(toolPath + "results/"));
715 File d = new File("../tools/results/generated_encoding/");
716 d.mkdirs();
717
718 if(!SCENCO){
719 // CALLING PROGRAMMER.X
720 boolean out = false;
721 boolean continuous = false;
722 int limit, it = 0;
723 if(settings.isContMode()){
724 limit = 100;
725 numSol = "1";
726 continuous = true;
727 }else{
728 limit = 1;
729 }
730 minArea = Double.MAX_VALUE;
731 Double currArea = Double.MAX_VALUE;
732 while(!out && it < limit){
733 if(callingProgrammer(currArea, we,it, continuous) != 0){
734 deleteTempFiles();
735 we.cancelMemento();
736 return;
737 }
738 it++;
739 }
740 // Print controller
741 printController(m);
742
743 }
744 } catch (IOException e1) {
745 System.out.println("Error.");
746 e1.printStackTrace();
747 }
748 // group similar constraints
749 HashMap<String, BooleanFormula> formulaeName = new HashMap<String, BooleanFormula>();
750 HashMap<String, Integer> task = new HashMap<String, Integer>();
751 for(int i = 0; i < n; i++)
752 for(int j = 0; j < n; j++)
753 if (trivialEncoding(constraints, m, i, j) == '?')
754 {
755 String constraint = generateConstraint(constraints, m, i, j);
756 if (!task.containsKey(constraint)){
757 task.put(constraint, task.size());
758 }
759 }
760
761 // call CPOG encoder
762
763 char [][] matrix = new char[m][task.size()];
764
765 String [] instance = new String[m];
766 for(String s : task.keySet())
767 for(int i = 0; i < m; i++) matrix[i][task.get(s)] = s.charAt(i);
768
769 for(int i = 0; i < m; i++) instance[i] = new String(matrix[i]);
770
771 int freeVariables;
772 if(settings.getGenMode() != generationMode.SCENCO)
773 freeVariables = opt_enc[0].length();
774 else
775 freeVariables = settings.getBits();
776 int derivedVariables = CpogSettings.getCircuitSize();
777
778 Optimiser<OneHotIntBooleanFormula> oneHot = new Optimiser<OneHotIntBooleanFormula>(new OneHotNumberProvider());
779
780 DefaultCpogSolver<BooleanFormula> solverCnf = new DefaultCpogSolver<BooleanFormula>(oneHot, new CleverCnfGenerator());
781
782 VisualVariable predicatives[] = new VisualVariable[n];
783 int pr = 0;
784 for(int k = 0; k < m; k++)
785 {
786 for(VisualComponent component : scenarios.get(k).getComponents()){
787 if(component instanceof VisualVariable){
788 predicatives[pr++] = (VisualVariable) component;
789 }
790 }
791 }
792
793 Variable [] vars = new Variable[freeVariables + pr];
794 for(int i = 0; i < freeVariables; i++) vars[i] = cpog.createVisualVariable().getMathVariable();
795 for(int i = 0; i< pr; i++) vars[freeVariables +i] = predicatives[i].getMathVariable();
796
797 // DEBUG PRINTING: printing variables needed to encode graph.
798 /*System.out.println("PRINTING VARIABLES:");
799 for(int i = 0; i< freeVariables + pr; i++)
800 System.out.println(vars[i].getLabel());*/
801
802 CpogEncoding solution = null;
803 try
804 {
805 // SCENCO EXECUTION TO FIND VARIABLES AND FUNCTIONS
806 solution = solverCnf.solve(instance, vars, derivedVariables);
807 CpogOptimisationTask opt_task = (CpogOptimisationTask) solverCnf.getTask(instance, vars, derivedVariables);
808 if (solution == null)
809 {
810 if(SCENCO){
811 we.cancelMemento();
812 JOptionPane.showMessageDialog(null, "SCENCO is not able to solve the CPOG, try other options.",
813 "Encoding result", JOptionPane.ERROR_MESSAGE);
814 deleteTempFiles();
815 return;
816 }
817 System.out.println("INFORMATION: Scenco cannot solve the CPOG.");
818 System.out.println();
819 }
820
821 System.out.println("Op-code selected for graphs:");
822 for(int i=0; i<m; i++){
823 String name;
824 if(scenarios.get(i).getLabel().equals("")){
825 name = "CPOG " + i;
826 }
827 else{
828 name = scenarios.get(i).getLabel();
829 }
830 System.out.println(name + ": " + opt_enc[i]);
831 }
832 solution = new CpogEncoding(null, null);
833
834 if(!SCENCO){
835
836 solution = new CpogEncoding(null, null);
837 BooleanFormula[][] encodingVars = opt_task.getEncodingVars();
838 BooleanFormula[] formule = new BooleanFormula[v + a];
839 // Set optimal formulae to graphs
840 final Variable [] variables = vars;
841 for(int i=0; i<v; i++){
842 if(opt_formulaeVertices[i].contains("x")){
843 BooleanFormula formula_opt = null;
844 formula_opt = BooleanParser.parse(opt_formulaeVertices[i], new Func<String, BooleanFormula>() {
845
846 @Override
847 public BooleanFormula eval(String arg) {
848 arg = arg.substring("x_".length());
849 int id = Integer.parseInt(arg);
850 return variables[id];
851 }
852 });
853
854 formulaeName.put(opt_vertices[i], formula_opt);
855
856 // OLD formulae array
857 /*if(task.containsKey(truthTableVertices[i])){
858 formule[task.get(truthTableVertices[i])] = formula_opt;
859 }*/
860 }
861 }
862 for(int i=0; i<a; i++){
863 if(opt_formulaeArcs[i].contains("x")){
864 BooleanFormula formula_opt = null;
865 formula_opt = BooleanParser.parse(opt_formulaeArcs[i], new Func<String, BooleanFormula>() {
866 @Override
867 public BooleanFormula eval(String arg) {
868 arg = arg.substring("x_".length());
869 int id = Integer.parseInt(arg);
870 return variables[id];
871 }
872 });
873
874 formulaeName.put(arcNames[i], formula_opt);
875
876 /*if(task.containsKey(truthTableArcs[i])){
877 formule[task.get(truthTableArcs[i])] = formula_opt;
878 }*/
879 }
880 }
881 solution.setFormule(formule);
882 //TODO
883 // Set optimal encoding to graphs
884 boolean[][] opt_encoding = new boolean[m][];
885 for(int i=0;i<m;i++)
886 {
887 opt_encoding[i] = new boolean[freeVariables + pr];
888 for(int j=0;j<freeVariables;j++){
889 if(opt_enc[i].charAt(j) == '0' || opt_enc[i].charAt(j) == '-') opt_encoding[i][j] = false;
890 else opt_encoding[i][j] = true;
891 }
892 for(int j=freeVariables;j<freeVariables + pr;j++){
893 opt_encoding[i][j] = false;
894 }
895
896 }
897 solution.setEncoding(opt_encoding);
898 }
899 }
900 catch(Exception e)
901 {
902 we.cancelMemento();
903 JOptionPane.showMessageDialog(null, e.getMessage(), "Encoding result", JOptionPane.ERROR_MESSAGE);
904 }
905
906 if(solution == null){
907 return;
908 }
909
910 // create result
911
912 boolean[][] encoding = solution.getEncoding();
913
914 if(settings.getGenMode() == generationMode.SCENCO){
915
916 try{
917 encodingFile = File.createTempFile("encoding", "cpog");
918 PrintStream Output = new PrintStream(encodingFile);
919
920 for(int i=0; i<m; i++){
921 for(int j=0; j<settings.getBits(); j++){
922 if(encoding[i][j]){
923 Output.print("1");
924 }
925 else{
926 Output.print("0");
927 }
928 }
929 Output.println();
930 }
931 Output.close();
932
933 customPath = encodingFile.getAbsolutePath();
934 if(callingProgrammer(Double.MAX_VALUE, we, 0, false) != 0){
935 deleteTempFiles();
936 we.cancelMemento();
937 return;
938 }
939
940 // Print controller
941 printController(m);
942 }catch (IOException e) {
943 System.out.println("Error: " + e);
944 }
945 }
946
947 //TODO
948 for(int k = 0; k < m; k++)
949 {
950 for(int i = 0; i < freeVariables; i++){
951 scenarios.get(k).getEncoding().setState(vars[i], VariableState.fromBoolean(encoding[k][i]));
952 }
953 for(int i = freeVariables; i < freeVariables + pr; i++){
954 scenarios.get(k).getEncoding().setState(vars[i], VariableState.fromBoolean(encoding[k][i]));
955 }
956 }
957
958 VisualScenario result = cpog.createVisualScenario();
959 result.setLabel("Composition");
960 VisualVertex [] vertices = new VisualVertex[n];
961 for(String eventName : events.keySet())
962 {
963 int id = events.get(eventName);
964 vertices[id] = cpog.createVisualVertex(result);
965 vertices[id].setLabel(eventName);
966 vertices[id].setPosition(Geometry.multiply(positions.get(id), 1.0/count.get(id)));
967 if(formulaeName.containsKey(eventName)){
968 vertices[id].setCondition(formulaeName.get(eventName));
969 }else
970 vertices[id].setCondition(One.instance());
971 }
972
973
974 // SET FORMULAE INTO RESULT GRAPH
975 BooleanFormula[] functions = solution.getFunctions();
976 for(int i = 0; i < n; i++)
977 for(int j = 0; j < n; j++)
978 {
979 BooleanFormula condition;
980
981 char trivial = trivialEncoding(constraints, m, i, j);
982 if (trivial != '?')
983 {
984 if (trivial == '1')
985 {
986 condition = One.instance();
987 }
988 else
989 {
990 continue;
991 }
992 }
993 /*else
994 {
995 String constraint = generateConstraint(constraints, m, i, j);
996 condition = functions[task.get(constraint)];
997 }*/
998
999 /*if (i == j)
1000 {
1001 vertices[i].setCondition(condition);
1002 }*/
1003 if (i != j)
1004 {
1005 VisualArc arc = cpog.connect(vertices[i], vertices[j]);
1006 String arcName = vertices[i].getLabel() + "->" + vertices[j].getLabel();
1007
1008 if(formulaeName.containsKey(arcName)){
1009 condition = formulaeName.get(arcName);
1010 }else
1011 condition = One.instance();
1012
1013 arc.setCondition(condition);
1014 }
1015 }
1016
1017 we.saveMemento();
1018 }
1019
1020 public void setSettings(EncoderSettings settings) {
1021 this.settings = settings;
1022 }
1023}
01024
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/CpogSettings.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/CpogSettings.java 2014-06-04 13:07:53 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/CpogSettings.java 2014-07-11 09:42:10 +0000
@@ -12,6 +12,8 @@
1212
13public class CpogSettings implements SettingsPage {13public class CpogSettings implements SettingsPage {
1414
15 private static LinkedList<PropertyDescriptor> properties;
16
15 public enum SatSolver {17 public enum SatSolver {
16 MINISAT("MiniSat"),18 MINISAT("MiniSat"),
17 CLASP("Clasp");19 CLASP("Clasp");
@@ -30,27 +32,15 @@
30 return choice;32 return choice;
31 }33 }
32 }34 }
33
34 private static LinkedList<PropertyDescriptor> properties;
35
36 private static final String prefix = "CpogSettings";
37 private static final String keySatSolver = prefix + ".satSolver";
38 private static final String keyEncodingWidth = prefix + ".encodingWidth";
39 private static final String keyCircuitSize = prefix + ".circuitSize";
40 private static final String keyClaspCommand = prefix + ".claspCommand";
41 private static final String keyMinisatCommand = prefix + ".minisatCommand";
42
43 private static final SatSolver defaultSatSolver = SatSolver.CLASP;
44 private static final int defaultEncodingWidth = 2;
45 private static final int defaultCircuitSize = 4;
46 private static final String defaultClaspCommand = "clasp";
47 private static final String defaultMinisatCommand = "minisat";
48 35
49 private static SatSolver satSolver = defaultSatSolver;36 private static SatSolver satSolver = SatSolver.CLASP;
50 private static int encodingWidth = defaultEncodingWidth;37 //private static int encodingWidth = 2;
51 private static int circuitSize = defaultCircuitSize;38 private static int circuitSize = 4;
52 private static String claspCommand = defaultClaspCommand;39 private static String claspCommand = "clasp";
53 private static String minisatCommand = defaultMinisatCommand;40 private static String minisatCommand = "minisat";
41 private static String espressoCommand = "espresso";
42 private static String abcFolder = "abc/";
43 private static String gatesLibrary = "90nm.genlib";
54 44
55 @Override45 @Override
56 public Collection<PropertyDescriptor> getDescriptors() {46 public Collection<PropertyDescriptor> getDescriptors() {
@@ -71,16 +61,6 @@
71 });61 });
7262
73 properties.add(new PropertyDeclaration<CpogSettings, Integer>(63 properties.add(new PropertyDeclaration<CpogSettings, Integer>(
74 this, "Encoding bit-width", Integer.class) {
75 protected void setter(CpogSettings object, Integer value) {
76 CpogSettings.setEncodingWidth(value);
77 }
78 protected Integer getter(CpogSettings object) {
79 return CpogSettings.getEncodingWidth();
80 }
81 });
82
83 properties.add(new PropertyDeclaration<CpogSettings, Integer>(
84 this, "Circuit size in 2-input gates", Integer.class) {64 this, "Circuit size in 2-input gates", Integer.class) {
85 protected void setter(CpogSettings object, Integer value) {65 protected void setter(CpogSettings object, Integer value) {
86 CpogSettings.setCircuitSize(value);66 CpogSettings.setCircuitSize(value);
@@ -109,11 +89,41 @@
109 return CpogSettings.getMinisatCommand();89 return CpogSettings.getMinisatCommand();
110 }90 }
111 });91 });
92
93 properties.add(new PropertyDeclaration<CpogSettings, String>(
94 this, "Espresso solver", String.class) {
95 protected void setter(CpogSettings object, String value) {
96 CpogSettings.setEspressoCommand(value);
97 }
98 protected String getter(CpogSettings object) {
99 return CpogSettings.getEspressoCommand();
100 }
101 });
102
103 properties.add(new PropertyDeclaration<CpogSettings, String>(
104 this, "Abc folder path", String.class) {
105 protected void setter(CpogSettings object, String value) {
106 CpogSettings.setAbcFolder(value);
107 }
108 protected String getter(CpogSettings object) {
109 return CpogSettings.getAbcFolder();
110 }
111 });
112
113 properties.add(new PropertyDeclaration<CpogSettings, String>(
114 this, "Gate library (genlib format) inside abc folder", String.class) {
115 protected void setter(CpogSettings object, String value) {
116 CpogSettings.setGatesLibrary(value);
117 }
118 protected String getter(CpogSettings object) {
119 return CpogSettings.getGatesLibrary();
120 }
121 });
112 }122 }
113 123
114 @Override124 @Override
115 public String getName() {125 public String getName() {
116 return "Scenco"; // SCENario ENCOder!126 return "SCENCO";
117 }127 }
118128
119 @Override129 @Override
@@ -123,59 +133,81 @@
123133
124 @Override134 @Override
125 public void load(Config config) {135 public void load(Config config) {
126 setSatSolver(config.getEnum(keySatSolver, SatSolver.class, defaultSatSolver));136 satSolver = config.getEnum("CpogSettings.satSolver", SatSolver.class, SatSolver.CLASP);
127 setEncodingWidth(config.getInt(keyEncodingWidth, defaultEncodingWidth));137 circuitSize = config.getInt("CpogSettings.circuitSize", 4);
128 setCircuitSize(config.getInt(keyCircuitSize, defaultCircuitSize));138 setClaspCommand(config.getString("CpogSettings.claspCommand", "clasp"));
129 setClaspCommand(config.getString(keyClaspCommand, defaultClaspCommand));139 setMinisatCommand(config.getString("CpogSettings.minisatCommand", "minisat"));
130 setMinisatCommand(config.getString(keyMinisatCommand, defaultMinisatCommand));140 setEspressoCommand(config.getString("CpogSettings.espressoCommand", "espresso"));
141 setAbcFolder(config.getString("CpogSettings.abcFolder", "abc/"));
142 setGatesLibrary(config.getString("CpogSettings.gatesLibrary", "90nm.genlib"));
131 }143 }
132144
133 @Override145 @Override
134 public void save(Config config) {146 public void save(Config config) {
135 config.setEnum(keySatSolver, SatSolver.class, satSolver);147 config.setEnum("CpogSettings.satSolver", SatSolver.class, satSolver);
136 config.setInt(keyEncodingWidth, getEncodingWidth());148 config.setInt("CpogSettings.circuitSize", circuitSize);
137 config.setInt(keyCircuitSize, getCircuitSize());149 config.set("CpogSettings.claspCommand", claspCommand);
138 config.set(keyClaspCommand, getClaspCommand());150 config.set("CpogSettings.minisatCommand", minisatCommand);
139 config.set(keyMinisatCommand, getMinisatCommand());151 config.set("CpogSettings.espressoCommand", espressoCommand);
152 config.set("CpogSettings.abcFolder", abcFolder);
153 config.set("CpogSettings.gatesLibrary", gatesLibrary);
140 }154 }
141155
142 public static SatSolver getSatSolver() {156 public static SatSolver getSatSolver() {
143 return satSolver;157 return satSolver;
144 }158 }
145159
146 public static void setSatSolver(SatSolver value) {160 public static void setSatSolver(SatSolver satSolver) {
147 satSolver = value;161 CpogSettings.satSolver = satSolver;
148 }
149
150 public static int getEncodingWidth() {
151 return encodingWidth;
152 }
153
154 public static void setEncodingWidth(int value) {
155 encodingWidth = value;
156 }162 }
157163
158 public static int getCircuitSize() {164 public static int getCircuitSize() {
159 return circuitSize;165 return circuitSize;
160 }166 }
161167
162 public static void setCircuitSize(int value) {168 public static void setCircuitSize(int circuitSize) {
163 circuitSize = value;169 CpogSettings.circuitSize = circuitSize;
164 }170 }
165171
166 public static String getClaspCommand() {172 public static String getClaspCommand() {
167 return claspCommand;173 return claspCommand;
168 }174 }
169175
170 public static void setClaspCommand(String value) {176 public static void setClaspCommand(String claspCommand) {
171 claspCommand = value;177 CpogSettings.claspCommand = claspCommand;
172 }178 }
173179
174 public static String getMinisatCommand() {180 public static String getMinisatCommand() {
175 return minisatCommand;181 return minisatCommand;
176 }182 }
177183
178 public static void setMinisatCommand(String value) {184 public static void setMinisatCommand(String minisatCommand) {
179 minisatCommand = value;185 CpogSettings.minisatCommand = minisatCommand;
180 }186 }
187
188 public static String getEspressoCommand() {
189 return espressoCommand;
190 }
191
192 public static void setEspressoCommand(String espressoCommand) {
193 CpogSettings.espressoCommand = espressoCommand;
194 }
195
196 public static String getAbcFolder() {
197 return abcFolder;
198 }
199
200 public static void setAbcFolder(String abcFolder) {
201 CpogSettings.abcFolder = abcFolder;
202 }
203
204 public static String getGatesLibrary() {
205 return gatesLibrary;
206 }
207
208 public static void setGatesLibrary(String gatesLibrary) {
209 CpogSettings.gatesLibrary = gatesLibrary;
210 }
211
212
181}213}
182214
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettings.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettings.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettings.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,208 @@
1package org.workcraft.plugins.cpog;
2
3import java.io.File;
4import java.io.IOException;
5import java.util.ArrayList;
6import java.util.LinkedHashMap;
7import java.util.Map;
8
9import org.workcraft.util.FileUtils;
10
11public class EncoderSettings {
12
13 public enum generationMode{
14 OPTIMAL_ENCODING("Simulated annealing"),
15 RECURSIVE("Exhaustive search"),
16 RANDOM("Random search"),
17 SCENCO("Old tool SCENCO"),
18 OLD_SYNT("Old synthesise");
19
20 public final String name;
21
22 public static final generationMode[] modes =
23 {
24 OPTIMAL_ENCODING,
25 RECURSIVE,
26 RANDOM,
27 SCENCO,
28 OLD_SYNT
29 };
30
31 private generationMode(String name){
32 this.name = name;
33 }
34
35 static public Map<String, generationMode> getChoice() {
36 LinkedHashMap<String, generationMode> choice = new LinkedHashMap<String, generationMode>();
37 for (generationMode item : generationMode.values()) {
38 choice.put(item.name, item);
39 }
40 return choice;
41 }
42 }
43
44 public EncoderSettings(String espressoPath, String abcPath, String libPath) {
45 this.espressoPath = espressoPath;
46 this.abcPath = abcPath;
47 this.libPath = libPath;
48 }
49
50 private int solutionNumber = 10, numPO,bits;
51 private generationMode genMode = generationMode.OPTIMAL_ENCODING;
52 private boolean verboseMode, customEncMode, effort, contMode, cpogSize, costFunc;
53 private String[] customEnc;
54 private String espressoPath,abcPath,libPath;
55
56 public boolean isCpogSize() {
57 return cpogSize;
58 }
59
60 public void setCpogSize(boolean cpogSize) {
61 this.cpogSize = cpogSize;
62 }
63
64 public boolean isCostFunc() {
65 return costFunc;
66 }
67
68 public void setCostFunc(boolean costFunc) {
69 this.costFunc = costFunc;
70 }
71
72 public boolean isContMode() {
73 return contMode;
74 }
75
76 public void setContMode(boolean contMode) {
77 this.contMode = contMode;
78 }
79
80 public boolean isEffort() {
81 return effort;
82 }
83
84 public void setEffort(boolean effort) {
85 this.effort = effort;
86 }
87 public int getBits() {
88 return bits;
89 }
90
91 public void setBits(int bits) {
92 this.bits = bits;
93 }
94
95 public String getEspressoPath() {
96 return espressoPath;
97 }
98
99 public void setEspressoPath(String espressoPath) {
100 this.espressoPath = espressoPath;
101 }
102
103 public String getAbcPath() {
104 return abcPath;
105 }
106
107 public void setAbcPath(String abcPath) {
108 this.abcPath = abcPath;
109 }
110
111 public EncoderSettings(int solutionNumber, generationMode genMode, boolean verboseMode,
112 boolean customEncMode, String[] customEnc, int numPO) {
113 this.solutionNumber = solutionNumber;
114 this.genMode = genMode;
115 this.verboseMode = verboseMode;
116 this.customEncMode = customEncMode;
117 this.numPO = numPO;
118 this.customEnc = customEnc;
119 }
120
121 public EncoderSettings(int solutionNumber, generationMode genMode, boolean verboseMode,
122 boolean customEncMode) {
123 this.solutionNumber = solutionNumber;
124 this.genMode = genMode;
125 this.verboseMode = verboseMode;
126 this.customEncMode = customEncMode;
127 }
128
129 public int getSolutionNumber() {
130 return solutionNumber;
131 }
132
133 public void setSolutionNumber(int number){
134 solutionNumber = number;
135 }
136
137 public void setGenerationModeInt(int index){
138 switch(index){
139 case 0:
140 genMode = generationMode.OPTIMAL_ENCODING;
141 break;
142 case 1:
143 genMode = generationMode.RECURSIVE;
144 break;
145 case 2:
146 genMode = generationMode.RANDOM;
147 break;
148 case 3:
149 genMode = generationMode.SCENCO;
150 break;
151 case 4:
152 genMode = generationMode.OLD_SYNT;
153 break;
154 default:
155 System.out.println("Error.");
156 }
157 }
158
159 public int getNumPO() {
160 return numPO;
161 }
162
163 public void setNumPO(int numPO) {
164 this.numPO = numPO;
165 }
166
167 public generationMode getGenMode() {
168 return genMode;
169 }
170
171 public void setGenMode(generationMode genMode) {
172 this.genMode = genMode;
173 }
174
175 public boolean isVerboseMode() {
176 return verboseMode;
177 }
178
179 public void setVerboseMode(boolean verboseMode) {
180 this.verboseMode = verboseMode;
181 }
182
183 public boolean isCustomEncMode() {
184 return customEncMode;
185 }
186
187 public void setCustomEncMode(boolean customEncMode) {
188 this.customEncMode = customEncMode;
189 }
190
191 public String[] getCustomEnc() {
192 return customEnc;
193 }
194
195 public void setCustomEnc(String[] customEnc) {
196 this.customEnc = customEnc;
197 }
198
199 public String getLibPath() {
200 return libPath;
201 }
202
203 public void setLibPath(String libPath) {
204 this.libPath = libPath;
205 }
206
207
208}
0209
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettingsSerialiser.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettingsSerialiser.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/EncoderSettingsSerialiser.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,29 @@
1package org.workcraft.plugins.cpog;
2
3import org.w3c.dom.Element;
4import org.workcraft.plugins.shared.presets.SettingsSerialiser;
5import org.workcraft.util.XmlUtil;
6
7public class EncoderSettingsSerialiser implements SettingsSerialiser<EncoderSettings> {
8
9 @Override
10 public EncoderSettings fromXML(Element e) {
11 String espressoPath = XmlUtil.readStringAttr(e, "Espresso");
12 String abcPath = XmlUtil.readStringAttr(e, "Abc");
13 String libraryPath = XmlUtil.readStringAttr(e, "Library");
14
15 return new EncoderSettings(espressoPath,abcPath,libraryPath);
16 }
17
18 @Override
19 public void toXML(EncoderSettings settings, Element parent) {
20 Element e = parent.getOwnerDocument().createElement("settings");
21 e.setAttribute("Espresso", settings.getEspressoPath());
22 e.setAttribute("Abc", settings.getAbcPath());
23 e.setAttribute("Library", settings.getLibPath());
24
25 parent.appendChild(e);
26
27 }
28
29}
030
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerChainResultHandler.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerChainResultHandler.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerChainResultHandler.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,95 @@
1package org.workcraft.plugins.cpog;
2
3import javax.swing.JOptionPane;
4import javax.swing.SwingUtilities;
5
6import org.workcraft.plugins.cpog.EncoderSettings.generationMode;
7import org.workcraft.plugins.cpog.tasks.ProgrammerChainResult;
8import org.workcraft.plugins.cpog.tasks.ProgrammerChainTask;
9import org.workcraft.plugins.shared.tasks.ExternalProcessResult;
10import org.workcraft.tasks.DummyProgressMonitor;
11import org.workcraft.tasks.Result;
12import org.workcraft.tasks.Result.Outcome;
13
14public class ProgrammerChainResultHandler extends DummyProgressMonitor<ProgrammerChainResult> {
15 private String errorMessage;
16 private final ProgrammerChainTask task;
17
18 public ProgrammerChainResultHandler(ProgrammerChainTask task) {
19 this.task = task;
20 }
21
22 @Override
23 public void finished(final Result<? extends ProgrammerChainResult> result, String description) {
24 if (result.getOutcome() == Outcome.FINISHED) {
25 final generationMode programmerMode = result.getReturnValue().getProgrammerSettings().getGenMode();
26 switch (programmerMode) {
27 case OPTIMAL_ENCODING:
28 case RECURSIVE:
29 //SwingUtilities.invokeLater(new MpsatStgReachabilityResultHandler(task, result));
30 break;
31 default:
32 SwingUtilities.invokeLater(new Runnable() {
33 @Override
34 public void run() {
35 JOptionPane.showMessageDialog(null,
36 "Scenco mode \"" + programmerMode + "\" is not (yet) supported." ,
37 "Sorry..", JOptionPane.WARNING_MESSAGE);
38 }
39 });
40 break;
41 }
42 }
43 else if (result.getOutcome() != Outcome.CANCELLED) {
44 errorMessage = "Scenco tool chain execution failed :-(";
45
46 Throwable cause1 = result.getCause();
47
48 if (cause1 != null) {
49 // Exception was thrown somewhere in the chain task run() method (not in any of the subtasks)
50 errorMessage += "\n\nFailure caused by: " + cause1.toString() + "\nPlease see the \"Problems\" tab for more details.";
51 } else
52 {
53 Result<? extends Object> exportResult = result.getReturnValue().getExportResult();
54 if (exportResult.getOutcome() == Outcome.FAILED) {
55 errorMessage += "\n\nFailed to export the model as a .g file.";
56 Throwable cause = exportResult.getCause();
57 if (cause != null)
58 errorMessage += "\n\nFailure caused by: " + cause.toString() + "\nPlease see the \"Problems\" tab for more details.";
59 else
60 errorMessage += "\n\nThe exporter class did not offer further explanation.";
61 } else {
62 Result<? extends ExternalProcessResult> punfResult = result.getReturnValue().getPunfResult();
63
64 if (punfResult.getOutcome() == Outcome.FAILED) {
65 errorMessage += "\n\nPunf could not build the unfolding prefix.";
66 Throwable cause = punfResult.getCause();
67 if (cause != null)
68 errorMessage += "\n\nFailure caused by: " + cause.toString() + "\nPlease see the \"Problems\" tab for more details.";
69 else
70 errorMessage += "\n\nFailure caused by the following errors:\n" + new String(punfResult.getReturnValue().getErrors());
71 } else {
72 Result<? extends ExternalProcessResult> encoderResult = result.getReturnValue().getEncoderResult();
73
74 if (encoderResult.getOutcome() == Outcome.FAILED) {
75 errorMessage += "\n\nEncoder failed to execute as expected.";
76 Throwable cause = encoderResult.getCause();
77 if (cause != null)
78 errorMessage += "\n\nFailure caused by: " + cause.toString() + "\nPlease see the \"Problems\" tab for more details.";
79 else
80 errorMessage += "\n\nFailure caused by the following errors:\n" + new String(encoderResult.getReturnValue().getErrors());
81 }
82 else {
83 errorMessage += "\n\nEncoder chain task returned failure status without further explanation. This should not have happened -_-a.";
84 }
85 }
86 }
87 }
88 SwingUtilities.invokeLater(new Runnable() {
89 @Override
90 public void run() {
91 JOptionPane.showMessageDialog(null, errorMessage, "Oops..", JOptionPane.ERROR_MESSAGE); }
92 });
93 }
94 }
95}
0\ No newline at end of file96\ No newline at end of file
197
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerMode.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerMode.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerMode.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,41 @@
1package org.workcraft.plugins.cpog;
2
3public enum ProgrammerMode {
4 MICROCONTROLLER("-M", "Microcontroller synthesising", false),
5 CPOG_SIZE("-C", "Element controller synthesising", false);
6
7 private String argument;
8 private String description;
9 private boolean reach;
10
11 public static final ProgrammerMode[] modes =
12 {
13 MICROCONTROLLER,
14 CPOG_SIZE
15 };
16
17 public static ProgrammerMode getMode (String arg) {
18 for (int i=0; i<modes.length; i++)
19 if (modes[i].getArgument().equals(arg))
20 return modes[i];
21 return null;
22 }
23
24 ProgrammerMode(String argument, String description, boolean reach) {
25 this.argument = argument;
26 this.description = description;
27 this.reach = reach;
28 }
29
30 public String toString() {
31 return description;
32 }
33
34 public String getArgument() {
35 return argument;
36 }
37
38 public boolean isReach() {
39 return reach;
40 }
41}
0\ No newline at end of file42\ No newline at end of file
143
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerUtilitySettings.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerUtilitySettings.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/ProgrammerUtilitySettings.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,110 @@
1package org.workcraft.plugins.cpog;
2
3import java.util.Collection;
4import java.util.LinkedList;
5import java.util.List;
6
7import org.workcraft.Config;
8import org.workcraft.gui.propertyeditor.PropertyDeclaration;
9import org.workcraft.gui.propertyeditor.PropertyDescriptor;
10import org.workcraft.gui.propertyeditor.SettingsPage;
11import org.workcraft.plugins.cpog.EncoderSettings.generationMode;
12
13public class ProgrammerUtilitySettings implements SettingsPage {
14private static LinkedList<PropertyDescriptor> properties;
15
16 private static final String commandKey = "Tools.encoder.command";
17 private static final String solutionModeKey = "Tools.encoder.solutionMode";
18 private static final String extraArgsKey = "Tools.encoder.args";
19
20 private static String command = "scenco";
21 private static generationMode genMode = generationMode.OPTIMAL_ENCODING;
22 private static String extraArgs = "";
23
24 public ProgrammerUtilitySettings() {
25 properties = new LinkedList<PropertyDescriptor>();
26
27 properties.add(new PropertyDeclaration<ProgrammerUtilitySettings, String>(
28 this, "Scenco command", String.class) {
29 protected void setter(ProgrammerUtilitySettings object, String value) {
30 ProgrammerUtilitySettings.setCommand(value);
31 }
32 protected String getter(ProgrammerUtilitySettings object) {
33 return ProgrammerUtilitySettings.getCommand();
34 }
35 });
36
37 properties.add(new PropertyDeclaration<ProgrammerUtilitySettings, generationMode>(
38 this, "Check mode", generationMode.class, generationMode.getChoice()) {
39 protected void setter(ProgrammerUtilitySettings object, generationMode value) {
40 ProgrammerUtilitySettings.setGenerationMode(value);
41 }
42 protected generationMode getter(ProgrammerUtilitySettings object) {
43 return ProgrammerUtilitySettings.getGenerationMode();
44 }
45 });
46
47 properties.add(new PropertyDeclaration<ProgrammerUtilitySettings, String>(
48 this, "Scenco additional arguments", String.class) {
49 protected void setter(ProgrammerUtilitySettings object, String value) {
50 ProgrammerUtilitySettings.setExtraArgs(value);
51 }
52 protected String getter(ProgrammerUtilitySettings object) {
53 return ProgrammerUtilitySettings.getExtraArgs();
54 }
55 });
56 }
57
58 @Override
59 public List<PropertyDescriptor> getDescriptors() {
60 return properties;
61 }
62
63 @Override
64 public void load(Config config) {
65 command = config.getString(commandKey, "scenco");
66 genMode = config.getEnum(solutionModeKey, generationMode.class, generationMode.OPTIMAL_ENCODING);
67 extraArgs = config.getString(extraArgsKey, "");
68 }
69
70 @Override
71 public void save(Config config) {
72 config.set(commandKey, command);
73 config.setEnum(solutionModeKey, generationMode.class, genMode);
74 config.set(extraArgsKey, extraArgs);
75 }
76
77 @Override
78 public String getSection() {
79 return "External tools";
80 }
81
82 @Override
83 public String getName() {
84 return "Scenco";
85 }
86
87 public static String getCommand() {
88 return command;
89 }
90
91 public static void setCommand(String value) {
92 ProgrammerUtilitySettings.command = value;
93 }
94
95 public static String getExtraArgs() {
96 return extraArgs;
97 }
98
99 public static void setExtraArgs(String value) {
100 ProgrammerUtilitySettings.extraArgs = value;
101 }
102
103 public static void setGenerationMode(generationMode value) {
104 ProgrammerUtilitySettings.genMode = value;
105 }
106
107 public static generationMode getGenerationMode() {
108 return genMode;
109 }
110}
0111
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/Variable.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/Variable.java 2014-04-07 16:35:42 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/Variable.java 2014-07-11 09:42:10 +0000
@@ -31,7 +31,8 @@
31@DisplayName("Variable")31@DisplayName("Variable")
32@VisualClass(org.workcraft.plugins.cpog.VisualVariable.class)32@VisualClass(org.workcraft.plugins.cpog.VisualVariable.class)
33public class Variable extends MathNode implements Comparable<Variable>, BooleanVariable33public class Variable extends MathNode implements Comparable<Variable>, BooleanVariable
34{34{
35
35 private VariableState state = VariableState.UNDEFINED;36 private VariableState state = VariableState.UNDEFINED;
36 37
37 private String label = "";38 private String label = "";
3839
=== added directory 'CpogsPlugin/src/org/workcraft/plugins/cpog/gui'
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/gui/EncoderConfigurationDialog.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/gui/EncoderConfigurationDialog.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/gui/EncoderConfigurationDialog.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,451 @@
1package org.workcraft.plugins.cpog.gui;
2
3import info.clearthought.layout.TableLayout;
4
5import java.awt.Color;
6import java.awt.Dimension;
7import java.awt.FlowLayout;
8import java.awt.Window;
9import java.awt.event.ActionEvent;
10import java.awt.event.ActionListener;
11import java.awt.event.KeyEvent;
12import java.util.ArrayList;
13
14import javax.swing.BorderFactory;
15import javax.swing.JButton;
16import javax.swing.JCheckBox;
17import javax.swing.JComboBox;
18import javax.swing.JComponent;
19import javax.swing.JDialog;
20import javax.swing.JLabel;
21import javax.swing.JPanel;
22import javax.swing.JScrollPane;
23import javax.swing.JTable;
24import javax.swing.JTextField;
25import javax.swing.KeyStroke;
26
27import org.workcraft.gui.SimpleFlowLayout;
28import org.workcraft.plugins.cpog.CpogProgrammer;
29import org.workcraft.plugins.cpog.EncoderSettings;
30import org.workcraft.plugins.cpog.EncoderSettings.generationMode;
31import org.workcraft.plugins.cpog.VisualCPOG;
32import org.workcraft.plugins.cpog.VisualScenario;
33import org.workcraft.plugins.shared.presets.PresetManager;
34import org.workcraft.workspace.WorkspaceEntry;
35
36public class EncoderConfigurationDialog extends JDialog {
37
38 private JLabel numberOfSolutionsLabel, contLabel,
39 verboseModeLabel,exampleLabel,exampleLabel2,exampleLabel3,exampleLabel4,
40 exampleLabel5,customEncLabel,bitsLabel,effortLabel,genLabel,
41 optimiseLabel, disableLabel;
42 private JCheckBox verboseModeCheck, customEncodings, effortCheck,
43 disableCheck, contCheck;
44 private JComboBox generationModeBox,OptimiseBox;
45 private JPanel generationPanel, buttonsPanel, content;
46 private JButton saveButton, closeButton;
47 private JTextField numberOfSolutionsText, bitsText;
48 private PresetManager<EncoderSettings> presetManager;
49 private JTable encodingTable;
50 JScrollPane scrollPane;
51 private TableLayout layout;
52 private int m,bits;
53
54 // Core variables
55 private CpogProgrammer encoder;
56 private EncoderSettings settings;
57 private WorkspaceEntry we;
58 private static boolean settingsPresent = false;
59
60 Dimension dimensionLabel = new Dimension(270, 22);
61 Dimension dimensionBox = new Dimension(270, 22);
62 Dimension dimensionText = new Dimension(585,22);
63 Dimension dimensionTable = new Dimension(942,100);
64 Dimension dimensionWindow = new Dimension(100,400);
65
66 //generationPanel.getPreferredSize().height
67
68 public EncoderSettings getSettings() {
69 return settings;
70 }
71
72 public EncoderConfigurationDialog(Window owner, PresetManager<EncoderSettings> presetManager, EncoderSettings settings,WorkspaceEntry we) {
73 super(owner, "SCENCO configuration", ModalityType.APPLICATION_MODAL);
74 this.presetManager = presetManager;
75 this.settings = settings;
76 this.we = we;
77
78 createGenerationPanel();
79 createButtonPanel();
80
81 /*double size[][] = new double[][] {
82 {TableLayout.FILL},
83 {TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL, dimensionWindow.height }
84 };*/
85 double size[][] = new double[][] {
86 {946},
87 {430,100}
88 };
89
90 layout = new TableLayout(size);
91 //layout.setHGap(3);
92 //layout.setVGap(3);
93
94 content = new JPanel(layout);
95 content.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
96
97 content.add(generationPanel, "0 0");
98 content.add(buttonsPanel, "0 1");
99 setContentPane(content);
100
101
102
103 getRootPane().registerKeyboardAction(new ActionListener() {
104 @Override
105 public void actionPerformed(ActionEvent e) {
106 setVisible(false);
107 }
108 },
109 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
110 JComponent.WHEN_IN_FOCUSED_WINDOW);
111
112 }
113
114 private void createButtonPanel() {
115 buttonsPanel = new JPanel (new FlowLayout(FlowLayout.RIGHT));
116
117 saveButton = new JButton ("Run");
118 saveButton.addActionListener(new ActionListener() {
119 @Override
120 public void actionPerformed(ActionEvent e) {
121 setVisible(false);
122
123
124 // ENCODER EXECUTION
125
126 // Read parameters
127 if (effortCheck.isSelected())
128 settings.setEffort(false);
129 else
130 settings.setEffort(true);
131 settings.setBits(Integer.valueOf(bitsText.getText()));
132 settings.setCpogSize(OptimiseBox.getSelectedIndex() == 0 ? false : true);
133 settings.setCostFunc(disableCheck.isSelected());
134 settings.setVerboseMode(verboseModeCheck.isSelected());
135 settings.setContMode(contCheck.isSelected());
136 settings.setGenerationModeInt(generationModeBox.getSelectedIndex());
137 settings.setSolutionNumber(Integer.parseInt(numberOfSolutionsText.getText()));
138 settings.setNumPO(m);
139 if(customEncodings.isSelected()){
140 settings.setCustomEncMode(true);
141 String encodings[] = new String[m];
142 for(int i = 0; i<m; i++){
143 encodings[i] = (String) encodingTable.getModel().getValueAt(i, 1);
144 }
145 settings.setCustomEnc(encodings);
146 }else{
147 settings.setBits(bits+1);
148 settings.setCustomEncMode(false);
149 }
150
151 // Set them on encoder
152 if(settingsPresent == false){
153 settingsPresent = true;
154 encoder = new CpogProgrammer(settings);
155 }else{
156 encoder.setSettings(settings);
157 }
158
159 // Execute programmer.x
160 encoder.run(we);
161 }
162 });
163
164 closeButton = new JButton ("Close");
165 closeButton.addActionListener(new ActionListener() {
166 @Override
167 public void actionPerformed(ActionEvent e) {
168 setVisible(false);
169 }
170 });
171
172 buttonsPanel.add(saveButton);
173 buttonsPanel.add(closeButton);
174
175 }
176
177 private void createGenerationPanel() {
178 setMinimumSize(new Dimension(600, 400));
179 generationPanel = new JPanel(new SimpleFlowLayout());
180 JPanel numberOfSolutionsPanel = new JPanel (new FlowLayout(FlowLayout.LEFT, 3, 0));
181 VisualCPOG cpog = (VisualCPOG)(we.getModelEntry().getVisualModel());
182 ArrayList<VisualScenario> scenarios = new ArrayList<VisualScenario>(cpog.getGroups());
183 m = scenarios.size();
184
185 // GENERATION MODE COMBOBOX
186 genLabel = new JLabel("Mode:");
187 genLabel.setPreferredSize(dimensionLabel);
188 generationModeBox = new JComboBox();
189 generationModeBox.setEditable(false);
190 generationModeBox.setPreferredSize(dimensionBox);
191 for (generationMode mode : generationMode.modes) {
192 generationModeBox.addItem(mode.name);
193 }
194 generationModeBox.setSelectedIndex(settings.getGenMode().ordinal());
195 generationModeBox.setBackground(Color.WHITE);
196 generationModeBox.addActionListener(new ActionListener() {
197
198 @Override
199 public void actionPerformed(ActionEvent e) {
200 switch(generationModeBox.getSelectedIndex()){
201 // SIMULATED ANNEALING
202 case 0:
203 numberOfSolutionsText.setBackground(Color.WHITE);
204 numberOfSolutionsText.setEnabled(true);
205 contCheck.setEnabled(true);
206 customEncodings.setEnabled(true);
207 disableCheck.setSelected(false);
208 disableCheck.setEnabled(true);
209 break;
210 // EXHAUSTIVE SEARCH
211 case 1:
212 numberOfSolutionsText.setBackground(Color.LIGHT_GRAY);
213 numberOfSolutionsText.setEnabled(false);
214 contCheck.setEnabled(false);
215 contCheck.setSelected(false);
216 customEncodings.setEnabled(false);
217 customEncodings.setSelected(false);
218 encodingTable.setEnabled(false);
219 encodingTable.setBackground(Color.LIGHT_GRAY);
220 bitsText.setBackground(Color.LIGHT_GRAY);
221 bitsText.setEnabled(false);
222 disableCheck.setSelected(false);
223 disableCheck.setEnabled(false);
224 break;
225 // RANDOM SEARCH
226 case 2:
227 numberOfSolutionsText.setBackground(Color.WHITE);
228 numberOfSolutionsText.setEnabled(true);
229 contCheck.setEnabled(true);
230 customEncodings.setEnabled(false);
231 customEncodings.setSelected(false);
232 encodingTable.setEnabled(false);
233 encodingTable.setBackground(Color.LIGHT_GRAY);
234 bitsText.setBackground(Color.LIGHT_GRAY);
235 bitsText.setEnabled(false);
236 disableCheck.setSelected(false);
237 disableCheck.setEnabled(false);
238 break;
239 // OLD SCENCO
240 case 3:
241 numberOfSolutionsText.setBackground(Color.LIGHT_GRAY);
242 numberOfSolutionsText.setEnabled(false);
243 contCheck.setEnabled(false);
244 contCheck.setSelected(false);
245 customEncodings.setSelected(false);
246 customEncodings.setEnabled(false);
247 encodingTable.setEnabled(false);
248 encodingTable.setBackground(Color.LIGHT_GRAY);
249 bitsText.setBackground(Color.LIGHT_GRAY);
250 bitsText.setEnabled(false);
251 disableCheck.setSelected(false);
252 disableCheck.setEnabled(false);
253 break;
254 // OLD SYNTHESISE
255 case 4:
256 numberOfSolutionsText.setBackground(Color.LIGHT_GRAY);
257 numberOfSolutionsText.setEnabled(false);
258 contCheck.setEnabled(false);
259 contCheck.setSelected(false);
260 customEncodings.setSelected(false);
261 customEncodings.setEnabled(false);
262 encodingTable.setEnabled(false);
263 encodingTable.setBackground(Color.LIGHT_GRAY);
264 bitsText.setBackground(Color.LIGHT_GRAY);
265 bitsText.setEnabled(false);
266 disableCheck.setSelected(false);
267 disableCheck.setEnabled(false);
268 break;
269 default:
270 }
271 }
272 });
273
274 // OPTIMISE FOR MICROCONTROLLER/CPOG SIZE
275 optimiseLabel = new JLabel("Optimise for:");
276 optimiseLabel.setPreferredSize(dimensionLabel);
277 OptimiseBox = new JComboBox();
278 OptimiseBox.setEditable(false);
279 OptimiseBox.setPreferredSize(dimensionBox);
280 OptimiseBox.addItem("microcontroller");
281 OptimiseBox.addItem("CPOG size");
282 OptimiseBox.setSelectedIndex(settings.isCpogSize() ? 1 : 0);
283 OptimiseBox.setBackground(Color.WHITE);
284
285 // DISABLE COST FUNCTION
286 disableLabel = new JLabel("Disable cost function approximation: ");
287 disableLabel.setPreferredSize(dimensionLabel);
288 disableCheck = new JCheckBox("",settings.isCostFunc());
289 disableCheck.setToolTipText("Requires a big amount of time");
290
291
292 // Speed-up
293 effortLabel = new JLabel("Using heuristic for speed-up:");
294 effortLabel.setPreferredSize(dimensionLabel);
295 effortCheck = new JCheckBox("",settings.isEffort());
296
297 // NUMBER OF SOLUTIONS TO GENERATE
298 numberOfSolutionsLabel = new JLabel("Number of encodings to generate: ");
299 numberOfSolutionsLabel.setPreferredSize(dimensionLabel);
300 numberOfSolutionsText = new JTextField();
301 numberOfSolutionsText.setText(String.valueOf(settings.getSolutionNumber()));
302 numberOfSolutionsText.setPreferredSize(new Dimension(70, 15));
303
304 // CONTINUOUS MODE
305 contCheck = new JCheckBox("",settings.isContMode());
306 contLabel = new JLabel("Continuous mode");
307 contLabel.setPreferredSize(new Dimension(150, 15));
308 contCheck.addActionListener(new ActionListener() {
309
310 @Override
311 public void actionPerformed(ActionEvent e) {
312 if(contCheck.isSelected()){
313 numberOfSolutionsText.setBackground(Color.LIGHT_GRAY);
314 numberOfSolutionsText.setEnabled(false);
315 }else{
316 numberOfSolutionsText.setBackground(Color.WHITE);
317 numberOfSolutionsText.setEnabled(true);
318 }
319 }
320 });
321
322 // TABLE OF ENCODINGS
323 exampleLabel = new JLabel("Fill in the table below if you want to set a custom op-code to a whichever Partial Order Graph. Below symbols allowed:");
324 exampleLabel2 = new JLabel("- 0 1 assign a specific bit 0 or 1;");
325 exampleLabel3 = new JLabel("- X find the best bit assignment;");
326 exampleLabel4 = new JLabel("- - a Don't Care bit.");
327 exampleLabel5 = new JLabel("You have to take care of selecting an enough number of bits for encoding all Partial Order.");
328 exampleLabel.setPreferredSize(new Dimension(942,15));
329 exampleLabel2.setPreferredSize(new Dimension(800,15));
330 exampleLabel3.setPreferredSize(new Dimension(800,15));
331 exampleLabel4.setPreferredSize(new Dimension(800,15));
332 exampleLabel5.setPreferredSize(new Dimension(800,15));
333 customEncLabel = new JLabel("Custom encodings: ");
334 customEncLabel.setPreferredSize(dimensionLabel);
335 customEncodings = new JCheckBox("", false);
336 customEncodings.addActionListener(new ActionListener() {
337
338 @Override
339 public void actionPerformed(ActionEvent e) {
340 if(customEncodings.isSelected()){
341 encodingTable.setEnabled(true);
342 encodingTable.setBackground(Color.WHITE);
343 bitsText.setBackground(Color.WHITE);
344 bitsText.setEnabled(true);
345 }
346 else{
347 encodingTable.setEnabled(false);
348 encodingTable.setBackground(Color.LIGHT_GRAY);
349 bitsText.setBackground(Color.LIGHT_GRAY);
350 bitsText.setEnabled(false);
351 }
352 }
353 });
354
355 bitsLabel = new JLabel("Number of bits to use: ");
356 bitsLabel.setPreferredSize(dimensionLabel);
357 int value = 2;
358 while(value < m){
359 value *=2;
360 bits++;
361 }
362
363 bitsText = new JTextField();
364 bitsText.setText(String.valueOf(bits + 1));
365 bitsText.setPreferredSize(new Dimension(70, 15));
366 bitsText.setBackground(Color.LIGHT_GRAY);
367 bitsText.setEnabled(false);
368 bitsText.addActionListener(new ActionListener() {
369
370 @Override
371 public void actionPerformed(ActionEvent e) {
372 if(Integer.parseInt(bitsText.getText()) < bits +1)
373 bitsText.setText(String.valueOf(bits + 1));
374 for(int i=0;i<m;i++){
375 String data = "";
376 for(int j=0; j < Integer.valueOf(bitsText.getText()); j++) data = data + "X";
377 encodingTable.getModel().setValueAt(data, i, 1);
378 }
379 }
380 });
381
382 String[] columnNames = {"Partial Order Name","Encoding"};
383 Object[][] data = new Object[m][3];
384 for(int i=0; i<m; i++){
385 String name;
386 if(scenarios.get(i).getLabel().equals("")){
387 name = "CPOG " + i;
388 }
389 else{
390 name = scenarios.get(i).getLabel();
391 }
392 data[i][0] = name;
393 data[i][1] = "";
394 for(int j=0; j < Integer.valueOf(bitsText.getText()); j++) data[i][1] = data[i][1] + "X";
395 }
396 encodingTable = new JTable(data, columnNames);
397 MyTableCellRenderer renderer = new MyTableCellRenderer();
398 encodingTable.setDefaultRenderer(Object.class, renderer);
399 scrollPane = new JScrollPane(encodingTable);
400 scrollPane.setPreferredSize(dimensionTable);
401 encodingTable.setFillsViewportHeight(false);
402 encodingTable.setEnabled(false);
403 encodingTable.setBackground(Color.LIGHT_GRAY);
404
405
406 // VERBOSE MODE INSTANTIATION
407 verboseModeLabel = new JLabel("Activate verbose mode:");
408 verboseModeLabel.setPreferredSize(dimensionLabel);
409 verboseModeCheck = new JCheckBox("",false);
410
411 // INSTANTATING PANEL
412 generationPanel.add(genLabel);
413 generationPanel.add(generationModeBox);
414 generationPanel.add(new SimpleFlowLayout.LineBreak());
415 generationPanel.add(optimiseLabel);
416 generationPanel.add(OptimiseBox);
417 generationPanel.add(new SimpleFlowLayout.LineBreak());
418 generationPanel.add(disableLabel);
419 generationPanel.add(disableCheck);
420 generationPanel.add(new SimpleFlowLayout.LineBreak());
421 generationPanel.add(effortLabel);
422 generationPanel.add(effortCheck);
423 generationPanel.add(new SimpleFlowLayout.LineBreak());
424 generationPanel.add(numberOfSolutionsLabel);
425 generationPanel.add(numberOfSolutionsText);
426 generationPanel.add(contCheck);
427 generationPanel.add(contLabel);
428 generationPanel.add(new SimpleFlowLayout.LineBreak());
429 generationPanel.add(verboseModeLabel);
430 generationPanel.add(verboseModeCheck);
431 generationPanel.add(new SimpleFlowLayout.LineBreak());
432 generationPanel.add(exampleLabel);
433 generationPanel.add(new SimpleFlowLayout.LineBreak());
434 generationPanel.add(exampleLabel2);
435 generationPanel.add(new SimpleFlowLayout.LineBreak());
436 generationPanel.add(exampleLabel3);
437 generationPanel.add(new SimpleFlowLayout.LineBreak());
438 generationPanel.add(exampleLabel4);
439 generationPanel.add(new SimpleFlowLayout.LineBreak());
440 generationPanel.add(exampleLabel5);
441 generationPanel.add(new SimpleFlowLayout.LineBreak());
442 generationPanel.add(customEncLabel);
443 generationPanel.add(customEncodings);
444 generationPanel.add(new SimpleFlowLayout.LineBreak());
445 generationPanel.add(bitsLabel);
446 generationPanel.add(bitsText);
447 generationPanel.add(new SimpleFlowLayout.LineBreak());
448 generationPanel.add(scrollPane);
449 generationPanel.add(new SimpleFlowLayout.LineBreak());
450 }
451}
0452
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/gui/MyTableCellRenderer.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/gui/MyTableCellRenderer.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/gui/MyTableCellRenderer.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,15 @@
1package org.workcraft.plugins.cpog.gui;
2
3import java.awt.Component;
4
5import javax.swing.JTable;
6import javax.swing.table.DefaultTableCellRenderer;
7
8public class MyTableCellRenderer extends DefaultTableCellRenderer{
9 public Component getTableCellRendererComponent(JTable table,Object value,
10 boolean isSelected, boolean hasFocus, int row, int column){
11 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
12 setHorizontalAlignment( CENTER );
13 return this;
14 }
15 }
0\ No newline at end of file16\ No newline at end of file
117
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/CpogEncoding.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/CpogEncoding.java 2010-04-09 17:40:12 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/CpogEncoding.java 2014-07-11 09:42:10 +0000
@@ -31,6 +31,15 @@
31 public boolean[][] getEncoding() {31 public boolean[][] getEncoding() {
32 return encoding;32 return encoding;
33 }33 }
34 private final BooleanFormula[] functions;34 public void setEncoding(boolean[][] encoding){
35 private final boolean[][] encoding;35 this.encoding = encoding;
36 }
37 public void setFormula(BooleanFormula formula,int index){
38 this.functions[index] = formula;
39 }
40 public void setFormule(BooleanFormula[] formula){
41 this.functions = formula;
42 }
43 private BooleanFormula[] functions;
44 private boolean[][] encoding;
36}45}
3746
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/DefaultCpogSolver.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/DefaultCpogSolver.java 2010-12-03 20:17:13 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/DefaultCpogSolver.java 2014-07-11 09:42:10 +0000
@@ -11,6 +11,12 @@
11 this.cnfConverter = simpleCnfTaskProvider;11 this.cnfConverter = simpleCnfTaskProvider;
12 }12 }
1313
14 public CpogOptimisationTask<? extends T> getTask(String[] scenarios, BooleanVariable [] variables, int derivedVars)
15 {
16 CpogOptimisationTask<? extends T> task = problemGenerator.getFormula(scenarios, variables, derivedVars);
17 return task;
18 }
19
14 public CpogEncoding solve(String[] scenarios, BooleanVariable [] variables, int derivedVars)20 public CpogEncoding solve(String[] scenarios, BooleanVariable [] variables, int derivedVars)
15 {21 {
16 CpogOptimisationTask<? extends T> task = problemGenerator.getFormula(scenarios, variables, derivedVars);22 CpogOptimisationTask<? extends T> task = problemGenerator.getFormula(scenarios, variables, derivedVars);
1723
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/FreeVariable.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/FreeVariable.java 2010-04-13 15:52:01 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/FreeVariable.java 2014-07-11 09:42:10 +0000
@@ -3,7 +3,7 @@
3import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor;3import org.workcraft.plugins.cpog.optimisation.expressions.BooleanVisitor;
44
5public class FreeVariable implements BooleanVariable, Comparable<FreeVariable> {5public class FreeVariable implements BooleanVariable, Comparable<FreeVariable> {
66
7 private final String label;7 private final String label;
88
9 public FreeVariable(String label) {9 public FreeVariable(String label) {
1010
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFormulaSerialiser.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFormulaSerialiser.java 2010-10-22 14:07:56 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFormulaSerialiser.java 2014-07-11 09:42:10 +0000
@@ -22,6 +22,8 @@
22package org.workcraft.plugins.cpog.serialisation;22package org.workcraft.plugins.cpog.serialisation;
2323
24import org.w3c.dom.Element;24import org.w3c.dom.Element;
25import org.workcraft.dom.hierarchy.NamespaceHelper;
26import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager;
25import org.workcraft.exceptions.SerialisationException;27import org.workcraft.exceptions.SerialisationException;
26import org.workcraft.plugins.cpog.optimisation.BooleanFormula;28import org.workcraft.plugins.cpog.optimisation.BooleanFormula;
27import org.workcraft.plugins.cpog.optimisation.BooleanVariable;29import org.workcraft.plugins.cpog.optimisation.BooleanVariable;
@@ -31,6 +33,7 @@
31import org.workcraft.serialisation.ReferenceProducer;33import org.workcraft.serialisation.ReferenceProducer;
32import org.workcraft.serialisation.xml.CustomXMLSerialiser;34import org.workcraft.serialisation.xml.CustomXMLSerialiser;
33import org.workcraft.serialisation.xml.NodeSerialiser;35import org.workcraft.serialisation.xml.NodeSerialiser;
36import org.workcraft.util.Identifier;
3437
35public abstract class BooleanFormulaSerialiser implements CustomXMLSerialiser38public abstract class BooleanFormulaSerialiser implements CustomXMLSerialiser
36{39{
@@ -52,10 +55,21 @@
52 }55 }
53 56
54 PrinterSuite printers = new FormulaToString.PrinterSuite();57 PrinterSuite printers = new FormulaToString.PrinterSuite();
55 printers.vars = new FormulaToString.VariablePrinter(){58 printers.vars = new FormulaToString.VariablePrinter() {
56 @Override59 @Override
57 public Void visit(BooleanVariable node) {60 public Void visit(BooleanVariable node) {
58 append("var_"+internalReferences.getReference(node));61
62 String ref = internalReferences.getReference(node);
63 // use full path to a flattened name
64 String flat = NamespaceHelper.getFlatName(ref);
65
66 // old style naming, if number is used as an ID for a contact
67 if (Identifier.isNumber(ref)) {
68 append("var_"+ref);
69 } else
70 append(flat);
71
72
59 return null;73 return null;
60 }74 }
61 };75 };
6276
=== modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFunctionDeserialiser.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFunctionDeserialiser.java 2010-10-22 14:07:56 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/serialisation/BooleanFunctionDeserialiser.java 2014-07-11 09:42:10 +0000
@@ -22,6 +22,7 @@
22package org.workcraft.plugins.cpog.serialisation;22package org.workcraft.plugins.cpog.serialisation;
2323
24import org.w3c.dom.Element;24import org.w3c.dom.Element;
25import org.workcraft.dom.hierarchy.NamespaceHelper;
25import org.workcraft.exceptions.DeserialisationException;26import org.workcraft.exceptions.DeserialisationException;
26import org.workcraft.plugins.cpog.optimisation.BooleanFormula;27import org.workcraft.plugins.cpog.optimisation.BooleanFormula;
27import org.workcraft.plugins.cpog.optimisation.BooleanVariable;28import org.workcraft.plugins.cpog.optimisation.BooleanVariable;
@@ -43,7 +44,30 @@
43 this.internalReferenceResolver = internalReferenceResolver;44 this.internalReferenceResolver = internalReferenceResolver;
44 }45 }
4546
46 public BooleanVariable eval(String ref){ return (BooleanVariable) internalReferenceResolver.getObject(ref.substring("var_".length())); }47 public BooleanVariable eval(String ref){
48
49 if (ref.startsWith("var_")) {
50 ref = ref.substring("var_".length());
51
52 BooleanVariable bv = (BooleanVariable)internalReferenceResolver.getObject(ref);
53 if (bv!=null)
54 return bv;
55
56// for (Object o: internalReferenceResolver.getObjects()) {
57// if (o instanceof BooleanVariable) {
58// bv = (BooleanVariable)o;
59// if (bv.getLegacyID().equals(Integer.valueOf(ref)))
60// return bv;
61//
62// return null;
63// }
64// }
65 }
66
67 String hier = NamespaceHelper.flatToHierarchicalName(ref);
68
69 return (BooleanVariable) internalReferenceResolver.getObject(hier);
70 }
47 }71 }
4872
49 @Override73 @Override
5074
=== added directory 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks'
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainResult.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainResult.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainResult.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,56 @@
1package org.workcraft.plugins.cpog.tasks;
2
3import org.workcraft.plugins.cpog.EncoderSettings;
4import org.workcraft.plugins.shared.tasks.ExternalProcessResult;
5import org.workcraft.tasks.Result;
6
7public class ProgrammerChainResult {
8 private Result<? extends ExternalProcessResult> punfResult;
9 private Result<? extends ExternalProcessResult> encoderResult;
10 private Result<? extends Object> exportResult;
11 private EncoderSettings encoderSettings;
12 private String message;
13
14 public ProgrammerChainResult(Result<? extends Object> exportResult,
15 Result<? extends ExternalProcessResult> punfResult,
16 Result<? extends ExternalProcessResult> encoderResult,
17 EncoderSettings encoderSettings) {
18 this.punfResult = punfResult;
19 this.encoderResult = encoderResult;
20 this.exportResult = exportResult;
21 this.encoderSettings = encoderSettings;
22 }
23
24 public ProgrammerChainResult(Result<? extends Object> exportResult,
25 Result<? extends ExternalProcessResult> punfResult,
26 Result<? extends ExternalProcessResult> encoderResult,
27 EncoderSettings encoderSettings, String message) {
28
29 this.punfResult = punfResult;
30 this.encoderResult = encoderResult;
31 this.exportResult = exportResult;
32 this.encoderSettings = encoderSettings;
33
34 this.message = message;
35 }
36
37 public EncoderSettings getProgrammerSettings() {
38 return encoderSettings;
39 }
40
41 public Result<? extends ExternalProcessResult> getPunfResult() {
42 return punfResult;
43 }
44
45 public Result<? extends ExternalProcessResult> getEncoderResult() {
46 return encoderResult;
47 }
48
49 public String getMessage() {
50 return message;
51 }
52
53 public Result<? extends Object> getExportResult() {
54 return exportResult;
55 }
56}
057
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainTask.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainTask.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerChainTask.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,103 @@
1package org.workcraft.plugins.cpog.tasks;
2
3import java.io.File;
4
5import org.workcraft.Framework;
6import org.workcraft.dom.visual.VisualModel;
7import org.workcraft.interop.Exporter;
8import org.workcraft.plugins.cpog.EncoderSettings;
9import org.workcraft.plugins.shared.tasks.ExternalProcessResult;
10import org.workcraft.serialisation.Format;
11import org.workcraft.tasks.ProgressMonitor;
12import org.workcraft.tasks.Result;
13import org.workcraft.tasks.SubtaskMonitor;
14import org.workcraft.tasks.Task;
15import org.workcraft.tasks.Result.Outcome;
16import org.workcraft.util.Export;
17import org.workcraft.util.WorkspaceUtils;
18import org.workcraft.util.Export.ExportTask;
19import org.workcraft.workspace.WorkspaceEntry;
20
21public class ProgrammerChainTask implements Task<ProgrammerChainResult> {
22
23 private final WorkspaceEntry we;
24 private final EncoderSettings settings;
25 private final Framework framework;
26 private VisualModel model;
27
28 public ProgrammerChainTask(WorkspaceEntry we, EncoderSettings settings, Framework framework) {
29 this.we = we;
30 this.settings = settings;
31 this.framework = framework;
32 this.model = null;
33 }
34
35 @Override
36 public Result<? extends ProgrammerChainResult> run(ProgressMonitor<? super ProgrammerChainResult> monitor) {
37 try {
38 if(model == null) {
39 model = WorkspaceUtils.getAs(getWorkspaceEntry(), VisualModel.class);
40 }
41 Exporter exporter = Export.chooseBestExporter(framework.getPluginManager(), model, Format.DOT);
42 if (exporter == null) {
43 throw new RuntimeException ("Exporter not available: model class " + model.getClass().getName() + " to format STG.");
44 }
45 File netFile = File.createTempFile("net", exporter.getExtenstion());
46 ExportTask exportTask;
47 exportTask = new ExportTask(exporter, model, netFile.getCanonicalPath());
48 SubtaskMonitor<Object> mon = new SubtaskMonitor<Object>(monitor);
49 Result<? extends Object> exportResult = framework.getTaskManager().execute(exportTask, "Exporting .g", mon);
50 if (exportResult.getOutcome() != Outcome.FINISHED) {
51 netFile.delete();
52 if (exportResult.getOutcome() == Outcome.CANCELLED)
53 return new Result<ProgrammerChainResult>(Outcome.CANCELLED);
54 return new Result<ProgrammerChainResult>(Outcome.FAILED, new ProgrammerChainResult(exportResult, null, null, settings));
55 }
56 monitor.progressUpdate(0.33);
57
58// File mciFile = File.createTempFile("unfolding", ".mci");
59// PunfTask punfTask = new PunfTask(netFile.getCanonicalPath(), mciFile.getCanonicalPath());
60// Result<? extends ExternalProcessResult> punfResult = framework.getTaskManager().execute(punfTask, "Unfolding .g", mon);
61// netFile.delete();
62//
63// if (punfResult.getOutcome() != Outcome.FINISHED) {
64// mciFile.delete();
65// if (punfResult.getOutcome() == Outcome.CANCELLED)
66// return new Result<ProgrammerChainResult>(Outcome.CANCELLED);
67// return new Result<ProgrammerChainResult>(Outcome.FAILED, new ProgrammerChainResult(exportResult, punfResult, null, settings));
68// }
69//
70// monitor.progressUpdate(0.66);
71//
72// ProgrammerTask programmerTask = new ProgrammerTask(null, mciFile.getCanonicalPath());
73// Result<? extends ExternalProcessResult> encoderResult = framework.getTaskManager().execute(programmerTask, "Running scenco model-checking", mon);
74// mciFile.delete();
75//
76// if (encoderResult.getOutcome() != Outcome.FINISHED) {
77// if (encoderResult.getOutcome() == Outcome.CANCELLED)
78// return new Result<ProgrammerChainResult>(Outcome.CANCELLED);
79// return new Result<ProgrammerChainResult>(Outcome.FAILED, new ProgrammerChainResult(exportResult, punfResult, encoderResult, settings ));
80// }
81
82 monitor.progressUpdate(1.0);
83
84// return new Result<ProgrammerChainResult>(Outcome.FINISHED, new ProgrammerChainResult(exportResult, punfResult, encoderResult, settings));
85 return new Result<ProgrammerChainResult>(Outcome.FINISHED, null);
86 } catch (Throwable e) {
87 return new Result<ProgrammerChainResult>(e);
88 }
89 }
90
91 public EncoderSettings getSettings() {
92 return settings;
93 }
94
95 public Framework getFramework() {
96 return framework;
97 }
98
99 public WorkspaceEntry getWorkspaceEntry() {
100 return we;
101 }
102
103}
0104
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerTask.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerTask.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tasks/ProgrammerTask.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,73 @@
1package org.workcraft.plugins.cpog.tasks;
2
3import java.io.File;
4import java.io.IOException;
5import java.util.ArrayList;
6import java.util.HashMap;
7import java.util.Map;
8
9import org.workcraft.plugins.cpog.ProgrammerUtilitySettings;
10import org.workcraft.plugins.shared.tasks.ExternalProcessResult;
11import org.workcraft.plugins.shared.tasks.ExternalProcessTask;
12import org.workcraft.tasks.ProgressMonitor;
13import org.workcraft.tasks.Result;
14import org.workcraft.tasks.Task;
15import org.workcraft.tasks.Result.Outcome;
16import org.workcraft.util.FileUtils;
17
18public class ProgrammerTask implements Task<ExternalProcessResult> {
19 private String[] args;
20 private String inputFileName;
21
22 public ProgrammerTask(String[] args, String inputFileName) {
23 this.args = args;
24 this.inputFileName = inputFileName;
25 }
26
27 @Override
28 public Result<? extends ExternalProcessResult> run(ProgressMonitor<? super ExternalProcessResult> monitor) {
29
30 ArrayList<String> command = new ArrayList<String>();
31 command.add(ProgrammerUtilitySettings.getCommand());
32
33 for (String arg : ProgrammerUtilitySettings.getExtraArgs().split(" "))
34 if (!arg.isEmpty())
35 command.add(arg);
36
37 for (String arg : args)
38 command.add(arg);
39
40 command.add(inputFileName);
41
42 File workingDir = FileUtils.createTempDirectory("scenco");
43
44 ExternalProcessTask externalProcessTask = new ExternalProcessTask(command, workingDir);
45
46 Result<? extends ExternalProcessResult> res = externalProcessTask.run(monitor);
47
48 if(res.getOutcome() == Outcome.CANCELLED)
49 return res;
50
51 Map<String, byte[]> outputFiles = new HashMap<String, byte[]>();
52
53 try {
54 File mci = new File(workingDir, "scenco.mci");
55 if(mci.exists())
56 outputFiles.put("scenco.mci", FileUtils.readAllBytes(mci));
57
58 File g = new File(workingDir, "scenco.g");
59 if(g.exists())
60 outputFiles.put("scenco.g", FileUtils.readAllBytes(g));
61 } catch (IOException e) {
62 return new Result<ExternalProcessResult>(e);
63 }
64
65 ExternalProcessResult retVal = res.getReturnValue();
66 ExternalProcessResult result = new ExternalProcessResult(retVal.getReturnCode(), retVal.getOutput(), retVal.getErrors(), outputFiles);
67
68 if (retVal.getReturnCode() < 2)
69 return Result.finished(result);
70 else
71 return Result.failed(result);
72 }
73}
074
=== added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/tools/EncoderPreferencesTool.java'
--- CpogsPlugin/src/org/workcraft/plugins/cpog/tools/EncoderPreferencesTool.java 1970-01-01 00:00:00 +0000
+++ CpogsPlugin/src/org/workcraft/plugins/cpog/tools/EncoderPreferencesTool.java 2014-07-11 09:42:10 +0000
@@ -0,0 +1,65 @@
1package org.workcraft.plugins.cpog.tools;
2
3import java.io.File;
4
5import org.workcraft.Framework;
6import org.workcraft.Tool;
7import org.workcraft.plugins.cpog.CpogProgrammer;
8import org.workcraft.plugins.cpog.EncoderSettings;
9import org.workcraft.plugins.cpog.EncoderSettings.generationMode;
10import org.workcraft.plugins.cpog.EncoderSettingsSerialiser;
11import org.workcraft.plugins.cpog.ProgrammerChainResultHandler;
12import org.workcraft.plugins.cpog.VisualCPOG;
13import org.workcraft.plugins.cpog.gui.EncoderConfigurationDialog;
14import org.workcraft.plugins.cpog.tasks.ProgrammerChainTask;
15import org.workcraft.plugins.shared.presets.PresetManager;
16import org.workcraft.util.GUI;
17import org.workcraft.workspace.WorkspaceEntry;
18
19public class EncoderPreferencesTool implements Tool {
20
21 private final Framework framework;
22 private static boolean settingPresent = false;
23 private EncoderSettings settings;
24 private EncoderConfigurationDialog dialog;
25 PresetManager<EncoderSettings> pmgr;
26
27 public EncoderPreferencesTool(Framework framework) {
28 this.framework = framework;
29 }
30
31 @Override
32 public boolean isApplicableTo(WorkspaceEntry we) {
33 if (we.getModelEntry() == null) return false;
34 if (we.getModelEntry().getVisualModel() instanceof VisualCPOG) return true;
35 return false;
36 }
37
38 @Override
39 public String getSection() {
40 return "Encoding";
41 }
42
43 @Override
44 public String getDisplayName() {
45 return "Cpog Programmer";
46 }
47
48 @Override
49 public void run(WorkspaceEntry we) {
50 if(settingPresent == false){
51 settingPresent = true;
52 settings = new EncoderSettings(10,generationMode.OPTIMAL_ENCODING,false, false);
53 pmgr = new PresetManager<EncoderSettings>(new File("config/cpog_presets.xml"), new EncoderSettingsSerialiser());
54 dialog = new EncoderConfigurationDialog(framework.getMainWindow(), pmgr, settings, we);
55 }
56
57 GUI.centerAndSizeToParent(dialog, framework.getMainWindow());
58 dialog.setVisible(true);
59 // TASK INSERTION
60 /*final ProgrammerChainTask programmerTask = new ProgrammerChainTask(we, dialog.getSettings(), framework);
61 framework.getTaskManager().queue(programmerTask, "Scenco tool chain",
62 new ProgrammerChainResultHandler(programmerTask));*/
63 }
64
65}
066
=== modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/Dfs.java'
--- DfsPlugin/src/org/workcraft/plugins/dfs/Dfs.java 2013-11-11 18:10:34 +0000
+++ DfsPlugin/src/org/workcraft/plugins/dfs/Dfs.java 2014-07-11 09:42:10 +0000
@@ -26,10 +26,12 @@
26import org.workcraft.dom.Connection;26import org.workcraft.dom.Connection;
27import org.workcraft.dom.Container;27import org.workcraft.dom.Container;
28import org.workcraft.dom.Node;28import org.workcraft.dom.Node;
29import org.workcraft.dom.hierarchy.NamespaceProvider;
29import org.workcraft.dom.math.AbstractMathModel;30import org.workcraft.dom.math.AbstractMathModel;
30import org.workcraft.dom.math.MathConnection;31import org.workcraft.dom.math.MathConnection;
32import org.workcraft.dom.math.MathGroup;
31import org.workcraft.dom.math.MathNode;33import org.workcraft.dom.math.MathNode;
32import org.workcraft.dom.references.UniqueNameReferenceManager;34import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager;
33import org.workcraft.gui.propertyeditor.Properties;35import org.workcraft.gui.propertyeditor.Properties;
34import org.workcraft.serialisation.References;36import org.workcraft.serialisation.References;
35import org.workcraft.util.Func;37import org.workcraft.util.Func;
@@ -40,11 +42,12 @@
40public class Dfs extends AbstractMathModel {42public class Dfs extends AbstractMathModel {
4143
42 public Dfs() {44 public Dfs() {
43 this(null, null);45 this(new MathGroup(), null);
44 }46 }
45 47
46 public Dfs(Container root, References refs) {48 public Dfs(Container root, References refs) {
47 super(root, new UniqueNameReferenceManager(refs, new Func<Node, String>() {49
50 super(root, new HierarchicalUniqueNameReferenceManager(refs, new Func<Node, String>() {
48 @Override51 @Override
49 public String eval(Node arg) {52 public String eval(Node arg) {
50 if ((arg instanceof Logic) || (arg instanceof CounterflowLogic))53 if ((arg instanceof Logic) || (arg instanceof CounterflowLogic))
@@ -82,11 +85,4 @@
82 return null;85 return null;
83 }86 }
8487
85 public String getName(Node node) {
86 return ((UniqueNameReferenceManager)getReferenceManager()).getName(node);
87 }
88
89 public void setName(Node node, String name) {
90 ((UniqueNameReferenceManager)getReferenceManager()).setName(node, name);
91 }
92}88}
9389
=== modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/stg/StgGenerator.java'
--- DfsPlugin/src/org/workcraft/plugins/dfs/stg/StgGenerator.java 2014-01-29 19:00:22 +0000
+++ DfsPlugin/src/org/workcraft/plugins/dfs/stg/StgGenerator.java 2014-07-11 09:42:10 +0000
@@ -10,6 +10,7 @@
10import java.util.Set;10import java.util.Set;
1111
12import org.workcraft.dom.Connection;12import org.workcraft.dom.Connection;
13import org.workcraft.dom.Container;
13import org.workcraft.dom.Node;14import org.workcraft.dom.Node;
14import org.workcraft.dom.visual.Movable;15import org.workcraft.dom.visual.Movable;
15import org.workcraft.dom.visual.Positioning;16import org.workcraft.dom.visual.Positioning;
@@ -197,7 +198,10 @@
197 SignalTransition.Type type = SignalTransition.Type.INTERNAL;198 SignalTransition.Type type = SignalTransition.Type.INTERNAL;
198 ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0);199 ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0);
199 200
200 VisualPlace C0 = stg.createPlace(nameC + name + name0);201
202 Container curContainer = null;
203
204 VisualPlace C0 = stg.createPlace(nameC + name + name0, curContainer);
201 C0.setLabel(labelC + name + label0);205 C0.setLabel(labelC + name + label0);
202 C0.setLabelPositioning(Positioning.BOTTOM);206 C0.setLabelPositioning(Positioning.BOTTOM);
203 if (!l.getReferencedLogic().isComputed()) {207 if (!l.getReferencedLogic().isComputed()) {
@@ -208,7 +212,7 @@
208 setPosition(C0, x + 2.0, y + 1.0);212 setPosition(C0, x + 2.0, y + 1.0);
209 nodes.add(C0);213 nodes.add(C0);
210214
211 VisualPlace C1 = stg.createPlace(nameC + name + name1);215 VisualPlace C1 = stg.createPlace(nameC + name + name1, curContainer);
212 C1.setLabel(labelC + name + label1);216 C1.setLabel(labelC + name + label1);
213 C1.setLabelPositioning(Positioning.TOP);217 C1.setLabelPositioning(Positioning.TOP);
214 if (l.getReferencedLogic().isComputed()) {218 if (l.getReferencedLogic().isComputed()) {
@@ -235,7 +239,7 @@
235 double dy = 0.0;239 double dy = 0.0;
236 for (Node n: preset) {240 for (Node n: preset) {
237 if (CR == null || l.getReferencedLogic().isEarlyEvaluation()) { 241 if (CR == null || l.getReferencedLogic().isEarlyEvaluation()) {
238 CR = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.PLUS);242 CR = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.PLUS, curContainer);
239 CR.setTokenColorGenerator(tokenColorGenerator);243 CR.setTokenColorGenerator(tokenColorGenerator);
240 createConsumingArc(C0, CR, false);244 createConsumingArc(C0, CR, false);
241 createProducingArc(CR, C1, true);245 createProducingArc(CR, C1, true);
@@ -244,7 +248,7 @@
244 }248 }
245 CRs.put(n, CR);249 CRs.put(n, CR);
246 if (CF == null) { 250 if (CF == null) {
247 CF = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.MINUS);251 CF = stg.createSignalTransition(nameC + name, type, SignalTransition.Direction.MINUS, curContainer);
248 createConsumingArc(C1, CF, false);252 createConsumingArc(C1, CF, false);
249 createProducingArc(CF, C0, false);253 createProducingArc(CF, C0, false);
250 setPosition(CF, x - 2.0, y - 1.0 - dy);254 setPosition(CF, x - 2.0, y - 1.0 - dy);
@@ -305,8 +309,9 @@
305 type = SignalTransition.Type.OUTPUT;309 type = SignalTransition.Type.OUTPUT;
306 }310 }
307 ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0);311 ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0);
312 Container curContainer = null;
308313
309 VisualPlace M0 = stg.createPlace(nameM + name + name0);314 VisualPlace M0 = stg.createPlace(nameM + name + name0, curContainer);
310 M0.setLabel(labelM + name + label0);315 M0.setLabel(labelM + name + label0);
311 M0.setLabelPositioning(Positioning.BOTTOM);316 M0.setLabelPositioning(Positioning.BOTTOM);
312 if (!r.getReferencedRegister().isMarked()) {317 if (!r.getReferencedRegister().isMarked()) {
@@ -317,7 +322,7 @@
317 setPosition(M0, x + 2.0, y + 1.0);322 setPosition(M0, x + 2.0, y + 1.0);
318 nodes.add(M0);323 nodes.add(M0);
319 324
320 VisualPlace M1 = stg.createPlace(nameM + name + name1);325 VisualPlace M1 = stg.createPlace(nameM + name + name1, curContainer);
321 M1.setLabel(labelM + name + label1);326 M1.setLabel(labelM + name + label1);
322 M1.setLabelPositioning(Positioning.TOP);327 M1.setLabelPositioning(Positioning.TOP);
323 if (r.getReferencedRegister().isMarked()) {328 if (r.getReferencedRegister().isMarked()) {
@@ -327,14 +332,14 @@
327 setPosition(M1, x + 2.0, y - 1.0);332 setPosition(M1, x + 2.0, y - 1.0);
328 nodes.add(M1);333 nodes.add(M1);
329 334
330 VisualSignalTransition MR = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.PLUS);335 VisualSignalTransition MR = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.PLUS, curContainer);
331 MR.setTokenColorGenerator(tokenColorGenerator);336 MR.setTokenColorGenerator(tokenColorGenerator);
332 createConsumingArc(M0, MR, false);337 createConsumingArc(M0, MR, false);
333 createProducingArc(MR, M1, true);338 createProducingArc(MR, M1, true);
334 setPosition(MR, x - 2.0, y + 1.0);339 setPosition(MR, x - 2.0, y + 1.0);
335 nodes.add(MR);340 nodes.add(MR);
336 341
337 VisualSignalTransition MF = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.MINUS);342 VisualSignalTransition MF = stg.createSignalTransition(nameM + name, type, SignalTransition.Direction.MINUS, curContainer);
338 createConsumingArc(M1, MF, false);343 createConsumingArc(M1, MF, false);
339 createProducingArc(MF, M0, false);344 createProducingArc(MF, M0, false);
340 setPosition(MF, x - 2.0, y - 1.0);345 setPosition(MF, x - 2.0, y - 1.0);
@@ -423,7 +428,9 @@
423 ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0);428 ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(l).size() == 0);
424 ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(l).size() == 0);429 ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(l).size() == 0);
425 430
426 VisualPlace fwC0 = stg.createPlace(nameFwC + name + name0);431 Container curContainer = null;
432
433 VisualPlace fwC0 = stg.createPlace(nameFwC + name + name0, curContainer);
427 fwC0.setLabel(labelFwC + name + label0);434 fwC0.setLabel(labelFwC + name + label0);
428 fwC0.setLabelPositioning(Positioning.BOTTOM);435 fwC0.setLabelPositioning(Positioning.BOTTOM);
429 if (!l.getReferencedCounterflowLogic().isForwardComputed()) {436 if (!l.getReferencedCounterflowLogic().isForwardComputed()) {
@@ -434,7 +441,7 @@
434 setPosition(fwC0, x + 2.0, y - 2.0);441 setPosition(fwC0, x + 2.0, y - 2.0);
435 nodes.add(fwC0);442 nodes.add(fwC0);
436443
437 VisualPlace fwC1 = stg.createPlace(nameFwC + name + name1);444 VisualPlace fwC1 = stg.createPlace(nameFwC + name + name1, curContainer);
438 fwC1.setLabel(labelFwC + name + label1);445 fwC1.setLabel(labelFwC + name + label1);
439 fwC1.setLabelPositioning(Positioning.TOP);446 fwC1.setLabelPositioning(Positioning.TOP);
440 if (l.getReferencedCounterflowLogic().isForwardComputed()) {447 if (l.getReferencedCounterflowLogic().isForwardComputed()) {
@@ -459,7 +466,7 @@
459 double dy = 0.0;466 double dy = 0.0;
460 for (Node n: preset) {467 for (Node n: preset) {
461 if (fwCR == null || l.getReferencedCounterflowLogic().isForwardEarlyEvaluation()) { 468 if (fwCR == null || l.getReferencedCounterflowLogic().isForwardEarlyEvaluation()) {
462 fwCR = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.PLUS);469 fwCR = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.PLUS, curContainer);
463 fwCR.setTokenColorGenerator(presetTokenColorGenerator);470 fwCR.setTokenColorGenerator(presetTokenColorGenerator);
464 createConsumingArc(fwC0, fwCR, false);471 createConsumingArc(fwC0, fwCR, false);
465 createProducingArc(fwCR, fwC1, true);472 createProducingArc(fwCR, fwC1, true);
@@ -468,7 +475,7 @@
468 }475 }
469 fwCRs.put(n, fwCR);476 fwCRs.put(n, fwCR);
470 if (fwCF == null) { 477 if (fwCF == null) {
471 fwCF = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.MINUS);478 fwCF = stg.createSignalTransition(nameFwC + name, type, SignalTransition.Direction.MINUS, curContainer);
472 createConsumingArc(fwC1, fwCF, false);479 createConsumingArc(fwC1, fwCF, false);
473 createProducingArc(fwCF, fwC0, false);480 createProducingArc(fwCF, fwC0, false);
474 stg.connect(fwC1, fwCF);481 stg.connect(fwC1, fwCF);
@@ -481,7 +488,7 @@
481 }488 }
482 }489 }
483 490
484 VisualPlace bwC0 = stg.createPlace(nameBwC + name + name0);491 VisualPlace bwC0 = stg.createPlace(nameBwC + name + name0, curContainer);
485 bwC0.setLabel(labelBwC + name + label0);492 bwC0.setLabel(labelBwC + name + label0);
486 bwC0.setLabelPositioning(Positioning.BOTTOM);493 bwC0.setLabelPositioning(Positioning.BOTTOM);
487 if (!l.getReferencedCounterflowLogic().isBackwardComputed()) {494 if (!l.getReferencedCounterflowLogic().isBackwardComputed()) {
@@ -492,7 +499,7 @@
492 setPosition(bwC0, x + 2.0, y + 4.0);499 setPosition(bwC0, x + 2.0, y + 4.0);
493 nodes.add(bwC0);500 nodes.add(bwC0);
494501
495 VisualPlace bwC1 = stg.createPlace(nameBwC + name + name1);502 VisualPlace bwC1 = stg.createPlace(nameBwC + name + name1, curContainer);
496 bwC1.setLabel(labelBwC + name + label1);503 bwC1.setLabel(labelBwC + name + label1);
497 bwC1.setLabelPositioning(Positioning.TOP);504 bwC1.setLabelPositioning(Positioning.TOP);
498 if (l.getReferencedCounterflowLogic().isBackwardComputed()) {505 if (l.getReferencedCounterflowLogic().isBackwardComputed()) {
@@ -517,7 +524,7 @@
517 double dy = 0.0;524 double dy = 0.0;
518 for (Node n: postset) {525 for (Node n: postset) {
519 if (bwCR == null || l.getReferencedCounterflowLogic().isBackwardEarlyEvaluation()) { 526 if (bwCR == null || l.getReferencedCounterflowLogic().isBackwardEarlyEvaluation()) {
520 bwCR = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.PLUS);527 bwCR = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.PLUS, curContainer);
521 bwCR.setTokenColorGenerator(postsetTokenColorGenerator);528 bwCR.setTokenColorGenerator(postsetTokenColorGenerator);
522 stg.connect(bwC0, bwCR);529 stg.connect(bwC0, bwCR);
523 stg.connect(bwCR, bwC1);530 stg.connect(bwCR, bwC1);
@@ -526,7 +533,7 @@
526 }533 }
527 bwCRs.put(n, bwCR);534 bwCRs.put(n, bwCR);
528 if (bwCF == null) { 535 if (bwCF == null) {
529 bwCF = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.MINUS);536 bwCF = stg.createSignalTransition(nameBwC + name, type, SignalTransition.Direction.MINUS, curContainer);
530 stg.connect(bwC1, bwCF);537 stg.connect(bwC1, bwCF);
531 stg.connect(bwCF, bwC0);538 stg.connect(bwCF, bwC0);
532 setPosition(bwCF, x - 2.0, y + 2.0 - dy);539 setPosition(bwCF, x - 2.0, y + 2.0 - dy);
@@ -585,7 +592,9 @@
585 ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0);592 ColorGenerator presetTokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0);
586 ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(r).size() == 0);593 ColorGenerator postsetTokenColorGenerator = createColorGenerator(dfs.getPostset(r).size() == 0);
587594
588 VisualPlace orM0 = stg.createPlace(nameOrM + name + name0);595 Container curContainer = null;
596
597 VisualPlace orM0 = stg.createPlace(nameOrM + name + name0, curContainer);
589 orM0.setLabel(labelOrM + name + label0);598 orM0.setLabel(labelOrM + name + label0);
590 orM0.setLabelPositioning(Positioning.BOTTOM);599 orM0.setLabelPositioning(Positioning.BOTTOM);
591 if (!r.getReferencedCounterflowRegister().isOrMarked()) {600 if (!r.getReferencedCounterflowRegister().isOrMarked()) {
@@ -596,7 +605,7 @@
596 setPosition(orM0, x + 2.0, y - 2.0);605 setPosition(orM0, x + 2.0, y - 2.0);
597 nodes.add(orM0);606 nodes.add(orM0);
598607
599 VisualPlace orM1 = stg.createPlace(nameOrM + name + name1);608 VisualPlace orM1 = stg.createPlace(nameOrM + name + name1, curContainer);
600 orM1.setLabel(labelOrM + name + label1);609 orM1.setLabel(labelOrM + name + label1);
601 orM1.setLabelPositioning(Positioning.TOP);610 orM1.setLabelPositioning(Positioning.TOP);
602 if (r.getReferencedCounterflowRegister().isOrMarked()) {611 if (r.getReferencedCounterflowRegister().isOrMarked()) {
@@ -607,33 +616,33 @@
607 setPosition(orM1, x + 2.0, y - 4.0);616 setPosition(orM1, x + 2.0, y - 4.0);
608 nodes.add(orM1);617 nodes.add(orM1);
609618
610 VisualSignalTransition orMRfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS);619 VisualSignalTransition orMRfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS, curContainer);
611 orMRfw.setTokenColorGenerator(presetTokenColorGenerator);620 orMRfw.setTokenColorGenerator(presetTokenColorGenerator);
612 createConsumingArc(orM0, orMRfw, false);621 createConsumingArc(orM0, orMRfw, false);
613 createProducingArc(orMRfw, orM1, true);622 createProducingArc(orMRfw, orM1, true);
614 setPosition(orMRfw, x - 2.0, y - 2.5);623 setPosition(orMRfw, x - 2.0, y - 2.5);
615 nodes.add(orMRfw);624 nodes.add(orMRfw);
616625
617 VisualSignalTransition orMRbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS);626 VisualSignalTransition orMRbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.PLUS, curContainer);
618 orMRbw.setTokenColorGenerator(postsetTokenColorGenerator);627 orMRbw.setTokenColorGenerator(postsetTokenColorGenerator);
619 createConsumingArc(orM0, orMRbw, false);628 createConsumingArc(orM0, orMRbw, false);
620 createProducingArc(orMRbw, orM1, true);629 createProducingArc(orMRbw, orM1, true);
621 setPosition(orMRbw, x - 2.0, y - 1.5);630 setPosition(orMRbw, x - 2.0, y - 1.5);
622 nodes.add(orMRbw);631 nodes.add(orMRbw);
623632
624 VisualSignalTransition orMFfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS);633 VisualSignalTransition orMFfw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS, curContainer);
625 createConsumingArc(orM1, orMFfw, false);634 createConsumingArc(orM1, orMFfw, false);
626 createProducingArc(orMFfw, orM0, false);635 createProducingArc(orMFfw, orM0, false);
627 setPosition(orMFfw, x - 2.0, y - 4.5);636 setPosition(orMFfw, x - 2.0, y - 4.5);
628 nodes.add(orMFfw);637 nodes.add(orMFfw);
629638
630 VisualSignalTransition orMFbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS);639 VisualSignalTransition orMFbw = stg.createSignalTransition(nameOrM + name, type, SignalTransition.Direction.MINUS, curContainer);
631 createConsumingArc(orM1, orMFbw, false);640 createConsumingArc(orM1, orMFbw, false);
632 createProducingArc(orMFbw, orM0, false);641 createProducingArc(orMFbw, orM0, false);
633 setPosition(orMFbw, x - 2.0, y - 3.5);642 setPosition(orMFbw, x - 2.0, y - 3.5);
634 nodes.add(orMFbw);643 nodes.add(orMFbw);
635644
636 VisualPlace andM0 = stg.createPlace(nameAndM + name + name0);645 VisualPlace andM0 = stg.createPlace(nameAndM + name + name0, curContainer);
637 andM0.setLabel(labelAndM + name + label0);646 andM0.setLabel(labelAndM + name + label0);
638 andM0.setLabelPositioning(Positioning.BOTTOM);647 andM0.setLabelPositioning(Positioning.BOTTOM);
639 if (!r.getReferencedCounterflowRegister().isAndMarked()) {648 if (!r.getReferencedCounterflowRegister().isAndMarked()) {
@@ -644,7 +653,7 @@
644 setPosition(andM0, x + 2.0, y + 4.0);653 setPosition(andM0, x + 2.0, y + 4.0);
645 nodes.add(andM0);654 nodes.add(andM0);
646655
647 VisualPlace andM1 = stg.createPlace(nameAndM + name + name1);656 VisualPlace andM1 = stg.createPlace(nameAndM + name + name1, curContainer);
648 andM1.setLabel(labelAndM + name + label1);657 andM1.setLabel(labelAndM + name + label1);
649 andM1.setLabelPositioning(Positioning.TOP);658 andM1.setLabelPositioning(Positioning.TOP);
650 if (r.getReferencedCounterflowRegister().isAndMarked()) {659 if (r.getReferencedCounterflowRegister().isAndMarked()) {
@@ -655,13 +664,13 @@
655 setPosition(andM1, x + 2.0, y + 2.0);664 setPosition(andM1, x + 2.0, y + 2.0);
656 nodes.add(andM1);665 nodes.add(andM1);
657666
658 VisualSignalTransition andMR = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.PLUS);667 VisualSignalTransition andMR = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.PLUS, curContainer);
659 createConsumingArc(andM0, andMR, false);668 createConsumingArc(andM0, andMR, false);
660 createProducingArc(andMR, andM1, false);669 createProducingArc(andMR, andM1, false);
661 setPosition(andMR, x - 2.0, y + 4.0);670 setPosition(andMR, x - 2.0, y + 4.0);
662 nodes.add(andMR);671 nodes.add(andMR);
663672
664 VisualSignalTransition andMF = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.MINUS);673 VisualSignalTransition andMF = stg.createSignalTransition(nameAndM + name, type, SignalTransition.Direction.MINUS, curContainer);
665 createConsumingArc(andM1, andMF, false);674 createConsumingArc(andM1, andMF, false);
666 createProducingArc(andMF, andM0, false);675 createProducingArc(andMF, andM0, false);
667 setPosition(andMF, x - 2.0, y + 2.0);676 setPosition(andMF, x - 2.0, y + 2.0);
@@ -749,8 +758,9 @@
749 type = SignalTransition.Type.OUTPUT;758 type = SignalTransition.Type.OUTPUT;
750 }759 }
751 ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0);760 ColorGenerator tokenColorGenerator = createColorGenerator(dfs.getPreset(r).size() == 0);
761 Container curContainer = null;
752762
753 VisualPlace M0 = stg.createPlace(nameM + name + name0);763 VisualPlace M0 = stg.createPlace(nameM + name + name0, curContainer);
754 M0.setLabel(labelM + name + label0);764 M0.setLabel(labelM + name + label0);
755 M0.setLabelPositioning(Positioning.BOTTOM);765 M0.setLabelPositioning(Positioning.BOTTOM);
756 if (!r.getReferencedBinaryRegister().isTrueMarked() && !r.getReferencedBinaryRegister().isFalseMarked()) {766 if (!r.getReferencedBinaryRegister().isTrueMarked() && !r.getReferencedBinaryRegister().isFalseMarked()) {
@@ -761,7 +771,7 @@
761 setPosition(M0, x - 4.0, y + 1.0);771 setPosition(M0, x - 4.0, y + 1.0);
762 nodes.add(M0);772 nodes.add(M0);
763773
764 VisualPlace M1 = stg.createPlace(nameM + name + name1);774 VisualPlace M1 = stg.createPlace(nameM + name + name1, curContainer);
765 M1.setLabel(labelM + name + label1);775 M1.setLabel(labelM + name + label1);
766 M1.setLabelPositioning(Positioning.TOP);776 M1.setLabelPositioning(Positioning.TOP);
767 if (r.getReferencedBinaryRegister().isTrueMarked() || r.getReferencedBinaryRegister().isFalseMarked()) {777 if (r.getReferencedBinaryRegister().isTrueMarked() || r.getReferencedBinaryRegister().isFalseMarked()) {
@@ -772,7 +782,7 @@
772 setPosition(M1, x - 4.0, y - 1.0);782 setPosition(M1, x - 4.0, y - 1.0);
773 nodes.add(M1);783 nodes.add(M1);
774784
775 VisualPlace tM0 = stg.createPlace(nameTrueM + name + name0);785 VisualPlace tM0 = stg.createPlace(nameTrueM + name + name0, curContainer);
776 tM0.setLabel(labelTrueM + name + label0);786 tM0.setLabel(labelTrueM + name + label0);
777 tM0.setLabelPositioning(Positioning.BOTTOM);787 tM0.setLabelPositioning(Positioning.BOTTOM);
778 if (!r.getReferencedBinaryRegister().isTrueMarked()) {788 if (!r.getReferencedBinaryRegister().isTrueMarked()) {
@@ -783,7 +793,7 @@
783 setPosition(tM0, x + 4.0, y - 2.0);793 setPosition(tM0, x + 4.0, y - 2.0);
784 nodes.add(tM0);794 nodes.add(tM0);
785795
786 VisualPlace tM1 = stg.createPlace(nameTrueM + name + name1);796 VisualPlace tM1 = stg.createPlace(nameTrueM + name + name1, curContainer);
787 tM1.setLabel(labelTrueM + name + label1);797 tM1.setLabel(labelTrueM + name + label1);
788 tM1.setLabelPositioning(Positioning.TOP);798 tM1.setLabelPositioning(Positioning.TOP);
789 if (r.getReferencedBinaryRegister().isTrueMarked()) {799 if (r.getReferencedBinaryRegister().isTrueMarked()) {
@@ -805,7 +815,7 @@
805 double dy = 0.0;815 double dy = 0.0;
806 for (Node n: preset) {816 for (Node n: preset) {
807 if (tMR == null || orSync) { 817 if (tMR == null || orSync) {
808 tMR = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.PLUS);818 tMR = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.PLUS, curContainer);
809 tMR.setTokenColorGenerator(tokenColorGenerator);819 tMR.setTokenColorGenerator(tokenColorGenerator);
810 createConsumingArc(tM0, tMR, false);820 createConsumingArc(tM0, tMR, false);
811 createProducingArc(tMR, tM1, true);821 createProducingArc(tMR, tM1, true);
@@ -817,7 +827,7 @@
817 tMRs.put(n, tMR);827 tMRs.put(n, tMR);
818 dy += 1.0;828 dy += 1.0;
819 }829 }
820 VisualSignalTransition tMF = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.MINUS);830 VisualSignalTransition tMF = stg.createSignalTransition(nameTrueM + name, type, SignalTransition.Direction.MINUS, curContainer);
821 createConsumingArc(tM1, tMF, false);831 createConsumingArc(tM1, tMF, false);
822 createProducingArc(tMF, tM0, false);832 createProducingArc(tMF, tM0, false);
823 createConsumingArc(M1, tMF, false);833 createConsumingArc(M1, tMF, false);
@@ -825,7 +835,8 @@
825 setPosition(tMF, x, y - 4.0 - dy);835 setPosition(tMF, x, y - 4.0 - dy);
826 nodes.add(tMF);836 nodes.add(tMF);
827837
828 VisualPlace fM0 = stg.createPlace(nameFalseM + name + name0);838
839 VisualPlace fM0 = stg.createPlace(nameFalseM + name + name0, curContainer);
829 fM0.setLabel(labelFalseM + name + label0);840 fM0.setLabel(labelFalseM + name + label0);
830 fM0.setLabelPositioning(Positioning.BOTTOM);841 fM0.setLabelPositioning(Positioning.BOTTOM);
831 if (!r.getReferencedBinaryRegister().isFalseMarked()) {842 if (!r.getReferencedBinaryRegister().isFalseMarked()) {
@@ -836,7 +847,7 @@
836 setPosition(fM0, x + 4.0, y + 4.0);847 setPosition(fM0, x + 4.0, y + 4.0);
837 nodes.add(fM0);848 nodes.add(fM0);
838849
839 VisualPlace fM1 = stg.createPlace(nameFalseM + name + name1);850 VisualPlace fM1 = stg.createPlace(nameFalseM + name + name1, curContainer);
840 fM1.setLabel(labelFalseM + name + label1);851 fM1.setLabel(labelFalseM + name + label1);
841 fM1.setLabelPositioning(Positioning.TOP);852 fM1.setLabelPositioning(Positioning.TOP);
842 if (r.getReferencedBinaryRegister().isFalseMarked()) {853 if (r.getReferencedBinaryRegister().isFalseMarked()) {
@@ -852,7 +863,7 @@
852 dy = 0.0;863 dy = 0.0;
853 for (Node n: preset) {864 for (Node n: preset) {
854 if (fMR == null || andSync) { 865 if (fMR == null || andSync) {
855 fMR = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.PLUS);866 fMR = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.PLUS, curContainer);
856 fMR.setTokenColorGenerator(tokenColorGenerator);867 fMR.setTokenColorGenerator(tokenColorGenerator);
857 createConsumingArc(fM0, fMR, false);868 createConsumingArc(fM0, fMR, false);
858 createProducingArc(fMR, fM1, true);869 createProducingArc(fMR, fM1, true);
@@ -864,7 +875,7 @@
864 fMRs.put(n, fMR);875 fMRs.put(n, fMR);
865 dy += 1.0;876 dy += 1.0;
866 }877 }
867 VisualSignalTransition fMF = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.MINUS);878 VisualSignalTransition fMF = stg.createSignalTransition(nameFalseM + name, type, SignalTransition.Direction.MINUS, curContainer);
868 createConsumingArc(fM1, fMF, false);879 createConsumingArc(fM1, fMF, false);
869 createProducingArc(fMF, fM0, false);880 createProducingArc(fMF, fM0, false);
870 createConsumingArc(M1, fMF, false);881 createConsumingArc(M1, fMF, false);
871882
=== modified file 'GraphPlugin/src/org/workcraft/plugins/graph/ToolsProvider.java'
--- GraphPlugin/src/org/workcraft/plugins/graph/ToolsProvider.java 2013-11-08 13:40:13 +0000
+++ GraphPlugin/src/org/workcraft/plugins/graph/ToolsProvider.java 2014-07-11 09:42:10 +0000
@@ -2,12 +2,14 @@
22
3import java.util.ArrayList;3import java.util.ArrayList;
44
5import org.workcraft.dom.math.PageNode;
5import org.workcraft.gui.graph.tools.CommentGeneratorTool;6import org.workcraft.gui.graph.tools.CommentGeneratorTool;
6import org.workcraft.gui.graph.tools.ConnectionTool;7import org.workcraft.gui.graph.tools.ConnectionTool;
7import org.workcraft.gui.graph.tools.CustomToolsProvider;8import org.workcraft.gui.graph.tools.CustomToolsProvider;
8import org.workcraft.gui.graph.tools.DefaultNodeGenerator;9import org.workcraft.gui.graph.tools.DefaultNodeGenerator;
9import org.workcraft.gui.graph.tools.GraphEditorTool;10import org.workcraft.gui.graph.tools.GraphEditorTool;
10import org.workcraft.gui.graph.tools.NodeGeneratorTool;11import org.workcraft.gui.graph.tools.NodeGeneratorTool;
12import org.workcraft.gui.graph.tools.PageGeneratorTool;
11import org.workcraft.gui.graph.tools.SelectionTool;13import org.workcraft.gui.graph.tools.SelectionTool;
1214
13public class ToolsProvider implements CustomToolsProvider {15public class ToolsProvider implements CustomToolsProvider {
@@ -18,6 +20,7 @@
18 20
19 result.add(new SelectionTool());21 result.add(new SelectionTool());
20 result.add(new CommentGeneratorTool());22 result.add(new CommentGeneratorTool());
23 result.add(new PageGeneratorTool(new DefaultNodeGenerator(PageNode.class)));
21 result.add(new ConnectionTool(true, false));24 result.add(new ConnectionTool(true, false));
22 result.add(new NodeGeneratorTool(new DefaultNodeGenerator(Vertex.class)));25 result.add(new NodeGeneratorTool(new DefaultNodeGenerator(Vertex.class)));
23 return result;26 return result;
2427
=== modified file 'GraphPlugin/src/org/workcraft/plugins/graph/VisualGraph.java'
--- GraphPlugin/src/org/workcraft/plugins/graph/VisualGraph.java 2013-11-08 13:40:13 +0000
+++ GraphPlugin/src/org/workcraft/plugins/graph/VisualGraph.java 2014-07-11 09:42:10 +0000
@@ -65,6 +65,7 @@
65 public void connect(Node first, Node second) throws InvalidConnectionException {65 public void connect(Node first, Node second) throws InvalidConnectionException {
66 validateConnection(first, second);66 validateConnection(first, second);
6767
68
68 VisualComponent c1 = (VisualComponent) first;69 VisualComponent c1 = (VisualComponent) first;
69 VisualComponent c2 = (VisualComponent) second;70 VisualComponent c2 = (VisualComponent) second;
7071
7172
=== modified file 'MpsatPlugin/src/org/workcraft/plugins/mpsat/MpsatResultParser.java'
--- MpsatPlugin/src/org/workcraft/plugins/mpsat/MpsatResultParser.java 2010-10-06 15:51:01 +0000
+++ MpsatPlugin/src/org/workcraft/plugins/mpsat/MpsatResultParser.java 2014-07-11 09:42:10 +0000
@@ -8,6 +8,7 @@
8import java.util.regex.Pattern;8import java.util.regex.Pattern;
99
10import org.workcraft.Trace;10import org.workcraft.Trace;
11import org.workcraft.dom.hierarchy.NamespaceHelper;
11import org.workcraft.plugins.shared.tasks.ExternalProcessResult;12import org.workcraft.plugins.shared.tasks.ExternalProcessResult;
1213
13public class MpsatResultParser {14public class MpsatResultParser {
@@ -34,6 +35,8 @@
34 String[] ss = mpsatTrace.split(",");35 String[] ss = mpsatTrace.split(",");
3536
36 for (String k: ss) {37 for (String k: ss) {
38 k=k.replace(NamespaceHelper.flatNameSeparator, NamespaceHelper.hierarchySeparator);
39
37 if (k.charAt(1) == '.')40 if (k.charAt(1) == '.')
38 trace.add(k.substring(2).trim());41 trace.add(k.substring(2).trim());
39 else42 else
4043
=== modified file 'PetriNetPlugin/src/org/workcraft/plugins/petri/PetriNet.java'
--- PetriNetPlugin/src/org/workcraft/plugins/petri/PetriNet.java 2013-10-07 09:51:12 +0000
+++ PetriNetPlugin/src/org/workcraft/plugins/petri/PetriNet.java 2014-07-11 09:42:10 +0000
@@ -29,10 +29,12 @@
29import org.workcraft.dom.Connection;29import org.workcraft.dom.Connection;
30import org.workcraft.dom.Container;30import org.workcraft.dom.Container;
31import org.workcraft.dom.Node;31import org.workcraft.dom.Node;
32import org.workcraft.dom.hierarchy.NamespaceProvider;
32import org.workcraft.dom.math.AbstractMathModel;33import org.workcraft.dom.math.AbstractMathModel;
33import org.workcraft.dom.math.MathConnection;34import org.workcraft.dom.math.MathConnection;
35import org.workcraft.dom.math.MathGroup;
34import org.workcraft.dom.math.MathNode;36import org.workcraft.dom.math.MathNode;
35import org.workcraft.dom.references.UniqueNameReferenceManager;37import org.workcraft.dom.references.HierarchicalUniqueNameReferenceManager;
36import org.workcraft.exceptions.InvalidConnectionException;38import org.workcraft.exceptions.InvalidConnectionException;
37import org.workcraft.exceptions.ModelValidationException;39import org.workcraft.exceptions.ModelValidationException;
38import org.workcraft.gui.propertyeditor.Properties;40import org.workcraft.gui.propertyeditor.Properties;
@@ -44,7 +46,7 @@
44public class PetriNet extends AbstractMathModel implements PetriNetModel {46public class PetriNet extends AbstractMathModel implements PetriNetModel {
4547
46 public PetriNet() {48 public PetriNet() {
47 this(null, null);49 this(new MathGroup(), null);
48 }50 }
4951
50 public PetriNet(Container root) {52 public PetriNet(Container root) {
@@ -61,7 +63,7 @@
61 }63 }
6264
63 public PetriNet(Container root, References refs, final Func<Node, String> nodePrefixFunc) {65 public PetriNet(Container root, References refs, final Func<Node, String> nodePrefixFunc) {
64 super(root, new UniqueNameReferenceManager(refs, new Func<Node, String>() {66 super(root, new HierarchicalUniqueNameReferenceManager(refs, new Func<Node, String>() {
65 @Override67 @Override
66 public String eval(Node arg) {68 public String eval(Node arg) {
67 String result = nodePrefixFunc.eval(arg);69 String result = nodePrefixFunc.eval(arg);
@@ -79,15 +81,9 @@
79 return result;81 return result;
80 }82 }
81 }));83 }));
82 }84
8385 }
84 public void setName(Node node, String name) {86
85 ((UniqueNameReferenceManager)getReferenceManager()).setName(node, name);
86 }
87
88 public String getName(Node node) {
89 return ((UniqueNameReferenceManager)getReferenceManager()).getName(node);
90 }
9187
92 final public Place createPlace(String name) {88 final public Place createPlace(String name) {
93 Place newPlace = new Place();89 Place newPlace = new Place();
@@ -125,7 +121,6 @@
125 final public Collection<Transition> getTransitions() {121 final public Collection<Transition> getTransitions() {
126 return Hierarchy.getDescendantsOfType(getRoot(), Transition.class);122 return Hierarchy.getDescendantsOfType(getRoot(), Transition.class);
127 }123 }
128
129 124
130 public boolean isUnfireEnabled(Transition t) {125 public boolean isUnfireEnabled(Transition t) {
131 return isUnfireEnabled (this, t);126 return isUnfireEnabled (this, t);
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches