1 package org.simantics.plant3d.geometry;
3 import java.util.Collection;
4 import java.util.Collections;
7 import javax.vecmath.AxisAngle4d;
8 import javax.vecmath.Vector3d;
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;
16 public class PumpGeometryProvider extends BuiltinGeometryProvider implements FixedNozzleProvider{
18 public PumpGeometryProvider(Resource resource) {
22 private double length = 0.5;
23 private double width = 0.25;
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;
34 double r1 = width * 0.5;
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;
43 double dir[] = new double[]{1.0,0.0,0.0};
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);
51 TopoDS_Shape shape = OccTriangulator.makeCompound(new TopoDS_Shape[]{foundation,rotator,axis,motor,motorBox});
57 return Collections.singletonList(shape);
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");
71 public int numberOfNozzles() {
76 public void updateNozzlePosition(int index, Nozzle nozzle) {
77 Double fl = (Double)nozzle.getParameterMap().get("length");
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)));
91 public String getNozzleName(int index) {
93 case 0 : return "Input";
94 case 1: return "Output";