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