]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java
Publish Plant3D feature
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / StraightGeometryProvider.java
diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java
new file mode 100644 (file)
index 0000000..ac63f91
--- /dev/null
@@ -0,0 +1,44 @@
+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 StraightGeometryProvider extends BuiltinGeometryProvider {
+       
+       public StraightGeometryProvider(Resource resource) {
+               super(resource);
+       }
+
+       private double length = 1.0;
+       private double radius = 0.01;
+       
+       @Override
+       public Collection<TopoDS_Shape> getModel() throws Exception {
+               TopoDS_Shape shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
+//             System.out.println("Create straight l:" + length + " r:" + radius);
+               return Collections.singletonList(shape);
+       }
+       
+       @Override
+       public void setProperties(Map<String, Object> props) {
+               if (props.containsKey("length"))
+                       length = (Double)props.get("length");
+               if (props.containsKey("radius")) {
+                       radius = (Double)props.get("radius");
+               }
+               if (length < 0.0)
+                       length = 0.0;
+               if (radius < MathTools.NEAR_ZERO)
+                       radius = MathTools.NEAR_ZERO;
+               
+       }
+       
+       
+
+}