X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Factions%2FAddBooleanOpAction2.java;h=be196042ff02c589bb53ddcc457d6cb8cbbfa576;hb=62fb6eb651ae640336d71746d7bfa79bcfa211df;hp=e4d824920f0094206078302261f1951de06e1729;hpb=289aaab900078ef56efc8779e4b15830e472149e;p=simantics%2F3d.git diff --git a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/actions/AddBooleanOpAction2.java b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/actions/AddBooleanOpAction2.java index e4d82492..be196042 100644 --- a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/actions/AddBooleanOpAction2.java +++ b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/actions/AddBooleanOpAction2.java @@ -1,80 +1,80 @@ -/******************************************************************************* - * 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.g3d.csg.actions; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.vecmath.Quat4d; -import javax.vecmath.Vector3d; - -import org.eclipse.jface.action.Action; -import org.simantics.g3d.csg.scenegraph2.CSGparentNode; -import org.simantics.g3d.csg.scenegraph2.CSGrootNode; -import org.simantics.g3d.csg.scenegraph2.ICSGnode; -import org.simantics.utils.ui.ExceptionUtils; - -public class AddBooleanOpAction2 extends Action { - CSGrootNode root; - Class booleanClass; - Collection nodes; - - public AddBooleanOpAction2(CSGrootNode root, Class booleanClass, Collection nodes) { - super(); - String name = booleanClass.getSimpleName(); - if (name.endsWith("Node")) - name = name.substring(0,name.length()-4); - setText(name); - this.booleanClass = booleanClass; - this.nodes = nodes; - this.root = root; - if (nodes.size() != 2) - setEnabled(false); - for (ICSGnode node : nodes) { - if (!node.getParent().equals(root)) - setEnabled(false); - } - } - - @Override - public void run() { - try { - CSGparentNode booleanNode = booleanClass.newInstance(); - Map positions = new HashMap(); - Map orientations = new HashMap(); - for (ICSGnode node : nodes) { - positions.put(node, node.getWorldPosition()); - orientations.put(node, node.getWorldOrientation()); - //root.remChild(node); - node.deattach(); - } - Iterator iter = nodes.iterator(); - booleanNode.addPrimaryChild(iter.next()); - booleanNode.addSecondaryChild(iter.next()); - - String name = root.getUniqueName(booleanNode.getClass().getSimpleName()); - booleanNode.setName(name); - - root.addChild(booleanNode); - for (ICSGnode node : nodes) { - node.setWorldPosition(positions.get(node)); - node.setWorldOrientation(orientations.get(node)); - } - root.getNodeMap().commit(); - } catch (Exception e) { - ExceptionUtils.logAndShowError("Cannot create boolean operation.", e); - } - } - -} +/******************************************************************************* + * 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.g3d.csg.actions; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.vecmath.Quat4d; +import javax.vecmath.Vector3d; + +import org.eclipse.jface.action.Action; +import org.simantics.g3d.csg.scenegraph2.CSGparentNode; +import org.simantics.g3d.csg.scenegraph2.CSGrootNode; +import org.simantics.g3d.csg.scenegraph2.ICSGnode; +import org.simantics.utils.ui.ExceptionUtils; + +public class AddBooleanOpAction2 extends Action { + CSGrootNode root; + Class booleanClass; + Collection nodes; + + public AddBooleanOpAction2(CSGrootNode root, Class booleanClass, Collection nodes) { + super(); + String name = booleanClass.getSimpleName(); + if (name.endsWith("Node")) + name = name.substring(0,name.length()-4); + setText(name); + this.booleanClass = booleanClass; + this.nodes = nodes; + this.root = root; + if (nodes.size() != 2) + setEnabled(false); + for (ICSGnode node : nodes) { + if (!node.getParent().equals(root)) + setEnabled(false); + } + } + + @Override + public void run() { + try { + CSGparentNode booleanNode = booleanClass.newInstance(); + Map positions = new HashMap(); + Map orientations = new HashMap(); + for (ICSGnode node : nodes) { + positions.put(node, node.getWorldPosition()); + orientations.put(node, node.getWorldOrientation()); + //root.remChild(node); + node.deattach(); + } + Iterator iter = nodes.iterator(); + booleanNode.addPrimaryChild(iter.next()); + booleanNode.addSecondaryChild(iter.next()); + + String name = root.getUniqueName(booleanNode.getClass().getSimpleName()); + booleanNode.setName(name); + + root.addChild(booleanNode); + for (ICSGnode node : nodes) { + node.setWorldPosition(positions.get(node)); + node.setWorldOrientation(orientations.get(node)); + } + root.getNodeMap().commit("Add Boolean Op"); + } catch (Exception e) { + ExceptionUtils.logAndShowError("Cannot create boolean operation.", e); + } + } + +}