private static boolean triedIR = false;
- private static List<PipeControlPoint> updates = new ArrayList<PipeControlPoint>();
+ private static List<PipeControlPoint> requestUpdates = new ArrayList<PipeControlPoint>();
+ private static List<PipeControlPoint> currentUpdates = new ArrayList<PipeControlPoint>();
- 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<PipeControlPoint> temp = new ArrayList<PipeControlPoint>(updates.size());
- synchronized(mutex) {
- temp.addAll(updates);
- updates.clear();
+
+ List<PipeControlPoint> temp = new ArrayList<PipeControlPoint>(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;
}
}
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)
public static void setEnabled(boolean enabled) {
PipingRules.enabled = enabled;
if(!enabled)
- updates.clear();
+ currentUpdates.clear();
}
public static boolean isEnabled() {
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;