]> gerrit.simantics Code Review - simantics/3d.git/blob - 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
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 ReducerGeometryProvider extends BuiltinGeometryProvider  {
13         
14         public ReducerGeometryProvider(Resource resource) {
15                 super(resource);
16         }
17
18         private double radius = 0.01;
19         private double radius2 = 0.02;
20         
21         @Override
22         public Collection<TopoDS_Shape> getModel() throws Exception {
23 //              GP_Circ circ = new GP_Circ(new double[]{-length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius);
24 //              GP_Circ circ2 = new GP_Circ(new double[]{length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius2);
25 //              System.out.println("Reducer " + length  + " " + radius + " " + radius2);
26                 double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
27                 TopoDS_Shape shape;
28                 if (Math.abs(radius-radius2) < MathTools.NEAR_ZERO) {
29                         shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
30                 } else {
31                         shape = OccTriangulator.makeCone(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius,radius2, length);
32                 }
33                 return Collections.singletonList(shape);
34         }
35         
36         @Override
37         public void setProperties(Map<String, Object> props) {
38
39                 
40                 if (props.containsKey("radius")) {
41                         radius = (Double)props.get("radius");
42                 }
43                 if (props.containsKey("radius2")) {
44                         radius2 = (Double)props.get("radius2");
45                 }
46                 
47                 
48                 
49         }
50         
51         @Override
52         public void updateCalculatedProperties(Map<String, Object> returnProps) {
53                 returnProps.put("length", Math.max(0.1, Math.abs(radius-radius2)*4.0));
54                 
55         }
56
57 }