X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Fhandler%2FNewCSGModelHandler.java;fp=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Fhandler%2FNewCSGModelHandler.java;h=668f7bfc61024e06d11fba913d60b962baec5806;hb=6308b57b2793abbd92da9e004f9f7c068f18eba6;hp=0000000000000000000000000000000000000000;hpb=0fb61ee28592dc5df41a4c7aae9913044313ee21;p=simantics%2F3d.git 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