]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/geometry/VerticalTankGeometryProvider.java
5cb078e0714511a78999020bb49c051fe9d2cc12
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / VerticalTankGeometryProvider.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.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
19 public class VerticalTankGeometryProvider extends BuiltinGeometryProvider  {
20         
21         public VerticalTankGeometryProvider(Resource resource) {
22                 super(resource);
23         }
24
25         private double height = 1.0;
26         private double radius = 0.2;
27         
28         @Override
29         public Collection<TopoDS_Shape> getModel() throws Exception {
30                 
31                 double p0[] = new double[]{       0.0,     height,0.0};
32                 double p1[] = new double[]{radius*0.6,height*0.98,0.0};
33                 double p2[] = new double[]{    radius,height*0.94,0.0};
34                 double p3[] = new double[]{    radius,        0.0,0.0};
35                 double p4[] = new double[]{       0.0,        0.0,0.0};
36                 
37                 GC_MakeArcOfCircle m1 = new GC_MakeArcOfCircle(p0,p1,p2);
38                 GC_MakeSegment s1 = new GC_MakeSegment(p2,p3);
39                 GC_MakeSegment s2 = new GC_MakeSegment(p3,p4);
40                 
41                 BRepBuilderAPI_MakeEdge edge = new BRepBuilderAPI_MakeEdge(m1.value());
42                 TopoDS_Edge e1 = (TopoDS_Edge)edge.shape();
43                 edge.delete();
44                 
45                 edge = new BRepBuilderAPI_MakeEdge(s1.value());
46                 TopoDS_Edge e2 = (TopoDS_Edge)edge.shape();
47                 edge.delete();
48                 
49                 edge = new BRepBuilderAPI_MakeEdge(s2.value());
50                 TopoDS_Edge e3 = (TopoDS_Edge)edge.shape();
51                 edge.delete();
52                 
53                 BRepBuilderAPI_MakeWire wire =  new BRepBuilderAPI_MakeWire(e1,e2,e3);
54                 TopoDS_Wire w = (TopoDS_Wire)wire.shape();
55                 wire.delete();
56                 
57                 BRepBuilderAPI_MakeFace face = new BRepBuilderAPI_MakeFace(w);
58                 TopoDS_Face F = (TopoDS_Face) face.shape();
59                 face.delete();
60                 
61                 BRepPrimAPI_MakeRevol revol = new BRepPrimAPI_MakeRevol(F,new double[]{0.0,0.0,0.0,0.0,1.0,0.0}); 
62                 TopoDS_Shape shape = revol.shape();
63                 revol.delete();
64         
65                 m1.delete();
66                 s1.delete();
67                 s2.delete();
68                 e1.delete();
69                 e2.delete();
70                 e3.delete();
71                 w.delete();
72                 F.delete();
73
74                 return Collections.singletonList(shape);
75         }
76         
77         @Override
78         public void setProperties(Map<String, Object> props) {
79                 if (props.containsKey("height"))
80                         height = (Double)props.get("height");
81                 if (props.containsKey("radius")) {
82                         radius = (Double)props.get("radius");
83                 }
84                 
85         }
86
87 }