]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.csg/src/org/simantics/g3d/csg/actions/SplitBooleanOpAction2.java
cebe1b453bef7d1391d218d6bf9f5eefd74df541
[simantics/3d.git] / org.simantics.g3d.csg / src / org / simantics / g3d / csg / actions / SplitBooleanOpAction2.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g3d.csg.actions;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import javax.vecmath.Quat4d;
20 import javax.vecmath.Vector3d;
21
22 import org.eclipse.jface.action.Action;
23 import org.simantics.g3d.csg.scenegraph2.CSGparentNode;
24 import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
25 import org.simantics.g3d.csg.scenegraph2.ICSGnode;
26
27 public class SplitBooleanOpAction2 extends Action {
28         private CSGrootNode root;
29         private CSGparentNode booleanOp;
30         
31         public SplitBooleanOpAction2(CSGrootNode root, CSGparentNode booleanOp)  {
32                 super();
33                 setText("Split");
34                 this.booleanOp = booleanOp;
35                 this.root = root;
36         }
37         
38         @Override
39         public void run() {
40                 Collection<ICSGnode> nodes = new ArrayList<ICSGnode>();
41                 nodes.addAll(booleanOp.getPrimaryChild());
42                 nodes.addAll(booleanOp.getSecondaryChild());
43                 Map<ICSGnode,Vector3d> positions = new HashMap<ICSGnode, Vector3d>();
44                 Map<ICSGnode,Quat4d> orientations = new HashMap<ICSGnode, Quat4d>();
45                 for (ICSGnode node : nodes) {
46                         positions.put(node, node.getWorldPosition());
47                         orientations.put(node, node.getWorldOrientation());
48                         node.deattach();
49                 }
50                 for (ICSGnode node : nodes) {
51                         root.addChild(node);
52                         node.setWorldPosition(positions.get(node));
53                         node.setWorldOrientation(orientations.get(node));
54                 }
55                 root.remChild(booleanOp);
56                 root.getNodeMap().commit("Split");
57
58         }
59
60 }