1 package org.simantics.g3d.csg.handler;
3 import org.eclipse.core.commands.AbstractHandler;
4 import org.eclipse.core.commands.ExecutionEvent;
5 import org.eclipse.core.commands.ExecutionException;
6 import org.simantics.Simantics;
7 import org.simantics.db.Resource;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.common.request.WriteRequest;
10 import org.simantics.db.common.utils.NameUtils;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.g3d.csg.model.ModelUtil;
13 import org.simantics.layer0.Layer0;
15 public class NewCSGModelHandler extends AbstractHandler {
17 private final String defaultName = "CSG Model";
21 public Object execute(ExecutionEvent event) throws ExecutionException {
22 final Resource library = Simantics.getProject().get();
24 Simantics.getSession().asyncRequest(new WriteRequest() {
27 public void perform(WriteGraph graph) throws DatabaseException {
28 Layer0 l0 = Layer0.getInstance(graph);
30 String name = NameUtils.findFreshName(graph, defaultName, library, l0.ConsistsOf, "%s%d");
32 Resource model = ModelUtil.createCSGModel(graph, name);
33 graph.claim(library, l0.ConsistsOf, model);