]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java
451abe1e1da5251bb096caefca8a9efea5cc58c1
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / PumpGeometryProvider.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 PumpGeometryProvider extends BuiltinGeometryProvider  {
13         
14         public PumpGeometryProvider(Resource resource) {
15                 super(resource);
16         }
17
18         private double length = 0.5;
19         private double width = 0.25;
20         
21         @Override
22         public Collection<TopoDS_Shape> getModel() throws Exception {
23                 if (width < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO)
24                         return Collections.emptyList();
25                 double h = width * 0.5;
26                 double h2 = width * 0.1;
27                 double ld2 = length * 0.5;
28                 double wd2 = width * 0.5;
29                 
30                 double r1 = width * 0.5;
31                 double r2 = r1 *0.2;
32                 double r3 = r1 *0.5;
33                 
34                 double l1 = length * 0.2;
35                 double l2 = length * 0.2;
36                 double l2b = l2 + length * 0.1;
37                 double l3 = length * 0.6;
38                 
39                 double dir[] = new double[]{1.0,0.0,0.0};
40                 
41                 TopoDS_Shape foundation = OccTriangulator.makeBox(-ld2, 0.0, -wd2, ld2, h2, wd2);
42                 TopoDS_Shape rotator = OccTriangulator.makeCylinder(new double[]{-ld2,h+h2,0.0}, dir, r1, l1);
43                 TopoDS_Shape axis = OccTriangulator.makeCylinder(new double[]{-ld2+l1,h+h2,0.0}, dir, r2, l2b);
44                 TopoDS_Shape motor = OccTriangulator.makeCylinder(new double[]{-ld2+l1+l2,h+h2,0.0}, dir, r3, l3);
45                 TopoDS_Shape motorBox = OccTriangulator.makeBox(-ld2+l1+l2, h2, -r3, ld2, h2+h-r3, r3);
46                 
47                 TopoDS_Shape shape = OccTriangulator.makeCompound(new TopoDS_Shape[]{foundation,rotator,axis,motor,motorBox});
48                 foundation.delete();
49                 rotator.delete();
50                 axis.delete();
51                 motor.delete();
52                 motorBox.delete();
53                 return Collections.singletonList(shape);
54         }
55         
56         @Override
57         public void setProperties(Map<String, Object> props) {
58                 if (props.containsKey("length"))
59                         length = (Double)props.get("length");
60                 if (props.containsKey("width")) {
61                         width = (Double)props.get("width");
62                 }
63                 
64         }
65
66 }