1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g3d.csg.scenegraph2;
14 import java.util.Collection;
15 import java.util.Collections;
17 import javax.vecmath.AxisAngle4d;
18 import javax.vecmath.Quat4d;
19 import javax.vecmath.Vector3d;
21 import org.jcae.opencascade.jni.TopoDS_Shape;
22 import org.simantics.g3d.property.annotations.GetPropertyValue;
23 import org.simantics.g3d.property.annotations.SetPropertyValue;
24 import org.simantics.g3d.scenegraph.G3DNode;
25 import org.simantics.g3d.vtk.common.VtkView;
26 import org.simantics.layer0.Layer0;
27 import org.simantics.objmap.graph.annotations.RelatedGetValue;
28 import org.simantics.objmap.graph.annotations.RelatedSetValue;
29 import org.simantics.opencascade.OccTriangulator;
30 import org.simantics.opencascade.vtk.vtkSolidObject;
31 import org.simantics.utils.threads.AWTThread;
35 public abstract class CSGnode extends G3DNode implements ICSGnode {
37 public static final double MIN_VALUE = 0.001;
42 @RelatedGetValue(Layer0.URIs.HasName)
43 @GetPropertyValue(value = Layer0.URIs.HasName, tabId = "Default", name = "Name")
44 public String getName() {
48 @RelatedSetValue(Layer0.URIs.HasName)
49 @SetPropertyValue(Layer0.URIs.HasName)
50 public void setName(String name) {
54 firePropertyChanged(Layer0.URIs.HasName);
58 public String toString() {
63 private vtkSolidObject solidObject;
66 public TopoDS_Shape getGeometry() {
67 TopoDS_Shape shape = getBaseGeometry();
70 Quat4d q = getOrientation();
71 AxisAngle4d r = new AxisAngle4d();
73 TopoDS_Shape tshape = OccTriangulator.makeRotation(shape, new double[] { 0.0, 0.0, 0.0, r.x, r.y, r.z }, r.angle);
76 Vector3d p = getPosition();
77 tshape = OccTriangulator.makeTranslation(shape, p.x, p.y, p.z);
82 public void visualize(VtkView panel) {
83 if (solidObject != null) {
87 TopoDS_Shape shape = getGeometry();
90 solidObject = new vtkSolidObject(panel, shape);
91 solidObject.visualizeSolid(true, false);
94 @SuppressWarnings("unchecked")
95 public Collection<vtkProp3D> getActors() {
96 if (solidObject == null)
97 return Collections.EMPTY_LIST;
98 return solidObject.getActors();
101 public void stopVisualize() {
102 if (solidObject != null) {
103 if (Thread.currentThread() == AWTThread.getThreadAccess().getThread())
104 solidObject.delete();
106 solidObject.dispose();
112 public void cleanup() {