]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java
Merge "Publish Plant3D feature"
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / StraightGeometryProvider.java
1 package org.simantics.plant3d.geometry;
2
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.Map;
6
7 import org.jcae.opencascade.jni.TopoDS_Shape;
8 import org.simantics.db.Resource;
9 import org.simantics.g3d.math.MathTools;
10 import org.simantics.opencascade.OccTriangulator;
11
12 public class StraightGeometryProvider extends BuiltinGeometryProvider {
13         
14         public StraightGeometryProvider(Resource resource) {
15                 super(resource);
16         }
17
18         private double length = 1.0;
19         private double radius = 0.01;
20         
21         @Override
22         public Collection<TopoDS_Shape> getModel() throws Exception {
23                 TopoDS_Shape shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
24 //              System.out.println("Create straight l:" + length + " r:" + radius);
25                 return Collections.singletonList(shape);
26         }
27         
28         @Override
29         public void setProperties(Map<String, Object> props) {
30                 if (props.containsKey("length"))
31                         length = (Double)props.get("length");
32                 if (props.containsKey("radius")) {
33                         radius = (Double)props.get("radius");
34                 }
35                 if (length < 0.0)
36                         length = 0.0;
37                 if (radius < MathTools.NEAR_ZERO)
38                         radius = MathTools.NEAR_ZERO;
39                 
40         }
41         
42         
43
44 }