Merge lp:~danilovesky/workcraft/trunk-bug-1338529 into lp:workcraft
- trunk-bug-1338529
- Merge into trunk
Proposed by
Danil Sokolov
Status: | Merged |
---|---|
Merged at revision: | 513 |
Proposed branch: | lp:~danilovesky/workcraft/trunk-bug-1338529 |
Merge into: | lp:workcraft |
Diff against target: |
190 lines (+50/-52) 3 files modified
CircuitPlugin/src/org/workcraft/plugins/circuit/FunctionContact.java (+2/-3) CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java (+5/-5) CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java (+43/-44) |
To merge this branch: | bzr merge lp:~danilovesky/workcraft/trunk-bug-1338529 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danil Sokolov | Approve | ||
Review via email: mp+225825@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Danil Sokolov (danilovesky) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/FunctionContact.java' | |||
2 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/FunctionContact.java 2014-06-27 14:48:42 +0000 | |||
3 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/FunctionContact.java 2014-07-07 13:25:20 +0000 | |||
4 | @@ -25,15 +25,14 @@ | |||
5 | 25 | import org.workcraft.annotations.VisualClass; | 25 | import org.workcraft.annotations.VisualClass; |
6 | 26 | import org.workcraft.observation.PropertyChangedEvent; | 26 | import org.workcraft.observation.PropertyChangedEvent; |
7 | 27 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | 27 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
8 | 28 | import org.workcraft.plugins.cpog.optimisation.expressions.Zero; | ||
9 | 29 | 28 | ||
10 | 30 | 29 | ||
11 | 31 | @DisplayName("FunctionContact") | 30 | @DisplayName("FunctionContact") |
12 | 32 | @VisualClass(org.workcraft.plugins.circuit.VisualFunctionContact.class) | 31 | @VisualClass(org.workcraft.plugins.circuit.VisualFunctionContact.class) |
13 | 33 | 32 | ||
14 | 34 | public class FunctionContact extends Contact { | 33 | public class FunctionContact extends Contact { |
17 | 35 | private BooleanFormula setFunction=Zero.instance(); | 34 | private BooleanFormula setFunction = null; |
18 | 36 | private BooleanFormula resetFunction=null; | 35 | private BooleanFormula resetFunction = null; |
19 | 37 | 36 | ||
20 | 38 | public FunctionContact(IOType ioType) { | 37 | public FunctionContact(IOType ioType) { |
21 | 39 | super(ioType); | 38 | super(ioType); |
22 | 40 | 39 | ||
23 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java' | |||
24 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-06-27 14:48:42 +0000 | |||
25 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-07-07 13:25:20 +0000 | |||
26 | @@ -346,12 +346,12 @@ | |||
27 | 346 | return (Contact)getReferencedComponent(); | 346 | return (Contact)getReferencedComponent(); |
28 | 347 | } | 347 | } |
29 | 348 | 348 | ||
33 | 349 | public static boolean isDriver(Node contact) { | 349 | public static boolean isDriver(Node node) { |
34 | 350 | if (!(contact instanceof VisualContact)) { | 350 | if (node instanceof VisualContact) { |
35 | 351 | return false; | 351 | VisualContact contact = (VisualContact)node; |
36 | 352 | return (contact.getIOType() == IOType.OUTPUT) || !(contact.getParent() instanceof VisualComponent); | ||
37 | 352 | } | 353 | } |
40 | 353 | return ( (((VisualContact)contact).getIOType() == IOType.OUTPUT) | 354 | return false; |
39 | 354 | == (((VisualContact)contact).getParent() instanceof VisualComponent) ); | ||
41 | 355 | } | 355 | } |
42 | 356 | 356 | ||
43 | 357 | public HashSet<SignalTransition> getReferencedTransitions() { | 357 | public HashSet<SignalTransition> getReferencedTransitions() { |
44 | 358 | 358 | ||
45 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java' | |||
46 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-06-27 14:48:42 +0000 | |||
47 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-07-07 13:25:20 +0000 | |||
48 | @@ -31,6 +31,7 @@ | |||
49 | 31 | import org.workcraft.plugins.circuit.VisualFunctionContact; | 31 | import org.workcraft.plugins.circuit.VisualFunctionContact; |
50 | 32 | import org.workcraft.plugins.circuit.VisualJoint; | 32 | import org.workcraft.plugins.circuit.VisualJoint; |
51 | 33 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; | 33 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
52 | 34 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; | ||
53 | 34 | import org.workcraft.plugins.cpog.optimisation.Literal; | 35 | import org.workcraft.plugins.cpog.optimisation.Literal; |
54 | 35 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString; | 36 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToString; |
55 | 36 | import org.workcraft.plugins.cpog.optimisation.dnf.Dnf; | 37 | import org.workcraft.plugins.cpog.optimisation.dnf.Dnf; |
56 | @@ -41,6 +42,7 @@ | |||
57 | 41 | import org.workcraft.plugins.stg.STG; | 42 | import org.workcraft.plugins.stg.STG; |
58 | 42 | import org.workcraft.plugins.stg.SignalTransition; | 43 | import org.workcraft.plugins.stg.SignalTransition; |
59 | 43 | import org.workcraft.plugins.stg.SignalTransition.Direction; | 44 | import org.workcraft.plugins.stg.SignalTransition.Direction; |
60 | 45 | import org.workcraft.plugins.stg.SignalTransition.Type; | ||
61 | 44 | import org.workcraft.plugins.stg.VisualSTG; | 46 | import org.workcraft.plugins.stg.VisualSTG; |
62 | 45 | import org.workcraft.plugins.stg.VisualSignalTransition; | 47 | import org.workcraft.plugins.stg.VisualSignalTransition; |
63 | 46 | import org.workcraft.util.Hierarchy; | 48 | import org.workcraft.util.Hierarchy; |
64 | @@ -144,71 +146,70 @@ | |||
65 | 144 | // if it is a driver, add it to the list of drivers | 146 | // if it is a driver, add it to the list of drivers |
66 | 145 | cstg = generatePlaces(circuit, stg, contact); | 147 | cstg = generatePlaces(circuit, stg, contact); |
67 | 146 | drivers.put(contact, cstg); | 148 | drivers.put(contact, cstg); |
68 | 147 | |||
69 | 148 | // attach driven wires to the place | 149 | // attach driven wires to the place |
70 | 149 | attachConnections(circuit, contact, cstg); | 150 | attachConnections(circuit, contact, cstg); |
71 | 150 | |||
72 | 151 | // put itself on a target list as well, so that it can be addressed by other drivers | 151 | // put itself on a target list as well, so that it can be addressed by other drivers |
73 | 152 | targetDrivers.put(contact.getReferencedContact(), contact); | 152 | targetDrivers.put(contact.getReferencedContact(), contact); |
74 | 153 | } else { | 153 | } else { |
75 | 154 | // if not a driver, find related driver, add to the map of targets | 154 | // if not a driver, find related driver, add to the map of targets |
76 | 155 | VisualContact driver = findDriver(circuit, contact); | 155 | VisualContact driver = findDriver(circuit, contact); |
79 | 156 | 156 | if (driver == null) { | |
78 | 157 | if (driver==null) { | ||
80 | 158 | // if target driver was not found, create artificial one that looks like input | 157 | // if target driver was not found, create artificial one that looks like input |
81 | 159 | //driver = new VisualContact(new Contact(IOType.INPUT), VisualContact.flipDirection(contact.getDirection()), contact.getName()); | ||
82 | 160 | //driver.setTransform(contact.getTransform()); | ||
83 | 161 | //driver.setParent(contact.getParent()); | ||
84 | 162 | driver = contact; | 158 | driver = contact; |
85 | 163 | cstg = generatePlaces(circuit, stg, contact); | 159 | cstg = generatePlaces(circuit, stg, contact); |
86 | 164 | |||
87 | 165 | drivers.put(driver, cstg); | 160 | drivers.put(driver, cstg); |
88 | 166 | // attach driven wires to the place | 161 | // attach driven wires to the place |
89 | 167 | attachConnections(circuit, contact, cstg); | 162 | attachConnections(circuit, contact, cstg); |
90 | 168 | } | 163 | } |
91 | 169 | |||
92 | 170 | targetDrivers.put(contact.getReferencedContact(), driver); | 164 | targetDrivers.put(contact.getReferencedContact(), driver); |
93 | 171 | } | 165 | } |
94 | 172 | } | 166 | } |
96 | 173 | 167 | ||
97 | 174 | // Generate implementation for each of the drivers | 168 | // Generate implementation for each of the drivers |
127 | 175 | for(VisualContact c : drivers.keySet()) { | 169 | for(VisualContact driver : drivers.keySet()) { |
128 | 176 | if (c instanceof VisualFunctionContact) { | 170 | BooleanFormula setFunc = null; |
129 | 177 | VisualFunctionContact contact = (VisualFunctionContact)c; | 171 | BooleanFormula resetFunc = null; |
130 | 178 | // Determine I/O type of the contact | 172 | Type signalType = Type.INPUT; |
131 | 179 | SignalTransition.Type ttype = SignalTransition.Type.OUTPUT; | 173 | if (driver instanceof VisualFunctionContact) { |
132 | 180 | boolean comesFromEnvironment = false; | 174 | VisualFunctionContact contact = (VisualFunctionContact)driver; |
133 | 181 | if (contact.getParent() instanceof VisualCircuitComponent) { | 175 | if ((contact.getIOType() == IOType.OUTPUT) && !isFromEnvironment(contact)) { |
134 | 182 | comesFromEnvironment = ((VisualCircuitComponent)contact.getParent()).getIsEnvironment(); | 176 | signalType = Type.OUTPUT; |
135 | 183 | } | 177 | } |
136 | 184 | if (comesFromEnvironment || (contact.getIOType()==IOType.INPUT)) { | 178 | if ((contact.getIOType() == IOType.OUTPUT) && !(contact.getParent() instanceof VisualCircuitComponent)) { |
137 | 185 | ttype = SignalTransition.Type.INPUT; | 179 | // Driver of the primary output port |
138 | 186 | } | 180 | VisualContact outputDriver = findDriver(circuit, contact); |
139 | 187 | // Function based driver | 181 | if (outputDriver != null) { |
140 | 188 | BooleanFormula setFunc = contact.getSetFunction(); | 182 | setFunc = outputDriver.getReferencedContact(); |
141 | 189 | BooleanFormula resetFunc = contact.getResetFunction(); | 183 | } |
142 | 190 | if ((setFunc != null) && (resetFunc == null)) { | 184 | } else { |
143 | 191 | resetFunc = new DumbBooleanWorker().not(setFunc); | 185 | // Function based driver |
144 | 192 | } else if ((setFunc == null) && (resetFunc != null)) { | 186 | setFunc = contact.getSetFunction(); |
145 | 193 | setFunc = new DumbBooleanWorker().not(resetFunc); | 187 | resetFunc = contact.getResetFunction(); |
146 | 194 | } | 188 | } |
147 | 195 | Dnf setDnf = DnfGenerator.generate(setFunc); | 189 | } |
148 | 196 | Dnf resetDnf = DnfGenerator.generate(resetFunc); | 190 | // Create complementary set/reset if only one of them is defined |
149 | 197 | implementDriver(circuit, stg, contact, drivers, targetDrivers, setDnf, resetDnf, ttype); | 191 | if ((setFunc != null) && (resetFunc == null)) { |
150 | 198 | } else { | 192 | resetFunc = new DumbBooleanWorker().not(setFunc); |
151 | 199 | // Some generic driver implementation otherwise | 193 | } else if ((setFunc == null) && (resetFunc != null)) { |
152 | 200 | Dnf setDnf = new Dnf(new DnfClause()); | 194 | setFunc = new DumbBooleanWorker().not(resetFunc); |
153 | 201 | Dnf resetDnf = new Dnf(new DnfClause()); | 195 | } |
154 | 202 | implementDriver(circuit, stg, c, drivers, targetDrivers, setDnf, resetDnf, SignalTransition.Type.INPUT); | 196 | Dnf setDnf = DnfGenerator.generate(setFunc); |
155 | 203 | } | 197 | Dnf resetDnf = DnfGenerator.generate(resetFunc); |
156 | 198 | implementDriver(circuit, stg, driver, drivers, targetDrivers, setDnf, resetDnf, signalType); | ||
157 | 204 | } | 199 | } |
158 | 205 | return stg; | 200 | return stg; |
159 | 206 | } catch (InvalidConnectionException e) { | 201 | } catch (InvalidConnectionException e) { |
160 | 207 | throw new RuntimeException(e); | 202 | throw new RuntimeException(e); |
161 | 208 | } | 203 | } |
162 | 209 | } | 204 | } |
163 | 205 | |||
164 | 206 | private static boolean isFromEnvironment(VisualContact contact) { | ||
165 | 207 | if (contact.getParent() instanceof VisualCircuitComponent) { | ||
166 | 208 | return ((VisualCircuitComponent)contact.getParent()).getIsEnvironment(); | ||
167 | 209 | } | ||
168 | 210 | return false; | ||
169 | 211 | } | ||
170 | 210 | 212 | ||
171 | 211 | |||
172 | 212 | private static void implementDriver(VisualCircuit circuit, VisualSTG stg, | 213 | private static void implementDriver(VisualCircuit circuit, VisualSTG stg, |
173 | 213 | VisualContact contact, | 214 | VisualContact contact, |
174 | 214 | Map<VisualContact, ContactSTG> drivers, | 215 | Map<VisualContact, ContactSTG> drivers, |
175 | @@ -276,13 +277,11 @@ | |||
176 | 276 | contact.getReferencedTransitions().clear(); | 277 | contact.getReferencedTransitions().clear(); |
177 | 277 | 278 | ||
178 | 278 | nodes.addAll(buildTransitions(contact, stg, circuit, drivers, targetDrivers, | 279 | nodes.addAll(buildTransitions(contact, stg, circuit, drivers, targetDrivers, |
181 | 279 | set, | 280 | set, add(add(center, direction), pOffset), plusDirection, |
180 | 280 | add(add(center, direction), pOffset), plusDirection, | ||
182 | 281 | signalName, ttype, SignalTransition.Direction.PLUS, p.p0, p.p1)); | 281 | signalName, ttype, SignalTransition.Direction.PLUS, p.p0, p.p1)); |
183 | 282 | 282 | ||
184 | 283 | nodes.addAll(buildTransitions(contact, stg, circuit, drivers, targetDrivers, | 283 | nodes.addAll(buildTransitions(contact, stg, circuit, drivers, targetDrivers, |
187 | 284 | reset, | 284 | reset, subtract(add(center, direction), pOffset), minusDirection, |
186 | 285 | subtract(add(center, direction), pOffset), minusDirection, | ||
188 | 286 | signalName, ttype, SignalTransition.Direction.MINUS, p.p1, p.p0)); | 285 | signalName, ttype, SignalTransition.Direction.MINUS, p.p1, p.p0)); |
189 | 287 | 286 | ||
190 | 288 | stg.select(nodes); | 287 | stg.select(nodes); |