]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Created Mesh API for Plant3D objects 17/3017/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 15 Jul 2019 13:28:38 +0000 (16:28 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 15 Jul 2019 13:28:38 +0000 (16:28 +0300)
* Replaced OCCT-based geometries for Straight and Elbow.
* MeshActor is able to bypass mesh normals to VTK

gitlab #10

Change-Id: Ib201d29802921df35a5fa88da922e8265b54df7c

21 files changed:
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/MeshActor.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/vtkMeshObject.java [new file with mode: 0644]
org.simantics.g3d/src/org/simantics/g3d/scenegraph/GeometryProvider.java [new file with mode: 0644]
org.simantics.g3d/src/org/simantics/g3d/scenegraph/MeshProvider.java [new file with mode: 0644]
org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricGeometryProvider.java [new file with mode: 0644]
org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricMeshProvider.java [new file with mode: 0644]
org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java
org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java
org.simantics.opencascade/META-INF/MANIFEST.MF
org.simantics.opencascade/src/org/simantics/opencascade/ParametricSolidModelProvider.java
org.simantics.opencascade/src/org/simantics/opencascade/SolidModelProvider.java
org.simantics.plant3d/adapters.xml
org.simantics.plant3d/src/org/simantics/plant3d/geometry/BuiltinMeshProvider.java [new file with mode: 0644]
org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryComponent.java [new file with mode: 0644]
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryNode.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DParentGeometryNode.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java

index b290f861d27fbcf6d7d7610b1ad22a5c491f4aad..c52e021ebf9ade2a718e1fed3785b0d592679d16 100644 (file)
 package org.simantics.g3d.vtk.shape;
 
 import javax.vecmath.Tuple3d;
-import javax.vecmath.Vector3d;
 
 import org.simantics.g3d.shape.Color4d;
 import org.simantics.g3d.shape.Mesh;
 
 import vtk.vtkActor;
-import vtk.vtkDataSetMapper;
+import vtk.vtkFloatArray;
 import vtk.vtkIdList;
+import vtk.vtkPointData;
 import vtk.vtkPoints;
 import vtk.vtkPolyData;
 import vtk.vtkPolyDataMapper;
@@ -29,6 +29,7 @@ import vtk.vtkUnsignedCharArray;
 
 public class MeshActor extends vtkActor {
        
+       
        public static vtkPolyData createPolyData(Mesh mesh) {
                vtkPolyData polyData = new vtkPolyData();
                polyData.Allocate(mesh.getIndices().size()/3, mesh.getIndices().size()/3);
@@ -43,7 +44,7 @@ public class MeshActor extends vtkActor {
         }
         list.Delete();
         triangle.Delete();
-               
+        
         
         vtkPoints points = new vtkPoints();
         for (int i = 0; i < mesh.getVertices().size(); i++) {
@@ -54,6 +55,19 @@ public class MeshActor extends vtkActor {
         polyData.SetPoints(points);
         points.Delete();
         
+        if (mesh.getNormals() != null) {
+               vtkFloatArray normals = new vtkFloatArray();
+               normals.SetNumberOfComponents(3);
+               normals.SetNumberOfTuples(mesh.getNormals().size());
+               for (int i = 0; i < mesh.getNormals().size(); i++) {
+               Tuple3d p = mesh.getNormals().get(i);
+               normals.InsertTuple3(i, p.x, p.y, p.z);
+            }
+               vtkPointData pointData = polyData.GetPointData();
+               pointData.SetNormals(normals);
+               normals.Delete();
+               pointData.Delete();
+        }
         if (mesh.getColors() != null) {
                vtkUnsignedCharArray colors = new vtkUnsignedCharArray();
                colors.SetName("Colors");
@@ -75,10 +89,11 @@ public class MeshActor extends vtkActor {
                vtkPolyDataMapper mapper = new vtkPolyDataMapper();
                vtkPolyData polyData = createPolyData(mesh);
                
-        boolean computeNormals = true;
-        if (computeNormals) {
+       
+        if (mesh.getNormals() == null) {
                vtkPolyDataNormals normals = new vtkPolyDataNormals();
                normals.SetInputData(polyData);
+               normals.ComputePointNormalsOn();
                mapper.SetInputConnection(normals.GetOutputPort());
                normals.GetOutputPort().Delete();
                normals.Delete();
@@ -98,5 +113,11 @@ public class MeshActor extends vtkActor {
         polyData.Delete();
         
        }
+       
+       @Override
+       public void Delete() {
+               // TODO Auto-generated method stub
+               super.Delete();
+       }
 
 }
diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/vtkMeshObject.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/vtkMeshObject.java
new file mode 100644 (file)
index 0000000..0e60a27
--- /dev/null
@@ -0,0 +1,111 @@
+package org.simantics.g3d.vtk.shape;
+
+import org.simantics.g3d.shape.Mesh;
+import org.simantics.utils.threads.AWTThread;
+import org.simantics.utils.threads.ThreadUtils;
+
+import vtk.vtkPanel;
+import vtk.vtkRenderer;
+
+public class vtkMeshObject {
+       
+       private vtkPanel panel;
+       private Mesh mesh;
+       
+       private MeshActor meshActor;
+       
+       public vtkMeshObject(vtkPanel panel, Mesh mesh) {
+               this.mesh = mesh;
+               this.panel = panel;
+       }
+       
+       public void visualizeMesh() {
+               clearActorsAWT();
+               meshActor = new MeshActor();
+               meshActor.setMesh(mesh);
+               //System.out.println("Set mesh " + mesh.getVertices().size() + " " + mesh.getIndices().size() + " " + this);
+               showActorsAWT();
+       }
+       
+       public MeshActor getActor() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               return meshActor;
+       }
+       
+       public void showActorsAWT() {
+               //System.out.println("showActorsAWT " + this + " " + meshActor != null);
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               vtkRenderer ren = panel.GetRenderer();
+               if (meshActor != null)
+                       ren.AddActor(meshActor);
+       }
+       
+       public void showActors() {
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               showActorsAWT();
+                       }
+               });
+       }
+       
+       public void clearActorsAWT() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               
+               if (meshActor == null)
+                       return;
+               //System.out.println("clearActorsAwt " + this);
+               vtkRenderer ren = panel.GetRenderer();
+               if (ren == null)
+                       return;
+               panel.lock();
+               if (meshActor.GetVTKId() != 0) {
+                       ren.RemoveActor(meshActor);
+                       meshActor.Delete();
+               }
+               panel.unlock();
+               meshActor = null;
+       }
+       
+       private void clearActorsAWT(MeshActor meshActor) {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               
+               if (meshActor == null)
+                       return;
+               //System.out.println("clearActorsAwt2 " + this);
+               vtkRenderer ren = panel.GetRenderer();
+               if (ren == null)
+                       return;
+               panel.lock();
+               if (meshActor.GetVTKId() != 0) {
+                       ren.RemoveActor(meshActor);
+                       meshActor.Delete();
+               }
+               panel.unlock();
+               meshActor = null;
+       }
+       
+       public void clearActors() {
+               if (meshActor == null)
+                       return;
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               clearActorsAWT(meshActor);
+                       }
+               });
+       }
+       
+       public void dispose() {
+               mesh = null;
+               clearActors();
+       }
+       
+       public void delete() {
+               mesh = null;
+               clearActorsAWT();
+       }
+
+}
diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/GeometryProvider.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/GeometryProvider.java
new file mode 100644 (file)
index 0000000..95c5f8a
--- /dev/null
@@ -0,0 +1,5 @@
+package org.simantics.g3d.scenegraph;
+
+public interface GeometryProvider {
+
+}
diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/MeshProvider.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/MeshProvider.java
new file mode 100644 (file)
index 0000000..6c258d4
--- /dev/null
@@ -0,0 +1,7 @@
+package org.simantics.g3d.scenegraph;
+
+import org.simantics.g3d.shape.Mesh;
+
+public interface MeshProvider extends GeometryProvider{
+       Mesh getMesh();
+}
diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricGeometryProvider.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricGeometryProvider.java
new file mode 100644 (file)
index 0000000..25951b8
--- /dev/null
@@ -0,0 +1,18 @@
+package org.simantics.g3d.scenegraph;
+
+import java.util.Map;
+
+public interface ParametricGeometryProvider extends GeometryProvider{
+
+       /**
+        * Sets parameters for geometry calculation
+        * @param props
+        */
+       public void setProperties(Map<String,Object> props);
+       
+       /** 
+        * Returns calculated parameters from geometry calculation
+        * @param returnProps
+        */
+       public void updateCalculatedProperties(Map<String,Object> returnProps);
+}
diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricMeshProvider.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricMeshProvider.java
new file mode 100644 (file)
index 0000000..e97ab7c
--- /dev/null
@@ -0,0 +1,5 @@
+package org.simantics.g3d.scenegraph;
+
+public interface ParametricMeshProvider extends MeshProvider, ParametricGeometryProvider{
+
+}
index 348fd8520cc5f27850b163454f7987eee8b60d53..6e4a3d3b96273a6c06e64a0fb27b08a7bcaa7ec7 100644 (file)
@@ -97,6 +97,56 @@ public class ArcCylinder {
                return new Mesh(vertices, normals, indices);
        }
        
