1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g3d.csg.editor;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
19 import org.simantics.db.Session;
20 import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
21 import org.simantics.g3d.csg.scenegraph2.ICSGnode;
22 import org.simantics.g3d.scenegraph.base.ParentNode;
23 import org.simantics.g3d.vtk.awt.InteractiveVtkPanel;
24 import org.simantics.g3d.vtk.common.AbstractVTKNodeMap;
25 import org.simantics.objmap.graph.IMapping;
30 public class CSGNodeMap extends AbstractVTKNodeMap<ICSGnode> {
34 public CSGNodeMap(Session session, IMapping mapping, InteractiveVtkPanel panel, CSGrootNode rootNode) {
35 super(session, mapping, panel, rootNode);
36 rootNode.setNodeMap(this);
40 @SuppressWarnings("unchecked")
41 protected void updateActor(ICSGnode node, Set<String> ids) {
42 //System.out.println("CSGNodeMap.updateActor " + node);
43 if (node.getParent() instanceof ICSGnode) {
44 ICSGnode parent = (ICSGnode) node.getParent();
45 if (!"child".equals(node.getParentRel())) {
46 updateActor(parent,null);
51 if (node instanceof ParentNode<?>) {
52 ParentNode<ICSGnode> p = (ParentNode<ICSGnode>)node;
53 for (ICSGnode n : p.getNodes())
63 protected Collection<vtkProp> getActors(ICSGnode node) {
64 List<vtkProp> props = new ArrayList<vtkProp>();
65 for (vtkProp3D p : ((ICSGnode)node).getActors())
70 protected void removeActor(ICSGnode node) {
71 //System.out.println("CSGNodeMap.removeActor " + node);
74 if (!"child".equals(node.getParentRel())) {
75 if (node.getParent() instanceof ICSGnode)
76 updateActor((ICSGnode)node.getParent(),null);
80 protected void addActor(ICSGnode node) {
81 //System.out.println("CSGNodeMap.addActor " + node);
84 if (Thread.currentThread() != view.getThreadQueue().getThread())
85 throw new RuntimeException("Illegal thread.");
91 for (vtkProp3D act : node.getActors()) {
92 nodeToActor.add(node, act);
93 actorToNode.put(act, node);
102 private boolean hasActor(ICSGnode node) {
103 List<vtkProp> list = nodeToActor.getValues(node);
104 if (list == null || list.size() == 0)
109 private void remActor(ICSGnode node) {
110 if (Thread.currentThread() != view.getThreadQueue().getThread())
111 throw new RuntimeException("Illegal thread.");
113 List<vtkProp> list = nodeToActor.getValues(node);
115 for (vtkProp obj : list) {
116 actorToNode.remove(obj);
118 nodeToActor.remove(node);
121 node.stopVisualize();