package org.simantics.plant3d.geometry; import java.util.Collection; import java.util.Collections; import java.util.Map; import javax.vecmath.AxisAngle4d; import javax.vecmath.Vector3d; import org.jcae.opencascade.jni.TopoDS_Shape; import org.simantics.db.Resource; import org.simantics.g3d.math.MathTools; import org.simantics.opencascade.OccTriangulator; import org.simantics.plant3d.scenegraph.Nozzle; public class PumpGeometryProvider extends BuiltinGeometryProvider implements FixedNozzleProvider{ public PumpGeometryProvider(Resource resource) { super(resource); } private double length = 0.5; private double width = 0.25; @Override public Collection getModel() throws Exception { if (width < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO) return Collections.emptyList(); double h = width * 0.5; double h2 = width * 0.1; double ld2 = length * 0.5; double wd2 = width * 0.5; double r1 = width * 0.5; double r2 = r1 *0.2; double r3 = r1 *0.5; double l1 = length * 0.2; double l2 = length * 0.2; double l2b = l2 + length * 0.1; double l3 = length * 0.6; double dir[] = new double[]{1.0,0.0,0.0}; TopoDS_Shape foundation = OccTriangulator.makeBox(-ld2, 0.0, -wd2, ld2, h2, wd2); TopoDS_Shape rotator = OccTriangulator.makeCylinder(new double[]{-ld2,h+h2,0.0}, dir, r1, l1); TopoDS_Shape axis = OccTriangulator.makeCylinder(new double[]{-ld2+l1,h+h2,0.0}, dir, r2, l2b); TopoDS_Shape motor = OccTriangulator.makeCylinder(new double[]{-ld2+l1+l2,h+h2,0.0}, dir, r3, l3); TopoDS_Shape motorBox = OccTriangulator.makeBox(-ld2+l1+l2, h2, -r3, ld2, h2+h-r3, r3); TopoDS_Shape shape = OccTriangulator.makeCompound(new TopoDS_Shape[]{foundation,rotator,axis,motor,motorBox}); foundation.delete(); rotator.delete(); axis.delete(); motor.delete(); motorBox.delete(); return Collections.singletonList(shape); } @Override public void setProperties(Map props) { if (props.containsKey("length")) length = (Double)props.get("length"); if (props.containsKey("width")) { width = (Double)props.get("width"); } } @Override public int numberOfNozzles() { return 2; } @Override public void updateNozzlePosition(int index, Nozzle nozzle) { Double fl = nozzle.getFlowLength(); if (fl == null) fl = 0.1; if (index == 0) { nozzle.setPosition(new Vector3d(-length*0.5- fl,width*0.6,0.0)); nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,1,0,Math.PI))); } else if (index == 1) { nozzle.setPosition(new Vector3d(-length*0.4,width*1.1+ fl,0.0)); nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,0,1,Math.PI*0.5))); } } @Override public String getNozzleName(int index) { switch (index) { case 0 : return "Input"; case 1: return "Output"; default: return null; } } }