]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Block parallel execution of position updates and validation. 10/3910/2
authorReino Ruusu <reino.ruusu@semantum.fi>
Tue, 25 Feb 2020 14:09:27 +0000 (16:09 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 26 Feb 2020 12:38:31 +0000 (14:38 +0200)
gitlab #92

Change-Id: I591afd4ee115a322e4edd6ad87aa3da89c453f9a

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java

index b2376341985d60247dece769a5be4921be26a78b..8864ffd8cc8cda8fde18258fc756404d9a9066ec 100644 (file)
@@ -68,11 +68,12 @@ public class PipingRules {
            if (!PipingRules.enabled)
                return false;
            
-               if (requestUpdates.size() == 0)
-                       return false;
-               
-               List<PipeControlPoint> temp = new ArrayList<PipeControlPoint>(requestUpdates.size());
-               synchronized(updateMutex) {
+           List<PipeControlPoint> temp;
+           synchronized(updateMutex) {
+                       if (requestUpdates.size() == 0)
+                               return false;
+                       
+                       temp = new ArrayList<PipeControlPoint>(requestUpdates.size());
                        temp.addAll(requestUpdates);
                        requestUpdates.clear();
                }
@@ -2075,50 +2076,52 @@ public class PipingRules {
        public static void validate(PipeRun pipeRun) {
                if (pipeRun == null)
                        return;
-               Collection<PipeControlPoint> pcps = pipeRun.getControlPoints();
-               int count = 0;
-               //System.out.println("Validate " + pipeRun.getName());
-               for (PipeControlPoint pcp : pcps) {
-                       if (pcp.getParentPoint() == null || pcp.getParentPoint().getPipeRun() != pipeRun)
-                               count++;
-               }
-               List<PipeControlPoint> runPcps = getControlPoints(pipeRun);
-               if (runPcps.size() != count) {
-                       System.out.println("Run " + pipeRun.getName() + " contains unconnected control points, found " + runPcps.size() + " connected, " + pcps.size() + " total.");
+               synchronized (ruleMutex) {
+                       Collection<PipeControlPoint> pcps = pipeRun.getControlPoints();
+                       int count = 0;
+                       //System.out.println("Validate " + pipeRun.getName());
                        for (PipeControlPoint pcp : pcps) {
-                           if (!runPcps.contains(pcp)) {
-                               System.out.println("Unconnected " + pcp + " " + pcp.getPipelineComponent());
-                           }
+                               if (pcp.getParentPoint() == null || pcp.getParentPoint().getPipeRun() != pipeRun)
+                                       count++;
                        }
-               }
-               for (PipeControlPoint pcp : pcps) {
-                   if (pcp.getPipeRun() == null) {
-                       System.out.println("PipeRun ref missing " + pcp + " " + pcp.getPipelineComponent());
-                   }
-                       if (!pcp.isDirected() && pcp.getNext() == null && pcp.getPrevious() == null)
-                               System.out.println("Orphan undirected " + pcp + " " + pcp.getPipelineComponent());
-               }
-               for (PipeControlPoint pcp : pcps) {
-                       if (pcp.getParentPoint() == null) {
-                               PipeControlPoint sub = null;
-                               if (pcp.isDualInline())
-                                       sub = pcp.getDualSub();
-                               PipeControlPoint next = pcp.getNext();
-                               PipeControlPoint prev = pcp.getPrevious();
-                               if (next != null) {
-                                       if (!(next.getPrevious() == pcp || next.getPrevious() == sub)) {
-                                               System.out.println("Inconsistency between " + pcp + " -> " +next );
-                                       }
+                       List<PipeControlPoint> runPcps = getControlPoints(pipeRun);
+                       if (runPcps.size() != count) {
+                               System.out.println("Run " + pipeRun.getName() + " contains unconnected control points, found " + runPcps.size() + " connected, " + pcps.size() + " total.");
+                               for (PipeControlPoint pcp : pcps) {
+                                   if (!runPcps.contains(pcp)) {
+                                       System.out.println("Unconnected " + pcp + " " + pcp.getPipelineComponent());
+                                   }
                                }
-                               if (prev != null) {
-                                       PipeControlPoint prevParent = null;
-                                       if (prev.isDualSub()) {
-                                               prevParent = prev.getParentPoint();
-                                       } else if (prev.isDualInline()) {
-                                               System.out.println("Inconsistency between " + pcp + " <-- " +prev );
+                       }
+                       for (PipeControlPoint pcp : pcps) {
+                           if (pcp.getPipeRun() == null) {
+                               System.out.println("PipeRun ref missing " + pcp + " " + pcp.getPipelineComponent());
+                           }
+                               if (!pcp.isDirected() && pcp.getNext() == null && pcp.getPrevious() == null)
+                                       System.out.println("Orphan undirected " + pcp + " " + pcp.getPipelineComponent());
+                       }
+                       for (PipeControlPoint pcp : pcps) {
+                               if (pcp.getParentPoint() == null) {
+                                       PipeControlPoint sub = null;
+                                       if (pcp.isDualInline())
+                                               sub = pcp.getDualSub();
+                                       PipeControlPoint next = pcp.getNext();
+                                       PipeControlPoint prev = pcp.getPrevious();
+                                       if (next != null) {
+                                               if (!(next.getPrevious() == pcp || next.getPrevious() == sub)) {
+                                                       System.out.println("Inconsistency between " + pcp + " -> " +next );
+                                               }
                                        }
-                                       if (!(prev.getNext() == pcp && (prevParent == null || prevParent.getNext() == pcp))) {
-                                               System.out.println("Inconsistency between " + pcp + " <-- " +prev );
+                                       if (prev != null) {
+                                               PipeControlPoint prevParent = null;
+                                               if (prev.isDualSub()) {
+                                                       prevParent = prev.getParentPoint();
+                                               } else if (prev.isDualInline()) {
+                                                       System.out.println("Inconsistency between " + pcp + " <-- " +prev );
+                                               }
+                                               if (!(prev.getNext() == pcp && (prevParent == null || prevParent.getNext() == pcp))) {
+                                                       System.out.println("Inconsistency between " + pcp + " <-- " +prev );
+                                               }
                                        }
                                }
                        }