]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java
Allow multiple radii for turns.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / PipeRun.java
1 package org.simantics.plant3d.scenegraph;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.Comparator;
7 import java.util.List;
8
9 import org.simantics.g3d.math.MathTools;
10 import org.simantics.g3d.property.annotations.GetPropertyValue;
11 import org.simantics.g3d.property.annotations.PropertyTabBlacklist;
12 import org.simantics.g3d.property.annotations.SetPropertyValue;
13 import org.simantics.g3d.scenegraph.IG3DNode;
14 import org.simantics.g3d.vtk.common.VtkView;
15 import org.simantics.objmap.graph.annotations.GraphType;
16 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
17 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
18 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
19 import org.simantics.objmap.graph.annotations.RelatedGetValue;
20 import org.simantics.objmap.graph.annotations.RelatedSetValue;
21 import org.simantics.plant3d.ontology.Plant3D;
22 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
23
24 import vtk.vtkProp3D;
25 import vtk.vtkRenderer;
26
27 @GraphType(Plant3D.URIs.PipeRun)
28 @PropertyTabBlacklist("Transform")
29 public class PipeRun extends P3DParentNode<IP3DNode> {
30         
31         private double pipeDiameter = 0.1;
32         private double[] turnRadius = new double[] {0.2};
33         
34         @Override
35         public void update(vtkRenderer ren) {
36                 
37         }
38         
39         @Override
40         public void visualize(VtkView panel) {
41                 
42         }
43         
44         @Override
45         public Collection<vtkProp3D> getActors() {
46                 return Collections.EMPTY_LIST;
47         }
48         
49         @Override
50         public void stopVisualize() {
51                 
52         }
53         
54         @RelatedGetValue(Plant3D.URIs.HasTurnRadius)
55         @GetPropertyValue(value=Plant3D.URIs.HasTurnRadius, name = "Elbow radius")
56         public double getTurnRadius() {
57                 return turnRadius[0];
58         }
59         
60         @RelatedSetValue(Plant3D.URIs.HasTurnRadius)
61         @SetPropertyValue(Plant3D.URIs.HasTurnRadius)
62         public void setTurnRadius(double turnRadius) {
63                 this.turnRadius[0] = turnRadius;
64                 firePropertyChanged(Plant3D.URIs.HasTurnRadius);
65                 firePropertyChanged(Plant3D.URIs.HasTurnRadiusArray);
66         }
67         
68         @RelatedGetValue(Plant3D.URIs.HasTurnRadiusArray)
69     @GetPropertyValue(value=Plant3D.URIs.HasTurnRadiusArray, name = "Elbow radius array")
70     public double[] getTurnRadiusArray() {
71         return turnRadius;
72     }
73     
74     @RelatedSetValue(Plant3D.URIs.HasTurnRadiusArray)
75     @SetPropertyValue(Plant3D.URIs.HasTurnRadiusArray)
76     public void setTurnRadiusArray(double[] turnRadiusArray) {
77         if (turnRadiusArray == null || turnRadiusArray.length == 0)
78             return;
79         this.turnRadius = turnRadiusArray;
80         firePropertyChanged(Plant3D.URIs.HasTurnRadiusArray);
81     }
82         
83         @RelatedGetValue(Plant3D.URIs.HasPipeDiameter)
84         @GetPropertyValue(value=Plant3D.URIs.HasPipeDiameter, name = "Diameter")
85         public double getPipeDiameter() {
86                 return pipeDiameter;
87         }
88         
89         @RelatedSetValue(Plant3D.URIs.HasPipeDiameter)
90         @SetPropertyValue(Plant3D.URIs.HasPipeDiameter)
91         public void setPipeDiameter(double pipeDiameter) {
92                 this.pipeDiameter = pipeDiameter;       
93                 firePropertyChanged(Plant3D.URIs.HasPipeDiameter);
94         }
95         
96         @RelatedElementsAdd(Plant3D.URIs.children)
97         public void addChild(PipelineComponent node) {
98                 addNode(Plant3D.URIs.children,node);
99         }
100         
101         @RelatedElementsGet(Plant3D.URIs.children)
102         public Collection<PipelineComponent> getChild() {
103                 Collection<PipelineComponent> coll = new ArrayList<PipelineComponent>();
104                 for (IG3DNode n : getNodes(Plant3D.URIs.children)) {
105                         coll.add((PipelineComponent)n);
106                 }
107                 return coll;
108         }
109         
110         @RelatedElementsRem(Plant3D.URIs.children)
111         public void remChild(PipelineComponent node) {
112                 removeNode(Plant3D.URIs.children, node);
113         }
114
115         
116         public List<PipelineComponent> getSortedChild() {
117                 List<PipelineComponent> coll = new ArrayList<PipelineComponent>();
118                 for (IG3DNode n : getNodes(Plant3D.URIs.children)) {
119                         coll.add((PipelineComponent)n);
120                 }
121                 Collections.sort(coll, new ComponentComparator());
122                 return coll;
123         }
124         private static String PIPECP = "pipecp";
125         
126         public void addChild(PipeControlPoint node) {
127                 addNode(PIPECP,node);
128         }
129         
130         public void remChild(PipeControlPoint node) {
131                 removeNode(PIPECP, node);
132         }
133         
134         public void deattachChild(PipeControlPoint node) {
135                 deattachNode(PIPECP, node);
136         }
137         
138         public Collection<PipeControlPoint> getControlPoints() {
139                 Collection<PipeControlPoint> coll = new ArrayList<PipeControlPoint>();
140                 for (IG3DNode n : getNodes(PIPECP)) {
141                         coll.add((PipeControlPoint)n);
142                 }
143                 return coll;
144         }
145         
146         
147         public boolean equalSpecs(PipeRun other) {
148                 if (!MathTools.equals(pipeDiameter,other.pipeDiameter))
149                         return false;
150                 if (turnRadius.length != other.turnRadius.length)
151                     return false;
152                 for (int i = 0; i < turnRadius.length; i++) {
153                     if (!MathTools.equals(turnRadius[i],other.turnRadius[i]))
154                         return false;
155                 }
156                 return true;
157         }
158         
159         private class ComponentComparator implements Comparator<PipelineComponent> {
160                 @Override
161                 public int compare(PipelineComponent o1, PipelineComponent o2) {
162                         if (o1 == o2)
163                                 return 0;
164                         int i = 1;
165                         PipelineComponent c = o1.getPrevious();
166                         while (c != null) {
167                                 if (c == o2)
168                                         return i;
169                                 c = c.getPrevious();
170                                 i++;
171                         }
172                         i = -1;
173                         c = o1.getNext();
174                         while (c != null) {
175                                 if (c == o2)
176                                         return i;
177                                 c = c.getNext();
178                                 i--;
179                         }
180                         return 0;
181                         
182                 }
183         }
184         
185 }