]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d.csg/src/org/simantics/g3d/csg/handler/NewCSGModelHandler.java
Include CSG modelling with Plant3D
[simantics/3d.git] / org.simantics.g3d.csg / src / org / simantics / g3d / csg / handler / NewCSGModelHandler.java
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 (file)
index 0000000..668f7bf
--- /dev/null
@@ -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