/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.g3d.csg.scenegraph2; import java.util.Collection; import java.util.Collections; import javax.vecmath.AxisAngle4d; import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.jcae.opencascade.jni.TopoDS_Shape; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.property.annotations.SetPropertyValue; import org.simantics.g3d.scenegraph.G3DNode; import org.simantics.g3d.vtk.common.VtkView; import org.simantics.layer0.Layer0; import org.simantics.objmap.graph.annotations.RelatedGetValue; import org.simantics.objmap.graph.annotations.RelatedSetValue; import org.simantics.opencascade.OccTriangulator; import org.simantics.opencascade.vtk.vtkSolidObject; import org.simantics.utils.threads.AWTThread; import vtk.vtkProp3D; public abstract class CSGnode extends G3DNode implements ICSGnode { public static final double MIN_VALUE = 0.001; private String name; @RelatedGetValue(Layer0.URIs.HasName) @GetPropertyValue(value = Layer0.URIs.HasName, tabId = "Default", name = "Name") public String getName() { return name; } @RelatedSetValue(Layer0.URIs.HasName) @SetPropertyValue(Layer0.URIs.HasName) public void setName(String name) { if (name == null || name.equals(this.name)) return; this.name = name; firePropertyChanged(Layer0.URIs.HasName); } @Override public String toString() { return getName(); } private vtkSolidObject solidObject; @Override public TopoDS_Shape getGeometry() { TopoDS_Shape shape = getBaseGeometry(); if (shape == null) return null; Quat4d q = getOrientation(); AxisAngle4d r = new AxisAngle4d(); r.set(q); TopoDS_Shape tshape = OccTriangulator.makeRotation(shape, new double[] { 0.0, 0.0, 0.0, r.x, r.y, r.z }, r.angle); shape.delete(); shape = tshape; Vector3d p = getPosition(); tshape = OccTriangulator.makeTranslation(shape, p.x, p.y, p.z); shape.delete(); return tshape; } public void visualize(VtkView panel) { if (solidObject != null) { solidObject.delete(); solidObject = null; } TopoDS_Shape shape = getGeometry(); if (shape == null) return; solidObject = new vtkSolidObject(panel, shape); solidObject.visualizeSolid(true, false); } @SuppressWarnings("unchecked") public Collection getActors() { if (solidObject == null) return Collections.EMPTY_LIST; return solidObject.getActors(); } public void stopVisualize() { if (solidObject != null) { if (Thread.currentThread() == AWTThread.getThreadAccess().getThread()) solidObject.delete(); else solidObject.dispose(); solidObject = null; } } @Override public void cleanup() { stopVisualize(); super.cleanup(); } }