]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/GeometryNode.java
Merge "Updated Plant3D ontology class"
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / GeometryNode.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 abstract class GeometryNode extends P3DNode implements ParameterizedNode, NodeHighlighter {
19         
20         private GeometryComponent component;
21
22         public GeometryNode() {
23                 component = new GeometryComponent() {
24                         @Override
25                         protected double[] getColor() {
26                                 return GeometryNode.this.getColor();
27                         }
28                         
29                         @Override
30                         protected double[] getSelectedColor() {
31                                 return GeometryNode.this.getSelectedColor();
32                         }
33                 };
34         }
35         
36         @Override
37         public void visualize(VtkView panel) {
38                 updateParameters();
39                 component.visualize(panel);
40                 update(panel.getRenderer());
41         }
42         
43         public void updateParameters() {
44                 component.updateParameters();
45         }
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         
57         public Map<String, Object> getTotalParameters() {
58         return component.getTotalParameters();
59     }
60         
61         public void setParametersUpdated(boolean parametersUpdated) {
62                 component.setParametersUpdated(parametersUpdated);
63         }
64         
65         public void setParameterMap(Map<String, Object> parameters) {
66                 Set<String> ids = component.setParameterMap(parameters);
67                 for (String id : ids) {
68                         firePropertyChanged(id);
69                 }
70         }
71         
72         @RelatedGetObj(Plant3D.URIs.hasGeometry)
73         public GeometryProvider getGeometry() {
74                 return component.getGeometry();
75         }
76         
77         @RelatedSetObj(Plant3D.URIs.hasGeometry)
78         public void setGeometry(final GeometryProvider provider) {
79                 if (provider != null && provider.equals(component.getGeometry()))
80                         return;
81                 component.setGeometry(provider);
82                 firePropertyChanged(Plant3D.URIs.hasGeometry);
83         }
84
85         @Override
86         public Collection<vtkProp3D> getActors() {
87                 return component.getActors();
88         }
89         
90         @Override
91         public void stopVisualize() {
92                 component.stopVisualize();
93         }
94         
95         @Override
96         public void highlight(HighlightEventType type) {
97                 component.highlight(type);
98                 
99         }
100         
101         protected double[] getSelectedColor() {
102                 return new double[]{1,0,0};
103         }
104         
105         protected double[] getColor() {
106                 return new double[]{1,1,0};
107         }
108         
109         public void update(vtkRenderer ren) {
110                 vtkUtil.updateTransform(getActors(), getWorldPosition(), getWorldOrientation());
111         }
112
113 }