]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java
Compiler warning elimination
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / controlpoint / PipingRules.java
index 854b265d3a09e7c00ae370a5c93460a4b99ef020..f5c6f876a98d507eca60c31bcd809dd8f25bb37d 100644 (file)
@@ -51,6 +51,8 @@ public class PipingRules {
        private static Object ruleMutex = new Object();
        
        public static void requestUpdate(PipeControlPoint pcp) {
+           if (!PipingRules.enabled)
+               return;
                if (DEBUG) System.out.println("PipingRules request " + pcp);
                synchronized (updateMutex) {
                        if (!requestUpdates.contains(pcp))
@@ -59,6 +61,9 @@ public class PipingRules {
        }
        
        public static boolean update() throws Exception {
+           if (!PipingRules.enabled)
+               return false;
+           
                if (requestUpdates.size() == 0)
                        return false;
                
@@ -304,6 +309,10 @@ public class PipingRules {
                        else if (us.end.equals(updated))
                                lengthChange = PathLegUpdateType.PREV;
                }
+               if (us == null) {
+                   System.out.println("Null update struct " + start);
+                   return; 
+               }
                updatePathLeg(us, lengthChange);
        }
        
@@ -316,6 +325,10 @@ public class PipingRules {
 //            else if (us.end.equals(updated))
 //                lengthChange = PathLegUpdateType.PREV;
 //        }
+               if (us == null) {
+            System.out.println("Null update struct " + start);
+            return; 
+        }
                updatePathLeg(us, lengthChange);
        }
 
@@ -362,6 +375,7 @@ public class PipingRules {
 
        }
 
+       @SuppressWarnings("unused")
        private static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, ArrayList<PipeControlPoint> list, Vector3d dir, Vector3d offset) {
                boolean hasOffsets = false;
                List<PipeControlPoint> offsets = new ArrayList<PipeControlPoint>(list.size());
@@ -448,7 +462,7 @@ public class PipingRules {
        private static boolean asDirected(PipeControlPoint pcp, Direction direction) {
                if (pcp.isDirected())
                        return true;
-               if (pcp.isTurn() && pcp.isFixed()) {
+               if (pcp.asFixedAngle()) {
                        if (!pcp._getReversed())
                                return direction == Direction.NEXT;
                        else
@@ -485,7 +499,7 @@ public class PipingRules {
                if (DEBUG)
                        System.out.println("PipingRules.updateFreePipeRun " + u + " " + lengthChange);
                checkExpandPathLeg(u, lengthChange);
-               if (u.start.isInline() || u.end.isInline() || u.start.isFixed() || u.end.isFixed())
+               if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle()|| u.end.asFixedAngle())
                        processPathLeg(u, true, false);
        }
 
@@ -671,6 +685,11 @@ public class PipingRules {
                        // must be removed
                        
                        if (icp.isDeletable()) {
+                           if (!allowInsertRemove) {
+                               icp.setLength(0.0001);
+                               triedIR = true;
+                               return false;
+                           }
                                if (DEBUG)
                                        System.out.println("PipingRules.updateVariableLength removing " + icp);
                                icp._remove();
@@ -700,7 +719,7 @@ public class PipingRules {
                                                                                                        // position of the
                                                                                                        // component
                                dir.add(prevPos);
-                               PipeControlPoint scp = insertStraight(prev, icp, dir, length);
+                               insertStraight(prev, icp, dir, length);
                                return true;
                        } else {
                                triedIR = true;
@@ -860,7 +879,7 @@ public class PipingRules {
                double distance = t.length();
                boolean aligned = (distance < ALLOWED_OFFSET);
                if (aligned) {
-                       if (u.start.isInline() || u.end.isInline() || u.start.isFixed() || u.end.isFixed())
+                       if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle())
                                processPathLeg(u, true, false);
                        checkExpandPathLeg(u, lengthChange, inlineEnd);
                        
@@ -882,14 +901,15 @@ public class PipingRules {
                                if (other.isVariableAngle()) {
 
                                        // TODO calculate needed space from next run end.
-                                       if (mu[0] < 1.0) {
+                                   double space = spaceForTurn(other);
+                                       if (mu[0] < space) {
                                                if (dcpStart) {
                                                        closest.set(u.startPoint);
                                                } else {
                                                        closest.set(u.endPoint);
                                                }
                                                Vector3d v = new Vector3d(directedDirection);
-                                               v.scale(spaceForTurn(other));
+                                               v.scale(space);
                                                closest.add(v);
                                        }
 
@@ -1069,7 +1089,7 @@ public class PipingRules {
                // TODO : this returns now space for 90 deg turn.
                // The challenge: position of tcp affects the turn angle, which then affects the required space. Perhaps we need to iterate...
                // Additionally, if the path legs contain offset, using just positions of opposite path leg ends is not enough,    
-               return tcp.getPipeRun().getTurnRadius();
+               return ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
        }
 
        private static void insertElbowUpdate(UpdateStruct2 u, PipeControlPoint dcp, PipeControlPoint next, boolean dcpStart, Vector3d position, Vector3d directedDirection) throws Exception{
@@ -1353,6 +1373,7 @@ public class PipingRules {
        // end,Point3d endPoint, Vector3d dir, boolean hasOffsets,int iter, boolean
        // reversed, ArrayList<ExpandIterInfo> toRemove) throws TransactionException
        // {
+       @SuppressWarnings("unused")
        private static void processPathLegNoOffset(UpdateStruct2 u) throws Exception {
                if (DEBUG)
                        System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
@@ -1472,24 +1493,9 @@ public class PipingRules {
        private static void updateEndComponentControlPoint(PipeControlPoint ecp, Vector3d start, Vector3d end) throws Exception {
                if (DEBUG)
                        System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp);
-               // PipeControlPoint next = ecp.getNext();
-               // PipeControlPoint prev = ecp.getPrevious();
-               // if (next != null) {
-               // end = G3DTools.getPoint(next.getLocalPosition());
-               // start = G3DTools.getPoint(ecp.getLocalPosition());
-               // } else if (prev != null) {
-               // end = G3DTools.getPoint(ecp.getLocalPosition());
-               // start = G3DTools.getPoint(prev.getLocalPosition());
-               // } else {
-               // // TODO : warning?
-               // return;
-               // }
-               // Vector3d dir = new Vector3d (end);
-               // dir.sub(start);
-               // dir.normalize();
-               // G3DTools.setTuple(ecp.getDirection(), dir);
-               if (!ecp.isFixed())
-                       updateControlPointOrientation(ecp);
+               //FIXME : end control point cannot be fixed!
+               //if (!ecp.isFixed())
+               updateControlPointOrientation(ecp);
 
                for (PipeControlPoint pcp : ecp.getSubPoint()) {
                        // TODO update position
@@ -1550,7 +1556,7 @@ public class PipingRules {
                        }
                }
                
-               if (!tcp.isFixed()) {
+               if (!tcp.asFixedAngle()) {
                        
                        
                        if (next == null || prev == null) {
@@ -1565,7 +1571,7 @@ public class PipingRules {
                        Vector3d turnAxis = new Vector3d();
                        turnAxis.cross(prev, next);
                        if (turnAxis.lengthSquared() > MathTools.NEAR_ZERO) {
-                               double elbowRadius = tcp.getPipelineComponent().getPipeRun().getTurnRadius();
+                               double elbowRadius = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
                                double R = elbowRadius / Math.tan(angle * 0.5);
                                
                                turnAxis.normalize();
@@ -1628,8 +1634,9 @@ public class PipingRules {
                PipeControlPoint pcp = pipeRun.getControlPoints().iterator().next();
                while (pcp.getPrevious() != null) {
                        PipeControlPoint prev = pcp.getPrevious();
-                       if (prev.getPipeRun() != pipeRun)
-                               break;
+                       if (prev.getPipeRun() != pipeRun && prev.getPipeRun() != null) { // bypass possible corruption
+                           break;
+                       }
                        pcp = prev;
                }
                if (pcp.isDualSub()) {
@@ -1753,7 +1760,8 @@ public class PipingRules {
                                }
                                
                        }
-                       if (current.isTurn() && current.isFixed()) {
+                       //if (current.isTurn() && current.isFixed()) {
+                       if (current.asFixedAngle()) {
                                current.setReversed(!current._getReversed());
                        }
                        if (current.isInline() && current.isReverse()) {
@@ -1799,11 +1807,19 @@ public class PipingRules {
                }
                List<PipeControlPoint> runPcps = getControlPoints(pipeRun);
                if (runPcps.size() != count) {
-                       System.out.println("Run " + pipeRun.getName() + " contains unconnected control points");
+                       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());
+                           }
+                       }
                }
                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);
+                               System.out.println("Orphan undirected " + pcp + " " + pcp.getPipelineComponent());
                }
                for (PipeControlPoint pcp : pcps) {
                        if (pcp.getParentPoint() == null) {
@@ -1833,8 +1849,8 @@ public class PipingRules {
        }
        
        public static void splitVariableLengthComponent(PipelineComponent newComponent, InlineComponent splittingComponent, boolean assignPos) throws Exception{
-               assert(!splittingComponent.getControlPoint().isFixed());
-               assert(!(newComponent instanceof  InlineComponent && !newComponent.getControlPoint().isFixed()));
+               assert(!splittingComponent.getControlPoint().isFixedLength());
+               assert(!(newComponent instanceof  InlineComponent && !newComponent.getControlPoint().isFixedLength()));
                PipeControlPoint newCP = newComponent.getControlPoint();
                PipeControlPoint splittingCP = splittingComponent.getControlPoint();
                PipeControlPoint nextCP = splittingCP.getNext();
@@ -1862,7 +1878,6 @@ public class PipingRules {
                        // this should not be possible
                        throw new RuntimeException("VariableLengthComponent " + splittingComponent + " is not connected to anything.");
                }
-               double reservedLength = splittingComponent.getControlPoint().getLength();
                double newLength = newComponent.getControlPoint().getLength();
                
                
@@ -1898,21 +1913,20 @@ public class PipingRules {
                vn.interpolate(next, 0.5);
                
                
-               PipeControlPoint newVariableLengthCP = null;//insertStraight(pcp1, pcp2, pos, length);
                if (nextCP == null) {
                        newCP.insert(splittingCP, Direction.NEXT);
-                       newVariableLengthCP = insertStraight(newCP, Direction.NEXT, new Vector3d(vn), ln);
+                       insertStraight(newCP, Direction.NEXT, new Vector3d(vn), ln);
                        splittingCP.setWorldPosition(new Vector3d(vp));
 //                     ControlPointTools.setWorldPosition(splittingCP, vp);
 //                     splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
                } else if (prevCP == null) {
                        newCP.insert(splittingCP, Direction.PREVIOUS);
-                       newVariableLengthCP = insertStraight(newCP, Direction.PREVIOUS, new Vector3d(vp), lp);
+                       insertStraight(newCP, Direction.PREVIOUS, new Vector3d(vp), lp);
                        splittingCP.setWorldPosition(new Vector3d(vn));
 //                     splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, ln);
                } else {
                        newCP.insert(splittingCP, nextCP);
-                       newVariableLengthCP = insertStraight(newCP, nextCP, new Vector3d(vn), ln);
+                       insertStraight(newCP, nextCP, new Vector3d(vn), ln);
                        splittingCP.setWorldPosition(new Vector3d(vp));
 //                     splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
                }