]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java
Publish Plant3D feature
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / ReducerGeometryProvider.java
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 (file)
index 0000000..d3387f7
--- /dev/null
@@ -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<TopoDS_Shape> 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<String, Object> props) {
+
+               
+               if (props.containsKey("radius")) {
+                       radius = (Double)props.get("radius");
+               }
+               if (props.containsKey("radius2")) {
+                       radius2 = (Double)props.get("radius2");
+               }
+               
+               
+               
+       }
+       
+       @Override
+       public void updateCalculatedProperties(Map<String, Object> returnProps) {
+               returnProps.put("length", Math.max(0.1, Math.abs(radius-radius2)*4.0));
+               
+       }
+
+}