From 86739231beb0535bde4abae49d2011e3a042810b Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 15 Jul 2019 16:28:38 +0300 Subject: [PATCH] Created Mesh API for Plant3D objects * Replaced OCCT-based geometries for Straight and Elbow. * MeshActor is able to bypass mesh normals to VTK gitlab #10 Change-Id: Ib201d29802921df35a5fa88da922e8265b54df7c --- .../simantics/g3d/vtk/shape/MeshActor.java | 31 +- .../g3d/vtk/shape/vtkMeshObject.java | 111 +++++++ .../g3d/scenegraph/GeometryProvider.java | 5 + .../g3d/scenegraph/MeshProvider.java | 7 + .../ParametricGeometryProvider.java | 18 ++ .../scenegraph/ParametricMeshProvider.java | 5 + .../org/simantics/g3d/shape/ArcCylinder.java | 50 +++ .../opencascade/vtk/vtkSolidObject.java | 6 + .../META-INF/MANIFEST.MF | 3 +- .../ParametricSolidModelProvider.java | 41 ++- .../opencascade/SolidModelProvider.java | 45 +-- org.simantics.plant3d/adapters.xml | 2 +- .../plant3d/geometry/BuiltinMeshProvider.java | 29 ++ .../geometry/ElbowGeometryProvider.java | 22 +- .../geometry/StraightGeometryProvider.java | 45 ++- .../plant3d/scenegraph/GeometryComponent.java | 297 ++++++++++++++++++ .../plant3d/scenegraph/GeometryNode.java | 200 ++---------- .../scenegraph/P3DParentGeometryNode.java | 202 +++--------- .../plant3d/scenegraph/PipelineComponent.java | 2 +- .../plant3d/scenegraph/SchemaBuilder.java | 4 +- .../plant3d/utils/ComponentUtils.java | 12 +- 21 files changed, 735 insertions(+), 402 deletions(-) create mode 100644 org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/vtkMeshObject.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/scenegraph/GeometryProvider.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/scenegraph/MeshProvider.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricGeometryProvider.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricMeshProvider.java create mode 100644 org.simantics.plant3d/src/org/simantics/plant3d/geometry/BuiltinMeshProvider.java create mode 100644 org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryComponent.java diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/MeshActor.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/MeshActor.java index b290f861..c52e021e 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/MeshActor.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/MeshActor.java @@ -12,14 +12,14 @@ 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 index 00000000..0e60a270 --- /dev/null +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/vtkMeshObject.java @@ -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 index 00000000..95c5f8a8 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/GeometryProvider.java @@ -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 index 00000000..6c258d4f --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/MeshProvider.java @@ -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 index 00000000..25951b81 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricGeometryProvider.java @@ -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 props); + + /** + * Returns calculated parameters from geometry calculation + * @param returnProps + */ + public void updateCalculatedProperties(Map 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 index 00000000..e97ab7c6 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/ParametricMeshProvider.java @@ -0,0 +1,5 @@ +package org.simantics.g3d.scenegraph; + +public interface ParametricMeshProvider extends MeshProvider, ParametricGeometryProvider{ + +} diff --git a/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java b/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java index 348fd852..6e4a3d3b 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java +++ b/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java @@ -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 vertices = new ArrayList(res * (steps+1)); + List normals = new ArrayList(res * (steps+1)); + List indices = new ArrayList(); + + 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 points, List normals, Tuple3d p, Vector3d t, Vector3d n, int res, double radius) { n = new Vector3d(n); n.scale(radius); diff --git a/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java b/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java index fd2c0bb1..f2501e95 100644 --- a/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java +++ b/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java @@ -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) { diff --git a/org.simantics.opencascade/META-INF/MANIFEST.MF b/org.simantics.opencascade/META-INF/MANIFEST.MF index 3456c4d4..6b4948b1 100644 --- a/org.simantics.opencascade/META-INF/MANIFEST.MF +++ b/org.simantics.opencascade/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.opencascade/src/org/simantics/opencascade/ParametricSolidModelProvider.java b/org.simantics.opencascade/src/org/simantics/opencascade/ParametricSolidModelProvider.java index f0621cb9..08e9cba0 100644 --- a/org.simantics.opencascade/src/org/simantics/opencascade/ParametricSolidModelProvider.java +++ b/org.simantics.opencascade/src/org/simantics/opencascade/ParametricSolidModelProvider.java @@ -1,22 +1,19 @@ -/******************************************************************************* - * 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.Map; - -public interface ParametricSolidModelProvider extends SolidModelProvider{ - - public void setProperties(Map props); - - public void updateCalculatedProperties(Map returnProps); - -} +/******************************************************************************* + * 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{ + + +} diff --git a/org.simantics.opencascade/src/org/simantics/opencascade/SolidModelProvider.java b/org.simantics.opencascade/src/org/simantics/opencascade/SolidModelProvider.java index 69e1d83b..5dbef231 100644 --- a/org.simantics.opencascade/src/org/simantics/opencascade/SolidModelProvider.java +++ b/org.simantics.opencascade/src/org/simantics/opencascade/SolidModelProvider.java @@ -1,22 +1,23 @@ -/******************************************************************************* - * 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; - -public interface SolidModelProvider { - - - public Collection getModel() throws Exception; -} +/******************************************************************************* + * 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 getModel() throws Exception; +} diff --git a/org.simantics.plant3d/adapters.xml b/org.simantics.plant3d/adapters.xml index 4fc03c1e..ba4cd10c 100644 --- a/org.simantics.plant3d/adapters.xml +++ b/org.simantics.plant3d/adapters.xml @@ -1,6 +1,6 @@ - + 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 index 00000000..ccfb5281 --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/BuiltinMeshProvider.java @@ -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 returnProps) { + + } + +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java index 46aea58c..ead9f0f5 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java @@ -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 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 props) { if (props.containsKey("turnRadius")) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java index ac63f915..df3281ec 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java @@ -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 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 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 vertices = new ArrayList(); + List radius = new ArrayList(); + List tangents = new ArrayList(); + 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 index 00000000..a11f912d --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryComponent.java @@ -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 currentParameters; + private Map calculatedParameters; + + private boolean parametersUpdated = true; + + private GeometryProvider geometryProvider; + + public GeometryComponent() { + currentParameters = new HashMap(); + calculatedParameters = new HashMap(); + } + + 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 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 getParameterMap() { + return Collections.unmodifiableMap(currentParameters); + } + + public Map getCalculatedParameters() { + return calculatedParameters; + } + + public void setParametersUpdated(boolean parametersUpdated) { + this.parametersUpdated = parametersUpdated; + } + + public Set setParameterMap(Map parameters) { + Set ids = new HashSet(); + 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 getActors() { + List list = new ArrayList(); + 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); +// } + } + } +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryNode.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryNode.java index 8d7ba9d9..feffaad3 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryNode.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryNode.java @@ -1,187 +1,94 @@ 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 currentParameters; - private Map calculatedParameters; - - private boolean parametersUpdated = true; - + private GeometryComponent component; + public GeometryNode() { - currentParameters = new HashMap(); - calculatedParameters = new HashMap(); + 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 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 getParameterMap() { - return Collections.unmodifiableMap(currentParameters); + return component.getParameterMap(); } public Map getCalculatedParameters() { - return calculatedParameters; + return component.getCalculatedParameters(); } public void setParametersUpdated(boolean parametersUpdated) { - this.parametersUpdated = parametersUpdated; + component.setParametersUpdated(parametersUpdated); } public void setParameterMap(Map 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 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 getActors() { - List list = new ArrayList(); - 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; - } + } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DParentGeometryNode.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DParentGeometryNode.java index c7492008..26d65c7a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DParentGeometryNode.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DParentGeometryNode.java @@ -1,184 +1,93 @@ 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 extends P3DParentNode implements ParameterizedNode, NodeHighlighter{ - private TopoDS_Shape solidModel; - private vtkSolidObject solidObject; - - private Map currentParameters; - private Map calculatedParameters; - - private boolean parametersUpdated = true; + + private GeometryComponent component; public P3DParentGeometryNode() { - currentParameters = new HashMap(); - calculatedParameters = new HashMap(); + 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 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 getParameterMap() { + return component.getParameterMap(); } - - - public Map getParameterMap() { - return Collections.unmodifiableMap(currentParameters); + public Map getCalculatedParameters() { + return component.getCalculatedParameters(); } public void setParameterMap(Map 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 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 getActors() { - List list = new ArrayList(); - 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 extends P3DParentNode 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; - } + } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java index 8fe597ca..03caa981 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java @@ -54,7 +54,7 @@ public abstract class PipelineComponent extends GeometryNode { } @RelatedGetObj(Plant3D.URIs.HasAlternativePipeRun) - public PipeRun getAlternaitvePipeRun() { + public PipeRun getAlternativePipeRun() { return alternativePipeRun; } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java index 761e1707..dd28e585 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/SchemaBuilder.java @@ -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); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index af64f180..b08c04cb 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -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> clazzes = new HashMap>(); - private static Map providers = new HashMap(); + private static Map providers = new HashMap(); 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 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); -- 2.47.1