1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.csg.editor;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.List;
\r
17 import java.util.Set;
\r
19 import org.simantics.db.Session;
\r
20 import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
\r
21 import org.simantics.g3d.csg.scenegraph2.ICSGnode;
\r
22 import org.simantics.g3d.scenegraph.base.ParentNode;
\r
23 import org.simantics.g3d.vtk.common.AbstractVTKNodeMap;
\r
24 import org.simantics.g3d.vtk.common.InteractiveVtkPanel;
\r
25 import org.simantics.objmap.graph.IMapping;
\r
26 import org.simantics.utils.threads.AWTThread;
\r
29 import vtk.vtkProp3D;
\r
30 import vtk.vtkRenderer;
\r
32 public class CSGNodeMap extends AbstractVTKNodeMap<ICSGnode> {
\r
36 public CSGNodeMap(Session session, IMapping mapping, InteractiveVtkPanel panel, CSGrootNode rootNode) {
\r
37 super(session, mapping, panel, rootNode);
\r
38 rootNode.setNodeMap(this);
\r
42 @SuppressWarnings("unchecked")
\r
43 protected void updateActor(ICSGnode node, Set<String> ids) {
\r
44 //System.out.println("CSGNodeMap.updateActor " + node);
\r
45 if (node.getParent() instanceof ICSGnode) {
\r
46 ICSGnode parent = (ICSGnode) node.getParent();
\r
47 if (!"child".equals(node.getParentRel())) {
\r
48 updateActor(parent,null);
\r
53 if (node instanceof ParentNode<?>) {
\r
54 ParentNode<ICSGnode> p = (ParentNode<ICSGnode>)node;
\r
55 for (ICSGnode n : p.getNodes())
\r
65 protected Collection<vtkProp> getActors(ICSGnode node) {
\r
66 List<vtkProp> props = new ArrayList<vtkProp>();
\r
67 for (vtkProp3D p : ((ICSGnode)node).getActors())
\r
72 protected void removeActor(ICSGnode node) {
\r
73 //System.out.println("CSGNodeMap.removeActor " + node);
\r
76 if (!"child".equals(node.getParentRel())) {
\r
77 if (node.getParent() instanceof ICSGnode)
\r
78 updateActor((ICSGnode)node.getParent(),null);
\r
82 protected void addActor(ICSGnode node) {
\r
83 //System.out.println("CSGNodeMap.addActor " + node);
\r
86 if (Thread.currentThread() != AWTThread.getThreadAccess().getThread())
\r
87 throw new RuntimeException("Illegal thread.");
\r
91 node.visualize(panel);
\r
93 for (vtkProp3D act : node.getActors()) {
\r
94 nodeToActor.add(node, act);
\r
95 actorToNode.put(act, node);
\r
104 private boolean hasActor(ICSGnode node) {
\r
105 List<vtkProp> list = nodeToActor.getValues(node);
\r
106 if (list == null || list.size() == 0)
\r
111 private void remActor(ICSGnode node) {
\r
112 if (Thread.currentThread() != AWTThread.getThreadAccess().getThread())
\r
113 throw new RuntimeException("Illegal thread.");
\r
115 List<vtkProp> list = nodeToActor.getValues(node);
\r
116 if (list != null) {
\r
117 for (vtkProp obj : list) {
\r
118 actorToNode.remove(obj);
\r
120 nodeToActor.remove(node);
\r
123 node.stopVisualize();
\r