+       public Mesh create(Point3d c, Vector3d axis, Vector3d an, double R, double r, double a, int res, double res2) {
+               
+       
+               
+               int steps = 0;
+               double sa = 0.0;
+               
+               Vector3d rn = new Vector3d(axis);
+               rn.normalize();
+               Vector3d r1 = new Vector3d(an);
+               r1.normalize();
+               r1.scale(R);
+
+               
+               if ((a +0.0001) > Math.PI) {
+                       steps = 1;
+               } else {
+                       steps = (int)(Math.ceil(a/res2));
+                       if (steps == 0)
+                               steps = 1;
+                       sa = a/steps;
+               }
+
+               List<Tuple3d> vertices = new ArrayList<Tuple3d>(res * (steps+1));
+               List<Tuple3d> normals = new ArrayList<Tuple3d>(res * (steps+1));
+               List<Integer> indices = new ArrayList<Integer>();
+               
+               for (int i = 0; i <= steps; i++) {
+                       Vector3d p;
+                       Vector3d t;
+                       p = new Vector3d();
+                       double ca = sa * i;
+                       Quat4d q = MathTools.getQuat(new AxisAngle4d(rn, ca));
+                       MathTools.rotate(q, r1, p);
+                       t = new Vector3d();
+                       t.cross(rn,p);
+                       t.normalize();
+                       p.add(c);
+                               
+                       
+                       createCircle(vertices, normals, p, t, rn, res, r);
+               }
+               int count = steps*res*6;
+               for (int i = 0; i < count; i++) {
+                       indices.add(-1);
+               }       
+               createIndices(steps, res, indices);
+               return new Mesh(vertices, normals, indices);
+       }
+       
        private static void createCircle(List<Tuple3d> points, List<Tuple3d> normals, Tuple3d p, Vector3d t, Vector3d n, int res, double radius) {
                n = new Vector3d(n);
                n.scale(radius);
index fd2c0bb1d6bc6637d7e613d671457fdd5e855a25..f2501e95d7fe659965b9421608a30db44e9feee2 100644 (file)
@@ -180,12 +180,16 @@ public class vtkSolidObject {
                if (actors.size() == 0)
                        return;
                vtkRenderer ren = panel.GetRenderer();
+               if (ren == null)
+                       return;
+               panel.lock();
                for (vtkProp3D act : actors) {
                        if (act.GetVTKId() != 0) {
                                ren.RemoveActor(act);
                                act.Delete();
                        }
                }
+               panel.unlock();
                actors.clear();
                solid.clear();
                edges.clear();
@@ -197,6 +201,8 @@ public class vtkSolidObject {
                if (actors.size() == 0)
                        return;
                vtkRenderer ren = panel.GetRenderer();
+               if (ren == null)
+                       return;
                panel.lock();
                for (vtkProp3D act : actors) {
                        if (act.GetVTKId() != 0) {
index 3456c4d4580ec15375d1ff0008f9f68520630e0f..6b4948b1e8616a82002e7794af551f7e232b22af 100644 (file)
@@ -8,7 +8,8 @@ Bundle-Vendor: VTT
 Require-Bundle: org.eclipse.core.runtime,
  javax.vecmath;bundle-version="1.5.2",
  org.jcae.opencascade;bundle-version="1.0.0",
- org.simantics.utils.datastructures;bundle-version="1.1.0"
+ org.simantics.utils.datastructures;bundle-version="1.1.0",
+ org.simantics.g3d;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.opencascade
index f0621cb9fdca973eb84bfb790531b91d32a4f674..08e9cba0f19bfd728aa85832da221f18538327ee 100644 (file)
@@ -1,22 +1,19 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.opencascade;\r
-\r
-import java.util.Map;\r
-\r
-public interface ParametricSolidModelProvider extends SolidModelProvider{\r
-       \r
-       public void setProperties(Map<String,Object> props);\r
-       \r
-       public void updateCalculatedProperties(Map<String,Object> returnProps);\r
-\r
-}\r
+/*******************************************************************************
+ * 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.opencascade;
+
+import org.simantics.g3d.scenegraph.ParametricGeometryProvider;
+
+public interface ParametricSolidModelProvider extends SolidModelProvider, ParametricGeometryProvider{
+       
+       
+}
index 69e1d83b6a464c499856319e4100c0f79d40d9dc..5dbef231c3d54111c1e71595896b0144b3c01c4b 100644 (file)
@@ -1,22 +1,23 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.opencascade;\r
-\r
-import java.util.Collection;\r
-\r
-import org.jcae.opencascade.jni.TopoDS_Shape;\r
-\r
-public interface SolidModelProvider {\r
-\r
-       \r
-       public Collection<TopoDS_Shape> getModel()  throws Exception;\r
-}\r
+/*******************************************************************************
+ * 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.opencascade;
+
+import java.util.Collection;
+
+import org.jcae.opencascade.jni.TopoDS_Shape;
+import org.simantics.g3d.scenegraph.GeometryProvider;
+
+public interface SolidModelProvider extends GeometryProvider {
+
+       
+       public Collection<TopoDS_Shape> getModel()  throws Exception;
+}
index 4fc03c1e8240f387e34205bc0d79b98e2e7d436f..ba4cd10cd7d96a53adcfa7f4f841be2003937bf9 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <adapters>
-<target interface="org.simantics.opencascade.SolidModelProvider">
+<target interface="org.simantics.g3d.scenegraph.GeometryProvider">
  <resource uri="http://www.simantics.org/Plant3D-0.1/Builtin/ElbowGeometryProvider"
   class="org.simantics.plant3d.geometry.ElbowGeometryProvider">
   <this />
diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/BuiltinMeshProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/BuiltinMeshProvider.java
new file mode 100644 (file)
index 0000000..ccfb528
--- /dev/null
@@ -0,0 +1,29 @@
+package org.simantics.plant3d.geometry;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.simantics.db.Resource;
+import org.simantics.g3d.scenegraph.ParametricMeshProvider;
+
+public abstract class BuiltinMeshProvider implements ParametricMeshProvider, IAdaptable{
+       
+       private Resource resource;
+       
+       public BuiltinMeshProvider(Resource resource) {
+               this.resource = resource;
+       }
+       
+       @Override
+       public Object getAdapter(Class adapter) {
+               if (Resource.class == adapter)
+                       return resource;
+               return null;
+       }
+       
+       @Override
+       public void updateCalculatedProperties(Map<String, Object> returnProps) {
+               
+       }
+
+}
index 46aea58cded408d0cc172090f5299387bae5cdb0..ead9f0f52292a0e9d00aa5d3e2f0cdfa8403dde7 100644 (file)
@@ -4,12 +4,18 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 
+import javax.vecmath.Point3d;
+import javax.vecmath.Vector3d;
+
 import org.jcae.opencascade.jni.TopoDS_Shape;
 import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.shape.ArcCylinder;
+import org.simantics.g3d.shape.Mesh;
 import org.simantics.opencascade.OccTriangulator;
 
-public class ElbowGeometryProvider extends BuiltinGeometryProvider  {
+//public class ElbowGeometryProvider extends BuiltinGeometryProvider  {
+public class ElbowGeometryProvider extends BuiltinMeshProvider {
        
        public ElbowGeometryProvider(Resource resource) {
                super(resource);
@@ -19,7 +25,7 @@ public class ElbowGeometryProvider extends BuiltinGeometryProvider  {
        private double turnRadius = 0.05;
        private double turnAngle = Math.PI * 0.5;
        
-       @Override
+//     @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
                double t = Math.tan((Math.PI - turnAngle) * 0.5);
                double R = 0.0;
@@ -30,6 +36,18 @@ public class ElbowGeometryProvider extends BuiltinGeometryProvider  {
                return Collections.singletonList(shape);
        }
        
+//     @Override
+       public Mesh getMesh() {
+               double t = Math.tan((Math.PI - turnAngle) * 0.5);
+               double R = 0.0;
+               if (t > MathTools.NEAR_ZERO)
+                       R = turnRadius / t;
+               ArcCylinder cyl = new ArcCylinder();
+               
+               //return cyl.create(new Point3d(-R, 0.0, -turnRadius), new Point3d(0.0,turnRadius,0.0), new Point3d(-R, 0.0, turnRadius), radius, 16, 0.2);
+               return cyl.create(new Point3d(-R, 0.0, -turnRadius), new Vector3d(0.0,1.0,0.0), new Vector3d(0.0,0.0, 1.0),turnRadius, radius, turnAngle,16, 0.2);
+       }
+       
        @Override
        public void setProperties(Map<String, Object> props) {
                if (props.containsKey("turnRadius"))
index ac63f91587d2239aedb5b66251ee148fd3f072a3..df3281eceb92607246837dabc9f0e9e1e99d448d 100644 (file)
@@ -1,15 +1,20 @@
 package org.simantics.plant3d.geometry;
 
-import java.util.Collection;
-import java.util.Collections;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
-import org.jcae.opencascade.jni.TopoDS_Shape;
+import javax.vecmath.Point3d;
+import javax.vecmath.Tuple3d;
+import javax.vecmath.Vector3d;
+
 import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
-import org.simantics.opencascade.OccTriangulator;
+import org.simantics.g3d.shape.Mesh;
+import org.simantics.g3d.shape.Tube;
 
-public class StraightGeometryProvider extends BuiltinGeometryProvider {
+//public class StraightGeometryProvider extends BuiltinGeometryProvider {
+public class StraightGeometryProvider extends BuiltinMeshProvider {
        
        public StraightGeometryProvider(Resource resource) {
                super(resource);
@@ -18,11 +23,33 @@ public class StraightGeometryProvider extends BuiltinGeometryProvider {
        private double length = 1.0;
        private double radius = 0.01;
        
-       @Override
-       public Collection<TopoDS_Shape> getModel() throws Exception {
-               TopoDS_Shape shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
+//     @Override
+//     public Collection<TopoDS_Shape> getModel() throws Exception {
+//             TopoDS_Shape shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
 //             System.out.println("Create straight l:" + length + " r:" + radius);
-               return Collections.singletonList(shape);
+//             return Collections.singletonList(shape);
+//     }
+       
+       @Override
+       public Mesh getMesh() {
+               if (length < .0001)
+                       return null;
+               Tube tube = new Tube();
+               tube.setResolution(16);
+               List<Tuple3d> vertices = new ArrayList<Tuple3d>();
+               List<Double> radius = new ArrayList<Double>();
+               List<Vector3d> tangents = new ArrayList<Vector3d>();
+               vertices.add(new Point3d(-length*0.5, 0.0, 0.0));
+               vertices.add(new Point3d( length*0.5, 0.0, 0.0));
+               radius.add(this.radius);
+               radius.add(this.radius);
+               tangents.add(new Vector3d(1.0,0.0,0.0));
+               tangents.add(new Vector3d(1.0,0.0,0.0));
+               tube.setVertices(vertices);
+               tube.setRadiis(radius);
+               tube.setTangents(tangents);
+               tube.setCap(false);
+               return tube.create();
        }
        
        @Override
diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryComponent.java
new file mode 100644 (file)
index 0000000..a11f912
--- /dev/null
@@ -0,0 +1,297 @@
+package org.simantics.plant3d.scenegraph;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jcae.opencascade.jni.TopoDS_Shape;
+import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.scenegraph.GeometryProvider;
+import org.simantics.g3d.scenegraph.MeshProvider;
+import org.simantics.g3d.scenegraph.NodeHighlighter.HighlightEventType;
+import org.simantics.g3d.scenegraph.ParametricGeometryProvider;
+import org.simantics.g3d.shape.Mesh;
+import org.simantics.g3d.vtk.shape.MeshActor;
+import org.simantics.g3d.vtk.shape.vtkMeshObject;
+import org.simantics.opencascade.OccTriangulator;
+import org.simantics.opencascade.SolidModelProvider;
+import org.simantics.opencascade.vtk.vtkSolidObject;
+
+import vtk.vtkActor;
+import vtk.vtkPanel;
+import vtk.vtkProp3D;
+import vtk.vtkProperty;
+
+public class GeometryComponent {
+       
+       private TopoDS_Shape solidModel;
+       private vtkSolidObject solidObject;
+       private Mesh mesh;
+       private vtkMeshObject meshObject;
+       
+       private Map<String,Object> currentParameters;
+       private Map<String,Object> calculatedParameters;
+       
+       private boolean parametersUpdated = true;
+       
+       private GeometryProvider geometryProvider;
+       
+       public GeometryComponent() {
+               currentParameters = new HashMap<String, Object>();
+               calculatedParameters = new HashMap<String, Object>();
+       }
+       
+       public void visualize(vtkPanel panel) {
+               if (geometryProvider != null) {
+                       updateParameters();
+                       
+                       if (geometryProvider instanceof SolidModelProvider) {
+                               SolidModelProvider solidModelProvider = (SolidModelProvider)geometryProvider;
+                               if (solidModel == null || parametersUpdated) {
+                                       createGeometry(solidModelProvider);     
+                               }
+                               if ((solidObject == null || parametersUpdated) && solidModel != null) {
+                                       solidObject = new vtkSolidObject(panel, solidModel);
+                               }
+                               if (solidObject != null) {
+                                       solidObject.visualizeSolid(true,true, false,false);
+                                       updateVisuals(true, true);
+                               }
+                       } else  if (geometryProvider instanceof MeshProvider) {
+                               MeshProvider provider = (MeshProvider)geometryProvider;
+                               if (mesh == null || parametersUpdated) {
+                                       mesh = provider.getMesh();
+                               }
+                               if ((meshObject== null || parametersUpdated) && mesh != null) {
+                                       meshObject = new vtkMeshObject(panel, mesh);
+                                       
+                               }
+                               if (meshObject != null) {
+                                       meshObject.visualizeMesh();
+                                       updateVisuals(true, true);
+                               }
+                       }
+               }
+               
+               parametersUpdated = false;
+
+       }
+       
+       public void updateParameters() {
+               //if (parametersUpdated && geometryProvider instanceof ParametricGeometryProvider) {
+               if (geometryProvider instanceof ParametricGeometryProvider) {
+                       ((ParametricGeometryProvider)geometryProvider).setProperties(currentParameters);
+                       ((ParametricGeometryProvider)geometryProvider).updateCalculatedProperties(calculatedParameters);
+               }
+       }
+       
+       private void createGeometry(SolidModelProvider solidModelProvider) {
+               Collection<TopoDS_Shape> shapes;
+               try {
+                       shapes = solidModelProvider.getModel();
+                       if (shapes.size() == 1) {
+                               solidModel = shapes.iterator().next();
+                       } else { 
+                               solidModel = OccTriangulator.makeCompound(shapes.toArray(new TopoDS_Shape[shapes.size()]));
+                               for (TopoDS_Shape shape : shapes) {
+                                       shape.delete();
+                               }
+                       }
+//                             shapes.clear();
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+       }
+       
+       public Map<String, Object> getParameterMap() {
+               return Collections.unmodifiableMap(currentParameters);
+       }
+       
+       public Map<String, Object> getCalculatedParameters() {
+               return calculatedParameters;
+       }
+       
+       public void setParametersUpdated(boolean parametersUpdated) {
+               this.parametersUpdated = parametersUpdated;
+       }
+       
+       public Set<String> setParameterMap(Map<String, Object> parameters) {
+               Set<String> ids = new HashSet<String>();
+               for (String id : parameters.keySet()) {
+                       Object currentValue = currentParameters.get(id);
+                       Object newValue = parameters.get(id);
+                       if (currentValue == newValue)
+                               continue;
+                       if (currentValue instanceof Double) {
+                               if (Math.abs((Double)currentValue-(Double)newValue) < MathTools.NEAR_ZERO)
+                                       continue;
+                       }
+                       currentParameters.put(id, newValue);
+                       parametersUpdated = true;
+                       ids.add(id);
+               }
+               return ids;
+       }
+       
+       public GeometryProvider getGeometry() {
+               return geometryProvider;
+       }
+       
+       public void setGeometry(final GeometryProvider provider) {
+               if (provider != null && provider.equals(geometryProvider))
+                       return;
+
+               if (geometryProvider != null) {
+                       deleteData();
+               }
+               geometryProvider = provider;
+       }
+       
+       private void deleteData() {
+               geometryProvider = null;
+               if (solidObject != null) {
+                       solidObject.clearActors();
+                       solidObject = null;
+               }
+               if (solidModel != null) {
+                       solidModel.delete();
+                       solidModel = null;
+               }
+               if (meshObject != null) {
+                       meshObject.clearActors();
+                       meshObject = null;
+               }
+               if (mesh != null)
+                       mesh = null;
+               
+       }
+
+       public Collection<vtkProp3D> getActors() {
+               List<vtkProp3D> list = new ArrayList<vtkProp3D>();
+               if (solidObject != null)
+                       list.addAll(solidObject.getActors());
+               if (meshObject != null && meshObject.getActor() != null)
+                       list.add(meshObject.getActor());
+               return list;
+       }
+       
+       public void stopVisualize() {
+               if (solidObject != null) {
+                       solidObject.clearActorsAWT();
+                       solidObject = null;
+               }
+               if (solidModel != null) {
+                       solidModel.delete();
+                       solidModel = null;
+               }
+               if (meshObject != null) {
+                       meshObject.clearActorsAWT();
+                       meshObject = null;
+               }
+               if (mesh != null)
+                       mesh = null;
+               
+       }
+       
+       private boolean selected = false;
+       private boolean hover = false;
+       
+       public void highlight(HighlightEventType type) {
+               if (type == HighlightEventType.Selection || type == HighlightEventType.ClearSelection) {
+                       selected = type == HighlightEventType.Selection;
+//                     hingeA.visualizeSolid(selected,true,false);
+//                     hingeB.visualizeSolid(selected,true,false);
+                       updateVisuals(true, false);
+//                     update(null);
+               } else {
+                       hover = type == HighlightEventType.Hover;
+                       updateVisuals(false, true);
+               }
+               
+               
+       }
+       
+       protected double[] getSelectedColor() {
+               return new double[]{1,0,0};
+       }
+       
+       protected double[] getColor() {
+               return new double[]{1,1,0};
+       }
+       
+       public void updateVisuals(boolean s, boolean h) {
+               if (solidObject != null) {
+                       if (s) {
+                               double color[];
+                               if (selected) {
+                                       color = getSelectedColor();
+                               
+                               } else {
+                                       color = getColor();
+
+                               }
+                               for (vtkProp3D prop : solidObject.getSolid()) {
+                                       vtkProperty property = ((vtkActor)prop).GetProperty();
+                                       property.SetColor(color);
+                                       property.Delete();
+                               }
+                       }
+                       if (h) {
+                               double color[] = new double[]{0,0,0};
+                               if (hover)
+                                       color = new double[]{1,0,1};
+                               for (vtkProp3D prop : solidObject.getEdges()) {
+                                       vtkProperty property = ((vtkActor)prop).GetProperty();
+                                       property.SetColor(color);
+                                       property.Delete();
+                               }
+                               
+                       }
+               } else if (meshObject != null) {
+                       if (s) {
+                               double color[];
+                               if (selected) {
+                                       color = getSelectedColor();
+                               
+                               } else {
+                                       color = getColor();
+
+                               }
+                               vtkProp3D prop = meshObject.getActor();
+                               if (prop != null) {
+                                       vtkProperty property = ((vtkActor)prop).GetProperty();
+                                       property.SetColor(color);
+                                       property.Delete();
+                               }
+                               
+                       }
+                       if (h) {
+                               double color[] = new double[]{0,0,0};
+                               MeshActor actor = meshObject.getActor();
+                               if (actor != null) {
+                                       vtkProperty property = actor.GetProperty();
+                                       if (hover) {
+                                               color = new double[]{1,0,1};
+                                               property.SetEdgeVisibility(1);
+                                               property.SetEdgeColor(color);
+                                       } else {
+                                               property.SetEdgeVisibility(0);
+                                               property.SetEdgeColor(color);
+                                       }
+                                       property.Delete();
+                               }
+                       }
+               } else {
+//                     if (s) {
+//                             axes.addToRenderer();
+//                             axes.setAxesVisibility(selected);
+//                     }
+               }
+       }
+}
index 8d7ba9d9825045c2eba417b38f23a08f99ef9960..feffaad3eec67a8ff23450d1afee4d5ee43a2fe9 100644 (file)
 package org.simantics.plant3d.scenegraph;
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
-import org.jcae.opencascade.jni.TopoDS_Shape;
-import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.scenegraph.GeometryProvider;
 import org.simantics.g3d.scenegraph.NodeHighlighter;
 import org.simantics.g3d.vtk.utils.vtkUtil;
 import org.simantics.objmap.graph.annotations.RelatedGetObj;
 import org.simantics.objmap.graph.annotations.RelatedSetObj;
-import org.simantics.opencascade.OccTriangulator;
-import org.simantics.opencascade.ParametricSolidModelProvider;
-import org.simantics.opencascade.SolidModelProvider;
-import org.simantics.opencascade.vtk.vtkSolidObject;
 import org.simantics.plant3d.ontology.Plant3D;
 
-import vtk.vtkActor;
 import vtk.vtkPanel;
 import vtk.vtkProp3D;
-import vtk.vtkProperty;
 import vtk.vtkRenderer;
 
 public abstract class GeometryNode extends P3DNode implements ParameterizedNode, NodeHighlighter {
        
-       private TopoDS_Shape solidModel;
-       private vtkSolidObject solidObject;
-       
-       private Map<String,Object> currentParameters;
-       private Map<String,Object> calculatedParameters;
-       
-       private boolean parametersUpdated = true;
-       
+       private GeometryComponent component;
+
        public GeometryNode() {
-               currentParameters = new HashMap<String, Object>();
-               calculatedParameters = new HashMap<String, Object>();
+               component = new GeometryComponent() {
+                       @Override
+                       protected double[] getColor() {
+                               return GeometryNode.this.getColor();
+                       }
+                       
+                       @Override
+                       protected double[] getSelectedColor() {
+                               return GeometryNode.this.getSelectedColor();
+                       }
+               };
        }
        
        @Override
        public void visualize(vtkPanel panel) {
-               if (solidModelProvider != null) {
-                       
-                       updateParameters();
-                       if (solidModel == null || parametersUpdated) {
-                               createGeometry();       
-                       }
-               }
-               if ((solidObject == null || parametersUpdated) && solidModel != null) {
-                       solidObject = new vtkSolidObject(panel, solidModel);
-               }
-               if (solidObject != null) {
-                       solidObject.visualizeSolid(true,true, false,false);
-                       updateVisuals(true, true);
-               }
-               parametersUpdated = false;
-
+               updateParameters();
+               component.visualize(panel);
        }
        
        public void updateParameters() {
-               if (solidModelProvider instanceof ParametricSolidModelProvider) {
-                       ((ParametricSolidModelProvider)solidModelProvider).setProperties(currentParameters);
-                       ((ParametricSolidModelProvider)solidModelProvider).updateCalculatedProperties(calculatedParameters);
-               }
-       }
-       
-       private void createGeometry() {
-               Collection<TopoDS_Shape> shapes;
-               try {
-                       shapes = solidModelProvider.getModel();
-                       if (shapes.size() == 1) {
-                               solidModel = shapes.iterator().next();
-                       } else { 
-                               solidModel = OccTriangulator.makeCompound(shapes.toArray(new TopoDS_Shape[shapes.size()]));
-                               for (TopoDS_Shape shape : shapes) {
-                                       shape.delete();
-                               }
-                       }
-//                             shapes.clear();
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
+               component.updateParameters();
        }
        
+
        public Map<String, Object> getParameterMap() {
-               return Collections.unmodifiableMap(currentParameters);
+               return component.getParameterMap();
        }
        
        public Map<String, Object> getCalculatedParameters() {
-               return calculatedParameters;
+               return component.getCalculatedParameters();
        }
        
        public void setParametersUpdated(boolean parametersUpdated) {
-               this.parametersUpdated = parametersUpdated;
+               component.setParametersUpdated(parametersUpdated);
        }
        
        public void setParameterMap(Map<String, Object> parameters) {
-               for (String id : parameters.keySet()) {
-                       Object currentValue = currentParameters.get(id);
-                       Object newValue = parameters.get(id);
-                       if (currentValue == newValue)
-                               continue;
-                       if (currentValue instanceof Double) {
-                               if (Math.abs((Double)currentValue-(Double)newValue) < MathTools.NEAR_ZERO)
-                                       continue;
-                       }
-                       currentParameters.put(id, newValue);
-                       parametersUpdated = true;
+               Set<String> ids = component.setParameterMap(parameters);
+               for (String id : ids) {
                        firePropertyChanged(id);
                }
        }
        
-       private SolidModelProvider solidModelProvider;
-       
        @RelatedGetObj(Plant3D.URIs.hasGeometry)
-       public SolidModelProvider getGeometry() {
-               return solidModelProvider;
+       public GeometryProvider getGeometry() {
+               return component.getGeometry();
        }
        
        @RelatedSetObj(Plant3D.URIs.hasGeometry)
-       public void setGeometry(final SolidModelProvider provider) {
-               if (provider != null && provider.equals(solidModelProvider))
+       public void setGeometry(final GeometryProvider provider) {
+               if (provider != null && provider.equals(component.getGeometry()))
                        return;
-
-               if (solidModelProvider != null) {
-                       deleteData();
-               }
-               solidModelProvider = provider;
+               component.setGeometry(provider);
                firePropertyChanged(Plant3D.URIs.hasGeometry);
        }
-       
-       private void deleteData() {
-               solidModelProvider = null;
-               if (solidObject != null) {
-                       solidObject.clearActors();
-                       solidObject = null;
-               }
-               if (solidModel != null) {
-                       solidModel.delete();
-                       solidModel = null;
-               }
-       }
-       
+
        @Override
        public Collection<vtkProp3D> getActors() {
-               List<vtkProp3D> list = new ArrayList<vtkProp3D>();
-               if (solidObject != null)
-                       list.addAll(solidObject.getActors());
-               return list;
+               return component.getActors();
        }
        
        @Override
        public void stopVisualize() {
-               if (solidObject != null) {
-                       solidObject.clearActorsAWT();
-                       solidObject = null;
-               }
-               if (solidModel != null) {
-                       solidModel.delete();
-                       solidModel = null;
-               }
-               
+               component.stopVisualize();
        }
        
-       private boolean selected = false;
-       private boolean hover = false;
-       
        @Override
        public void highlight(HighlightEventType type) {
-               if (type == HighlightEventType.Selection || type == HighlightEventType.ClearSelection) {
-                       selected = type == HighlightEventType.Selection;
-//                     hingeA.visualizeSolid(selected,true,false);
-//                     hingeB.visualizeSolid(selected,true,false);
-                       updateVisuals(true, false);
-//                     update(null);
-               } else {
-                       hover = type == HighlightEventType.Hover;
-                       updateVisuals(false, true);
-               }
-               
+               component.highlight(type);
                
        }
        
@@ -193,47 +100,8 @@ public abstract class GeometryNode extends P3DNode implements ParameterizedNode,
                return new double[]{1,1,0};
        }
        
-       private void updateVisuals(boolean s, boolean h) {
-               if (solidObject != null) {
-                       if (s) {
-                               double color[];
-                               if (selected) {
-                                       color = getSelectedColor();
-                               
-                               } else {
-                                       color = getColor();
-
-                               }
-                               for (vtkProp3D prop : solidObject.getSolid()) {
-                                       vtkProperty property = ((vtkActor)prop).GetProperty();
-                                       property.SetColor(color);
-                                       property.Delete();
-                               }
-                       }
-                       if (h) {
-                               double color[] = new double[]{0,0,0};
-                               if (hover)
-                                       color = new double[]{1,0,1};
-                               for (vtkProp3D prop : solidObject.getEdges()) {
-                                       vtkProperty property = ((vtkActor)prop).GetProperty();
-                                       property.SetColor(color);
-                                       property.Delete();
-                               }
-                               
-                       }
-               } else {
-//                     if (s) {
-//                             axes.addToRenderer();
-//                             axes.setAxesVisibility(selected);
-//                     }
-               }
-       }
-       
        public void update(vtkRenderer ren) {
                vtkUtil.updateTransform(getActors(), getWorldPosition(), getWorldOrientation());
        }
-       
-       public TopoDS_Shape getSolidModel() {
-               return solidModel;
-       }
+
 }
index c74920085aafa877f871cb314c5ef8da4cc9fdd4..26d65c7a1270e53bbc61928e8b7ac18f56529660 100644 (file)
 package org.simantics.plant3d.scenegraph;
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
-import org.jcae.opencascade.jni.TopoDS_Shape;
-import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.scenegraph.GeometryProvider;
 import org.simantics.g3d.scenegraph.NodeHighlighter;
 import org.simantics.g3d.vtk.utils.vtkUtil;
 import org.simantics.objmap.graph.annotations.RelatedGetObj;
 import org.simantics.objmap.graph.annotations.RelatedSetObj;
-import org.simantics.opencascade.OccTriangulator;
-import org.simantics.opencascade.ParametricSolidModelProvider;
-import org.simantics.opencascade.SolidModelProvider;
-import org.simantics.opencascade.vtk.vtkSolidObject;
 import org.simantics.plant3d.ontology.Plant3D;
 
-import vtk.vtkActor;
 import vtk.vtkPanel;
 import vtk.vtkProp3D;
-import vtk.vtkProperty;
 import vtk.vtkRenderer;
 
 public class P3DParentGeometryNode<T extends IP3DNode> extends P3DParentNode<T> implements ParameterizedNode, NodeHighlighter{
-       private TopoDS_Shape solidModel;
-       private vtkSolidObject solidObject;
-       
-       private Map<String,Object> currentParameters;
-       private Map<String,Object> calculatedParameters;
-       
-       private boolean parametersUpdated = true;
+
+       private GeometryComponent component;
        
        
        public P3DParentGeometryNode() {
-               currentParameters = new HashMap<String, Object>();
-               calculatedParameters = new HashMap<String, Object>();
+               component = new GeometryComponent() {
+                       @Override
+                       protected double[] getColor() {
+                               return P3DParentGeometryNode.this.getColor();
+                       }
+                       
+                       @Override
+                       protected double[] getSelectedColor() {
+                               return P3DParentGeometryNode.this.getSelectedColor();
+                       }
+               };
        }
        
        @Override
        public void visualize(vtkPanel ren) {
-               if (solidModelProvider != null) {
-                       
-                       updateParameters();
-                       
-                       if (solidModel == null || parametersUpdated) {
-                               createGeometry();       
-                       }
-               }
-               if ((solidObject == null || parametersUpdated) && solidModel != null) {
-                       solidObject = new vtkSolidObject(ren, solidModel);
-               }
-               if (solidObject != null) {
-                       solidObject.visualizeSolid(true,true, false,false);
-                       updateVisuals(true, true);
-               }
-               parametersUpdated = false;
-
+               updateParameters();
+               component.visualize(ren);
        }
        
        public void updateParameters() {
-               if (solidModelProvider instanceof ParametricSolidModelProvider) {
-                       ((ParametricSolidModelProvider)solidModelProvider).setProperties(currentParameters);
-                       ((ParametricSolidModelProvider)solidModelProvider).updateCalculatedProperties(calculatedParameters);
-               }
+               component.updateParameters();
        }
-       
-       private void createGeometry() {
-               Collection<TopoDS_Shape> shapes;
-               try {
-                       shapes = solidModelProvider.getModel();
-                       if (shapes.size() == 1) {
-                               solidModel = shapes.iterator().next();
-                       } else { 
-                               solidModel = OccTriangulator.makeCompound(shapes.toArray(new TopoDS_Shape[shapes.size()]));
-                               for (TopoDS_Shape shape : shapes) {
-                                       shape.delete();
-                               }
-                       }
-//                             shapes.clear();
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
+
+       public Map<String, Object> getParameterMap() {
+               return component.getParameterMap();
        }
        
-       
-       
-       public Map<String, Object> getParameterMap() {
-               return Collections.unmodifiableMap(currentParameters);
+       public Map<String, Object> getCalculatedParameters() {
+               return component.getCalculatedParameters();
        }
        
        public void setParameterMap(Map<String, Object> parameters) {
-               for (String id : parameters.keySet()) {
-                       Object currentValue = currentParameters.get(id);
-                       Object newValue = parameters.get(id);
-                       if (currentValue == newValue)
-                               continue;
-                       if (currentValue instanceof Double) {
-                               if (Math.abs((Double)currentValue-(Double)newValue) < MathTools.NEAR_ZERO)
-                                       continue;
-                       }
-                       currentParameters.put(id, newValue);
-                       parametersUpdated = true;
+               Set<String> ids = component.setParameterMap(parameters);
+               for (String id : ids) {
                        firePropertyChanged(id);
                }
        }
-       
-       
-       private SolidModelProvider solidModelProvider;
+
        
        @RelatedGetObj(Plant3D.URIs.hasGeometry)
-       public SolidModelProvider getGeometry() {
-               return solidModelProvider;
+       public GeometryProvider getGeometry() {
+               //return geometryProvider;
+               return component.getGeometry();
        }
        
        @RelatedSetObj(Plant3D.URIs.hasGeometry)
-       public void setGeometry(final SolidModelProvider provider) {
-               if (provider != null && provider.equals(solidModelProvider))
+       public void setGeometry(final GeometryProvider provider) {
+               if (provider != null && provider.equals(component.getGeometry()))
                        return;
-
-               if (solidModelProvider != null) {
-                       deleteData();
-               }
-               solidModelProvider = provider;
+               component.setGeometry(provider);
                firePropertyChanged(Plant3D.URIs.hasGeometry);
        }
        
-       private void deleteData() {
-               solidModelProvider = null;
-               if (solidObject != null) {
-                       solidObject.clearActors();
-                       solidObject = null;
-               }
-               if (solidModel != null) {
-                       solidModel.delete();
-                       solidModel = null;
-               }
-       }
        
        @Override
        public Collection<vtkProp3D> getActors() {
-               List<vtkProp3D> list = new ArrayList<vtkProp3D>();
-               if (solidObject != null)
-                       list.addAll(solidObject.getActors());
-               return list;
+               return component.getActors();
        }
        
        @Override
        public void stopVisualize() {
-               if (solidObject != null) {
-                       solidObject.clearActorsAWT();
-                       solidObject = null;
-               }
-               if (solidModel != null) {
-                       solidModel.delete();
-                       solidModel = null;
-               }
-               
+               component.stopVisualize();
        }
-       
-       private boolean selected = false;
-       private boolean hover = false;
-       
+
        @Override
        public void highlight(HighlightEventType type) {
-               if (type == HighlightEventType.Selection || type == HighlightEventType.ClearSelection) {
-                       selected = type == HighlightEventType.Selection;
-//                     hingeA.visualizeSolid(selected,true,false);
-//                     hingeB.visualizeSolid(selected,true,false);
-                       updateVisuals(true, false);
-//                     update(null);
-               } else {
-                       hover = type == HighlightEventType.Hover;
-                       updateVisuals(false, true);
-               }
-               
-               
+               component.highlight(type);
        }
        
        protected double[] getSelectedColor() {
@@ -189,47 +98,10 @@ public class P3DParentGeometryNode<T extends IP3DNode> extends P3DParentNode<T>
                return new double[]{1,1,0};
        }
        
-       private void updateVisuals(boolean s, boolean h) {
-               if (solidObject != null) {
-                       if (s) {
-                               double color[];
-                               if (selected) {
-                                       color = getSelectedColor();
-                               
-                               } else {
-                                       color = getColor();
 
-                               }
-                               for (vtkProp3D prop : solidObject.getSolid()) {
-                                       vtkProperty property = ((vtkActor)prop).GetProperty();
-                                       property.SetColor(color);
-                                       property.Delete();
-                               }
-                       }
-                       if (h) {
-                               double color[] = new double[]{0,0,0};
-                               if (hover)
-                                       color = new double[]{1,0,1};
-                               for (vtkProp3D prop : solidObject.getEdges()) {
-                                       vtkProperty property = ((vtkActor)prop).GetProperty();
-                                       property.SetColor(color);
-                                       property.Delete();
-                               }
-                               
-                       }
-               } else {
-//                     if (s) {
-//                             axes.addToRenderer();
-//                             axes.setAxesVisibility(selected);
-//                     }
-               }
-       }
        
        public void update(vtkRenderer ren) {
                vtkUtil.updateTransform(getActors(), getWorldPosition(), getWorldOrientation());
        }
-       
-       public TopoDS_Shape getSolidModel() {
-               return solidModel;
-       }
+
 }
index 8fe597cad4f760a58dcf82636a594a8c88eb44ae..03caa9815dfcf08dcc16394332b89d13719b0a70 100644 (file)
@@ -54,7 +54,7 @@ public abstract class PipelineComponent extends GeometryNode {
        }
        
        @RelatedGetObj(Plant3D.URIs.HasAlternativePipeRun)
-       public PipeRun getAlternaitvePipeRun() {
+       public PipeRun getAlternativePipeRun() {
                return alternativePipeRun;
        }
        
index 761e1707da40e865be635af5b22ee23ed0c13324..dd28e585def9ae2ea079e59dc87db51446d85956 100644 (file)
@@ -5,10 +5,10 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Read;
+import org.simantics.g3d.scenegraph.GeometryProvider;
 import org.simantics.objmap.graph.schema.IMappingSchema;
 import org.simantics.objmap.graph.schema.MappingSchemas;
 import org.simantics.objmap.graph.schema.SimpleSchema;
-import org.simantics.opencascade.SolidModelProvider;
 import org.simantics.plant3d.ontology.Plant3D;
 
 public class SchemaBuilder {
@@ -33,7 +33,7 @@ public class SchemaBuilder {
                        schema.addLinkType(MappingSchemas.fromAnnotations(g, P3DRootNode.class));
                        schema.addLinkType(MappingSchemas.fromAnnotations(g, PipeRun.class));
                        
-                       schema.addLinkType(MappingSchemas.fromAdaptable(g, Plant3D.URIs.Builtin_GeometryProvider, SolidModelProvider.class));
+                       schema.addLinkType(MappingSchemas.fromAdaptable(g, Plant3D.URIs.Builtin_GeometryProvider, GeometryProvider.class));
                        return schema;
                } catch (IllegalAccessException e) {
                        throw new DatabaseException(e);
index af64f180b5d1fde1fb14a70cd02f76ccce91f8b0..b08c04cb41a2b4cace86fd1b683e29b705a4fa7f 100644 (file)
@@ -10,8 +10,8 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.g3d.scenegraph.GeometryProvider;
 import org.simantics.layer0.Layer0;
-import org.simantics.opencascade.SolidModelProvider;
 import org.simantics.plant3d.ontology.Plant3D;
 import org.simantics.plant3d.scenegraph.EndComponent;
 import org.simantics.plant3d.scenegraph.InlineComponent;
@@ -24,7 +24,7 @@ public class ComponentUtils {
 
        
        private static Map<String,Class<? extends PipelineComponent>> clazzes = new HashMap<String, Class<? extends PipelineComponent>>();
-       private static Map<String,SolidModelProvider> providers = new HashMap<String,SolidModelProvider>();
+       private static Map<String,GeometryProvider> providers = new HashMap<String,GeometryProvider>();
        
        public static void preloadCache() {
                Simantics.getSession().asyncRequest(new ReadRequest() {
@@ -45,7 +45,7 @@ public class ComponentUtils {
                });
        }
        
-       private static SolidModelProvider getProvider(ReadGraph graph, Resource type) throws DatabaseException {
+       private static GeometryProvider getProvider(ReadGraph graph, Resource type) throws DatabaseException {
                
                Layer0 l0 = Layer0.getInstance(graph);
                Plant3D p3d = Plant3D.getInstance(graph);
@@ -59,7 +59,7 @@ public class ComponentUtils {
                        }
                }
                if (geom != null) {
-                       SolidModelProvider provider = graph.adapt(geom, SolidModelProvider.class);
+                       GeometryProvider provider = graph.adapt(geom, GeometryProvider.class);
                        return provider;
                }
                return null;
@@ -82,7 +82,7 @@ public class ComponentUtils {
                Plant3D p3d = Plant3D.getInstance(graph);
                Resource type = graph.getResource(typeURI);
                
-               SolidModelProvider provider = getProvider(graph, type);
+               GeometryProvider provider = getProvider(graph, type);
                if (provider != null || graph.hasStatement(type,p3d.NonVisibleComponent)) {
                        providers.put(typeURI, provider);
                        ComponentUtils.clazzes.put(typeURI,getClazz(graph, type));
@@ -103,7 +103,7 @@ public class ComponentUtils {
        
        public static PipelineComponent createComponent(P3DRootNode root, String typeURI) throws Exception {
                Class<? extends PipelineComponent> type = clazzes.get(typeURI);
-               SolidModelProvider provider = providers.get(typeURI);
+               GeometryProvider provider = providers.get(typeURI);
                if (type == null || provider == null) {
                        load(typeURI);
                        type = clazzes.get(typeURI);