1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.csg.scenegraph2;
\r
14 import org.jcae.opencascade.jni.BRepBuilderAPI_MakeEdge;
\r
15 import org.jcae.opencascade.jni.BRepBuilderAPI_MakeFace;
\r
16 import org.jcae.opencascade.jni.BRepBuilderAPI_MakeWire;
\r
17 import org.jcae.opencascade.jni.BRepPrimAPI_MakeRevol;
\r
18 import org.jcae.opencascade.jni.GC_MakeArcOfCircle;
\r
19 import org.jcae.opencascade.jni.GC_MakeSegment;
\r
20 import org.jcae.opencascade.jni.TopoDS_Edge;
\r
21 import org.jcae.opencascade.jni.TopoDS_Face;
\r
22 import org.jcae.opencascade.jni.TopoDS_Shape;
\r
23 import org.jcae.opencascade.jni.TopoDS_Wire;
\r
24 import org.simantics.g3d.csg.ontology.CSG;
\r
25 import org.simantics.g3d.property.annotations.GetPropertyValue;
\r
26 import org.simantics.g3d.property.annotations.SetPropertyValue;
\r
27 import org.simantics.objmap.graph.annotations.GraphType;
\r
28 import org.simantics.objmap.graph.annotations.RelatedGetValue;
\r
29 import org.simantics.objmap.graph.annotations.RelatedSetValue;
\r
31 @GraphType(CSG.URIs.Barrel)
\r
32 public class BarrelNode extends CSGnode {
\r
34 private double r1 = 1.0;
\r
35 private double r2 = 1.1;
\r
36 private double h = 1.0;
\r
40 @RelatedSetValue(CSG.URIs.HasMinorRadius)
\r
41 @SetPropertyValue(CSG.URIs.HasMinorRadius)
\r
42 public void setR1(double r1) {
\r
44 firePropertyChanged(CSG.URIs.HasMinorRadius);
\r
47 @RelatedSetValue(CSG.URIs.HasMajorRadius)
\r
48 @SetPropertyValue(CSG.URIs.HasMajorRadius)
\r
49 public void setR2(double r2) {
\r
51 firePropertyChanged(CSG.URIs.HasMajorRadius);
\r
54 @RelatedSetValue(CSG.URIs.HasHeight)
\r
55 @SetPropertyValue(CSG.URIs.HasHeight)
\r
56 public void setH(double h) {
\r
58 firePropertyChanged(CSG.URIs.HasHeight);
\r
61 @RelatedGetValue(CSG.URIs.HasHeight)
\r
62 @GetPropertyValue(value=CSG.URIs.HasHeight, name = "Height")
\r
63 public double getH() {
\r
67 @RelatedGetValue(CSG.URIs.HasMinorRadius)
\r
68 @GetPropertyValue(value=CSG.URIs.HasMinorRadius, name = "Minor Radius")
\r
69 public double getR1() {
\r
73 @RelatedGetValue(CSG.URIs.HasMajorRadius)
\r
74 @GetPropertyValue(value=CSG.URIs.HasMajorRadius, name = "Major Radius")
\r
75 public double getR2() {
\r
80 public TopoDS_Shape getBaseGeometry() {
\r
81 if (Math.abs(r1 -r2)< MIN_VALUE)
\r
82 r2 = r1 + MIN_VALUE;
\r
83 double p0[] = new double[]{0.0,-h*0.5,0.0};
\r
84 double p1[] = new double[]{0.0,-h*0.5,r1};
\r
85 double p2[] = new double[]{0.0, 0.0 ,r2};
\r
86 double p3[] = new double[]{0.0, h*0.5,r1};
\r
87 double p4[] = new double[]{0.0, h*0.5,0.0};
\r
88 GC_MakeArcOfCircle m = new GC_MakeArcOfCircle(p1,p2,p3);
\r
89 GC_MakeSegment s1 = new GC_MakeSegment(p0,p1);
\r
90 GC_MakeSegment s2 = new GC_MakeSegment(p3,p4);
\r
92 BRepBuilderAPI_MakeEdge edge = new BRepBuilderAPI_MakeEdge(s1.value());
\r
93 TopoDS_Edge e1 = (TopoDS_Edge)edge.shape();
\r
96 edge = new BRepBuilderAPI_MakeEdge(m.value());
\r
97 TopoDS_Edge e2 = (TopoDS_Edge)edge.shape();
\r
100 edge = new BRepBuilderAPI_MakeEdge(s2.value());
\r
101 TopoDS_Edge e3 = (TopoDS_Edge)edge.shape();
\r
104 BRepBuilderAPI_MakeWire wire = new BRepBuilderAPI_MakeWire(e1,e2,e3);
\r
105 TopoDS_Wire w = (TopoDS_Wire)wire.shape();
\r
108 BRepBuilderAPI_MakeFace face = new BRepBuilderAPI_MakeFace(w);
\r
109 TopoDS_Face F = (TopoDS_Face) face.shape();
\r
112 BRepPrimAPI_MakeRevol revol = new BRepPrimAPI_MakeRevol(F,new double[]{0.0,0.0,0.0,0.0,1.0,0.0});
\r
113 TopoDS_Shape shape = revol.shape();
\r