]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGNodeMap.java
Compiler warning elimination
[simantics/3d.git] / org.simantics.g3d.csg / src / org / simantics / g3d / csg / editor / CSGNodeMap.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.editor;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
17 import java.util.Set;
18
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.INode;
24 import org.simantics.g3d.scenegraph.base.ParentNode;
25 import org.simantics.g3d.vtk.awt.InteractiveVtkPanel;
26 import org.simantics.g3d.vtk.common.AbstractVTKNodeMap;
27 import org.simantics.objmap.graph.IMapping;
28
29 import vtk.vtkProp;
30 import vtk.vtkProp3D;
31
32 public class CSGNodeMap extends AbstractVTKNodeMap<Resource,ICSGnode> {
33         
34         public CSGNodeMap(Session session, IMapping<Resource,INode> mapping, InteractiveVtkPanel panel, CSGrootNode rootNode) {
35                 super(session, mapping, panel, rootNode);
36                 rootNode.setNodeMap(this);
37         }
38         
39
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);
47                                 return;
48                         }
49                 }
50                 
51                 if (node instanceof ParentNode<?>) {
52                         ParentNode<ICSGnode> p = (ParentNode<ICSGnode>)node;
53                         for (ICSGnode n : p.getNodes())
54                                 remActor(n);
55                 }
56                 
57                 remActor(node);
58                 addActor(node);
59
60         }
61
62         @Override
63         protected Collection<vtkProp> getActors(ICSGnode node) {
64                 List<vtkProp> props = new ArrayList<vtkProp>();
65                 for (vtkProp3D p : ((ICSGnode)node).getActors())
66                         props.add(p);
67                 return props;
68         }
69         
70         protected void removeActor(ICSGnode node) {
71                 //System.out.println("CSGNodeMap.removeActor " + node);
72                 remActor(node);
73                 
74                 if (!"child".equals(node.getParentRel())) {
75                         if (node.getParent() instanceof ICSGnode)
76                                 updateActor((ICSGnode)node.getParent(),null);
77                 }
78         }
79         
80         protected void addActor(ICSGnode node) {
81                 //System.out.println("CSGNodeMap.addActor " + node);
82                 if (hasActor(node))
83                         return;
84                 if (Thread.currentThread() != view.getThreadQueue().getThread())
85                         throw new RuntimeException("Illegal thread.");
86                 
87                 view.lock();
88                 
89                 node.visualize(view);
90                 
91                 map(node, node.getActors());
92
93                 view.unlock();
94
95         }
96         
97         
98         
99         private boolean hasActor(ICSGnode node) {
100                 Collection<vtkProp> list = getRenderObjects(node);
101                 if (list == null || list.size() == 0)
102                         return false;
103                 return true;
104         }
105         
106         private void remActor(ICSGnode node) {
107                 if (Thread.currentThread() != view.getThreadQueue().getThread())
108                         throw new RuntimeException("Illegal thread.");
109
110                 Collection<vtkProp> list = getRenderObjects(node);
111                 if (list.size() > 0) {
112                     removeMap(node);
113                         view.lock();
114                         node.stopVisualize();
115                         view.unlock();
116                 }
117         }
118         
119
120 }