From 7505a3c42c08da8a8bc0128ffa024ec4e9f0a47d Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 18 Jul 2019 17:50:36 +0300 Subject: [PATCH] Check parameter inputs in geometry providers. gitlab #15 Change-Id: Ib891e910c7a78d1d4f9e6ff8ca1bad137e3ff95d --- .../plant3d/geometry/BallValveGeometryProvider.java | 2 ++ .../simantics/plant3d/geometry/CapGeometryProvider.java | 5 +++-- .../plant3d/geometry/CheckValveGeometryProvider.java | 2 ++ .../simantics/plant3d/geometry/ElbowGeometryProvider.java | 4 ++++ .../plant3d/geometry/GateValveGeometryProvider.java | 3 ++- .../plant3d/geometry/HorizontalTankGeometryProvider.java | 4 +++- .../simantics/plant3d/geometry/NozzleGeometryProvider.java | 3 +++ .../simantics/plant3d/geometry/PumpGeometryProvider.java | 3 +++ .../plant3d/geometry/ReducerGeometryProvider.java | 7 +++---- .../plant3d/geometry/StraightGeometryProvider.java | 2 +- .../plant3d/geometry/VerticalTankGeometryProvider.java | 3 +++ 11 files changed, 29 insertions(+), 9 deletions(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/BallValveGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/BallValveGeometryProvider.java index b0da882a..c58ce987 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/BallValveGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/BallValveGeometryProvider.java @@ -19,6 +19,8 @@ public class BallValveGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { + if (radius < MathTools.NEAR_ZERO) + return Collections.emptyList(); TopoDS_Shape cyl = OccTriangulator.makeCylinder(new double[] {-radius*2, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*4); TopoDS_Shape sph = OccTriangulator.makeSphere(0, 0, 0, radius*1.5); TopoDS_Shape shape = OccTriangulator.makeCompound(new TopoDS_Shape[]{cyl, sph}); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CapGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CapGeometryProvider.java index 4161d941..80e3bb2c 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CapGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CapGeometryProvider.java @@ -27,8 +27,9 @@ public class CapGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { -// TopoDS_Shape cyl = OccTriangulator.makeCylinder(new double[] {0.0, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*0.25); -// return Collections.singletonList(cyl); + if (radius < MathTools.NEAR_ZERO) + return Collections.emptyList(); + double length = radius * 0.5; double p0[] = new double[]{ length, 0.0,0.0}; double p1[] = new double[]{length*0.8, radius*0.6,0.0}; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CheckValveGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CheckValveGeometryProvider.java index 51067316..c14ff4b4 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CheckValveGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/CheckValveGeometryProvider.java @@ -19,6 +19,8 @@ public class CheckValveGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { + if (radius < MathTools.NEAR_ZERO) + return Collections.emptyList(); double l = radius*0.2; TopoDS_Shape cyl = OccTriangulator.makeCylinder(new double[] {radius-l, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, l); TopoDS_Shape con = OccTriangulator.makeCone(new double[] {-radius, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*0.1,radius*2); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java index ead9f0f5..70463979 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java @@ -27,6 +27,8 @@ public class ElbowGeometryProvider extends BuiltinMeshProvider { // @Override public Collection getModel() throws Exception { + if (radius < MathTools.NEAR_ZERO || turnRadius < MathTools.NEAR_ZERO) + return Collections.emptyList(); double t = Math.tan((Math.PI - turnAngle) * 0.5); double R = 0.0; if (t > MathTools.NEAR_ZERO) @@ -38,6 +40,8 @@ public class ElbowGeometryProvider extends BuiltinMeshProvider { // @Override public Mesh getMesh() { + if (radius < MathTools.NEAR_ZERO || turnRadius < MathTools.NEAR_ZERO) + return null; double t = Math.tan((Math.PI - turnAngle) * 0.5); double R = 0.0; if (t > MathTools.NEAR_ZERO) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java index 90c39363..3ab95889 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java @@ -19,7 +19,8 @@ public class GateValveGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { - + if (radius < MathTools.NEAR_ZERO) + return Collections.emptyList(); TopoDS_Shape con = OccTriangulator.makeCone(new double[] {-radius, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*0.1,radius); TopoDS_Shape con2 = OccTriangulator.makeCone(new double[] {radius, 0.0, 0.0}, new double[] { -1.0, 0.0, 0.0 }, radius, radius*0.1,radius); //TopoDS_Shape sph = OccTriangulator.makeSphere(0, 0, 0, radius*0.75); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/HorizontalTankGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/HorizontalTankGeometryProvider.java index c6d42015..1b68ce75 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/HorizontalTankGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/HorizontalTankGeometryProvider.java @@ -15,6 +15,7 @@ import org.jcae.opencascade.jni.TopoDS_Face; import org.jcae.opencascade.jni.TopoDS_Shape; import org.jcae.opencascade.jni.TopoDS_Wire; import org.simantics.db.Resource; +import org.simantics.g3d.math.MathTools; import org.simantics.opencascade.OccTriangulator; public class HorizontalTankGeometryProvider extends BuiltinGeometryProvider { @@ -28,7 +29,8 @@ public class HorizontalTankGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { - + if (radius < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO) + return Collections.emptyList(); double p0[] = new double[]{ length*0.50, 0.0,0.0}; double p1[] = new double[]{ length*0.488, radius*0.6,0.0}; double p2[] = new double[]{ length*0.46, radius,0.0}; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/NozzleGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/NozzleGeometryProvider.java index cdfe73cc..0b0f4884 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/NozzleGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/NozzleGeometryProvider.java @@ -6,6 +6,7 @@ import java.util.Map; import org.jcae.opencascade.jni.TopoDS_Shape; import org.simantics.db.Resource; +import org.simantics.g3d.math.MathTools; import org.simantics.opencascade.OccTriangulator; public class NozzleGeometryProvider extends BuiltinGeometryProvider { @@ -19,6 +20,8 @@ public class NozzleGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { + if (radius < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO) + return Collections.emptyList(); TopoDS_Shape shape = OccTriangulator.makeCylinder(new double[] {-length, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length); TopoDS_Shape shape2 = OccTriangulator.makeCylinder(new double[] {-length*0.25, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius*1.2, length*0.25); TopoDS_Shape shape3 = OccTriangulator.makeCompound(new TopoDS_Shape[]{shape,shape2}); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java index 29a6869f..451abe1e 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java @@ -6,6 +6,7 @@ import java.util.Map; import org.jcae.opencascade.jni.TopoDS_Shape; import org.simantics.db.Resource; +import org.simantics.g3d.math.MathTools; import org.simantics.opencascade.OccTriangulator; public class PumpGeometryProvider extends BuiltinGeometryProvider { @@ -19,6 +20,8 @@ public class PumpGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { + if (width < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO) + return Collections.emptyList(); double h = width * 0.5; double h2 = width * 0.1; double ld2 = length * 0.5; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java index 5ca0330d..8697fe14 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java @@ -30,9 +30,8 @@ public class ReducerGeometryProvider extends BuiltinMeshProvider { // @Override public Collection getModel() throws Exception { -// GP_Circ circ = new GP_Circ(new double[]{-length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius); -// GP_Circ circ2 = new GP_Circ(new double[]{length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius2); -// System.out.println("Reducer " + length + " " + radius + " " + radius2); + if (radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO) + return Collections.emptyList(); double length = Math.max(0.1, Math.abs(radius-radius2)*4.0); TopoDS_Shape shape; if (Math.abs(radius-radius2) < MathTools.NEAR_ZERO) { @@ -46,7 +45,7 @@ public class ReducerGeometryProvider extends BuiltinMeshProvider { @Override public Mesh getMesh() { double length = Math.max(0.1, Math.abs(radius-radius2)*4.0); - if (length < .0001) + if (length < .0001 || radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO) return null; Tube tube = new Tube(); tube.setResolution(16); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java index 6879b223..c7df71a1 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java @@ -32,7 +32,7 @@ public class StraightGeometryProvider extends BuiltinMeshProvider { @Override public Mesh getMesh() { - if (length < .001) + if (length < .001 || radius < MathTools.NEAR_ZERO ) return null; Tube tube = new Tube(); tube.setResolution(16); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/VerticalTankGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/VerticalTankGeometryProvider.java index 5cb078e0..c29b3bca 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/VerticalTankGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/VerticalTankGeometryProvider.java @@ -15,6 +15,7 @@ import org.jcae.opencascade.jni.TopoDS_Face; import org.jcae.opencascade.jni.TopoDS_Shape; import org.jcae.opencascade.jni.TopoDS_Wire; import org.simantics.db.Resource; +import org.simantics.g3d.math.MathTools; public class VerticalTankGeometryProvider extends BuiltinGeometryProvider { @@ -27,6 +28,8 @@ public class VerticalTankGeometryProvider extends BuiltinGeometryProvider { @Override public Collection getModel() throws Exception { + if (radius < MathTools.NEAR_ZERO || height < MathTools.NEAR_ZERO) + return Collections.emptyList(); double p0[] = new double[]{ 0.0, height,0.0}; double p1[] = new double[]{radius*0.6,height*0.98,0.0}; -- 2.47.1