1 package org.simantics.plant3d.geometry;
3 import java.util.Collection;
4 import java.util.Collections;
7 import org.jcae.opencascade.jni.BRepBuilderAPI_MakeEdge;
8 import org.jcae.opencascade.jni.BRepBuilderAPI_MakeFace;
9 import org.jcae.opencascade.jni.BRepBuilderAPI_MakeWire;
10 import org.jcae.opencascade.jni.BRepPrimAPI_MakeRevol;
11 import org.jcae.opencascade.jni.GC_MakeArcOfCircle;
12 import org.jcae.opencascade.jni.GC_MakeSegment;
13 import org.jcae.opencascade.jni.TopoDS_Edge;
14 import org.jcae.opencascade.jni.TopoDS_Face;
15 import org.jcae.opencascade.jni.TopoDS_Shape;
16 import org.jcae.opencascade.jni.TopoDS_Wire;
17 import org.simantics.db.Resource;
18 import org.simantics.g3d.math.MathTools;
20 public class VerticalTankGeometryProvider extends BuiltinGeometryProvider {
22 public VerticalTankGeometryProvider(Resource resource) {
26 private double height = 1.0;
27 private double radius = 0.2;
30 public Collection<TopoDS_Shape> getModel() throws Exception {
31 if (radius < MathTools.NEAR_ZERO || height < MathTools.NEAR_ZERO)
32 return Collections.emptyList();
34 double p0[] = new double[]{ 0.0, height,0.0};
35 double p1[] = new double[]{radius*0.6,height*0.98,0.0};
36 double p2[] = new double[]{ radius,height*0.94,0.0};
37 double p3[] = new double[]{ radius, 0.0,0.0};
38 double p4[] = new double[]{ 0.0, 0.0,0.0};
40 GC_MakeArcOfCircle m1 = new GC_MakeArcOfCircle(p0,p1,p2);
41 GC_MakeSegment s1 = new GC_MakeSegment(p2,p3);
42 GC_MakeSegment s2 = new GC_MakeSegment(p3,p4);
44 BRepBuilderAPI_MakeEdge edge = new BRepBuilderAPI_MakeEdge(m1.value());
45 TopoDS_Edge e1 = (TopoDS_Edge)edge.shape();
48 edge = new BRepBuilderAPI_MakeEdge(s1.value());
49 TopoDS_Edge e2 = (TopoDS_Edge)edge.shape();
52 edge = new BRepBuilderAPI_MakeEdge(s2.value());
53 TopoDS_Edge e3 = (TopoDS_Edge)edge.shape();
56 BRepBuilderAPI_MakeWire wire = new BRepBuilderAPI_MakeWire(e1,e2,e3);
57 TopoDS_Wire w = (TopoDS_Wire)wire.shape();
60 BRepBuilderAPI_MakeFace face = new BRepBuilderAPI_MakeFace(w);
61 TopoDS_Face F = (TopoDS_Face) face.shape();
64 BRepPrimAPI_MakeRevol revol = new BRepPrimAPI_MakeRevol(F,new double[]{0.0,0.0,0.0,0.0,1.0,0.0});
65 TopoDS_Shape shape = revol.shape();
77 return Collections.singletonList(shape);
81 public void setProperties(Map<String, Object> props) {
82 if (props.containsKey("height"))
83 height = (Double)props.get("height");
84 if (props.containsKey("radius")) {
85 radius = (Double)props.get("radius");