X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2Fcontrolpoint%2FPipingRules.java;h=386cc56a211d3245d6bb07137550d538d31a50f6;hb=6f6aa87201058478da5a0253118f2be10d946982;hp=6a5d04fb345731d9fb88cbbc86c7494611bc4f9c;hpb=8c9f0422ff951285f8c00bec6686817fd8d3ec09;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java index 6a5d04fb..386cc56a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java @@ -44,29 +44,41 @@ public class PipingRules { private static boolean triedIR = false; - private static List updates = new ArrayList(); + private static List requestUpdates = new ArrayList(); + private static List currentUpdates = new ArrayList(); - private static Object mutex = new Object(); + private static Object updateMutex = new Object(); + private static Object ruleMutex = new Object(); public static void requestUpdate(PipeControlPoint pcp) { if (DEBUG) System.out.println("PipingRules request " + pcp); - synchronized (mutex) { - if (!updates.contains(pcp)) - updates.add(pcp); + synchronized (updateMutex) { + if (!requestUpdates.contains(pcp)) + requestUpdates.add(pcp); } } - public static synchronized boolean update() throws Exception { - if (updates.size() == 0) + public static boolean update() throws Exception { + if (requestUpdates.size() == 0) return false; - List temp = new ArrayList(updates.size()); - synchronized(mutex) { - temp.addAll(updates); - updates.clear(); + + List temp = new ArrayList(requestUpdates.size()); + synchronized(updateMutex) { + temp.addAll(requestUpdates); + requestUpdates.clear(); + } + synchronized (ruleMutex) { + currentUpdates.clear(); + currentUpdates.addAll(temp); + // TODO : we should remove already processed control points from currentUpdates after each _positionUpdate call. + for (PipeControlPoint pcp : currentUpdates) + _positionUpdate(pcp, true); + currentUpdates.clear(); + } + synchronized(updateMutex) { + requestUpdates.removeAll(temp); } - for (PipeControlPoint pcp : temp) - positionUpdate(pcp); return true; } @@ -76,6 +88,16 @@ public class PipingRules { } public static boolean positionUpdate(PipeControlPoint pcp, boolean allowIR) throws Exception { + synchronized (ruleMutex) { + currentUpdates.add(pcp); + boolean b = _positionUpdate(pcp, allowIR); + currentUpdates.clear(); + return b; + } + + } + + private static boolean _positionUpdate(PipeControlPoint pcp, boolean allowIR) throws Exception { if (updating || !enabled) return true; if (pcp.getPipeRun() == null) @@ -106,7 +128,7 @@ public class PipingRules { public static void setEnabled(boolean enabled) { PipingRules.enabled = enabled; if(!enabled) - updates.clear(); + currentUpdates.clear(); } public static boolean isEnabled() { @@ -714,11 +736,13 @@ public class PipingRules { Vector3d dir = new Vector3d(); dir.sub(currentPos, prevPos); - boolean simple = true; + boolean simple = currentUpdates.contains(icp); if (simple) { + // Update based on position -> adjust length double currentLength = (dir.length() - prev.getInlineLength()) * 2.0; icp.setLength(currentLength); } else { + // Update based on neighbour movement -> adjust length and position, so that free end stays in place. double currentLength = icp.getLength(); if (currentLength < MathTools.NEAR_ZERO) { currentLength = (dir.length() - prev.getInlineLength()) * 2.0;