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_MakeWire;
\r
16 import org.jcae.opencascade.jni.BRepOffsetAPI_ThruSections;
\r
17 import org.jcae.opencascade.jni.TopoDS_Edge;
\r
18 import org.jcae.opencascade.jni.TopoDS_Shape;
\r
19 import org.jcae.opencascade.jni.TopoDS_Wire;
\r
20 import org.simantics.g3d.csg.ontology.CSG;
\r
21 import org.simantics.g3d.property.annotations.GetPropertyValue;
\r
22 import org.simantics.g3d.property.annotations.SetPropertyValue;
\r
23 import org.simantics.objmap.graph.annotations.GraphType;
\r
24 import org.simantics.objmap.graph.annotations.RelatedGetValue;
\r
25 import org.simantics.objmap.graph.annotations.RelatedSetValue;
\r
28 @GraphType(CSG.URIs.RectangularSolid)
\r
29 public class RectangularSolidNode extends CSGnode {
\r
38 @RelatedSetValue(CSG.URIs.HasXAxisMinimumSize)
\r
39 @SetPropertyValue(CSG.URIs.HasXAxisMinimumSize)
\r
40 public void setX1(double d) {
\r
42 firePropertyChanged(CSG.URIs.HasXAxisMinimumSize);
\r
45 @RelatedSetValue(CSG.URIs.HasXAxisMaximumSize)
\r
46 @SetPropertyValue(CSG.URIs.HasXAxisMaximumSize)
\r
47 public void setX2(double d) {
\r
49 firePropertyChanged(CSG.URIs.HasXAxisMaximumSize);
\r
52 @RelatedSetValue(CSG.URIs.HasYAxisSize)
\r
53 @SetPropertyValue(CSG.URIs.HasYAxisSize)
\r
54 public void setSY(double d) {
\r
56 firePropertyChanged(CSG.URIs.HasYAxisSize);
\r
59 @RelatedSetValue(CSG.URIs.HasZAxisMinimumSize)
\r
60 @SetPropertyValue(CSG.URIs.HasZAxisMinimumSize)
\r
61 public void setZ1(double d) {
\r
63 firePropertyChanged(CSG.URIs.HasZAxisMinimumSize);
\r
66 @RelatedSetValue(CSG.URIs.HasZAxisMaximumSize)
\r
67 @SetPropertyValue(CSG.URIs.HasZAxisMaximumSize)
\r
68 public void setZ2(double d) {
\r
70 firePropertyChanged(CSG.URIs.HasZAxisMaximumSize);
\r
73 @RelatedGetValue(CSG.URIs.HasXAxisMinimumSize)
\r
74 @GetPropertyValue(value=CSG.URIs.HasXAxisMinimumSize, name = "X Min Size")
\r
75 public double getX1() {
\r
79 @RelatedGetValue(CSG.URIs.HasXAxisMaximumSize)
\r
80 @GetPropertyValue(value=CSG.URIs.HasXAxisMaximumSize, name = "X Max Size")
\r
81 public double getX2() {
\r
85 @RelatedGetValue(CSG.URIs.HasYAxisSize)
\r
86 @GetPropertyValue(value=CSG.URIs.HasYAxisSize, name = "Y Size")
\r
87 public double getY() {
\r
91 @RelatedGetValue(CSG.URIs.HasZAxisMinimumSize)
\r
92 @GetPropertyValue(value=CSG.URIs.HasZAxisMinimumSize, name = "Z Min Size")
\r
93 public double getZ1() {
\r
97 @RelatedGetValue(CSG.URIs.HasZAxisMaximumSize)
\r
98 @GetPropertyValue(value=CSG.URIs.HasZAxisMaximumSize, name = "Z Max Size")
\r
99 public double getZ2() {
\r
104 public TopoDS_Shape getBaseGeometry() {
\r
105 double x1 = this.x1 *0.5;
\r
106 double x2 = this.x2 *0.5;
\r
107 double z1 = this.z1 *0.5;
\r
108 double z2 = this.z2 *0.5;
\r
109 double y = this.y * 0.5;
\r
111 BRepBuilderAPI_MakeWire wire = new BRepBuilderAPI_MakeWire();
\r
112 BRepBuilderAPI_MakeEdge edge = new BRepBuilderAPI_MakeEdge(new double[]{x1,-y,z1},new double[]{x1,-y,-z1});
\r
113 TopoDS_Edge top_edge = (TopoDS_Edge)edge.shape();
\r
114 wire.add(top_edge);
\r
118 edge = new BRepBuilderAPI_MakeEdge(new double[]{x1,-y,-z1},new double[]{-x1,-y,-z1});
\r
119 top_edge = (TopoDS_Edge)edge.shape();
\r
120 wire.add(top_edge);
\r
124 edge = new BRepBuilderAPI_MakeEdge(new double[]{-x1,-y,-z1},new double[]{-x1,-y,z1});
\r
125 top_edge = (TopoDS_Edge)edge.shape();
\r
126 wire.add(top_edge);
\r
130 edge = new BRepBuilderAPI_MakeEdge(new double[]{-x1,-y,z1},new double[]{x1,-y,z1});
\r
131 top_edge = (TopoDS_Edge)edge.shape();
\r
132 wire.add(top_edge);
\r
136 TopoDS_Wire w1 = (TopoDS_Wire)wire.shape();
\r
138 wire = new BRepBuilderAPI_MakeWire();
\r
141 edge = new BRepBuilderAPI_MakeEdge(new double[]{x2, y,z2},new double[]{x2, y,-z2});
\r
142 top_edge = (TopoDS_Edge)edge.shape();
\r
143 wire.add(top_edge);
\r
147 edge = new BRepBuilderAPI_MakeEdge(new double[]{x2, y,-z2},new double[]{-x2, y,-z2});
\r
148 top_edge = (TopoDS_Edge)edge.shape();
\r
149 wire.add(top_edge);
\r
153 edge = new BRepBuilderAPI_MakeEdge(new double[]{-x2, y,-z2},new double[]{-x2, y,z2});
\r
154 top_edge = (TopoDS_Edge)edge.shape();
\r
155 wire.add(top_edge);
\r
159 edge = new BRepBuilderAPI_MakeEdge(new double[]{-x2, y,z2},new double[]{x2, y,z2});
\r
160 top_edge = (TopoDS_Edge)edge.shape();
\r
161 wire.add(top_edge);
\r
165 TopoDS_Wire w2 = (TopoDS_Wire)wire.shape();
\r
168 BRepOffsetAPI_ThruSections generatorb = new BRepOffsetAPI_ThruSections(true, true);
\r
169 generatorb.addWire(w1);
\r
170 generatorb.addWire(w2);
\r
171 generatorb.build();
\r
175 TopoDS_Shape shape = generatorb.shape();
\r
176 generatorb.delete();
\r