]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java
White space clean-up
[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 javax.vecmath.AxisAngle4d;
8 import javax.vecmath.Vector3d;
9
10 import org.jcae.opencascade.jni.TopoDS_Shape;
11 import org.simantics.db.Resource;
12 import org.simantics.g3d.math.MathTools;
13 import org.simantics.opencascade.OccTriangulator;
14 import org.simantics.plant3d.scenegraph.Nozzle;
15
16 public class PumpGeometryProvider extends BuiltinGeometryProvider  implements FixedNozzleProvider{
17         
18         public PumpGeometryProvider(Resource resource) {
19                 super(resource);
20         }
21
22         private double length = 0.5;
23         private double width = 0.25;
24         
25         @Override
26         public Collection<TopoDS_Shape> getModel() throws Exception {
27                 if (width < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO)
28                         return Collections.emptyList();
29                 double h = width * 0.5;
30                 double h2 = width * 0.1;
31                 double ld2 = length * 0.5;
32                 double wd2 = width * 0.5;
33                 
34                 double r1 = width * 0.5;
35                 double r2 = r1 *0.2;
36                 double r3 = r1 *0.5;
37                 
38                 double l1 = length * 0.2;
39                 double l2 = length * 0.2;
40                 double l2b = l2 + length * 0.1;
41                 double l3 = length * 0.6;
42                 
43                 double dir[] = new double[]{1.0,0.0,0.0};
44                 
45                 TopoDS_Shape foundation = OccTriangulator.makeBox(-ld2, 0.0, -wd2, ld2, h2, wd2);
46                 TopoDS_Shape rotator = OccTriangulator.makeCylinder(new double[]{-ld2,h+h2,0.0}, dir, r1, l1);
47                 TopoDS_Shape axis = OccTriangulator.makeCylinder(new double[]{-ld2+l1,h+h2,0.0}, dir, r2, l2b);
48                 TopoDS_Shape motor = OccTriangulator.makeCylinder(new double[]{-ld2+l1+l2,h+h2,0.0}, dir, r3, l3);
49                 TopoDS_Shape motorBox = OccTriangulator.makeBox(-ld2+l1+l2, h2, -r3, ld2, h2+h-r3, r3);
50                 
51                 TopoDS_Shape shape = OccTriangulator.makeCompound(new TopoDS_Shape[]{foundation,rotator,axis,motor,motorBox});
52                 foundation.delete();
53                 rotator.delete();
54                 axis.delete();
55                 motor.delete();
56                 motorBox.delete();
57                 return Collections.singletonList(shape);
58         }
59         
60         @Override
61         public void setProperties(Map<String, Object> props) {
62                 if (props.containsKey("length"))
63                         length = (Double)props.get("length");
64                 if (props.containsKey("width")) {
65                         width = (Double)props.get("width");
66                 }
67                 
68         }
69         
70         @Override
71         public int numberOfNozzles() {
72                 return 2;
73         }
74         
75         @Override
76         public void updateNozzlePosition(int index, Nozzle nozzle) {
77                 Double fl = nozzle.getFlowLength();
78                 if (fl == null)
79                         fl = 0.1;
80                 if (index == 0) {
81                         nozzle.setPosition(new Vector3d(-length*0.5- fl,width*0.6,0.0));
82                         nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,1,0,Math.PI)));
83                 } else if (index == 1) {
84                         nozzle.setPosition(new Vector3d(-length*0.4,width*1.1+ fl,0.0));
85                         nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,0,1,Math.PI*0.5)));
86                 }
87                 
88         }
89         
90         @Override
91         public String getNozzleName(int index) {
92                 switch (index) {
93                 case 0 : return "Input";
94                 case 1: return "Output";
95                 default: return null;
96                 }
97         }
98
99 }