X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fgeometry%2FReducerGeometryProvider.java;fp=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fgeometry%2FReducerGeometryProvider.java;h=d3387f799181226eda8fe0ae373ec674d8a5bb4d;hb=22bb24d2a7e26c70b0dd4c57080f2c25ac3d40a8;hp=0000000000000000000000000000000000000000;hpb=16ec8075f708c6589937f8e760f8074ba27d86c4;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java new file mode 100644 index 00000000..d3387f79 --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java @@ -0,0 +1,57 @@ +package org.simantics.plant3d.geometry; + +import java.util.Collection; +import java.util.Collections; +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 ReducerGeometryProvider extends BuiltinGeometryProvider { + + public ReducerGeometryProvider(Resource resource) { + super(resource); + } + + private double radius = 0.01; + private double radius2 = 0.02; + + @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); + double length = Math.max(0.1, Math.abs(radius-radius2)*4.0); + TopoDS_Shape shape; + if (Math.abs(radius-radius2) < MathTools.NEAR_ZERO) { + shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length); + } else { + shape = OccTriangulator.makeCone(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius,radius2, length); + } + return Collections.singletonList(shape); + } + + @Override + public void setProperties(Map props) { + + + if (props.containsKey("radius")) { + radius = (Double)props.get("radius"); + } + if (props.containsKey("radius2")) { + radius2 = (Double)props.get("radius2"); + } + + + + } + + @Override + public void updateCalculatedProperties(Map returnProps) { + returnProps.put("length", Math.max(0.1, Math.abs(radius-radius2)*4.0)); + + } + +}