From 6308b57b2793abbd92da9e004f9f7c068f18eba6 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 6 Aug 2019 12:46:44 +0300 Subject: [PATCH] Include CSG modelling with Plant3D gitlab #20 Change-Id: I2e2da1579d4982abfe08c9548f9f335ba3353110 --- org.simantics.g3d.csg/META-INF/MANIFEST.MF | 2 + .../g3d/csg/handler/NewCSGModelHandler.java | 40 +++++++++++++++++++ .../simantics/g3d/csg/model/ModelUtil.java | 19 +++++++++ .../feature.xml | 14 +++++++ .../graph/plant3d_viewpoint.pgraph | 1 + org.simantics.plant3d/META-INF/MANIFEST.MF | 3 +- org.simantics.plant3d/plugin.xml | 16 +++++++- 7 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 org.simantics.g3d.csg/src/org/simantics/g3d/csg/handler/NewCSGModelHandler.java create mode 100644 org.simantics.g3d.csg/src/org/simantics/g3d/csg/model/ModelUtil.java diff --git a/org.simantics.g3d.csg/META-INF/MANIFEST.MF b/org.simantics.g3d.csg/META-INF/MANIFEST.MF index a0a1c81b..c2c209c9 100644 --- a/org.simantics.g3d.csg/META-INF/MANIFEST.MF +++ b/org.simantics.g3d.csg/META-INF/MANIFEST.MF @@ -24,3 +24,5 @@ Require-Bundle: org.eclipse.core.runtime, org.simantics.opencascade.vtk;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy +Export-Package: org.simantics.g3d.csg.handler, + org.simantics.g3d.csg.model diff --git a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/handler/NewCSGModelHandler.java b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/handler/NewCSGModelHandler.java new file mode 100644 index 00000000..668f7bfc --- /dev/null +++ b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/handler/NewCSGModelHandler.java @@ -0,0 +1,40 @@ +package org.simantics.g3d.csg.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.g3d.csg.model.ModelUtil; +import org.simantics.layer0.Layer0; + +public class NewCSGModelHandler extends AbstractHandler { + + private final String defaultName = "CSG Model"; + + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + final Resource library = Simantics.getProject().get(); + + Simantics.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + + String name = NameUtils.findFreshName(graph, defaultName, library, l0.ConsistsOf, "%s%d"); + + Resource model = ModelUtil.createCSGModel(graph, name); + graph.claim(library, l0.ConsistsOf, model); + + } + }); + return null; + } + +} \ No newline at end of file diff --git a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/model/ModelUtil.java b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/model/ModelUtil.java new file mode 100644 index 00000000..743ca8e6 --- /dev/null +++ b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/model/ModelUtil.java @@ -0,0 +1,19 @@ +package org.simantics.g3d.csg.model; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.g3d.csg.ontology.CSG; +import org.simantics.layer0.Layer0; + +public class ModelUtil { + + public static Resource createCSGModel(WriteGraph graph, String name) throws DatabaseException{ + Layer0 l0 = Layer0.getInstance(graph); + CSG csg = CSG.getInstance(graph); + Resource model = graph.newResource(); + graph.claim(model, l0.InstanceOf, csg.Model); + graph.claimLiteral(model, l0.HasName, name); + return model; + } +} diff --git a/org.simantics.plant3d.modeling.feature/feature.xml b/org.simantics.plant3d.modeling.feature/feature.xml index e307342b..96f2034f 100644 --- a/org.simantics.plant3d.modeling.feature/feature.xml +++ b/org.simantics.plant3d.modeling.feature/feature.xml @@ -55,4 +55,18 @@ version="0.0.0" unpack="false"/> + + + + diff --git a/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph b/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph index c2d02ada..bb06785b 100644 --- a/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph +++ b/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph @@ -20,6 +20,7 @@ PBC = P3D.P3DBrowseContext : VP.BrowseContext @VP.constantImageRule P3D.EndComponent IMAGES.Component @VP.constantImageRule P3D.PipeRun IMAGES.Straight @VP.relationChildRule PROJ.Project L0.ConsistsOf P3D.Plant + @VP.relationChildRule PROJ.Project L0.ConsistsOf CSG.Model @VP.relationChildRule P3D.Node P3D.childen P3D.Node @VP.relationChildRule P3D.Node P3D.HasNozzle P3D.Node diff --git a/org.simantics.plant3d/META-INF/MANIFEST.MF b/org.simantics.plant3d/META-INF/MANIFEST.MF index 6f2e691d..2b216e01 100644 --- a/org.simantics.plant3d/META-INF/MANIFEST.MF +++ b/org.simantics.plant3d/META-INF/MANIFEST.MF @@ -31,7 +31,8 @@ Require-Bundle: org.eclipse.core.runtime, org.simantics.ui;bundle-version="1.0.0", org.simantics.opencascade.vtk;bundle-version="1.0.0", org.simantics.browsing.ui.platform;bundle-version="1.1.0", - org.simantics.structural.ui;bundle-version="1.1.1" + org.simantics.structural.ui;bundle-version="1.1.1", + org.simantics.g3d.csg;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.simantics.plant3d.editor, diff --git a/org.simantics.plant3d/plugin.xml b/org.simantics.plant3d/plugin.xml index e256683a..29f03e32 100644 --- a/org.simantics.plant3d/plugin.xml +++ b/org.simantics.plant3d/plugin.xml @@ -93,6 +93,11 @@ label="New Plant" style="push"> + + + + @@ -218,6 +228,10 @@ + + -- 2.45.2