Merge lp:~danilovesky/workcraft/trunk-bug-1395102 into lp:workcraft

Proposed by Danil Sokolov
Status: Merged
Merged at revision: 571
Proposed branch: lp:~danilovesky/workcraft/trunk-bug-1395102
Merge into: lp:workcraft
Diff against target: 779 lines (+282/-125)
17 files modified
CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java (+10/-0)
CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java (+20/-0)
CircuitPlugin/src/org/workcraft/plugins/circuit/Environment.java (+10/-0)
CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java (+24/-1)
CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java (+18/-10)
CircuitPlugin/src/org/workcraft/plugins/circuit/tasks/CheckCircuitTask.java (+8/-4)
CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java (+135/-58)
WorkcraftCore/src/org/workcraft/Framework.java (+3/-2)
WorkcraftCore/src/org/workcraft/Info.java (+2/-2)
WorkcraftCore/src/org/workcraft/dom/DefaultMathNodeRemover.java (+35/-34)
WorkcraftCore/src/org/workcraft/gui/MainWindow.java (+8/-8)
WorkcraftCore/src/org/workcraft/gui/propertyeditor/FileCellEditor.java (+1/-1)
WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileDeserialiser.java (+2/-1)
WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileSerialiser.java (+3/-1)
WorkcraftCore/src/org/workcraft/workspace/WorkspaceEntry.java (+1/-1)
build_distr_linux.sh (+1/-1)
build_distr_windows.sh (+1/-1)
To merge this branch: bzr merge lp:~danilovesky/workcraft/trunk-bug-1395102
Reviewer Review Type Date Requested Status
Danil Sokolov Approve
Review via email: mp+242685@code.launchpad.net
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/CircuitComponent.java'
2--- CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java 2014-11-12 12:46:02 +0000
3+++ CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitComponent.java 2014-11-24 17:05:32 +0000
4@@ -151,6 +151,16 @@
5 }
6 return result;
7 }
8+
9+ public Collection<Contact> getOutputs() {
10+ ArrayList<Contact> result = new ArrayList<Contact>();
11+ for(Contact c : getContacts()) {
12+ if(c.getIOType() == IOType.OUTPUT) {
13+ result.add(c);
14+ }
15+ }
16+ return result;
17+ }
18
19 public void setName(String name) {
20 this.name = name;
21
22=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java'
23--- CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java 2014-09-05 14:09:00 +0000
24+++ CircuitPlugin/src/org/workcraft/plugins/circuit/Contact.java 2014-11-24 17:05:32 +0000
25@@ -103,4 +103,24 @@
26 return getName();
27 }
28
29+ public boolean isInput() {
30+ return (getIOType() == IOType.INPUT);
31+ }
32+
33+ public boolean isOutput() {
34+ return (getIOType() == IOType.OUTPUT);
35+ }
36+
37+ public boolean isPort() {
38+ return !(getParent() instanceof CircuitComponent);
39+ }
40+
41+ public boolean isDriver() {
42+ return (isOutput() != isPort());
43+ }
44+
45+ public boolean isDriven() {
46+ return (isOutput() == isPort());
47+ }
48+
49 }
50
51=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/Environment.java'
52--- CircuitPlugin/src/org/workcraft/plugins/circuit/Environment.java 2014-04-24 20:24:53 +0000
53+++ CircuitPlugin/src/org/workcraft/plugins/circuit/Environment.java 2014-11-24 17:05:32 +0000
54@@ -6,6 +6,7 @@
55
56 public class Environment extends MathNode {
57 private File file;
58+ private File base;
59
60 public Environment() {
61
62@@ -18,4 +19,13 @@
63 public void setFile(File file) {
64 this.file = file;
65 }
66+
67+ public File getBase() {
68+ return base;
69+ }
70+
71+ public void setBase(File base) {
72+ this.base = base;
73+ }
74+
75 }
76
77=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java'
78--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java 2014-11-10 10:31:47 +0000
79+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuit.java 2014-11-24 17:05:32 +0000
80@@ -24,11 +24,12 @@
81 import java.awt.geom.AffineTransform;
82 import java.awt.geom.Point2D;
83 import java.io.File;
84+import java.net.URI;
85 import java.util.Collection;
86 import java.util.LinkedList;
87 import java.util.List;
88-import java.util.ListIterator;
89
90+import org.workcraft.Framework;
91 import org.workcraft.annotations.CustomTools;
92 import org.workcraft.annotations.DisplayName;
93 import org.workcraft.annotations.ShortName;
94@@ -49,12 +50,14 @@
95 import org.workcraft.exceptions.InvalidConnectionException;
96 import org.workcraft.exceptions.NodeCreationException;
97 import org.workcraft.exceptions.VisualModelInstantiationException;
98+import org.workcraft.gui.graph.GraphEditorPanel;
99 import org.workcraft.gui.propertyeditor.ModelProperties;
100 import org.workcraft.plugins.circuit.Contact.IOType;
101 import org.workcraft.plugins.circuit.VisualContact.Direction;
102 import org.workcraft.serialisation.xml.NoAutoSerialisation;
103 import org.workcraft.util.Func;
104 import org.workcraft.util.Hierarchy;
105+import org.workcraft.workspace.WorkspaceEntry;
106
107 @DisplayName("Digital Circuit")
108 @ShortName("circuit")
109@@ -217,12 +220,27 @@
110 public Collection<Environment> getEnvironments() {
111 return Hierarchy.getChildrenOfType(getRoot(), Environment.class);
112 }
113+
114+ private File getBase() {
115+ Framework framework = Framework.INSTANCE;
116+ GraphEditorPanel editor = framework.getMainWindow().getCurrentEditor();
117+ WorkspaceEntry we = editor.getWorkspaceEntry();
118+ return we.getFile().getParentFile();
119+ }
120
121 @NoAutoSerialisation
122 public File getEnvironmentFile() {
123 File result = null;
124 for (Environment env: getEnvironments()) {
125 result = env.getFile();
126+ File base = env.getBase();
127+ if (base != null) {
128+ URI relativeUri = base.toURI().relativize(result.toURI());
129+ if (!relativeUri.equals(result.toURI())) {
130+ result = new File(getBase(), relativeUri.getPath());
131+ }
132+ }
133+ break;
134 }
135 return result;
136 }
137@@ -234,6 +252,7 @@
138 }
139 Environment env = new Environment();
140 env.setFile(value);
141+ env.setBase(getBase());
142 add(env);
143 }
144
145@@ -251,4 +270,8 @@
146 return properties;
147 }
148
149+ public String getMathName(VisualComponent component) {
150+ return getMathModel().getName(component.getReferencedComponent());
151+ }
152+
153 }
154
155=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java'
156--- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-10-10 10:35:07 +0000
157+++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualContact.java 2014-11-24 17:05:32 +0000
158@@ -36,7 +36,6 @@
159 import java.util.LinkedHashMap;
160 import java.util.Map;
161
162-import org.workcraft.dom.Node;
163 import org.workcraft.dom.visual.DrawRequest;
164 import org.workcraft.dom.visual.VisualComponent;
165 import org.workcraft.gui.Coloriser;
166@@ -331,16 +330,25 @@
167 public Contact getReferencedContact() {
168 return (Contact)getReferencedComponent();
169 }
170+
171+ public boolean isInput() {
172+ return getReferencedContact().isInput();
173+ }
174+
175+ public boolean isOutput() {
176+ return getReferencedContact().isOutput();
177+ }
178+
179+ public boolean isPort() {
180+ return getReferencedContact().isPort();
181+ }
182+
183+ public boolean isDriver() {
184+ return getReferencedContact().isDriver();
185+ }
186
187-
188- public static boolean isDriver(Node node) {
189- if (node instanceof VisualContact) {
190- VisualContact contact = (VisualContact)node;
191- boolean ret = (contact.getIOType() == IOType.OUTPUT) ||
192- !(contact.getParent() instanceof VisualCircuitComponent);
193- return ret;
194- }
195- return false;
196+ public boolean isDriven() {
197+ return getReferencedContact().isDriven();
198 }
199
200 public HashSet<SignalTransition> getReferencedTransitions() {
201
202=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tasks/CheckCircuitTask.java'
203--- CircuitPlugin/src/org/workcraft/plugins/circuit/tasks/CheckCircuitTask.java 2014-09-05 16:36:36 +0000
204+++ CircuitPlugin/src/org/workcraft/plugins/circuit/tasks/CheckCircuitTask.java 2014-11-24 17:05:32 +0000
205@@ -79,7 +79,8 @@
206 monitor.progressUpdate(0.10);
207
208 // Generating .g for the circuit
209- File circuitStgFile = File.createTempFile(title + "-circuit-", stgExporter.getExtenstion());
210+ String circuitFilePrefix = title + "-circuit-";
211+ File circuitStgFile = File.createTempFile(circuitFilePrefix.replaceAll("\\s",""), stgExporter.getExtenstion());
212 ExportTask circuitExportTask = new ExportTask(stgExporter, circuitStg, circuitStgFile.getCanonicalPath());
213 Result<? extends Object> circuitExportResult = framework.getTaskManager().execute(
214 circuitExportTask, "Exporting circuit .g", subtaskMonitor);
215@@ -111,7 +112,8 @@
216 environmentStgFile = environmentFile;
217 } else {
218 STG environementStg = (STG)framework.loadFile(environmentFile).getMathModel();
219- environmentStgFile = File.createTempFile(title + "-environment-", stgExporter.getExtenstion());
220+ String environmentFilePrefix = title + "-environment-";
221+ environmentStgFile = File.createTempFile(environmentFilePrefix.replaceAll("\\s",""), stgExporter.getExtenstion());
222 ExportTask environmentExportTask = new ExportTask(stgExporter, environementStg, environmentStgFile.getCanonicalPath());
223 Result<? extends Object> environmentExportResult = framework.getTaskManager().execute(
224 environmentExportTask, "Exporting environment .g", subtaskMonitor);
225@@ -128,7 +130,8 @@
226 monitor.progressUpdate(0.25);
227
228 // Generating .g for the whole system (circuit and environment)
229- stgFile = File.createTempFile(title + "-system-", stgExporter.getExtenstion());
230+ String systemFilePrefix = title + "-system-";
231+ stgFile = File.createTempFile(systemFilePrefix.replaceAll("\\s",""), stgExporter.getExtenstion());
232 PcompTask pcompTask = new PcompTask(new File[]{circuitStgFile, environmentStgFile}, PCompOutputMode.OUTPUT, true, false);
233 pcompResult = framework.getTaskManager().execute(
234 pcompTask, "Running pcomp", subtaskMonitor);
235@@ -148,7 +151,8 @@
236 monitor.progressUpdate(0.30);
237
238 // Generate unfolding
239- File unfoldingFile = File.createTempFile(title+"-unfolding-", MpsatUtilitySettings.getUnfoldingExtension());
240+ String unfoldingFilePrefix = title + "-unfolding-";
241+ File unfoldingFile = File.createTempFile(unfoldingFilePrefix.replaceAll("\\s",""), MpsatUtilitySettings.getUnfoldingExtension());
242 PunfTask punfTask = new PunfTask(stgFile.getCanonicalPath(), unfoldingFile.getCanonicalPath());
243 Result<? extends ExternalProcessResult> punfResult = framework.getTaskManager().execute(
244 punfTask, "Unfolding .g", subtaskMonitor);
245
246=== modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java'
247--- CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-11-07 18:09:40 +0000
248+++ CircuitPlugin/src/org/workcraft/plugins/circuit/tools/STGGenerator.java 2014-11-24 17:05:32 +0000
249@@ -11,6 +11,7 @@
250 import java.util.HashSet;
251 import java.util.LinkedList;
252 import java.util.Map;
253+import java.util.Queue;
254 import java.util.Set;
255 import java.util.TreeSet;
256
257@@ -68,22 +69,42 @@
258 TransformHelper.applyTransform(node, AffineTransform.getTranslateInstance(point.getX(), point.getY()));
259 }
260
261- public static VisualContact findDriver(VisualCircuit circuit, VisualContact target) {
262- Set<Node> neighbours = new HashSet<Node>(circuit.getPreset(target));
263-
264- while (neighbours.size()>=1) {
265- if(neighbours.size() != 1) throw new RuntimeException("Found more than one potential driver for target "+getContactName(circuit, target)+"!");
266-
267- Node node = neighbours.iterator().next();
268- if (VisualContact.isDriver(node)) {
269- // if it is a driver, return it
270- return (VisualContact)node;
271- }
272-
273- // continue searching otherwise
274- neighbours = new HashSet<Node>(circuit.getPreset(node));
275+ public static VisualContact findDriver(VisualCircuit circuit, VisualContact contact) {
276+ VisualContact result = null;
277+ Queue<Node> queue = new LinkedList<Node>(circuit.getPreset(contact));
278+ while (!queue.isEmpty()) {
279+ if (queue.size() != 1) {
280+ throw new RuntimeException("Found more than one potential driver for target "
281+ + getContactName(circuit, contact) + "!");
282+ }
283+ Node node = queue.remove();
284+ if (node instanceof VisualContact) {
285+ VisualContact vc = (VisualContact)node;
286+ if (vc.isDriver()) {
287+ result = vc;
288+ }
289+ } else {
290+ queue.addAll(circuit.getPreset(node));
291+ }
292 }
293- return null;
294+ return result;
295+ }
296+
297+ public static Collection<VisualContact> findDriven(VisualCircuit circuit, VisualContact contact) {
298+ Set<VisualContact> result = new HashSet<VisualContact>();
299+ Queue<Node> queue = new LinkedList<Node>(circuit.getPostset(contact));
300+ while (!queue.isEmpty()) {
301+ Node node = queue.remove();
302+ if (node instanceof VisualContact) {
303+ VisualContact vc = (VisualContact)node;
304+ if (vc.isDriven()) {
305+ result.add(vc);
306+ }
307+ } else {
308+ queue.addAll(circuit.getPostset(node));
309+ }
310+ }
311+ return result;
312 }
313
314 private static ContactSTG generatePlaces(VisualCircuit circuit, VisualSTG stg, VisualContact contact) {
315@@ -121,7 +142,7 @@
316 }
317
318 for (Connection c: circuit.getConnections(component)) {
319- if (c.getFirst()==component&&c instanceof VisualCircuitConnection) {
320+ if ((c.getFirst() == component) && (c instanceof VisualCircuitConnection)) {
321
322 ((VisualCircuitConnection)c).setReferencedOnePlace(cstg.p1.getReferencedPlace());
323 ((VisualCircuitConnection)c).setReferencedZeroPlace(cstg.p0.getReferencedPlace());
324@@ -141,8 +162,6 @@
325 }
326 }
327
328-
329-
330 // store created containers in a separate map
331 private static HashMap<String, Node> createdContainers = null;
332
333@@ -160,7 +179,7 @@
334 for (VisualContact contact : Hierarchy.getDescendantsOfType(circuit.getRoot(), VisualContact.class)) {
335 ContactSTG cstg;
336
337- if(VisualContact.isDriver(contact)) {
338+ if(contact.isDriver()) {
339 // if it is a driver, add it to the list of drivers
340 cstg = generatePlaces(circuit, stg, contact);
341 drivers.put(contact, cstg);
342@@ -191,9 +210,9 @@
343 if (driver instanceof VisualFunctionContact) {
344 // Determine signal type
345 VisualFunctionContact contact = (VisualFunctionContact)driver;
346- signalType = getSignalType(contact);
347+ signalType = getSignalType(circuit, contact);
348
349- if ((contact.getIOType() == IOType.OUTPUT) && !(contact.getParent() instanceof VisualCircuitComponent)) {
350+ if (contact.isOutput() && contact.isPort()) {
351 // Driver of the primary output port
352 VisualContact outputDriver = findDriver(circuit, contact);
353 if (outputDriver != null) {
354@@ -221,17 +240,30 @@
355 }
356 }
357
358- private static Type getSignalType(VisualFunctionContact contact) {
359- Type result = Type.INPUT;
360- if (contact.getIOType() == IOType.OUTPUT) {
361- if (contact.getParent() instanceof VisualCircuitComponent) {
362- VisualCircuitComponent component = (VisualCircuitComponent)contact.getParent();
363- if (!component.getIsEnvironment()) {
364- result = Type.INTERNAL;
365- }
366- } else {
367+ private static Type getSignalType(VisualCircuit circuit, VisualFunctionContact contact) {
368+ Type result = Type.INTERNAL;
369+ if (contact.isPort()) {
370+ // Primary port
371+ if (contact.isInput()) {
372+ result = Type.INPUT;
373+ } else if (contact.isOutput()) {
374 result = Type.OUTPUT;
375- }
376+ }
377+ } else {
378+ VisualCircuitComponent component = (VisualCircuitComponent)contact.getParent();
379+ if (component.getIsEnvironment()) {
380+ // Contact of an environment component
381+ if (contact.isInput()) {
382+ result = Type.OUTPUT;
383+ } else if (contact.isOutput()) {
384+ result = Type.INPUT;
385+ }
386+ } else {
387+ // Contact of an ordinary component
388+ if (contact.isOutput() && (getDrivenOutputPort(circuit, contact) != null)) {
389+ result = Type.OUTPUT;
390+ }
391+ }
392 }
393 return result;
394 }
395@@ -401,32 +433,77 @@
396 }
397
398 private static String getContactName(VisualCircuit circuit, VisualContact contact) {
399- String result = "";
400- Node parent = contact.getParent();
401- if (parent instanceof VisualFunctionComponent) {
402- int output_cnt=0;
403- VisualFunctionComponent vc = (VisualFunctionComponent)parent;
404- for (Node n: vc.getChildren()) {
405- if ((n instanceof VisualContact)&&
406- ((VisualContact)n).getIOType()!=IOType.INPUT) {
407- output_cnt++;
408- }
409- }
410-
411- result = NamespaceHelper.getFlatName(
412- circuit.getMathModel().getName(vc.getReferencedComponent())
413- );
414-
415-// result = HierarchicalNames.getFlatName(
416-// circuit.getMathModel().getNodeReference(vc.getReferencedComponent())
417-// );
418-
419- if (contact.getIOType() == IOType.INPUT || output_cnt > 1) {
420- result += "_" + circuit.getMathModel().getName(contact.getReferencedContact());
421- }
422+ String result = null;
423+ if (contact.isPort()) {
424+ result = circuit.getMathName(contact);
425 } else {
426- result = circuit.getMathModel().getName(contact.getReferencedContact());
427- }
428- return result;
429- }
430+ if (contact.isInput()) {
431+ result = getInputContactName(circuit, contact);
432+ } else if (contact.isOutput()) {
433+ result = getOutputContactName(circuit, contact);
434+ }
435+ }
436+ return result;
437+ }
438+
439+ private static String getInputContactName(VisualCircuit circuit, VisualContact contact) {
440+ String result = null;
441+ Node parent = contact.getParent();
442+ if (parent instanceof VisualFunctionComponent) {
443+ VisualFunctionComponent component = (VisualFunctionComponent)parent;
444+ String componentName = NamespaceHelper.getFlatName(circuit.getMathName(component));
445+ String contactName = circuit.getMathName(contact);
446+ result = componentName + "_" + contactName;
447+ }
448+ return result;
449+ }
450+
451+ private static String getOutputContactName(VisualCircuit circuit, VisualContact contact) {
452+ String result = null;
453+ Node parent = contact.getParent();
454+ if (parent instanceof VisualFunctionComponent) {
455+ VisualFunctionComponent component = (VisualFunctionComponent)parent;
456+
457+ VisualContact outputPort = getDrivenOutputPort(circuit, contact);
458+ if (outputPort != null) {
459+ // If a single output port is driven, then take its name.
460+ result = circuit.getMathName(outputPort);
461+ } else {
462+ // If the component has a single output, use the component name. Otherwise append the contact.
463+ result = NamespaceHelper.getFlatName(circuit.getMathName(component));
464+ int output_cnt = 0;
465+ for (Node node: component.getChildren()) {
466+ if (node instanceof VisualContact) {
467+ VisualContact vc = (VisualContact)node;
468+ if (vc.isOutput()) {
469+ output_cnt++;
470+ }
471+ }
472+ }
473+ if (output_cnt > 1) {
474+ String suffix = "_" + circuit.getMathName(contact);
475+ result += suffix;
476+ }
477+ }
478+ }
479+ return result;
480+ }
481+
482+ private static VisualContact getDrivenOutputPort(VisualCircuit circuit, VisualContact contact) {
483+ VisualContact result = null;
484+ boolean multipleOutputPorts = false;
485+ for (VisualContact vc: findDriven(circuit, contact)) {
486+ if (vc.isPort() && vc.isOutput()) {
487+ if (result != null) {
488+ multipleOutputPorts = true;
489+ }
490+ result = vc;
491+ }
492+ }
493+ if (multipleOutputPorts) {
494+ result = null;
495+ }
496+ return result;
497+ }
498+
499 }
500
501=== modified file 'WorkcraftCore/src/org/workcraft/Framework.java'
502--- WorkcraftCore/src/org/workcraft/Framework.java 2014-11-14 23:43:09 +0000
503+++ WorkcraftCore/src/org/workcraft/Framework.java 2014-11-24 17:05:32 +0000
504@@ -94,8 +94,7 @@
505
506
507 public class Framework {
508- public static final String FRAMEWORK_VERSION_MAJOR = "2";
509- public static final String FRAMEWORK_VERSION_MINOR = "dev";
510+ public static Framework INSTANCE;
511
512 class ExecuteScriptAction implements ContextAction {
513 private String script;
514@@ -195,6 +194,8 @@
515 public Memento clipboard;
516
517 public Framework() {
518+ Framework.INSTANCE = this;
519+
520 pluginManager = new PluginManager(this);
521 taskManager = new DefaultTaskManager()
522 {
523
524=== modified file 'WorkcraftCore/src/org/workcraft/Info.java'
525--- WorkcraftCore/src/org/workcraft/Info.java 2014-11-12 16:27:29 +0000
526+++ WorkcraftCore/src/org/workcraft/Info.java 2014-11-24 17:05:32 +0000
527@@ -12,8 +12,8 @@
528
529 private static final int majorVersion = 3;
530 private static final int minorVersion = 0;
531- private static final int revisionVersion = 2;
532- private static final String statusVersion = "";
533+ private static final int revisionVersion = 3;
534+ private static final String statusVersion = "alpha";
535
536 private static final int startYear = 2006;
537 private static final int currentYear = Calendar.getInstance().get(Calendar.YEAR);
538
539=== modified file 'WorkcraftCore/src/org/workcraft/dom/DefaultMathNodeRemover.java'
540--- WorkcraftCore/src/org/workcraft/dom/DefaultMathNodeRemover.java 2014-11-12 22:33:34 +0000
541+++ WorkcraftCore/src/org/workcraft/dom/DefaultMathNodeRemover.java 2014-11-24 17:05:32 +0000
542@@ -22,6 +22,7 @@
543 package org.workcraft.dom;
544
545 import java.util.HashMap;
546+import java.util.HashSet;
547
548 import org.workcraft.dom.math.MathNode;
549 import org.workcraft.dom.visual.DependentNode;
550@@ -32,33 +33,31 @@
551
552 public class DefaultMathNodeRemover extends HierarchySupervisor {
553
554- private HashMap<MathNode, Integer> refCount = new HashMap<MathNode, Integer>();
555+ private HashMap<MathNode, HashSet<DependentNode>> referenceTracker = new HashMap<MathNode, HashSet<DependentNode>>();
556
557- private void incRef(MathNode node) {
558- if (node != null) {
559- Integer count = refCount.get(node);
560- if (count == null) {
561- refCount.put(node, 1);
562- } else {
563- refCount.put(node, count + 1);
564- if (count > 1) {
565- System.out.println("Debug info: node " + node + "is referenced " + (count+1) + " times");
566- }
567+ private void addReference(MathNode mathNode, DependentNode dependentNode) {
568+ if (mathNode != null) {
569+ HashSet<DependentNode> refs = referenceTracker.get(mathNode);
570+ if (refs == null) {
571+ refs = new HashSet<DependentNode>();
572+ referenceTracker.put(mathNode ,refs);
573 }
574+ refs.add(dependentNode);
575 }
576 }
577
578- private void decRef(MathNode node) {
579- if (node != null) {
580- Integer refs = refCount.get(node) - 1;
581- if (refs == 0) {
582- refCount.remove(node);
583- Node parent = node.getParent();
584+ private void removeReference(MathNode mathNode, DependentNode dependentNode) {
585+ if (mathNode != null) {
586+ HashSet<DependentNode> refs = referenceTracker.get(mathNode);
587+ if (refs != null) {
588+ refs.remove(dependentNode);
589+ }
590+ if ((refs == null) || refs.isEmpty()) {
591+ referenceTracker.remove(mathNode);
592+ Node parent = mathNode.getParent();
593 if (parent instanceof Container) {
594- ((Container)parent).remove(node);
595+ ((Container)parent).remove(mathNode);
596 }
597- } else {
598- refCount.put(node, refs);
599 }
600 }
601 }
602@@ -78,27 +77,29 @@
603 }
604
605 private void nodeAdded(Node node) {
606+ if (node instanceof DependentNode) {
607+ DependentNode dependentNode = (DependentNode)node;
608+ for (MathNode mathNode : dependentNode.getMathReferences()) {
609+ addReference(mathNode, dependentNode);
610+ }
611+ }
612 if (node != null) {
613- if (node instanceof DependentNode) {
614- for (MathNode mn : ((DependentNode)node).getMathReferences()) {
615- incRef(mn);
616- }
617- }
618- for (Node n : node.getChildren()) {
619- nodeAdded(n);
620+ for (Node childNode : node.getChildren()) {
621+ nodeAdded(childNode);
622 }
623 }
624 }
625
626 private void nodeRemoved(Node node) {
627+ if (node instanceof DependentNode) {
628+ DependentNode dependentNode = (DependentNode)node;
629+ for (MathNode mathNode : dependentNode.getMathReferences()) {
630+ removeReference(mathNode, dependentNode);
631+ }
632+ }
633 if (node != null) {
634- if (node instanceof DependentNode) {
635- for (MathNode mn : ((DependentNode)node).getMathReferences()) {
636- decRef(mn);
637- }
638- }
639- for (Node n : node.getChildren()) {
640- nodeRemoved(n);
641+ for (Node childNode : node.getChildren()) {
642+ nodeRemoved(childNode);
643 }
644 }
645 }
646
647=== modified file 'WorkcraftCore/src/org/workcraft/gui/MainWindow.java'
648--- WorkcraftCore/src/org/workcraft/gui/MainWindow.java 2014-11-14 17:38:33 +0000
649+++ WorkcraftCore/src/org/workcraft/gui/MainWindow.java 2014-11-24 17:05:32 +0000
650@@ -621,13 +621,14 @@
651 }
652
653 public void toggleDockableWindow(DockableWindow window) {
654- if (window.isClosed())
655+ if (window.isClosed()) {
656 displayDockableWindow(window);
657- else
658+ } else {
659 try {
660 closeDockableWindow(window);
661 } catch (OperationCancelledException e) {
662 }
663+ }
664 }
665
666 private void saveDockingLayout() {
667@@ -642,10 +643,9 @@
668 try {
669 File file = new File(UILAYOUT_PATH);
670 File parentDir = file.getParentFile();
671- if (parentDir != null)
672- if (!parentDir.exists())
673- parentDir.mkdirs();
674-
675+ if ((parentDir != null) && !parentDir.exists()) {
676+ parentDir.mkdirs();
677+ }
678 FileOutputStream os = new FileOutputStream(file);
679 pers.store(os, pmodel);
680 os.close();
681@@ -1133,7 +1133,7 @@
682 suffix = " - " + model.getDisplayName();
683 break;
684 case SHORT:
685- suffix += " [" + model.getShortName() + "]";
686+ suffix = " [" + model.getShortName() + "]";
687 break;
688 default:
689 suffix = "";
690@@ -1144,7 +1144,7 @@
691
692 public void refreshTitle(WorkspaceEntry we) {
693 for (DockableWindow w : editorWindows.get(we)) {
694- final GraphEditorPanel editor = new GraphEditorPanel(MainWindow.this, we);
695+ final GraphEditorPanel editor = getCurrentEditor();
696 String title = getTitle(we, editor.getModel());
697 w.getContentPanel().setTitle(title);
698 w.setTabText(title);
699
700=== modified file 'WorkcraftCore/src/org/workcraft/gui/propertyeditor/FileCellEditor.java'
701--- WorkcraftCore/src/org/workcraft/gui/propertyeditor/FileCellEditor.java 2014-04-24 20:24:53 +0000
702+++ WorkcraftCore/src/org/workcraft/gui/propertyeditor/FileCellEditor.java 2014-11-24 17:05:32 +0000
703@@ -19,7 +19,7 @@
704 JButton button;
705 File file;
706
707- public FileCellEditor() {
708+ public FileCellEditor() {
709 button = new JButton();
710 button.setActionCommand(EDIT);
711 button.addActionListener(this);
712
713=== modified file 'WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileDeserialiser.java'
714--- WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileDeserialiser.java 2014-04-24 20:24:53 +0000
715+++ WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileDeserialiser.java 2014-11-24 17:05:32 +0000
716@@ -13,7 +13,8 @@
717 }
718
719 public Object deserialise(Element element) throws DeserialisationException {
720- return new File(element.getAttribute("path"));
721+ String path = element.getAttribute("path");
722+ return new File(path);
723 }
724
725 }
726
727=== modified file 'WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileSerialiser.java'
728--- WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileSerialiser.java 2014-04-24 20:24:53 +0000
729+++ WorkcraftCore/src/org/workcraft/plugins/serialisation/xml/FileSerialiser.java 2014-11-24 17:05:32 +0000
730@@ -15,7 +15,9 @@
731 public void serialise(Element element, Object object)
732 throws SerialisationException {
733 if (object != null) {
734- element.setAttribute("path", ((File)object).getPath());
735+ File file = (File)object;
736+ String path = file.getPath();
737+ element.setAttribute("path", path);
738 }
739 }
740
741
742=== modified file 'WorkcraftCore/src/org/workcraft/workspace/WorkspaceEntry.java'
743--- WorkcraftCore/src/org/workcraft/workspace/WorkspaceEntry.java 2014-11-14 17:38:33 +0000
744+++ WorkcraftCore/src/org/workcraft/workspace/WorkspaceEntry.java 2014-11-24 17:05:32 +0000
745@@ -133,7 +133,7 @@
746 if (dot == -1) {
747 res = name;
748 } else {
749- res = name.substring(0,dot);
750+ res = name.substring(0, dot);
751 }
752 } else {
753 res = name;
754
755=== modified file 'build_distr_linux.sh'
756--- build_distr_linux.sh 2014-11-12 16:27:29 +0000
757+++ build_distr_linux.sh 2014-11-24 17:05:32 +0000
758@@ -1,7 +1,7 @@
759 #!/usr/bin/env bash
760
761 src_dir="."
762-distr_dir="../../workcraft_3.0.2"
763+distr_dir="../../workcraft_3.0.3_alpha"
764 template_dir="../../distr-template-linux"
765
766 ./build_distr.sh -s $src_dir -d $distr_dir -t $template_dir
767
768=== modified file 'build_distr_windows.sh'
769--- build_distr_windows.sh 2014-11-12 16:27:29 +0000
770+++ build_distr_windows.sh 2014-11-24 17:05:32 +0000
771@@ -1,7 +1,7 @@
772 #!/usr/bin/env bash
773
774 src_dir="."
775-distr_dir="../../workcraft_3.0.2"
776+distr_dir="../../workcraft_3.0.3_alpha"
777 template_dir="../../distr-template-windows"
778
779 ./build_distr.sh -s $src_dir -d $distr_dir -t $template_dir

Subscribers

People subscribed via source and target branches