X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Fscenegraph2%2FCSGnode.java;fp=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Fscenegraph2%2FCSGnode.java;h=68c1c015f2f1d67c610f858efb54ca44c26f2636;hb=84132a1d750c45f9161afbd58b78572964e50d26;hp=a28e5a3a13abcab06c07f259c1dcc47640ccbf1d;hpb=6308b57b2793abbd92da9e004f9f7c068f18eba6;p=simantics%2F3d.git diff --git a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGnode.java b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGnode.java index a28e5a3a..68c1c015 100644 --- a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGnode.java +++ b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGnode.java @@ -1,120 +1,119 @@ -/******************************************************************************* - * 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.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.vtkPanel; -import vtk.vtkProp3D; -import vtk.vtkRenderer; - -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) - 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(vtkPanel 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(); - } - - - -} +/******************************************************************************* + * 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) + 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(); + } + + + +}