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