]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/geometry/HorizontalTankGeometryProvider.java
Merge "Publish Plant3D feature"
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / HorizontalTankGeometryProvider.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 import org.simantics.opencascade.OccTriangulator;
19
20 public class HorizontalTankGeometryProvider extends BuiltinGeometryProvider  {
21         
22         public HorizontalTankGeometryProvider(Resource resource) {
23                 super(resource);
24         }
25
26         private double length = 1.0;
27         private double radius = 0.2;
28         
29         @Override
30         public Collection<TopoDS_Shape> getModel() throws Exception {
31                 
32                 double p0[] = new double[]{-length*0.50,        0.0,0.0};
33                 double p1[] = new double[]{-length*0.488, radius*0.6,0.0};
34                 double p2[] = new double[]{-length*0.46,     radius,0.0};
35                 double p3[] = new double[]{ length*0.46,     radius,0.0};
36                 double p4[] = new double[]{ length*0.488, radius*0.6,0.0};
37                 double p5[] = new double[]{ length*0.50,        0.0,0.0};
38                 
39                 GC_MakeArcOfCircle m1 = new GC_MakeArcOfCircle(p0,p1,p2);
40                 GC_MakeSegment s1 = new GC_MakeSegment(p2,p3);
41                 GC_MakeArcOfCircle m2 = new GC_MakeArcOfCircle(p3,p4,p5);
42                 
43                 BRepBuilderAPI_MakeEdge edge = new BRepBuilderAPI_MakeEdge(m1.value());
44                 TopoDS_Edge e1 = (TopoDS_Edge)edge.shape();
45                 edge.delete();
46                 
47                 edge = new BRepBuilderAPI_MakeEdge(s1.value());
48                 TopoDS_Edge e2 = (TopoDS_Edge)edge.shape();
49                 edge.delete();
50                 
51                 edge = new BRepBuilderAPI_MakeEdge(m2.value());
52                 TopoDS_Edge e3 = (TopoDS_Edge)edge.shape();
53                 edge.delete();
54                 
55                 BRepBuilderAPI_MakeWire wire =  new BRepBuilderAPI_MakeWire(e1,e2,e3);
56                 TopoDS_Wire w = (TopoDS_Wire)wire.shape();
57                 wire.delete();
58                 
59                 BRepBuilderAPI_MakeFace face = new BRepBuilderAPI_MakeFace(w);
60                 TopoDS_Face F = (TopoDS_Face) face.shape();
61                 face.delete();
62                 
63                 BRepPrimAPI_MakeRevol revol = new BRepPrimAPI_MakeRevol(F,new double[]{0.0,0.0,0.0,1.0,0.0,0.0}); 
64                 TopoDS_Shape shape = revol.shape();
65                 revol.delete();
66         
67                 m1.delete();
68                 s1.delete();
69                 m2.delete();
70                 e1.delete();
71                 e2.delete();
72                 e3.delete();
73                 w.delete();
74                 F.delete();
75                 
76                 TopoDS_Shape shape2 = OccTriangulator.makeTranslation(shape, 0.0, radius, 0.0);
77                 shape.delete();
78                 shape = shape2;
79                 TopoDS_Shape box = OccTriangulator.makeBox(-length*0.4, 0.0, -radius*0.5, -length*0.3, radius, radius*0.5);
80                 shape2 = OccTriangulator.makeFuse(shape, box);
81                 shape.delete();
82                 box.delete();
83                 box = OccTriangulator.makeBox(length*0.3, 0.0, -radius*0.5, length*0.4, radius, radius*0.5);
84                 shape = OccTriangulator.makeFuse(shape2, box);
85                 shape2.delete();
86                 box.delete();
87                 
88                 return Collections.singletonList(shape);
89         }
90         
91         @Override
92         public void setProperties(Map<String, Object> props) {
93                 if (props.containsKey("length"))
94                         length = (Double)props.get("length");
95                 if (props.containsKey("radius")) {
96                         radius = (Double)props.get("radius");
97                 }
98                 
99         }
100
101 }