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