]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d.csg/src/org/simantics/g3d/csg/actions/AddBooleanOpAction2.java
Merge changes Ia3e00f11,I7f3a3a75
[simantics/3d.git] / org.simantics.g3d.csg / src / org / simantics / g3d / csg / actions / AddBooleanOpAction2.java
index e4d824920f0094206078302261f1951de06e1729..be196042ff02c589bb53ddcc457d6cb8cbbfa576 100644 (file)
@@ -1,80 +1,80 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.csg.actions;\r
-\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-\r
-import javax.vecmath.Quat4d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.simantics.g3d.csg.scenegraph2.CSGparentNode;\r
-import org.simantics.g3d.csg.scenegraph2.CSGrootNode;\r
-import org.simantics.g3d.csg.scenegraph2.ICSGnode;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-public class AddBooleanOpAction2 extends Action {\r
-       CSGrootNode root;\r
-       Class<? extends CSGparentNode> booleanClass;\r
-       Collection<ICSGnode> nodes;\r
-       \r
-       public AddBooleanOpAction2(CSGrootNode root, Class<? extends CSGparentNode> booleanClass, Collection<ICSGnode> nodes) {\r
-               super();\r
-               String name = booleanClass.getSimpleName();\r
-               if (name.endsWith("Node"))\r
-                       name = name.substring(0,name.length()-4);\r
-               setText(name);\r
-               this.booleanClass = booleanClass;\r
-               this.nodes = nodes;\r
-               this.root = root;\r
-               if (nodes.size() != 2)\r
-                       setEnabled(false);\r
-               for (ICSGnode node : nodes) {\r
-                       if (!node.getParent().equals(root))\r
-                               setEnabled(false);\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public void run() {\r
-               try {\r
-                       CSGparentNode booleanNode = booleanClass.newInstance();\r
-                       Map<ICSGnode,Vector3d> positions = new HashMap<ICSGnode, Vector3d>();\r
-                       Map<ICSGnode,Quat4d> orientations = new HashMap<ICSGnode, Quat4d>();\r
-                       for (ICSGnode node : nodes) {\r
-                               positions.put(node, node.getWorldPosition());\r
-                               orientations.put(node, node.getWorldOrientation());\r
-                               //root.remChild(node);\r
-                               node.deattach();\r
-                       }\r
-                       Iterator<ICSGnode> iter = nodes.iterator();\r
-                       booleanNode.addPrimaryChild(iter.next());\r
-                       booleanNode.addSecondaryChild(iter.next());\r
-                       \r
-                       String name = root.getUniqueName(booleanNode.getClass().getSimpleName());\r
-                       booleanNode.setName(name);\r
-                       \r
-                       root.addChild(booleanNode);\r
-                       for (ICSGnode node : nodes) {\r
-                               node.setWorldPosition(positions.get(node));\r
-                               node.setWorldOrientation(orientations.get(node));\r
-                       }\r
-                       root.getNodeMap().commit();\r
-               } catch (Exception e) {\r
-                       ExceptionUtils.logAndShowError("Cannot create boolean operation.", e);\r
-               }\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * 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<? extends CSGparentNode> booleanClass;
+       Collection<ICSGnode> nodes;
+       
+       public AddBooleanOpAction2(CSGrootNode root, Class<? extends CSGparentNode> booleanClass, Collection<ICSGnode> 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<ICSGnode,Vector3d> positions = new HashMap<ICSGnode, Vector3d>();
+                       Map<ICSGnode,Quat4d> orientations = new HashMap<ICSGnode, Quat4d>();
+                       for (ICSGnode node : nodes) {
+                               positions.put(node, node.getWorldPosition());
+                               orientations.put(node, node.getWorldOrientation());
+                               //root.remChild(node);
+                               node.deattach();
+                       }
+                       Iterator<ICSGnode> 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);
+               }
+       }
+
+}