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.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
22 import org.simantics.g3d.csg.scenegraph2.ICSGnode;
23 import org.simantics.g3d.scenegraph.base.ParentNode;
24 import org.simantics.g3d.vtk.awt.InteractiveVtkPanel;
25 import org.simantics.g3d.vtk.common.AbstractVTKNodeMap;
26 import org.simantics.objmap.graph.IMapping;
31 public class CSGNodeMap extends AbstractVTKNodeMap<Resource,ICSGnode> {
35 public CSGNodeMap(Session session, IMapping mapping, InteractiveVtkPanel panel, CSGrootNode rootNode) {
36 super(session, mapping, panel, rootNode);
37 rootNode.setNodeMap(this);
41 @SuppressWarnings("unchecked")
42 protected void updateActor(ICSGnode node, Set<String> ids) {
43 //System.out.println("CSGNodeMap.updateActor " + node);
44 if (node.getParent() instanceof ICSGnode) {
45 ICSGnode parent = (ICSGnode) node.getParent();
46 if (!"child".equals(node.getParentRel())) {
47 updateActor(parent,null);
52 if (node instanceof ParentNode<?>) {
53 ParentNode<ICSGnode> p = (ParentNode<ICSGnode>)node;
54 for (ICSGnode n : p.getNodes())
64 protected Collection<vtkProp> getActors(ICSGnode node) {
65 List<vtkProp> props = new ArrayList<vtkProp>();
66 for (vtkProp3D p : ((ICSGnode)node).getActors())
71 protected void removeActor(ICSGnode node) {
72 //System.out.println("CSGNodeMap.removeActor " + node);
75 if (!"child".equals(node.getParentRel())) {
76 if (node.getParent() instanceof ICSGnode)
77 updateActor((ICSGnode)node.getParent(),null);
81 protected void addActor(ICSGnode node) {
82 //System.out.println("CSGNodeMap.addActor " + node);
85 if (Thread.currentThread() != view.getThreadQueue().getThread())
86 throw new RuntimeException("Illegal thread.");
92 map(node, node.getActors());
100 private boolean hasActor(ICSGnode node) {
101 Collection<vtkProp> list = getRenderObjects(node);
102 if (list == null || list.size() == 0)
107 private void remActor(ICSGnode node) {
108 if (Thread.currentThread() != view.getThreadQueue().getThread())
109 throw new RuntimeException("Illegal thread.");
111 Collection<vtkProp> list = getRenderObjects(node);
112 if (list.size() > 0) {
115 node.stopVisualize();