]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DParentGeometryNode.java
Enable model loading using an existing transaction.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / P3DParentGeometryNode.java
1 package org.simantics.plant3d.scenegraph;
2
3 import java.util.Collection;
4 import java.util.Map;
5 import java.util.Set;
6
7 import org.simantics.g3d.scenegraph.GeometryProvider;
8 import org.simantics.g3d.scenegraph.NodeHighlighter;
9 import org.simantics.g3d.vtk.common.VtkView;
10 import org.simantics.g3d.vtk.utils.vtkUtil;
11 import org.simantics.objmap.graph.annotations.RelatedGetObj;
12 import org.simantics.objmap.graph.annotations.RelatedSetObj;
13 import org.simantics.plant3d.ontology.Plant3D;
14
15 import vtk.vtkProp3D;
16 import vtk.vtkRenderer;
17
18 public class P3DParentGeometryNode<T extends IP3DNode> extends P3DParentNode<T> implements ParameterizedNode, NodeHighlighter{
19
20         private GeometryComponent component;
21         
22         
23         public P3DParentGeometryNode() {
24                 component = new GeometryComponent() {
25                         @Override
26                         protected double[] getColor() {
27                                 return P3DParentGeometryNode.this.getColor();
28                         }
29                         
30                         @Override
31                         protected double[] getSelectedColor() {
32                                 return P3DParentGeometryNode.this.getSelectedColor();
33                         }
34                 };
35         }
36         
37         @Override
38         public void visualize(VtkView ren) {
39                 updateParameters();
40                 component.visualize(ren);
41                 update(ren.getRenderer());
42         }
43         
44         public void updateParameters() {
45                 component.updateParameters();
46         }
47
48         public Map<String, Object> getParameterMap() {
49                 return component.getParameterMap();
50         }
51         
52         public Map<String, Object> getCalculatedParameters() {
53                 return component.getCalculatedParameters();
54         }
55         
56         public void setParameterMap(Map<String, Object> parameters) {
57                 Set<String> ids = component.setParameterMap(parameters);
58                 for (String id : ids) {
59                         firePropertyChanged(id);
60                 }
61         }
62
63         
64         @RelatedGetObj(Plant3D.URIs.hasGeometry)
65         public GeometryProvider getGeometry() {
66                 //return geometryProvider;
67                 return component.getGeometry();
68         }
69         
70         @RelatedSetObj(Plant3D.URIs.hasGeometry)
71         public void setGeometry(final GeometryProvider provider) {
72                 if (provider != null && provider.equals(component.getGeometry()))
73                         return;
74                 component.setGeometry(provider);
75                 firePropertyChanged(Plant3D.URIs.hasGeometry);
76         }
77         
78         
79         @Override
80         public Collection<vtkProp3D> getActors() {
81                 return component.getActors();
82         }
83         
84         @Override
85         public void stopVisualize() {
86                 component.stopVisualize();
87         }
88
89         @Override
90         public void highlight(HighlightEventType type) {
91                 component.highlight(type);
92         }
93         
94         protected double[] getSelectedColor() {
95                 return new double[]{1,0,0};
96         }
97         
98         protected double[] getColor() {
99                 return new double[]{1,1,0};
100         }
101         
102
103         
104         public void update(vtkRenderer ren) {
105                 vtkUtil.updateTransform(getActors(), getWorldPosition(), getWorldOrientation());
106         }
107
108 }