]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java
958228e8eefad236d03d6485f5f3a8d0b08030d1
[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.emptyList();
47         }
48         
49         @Override
50         public void stopVisualize() {
51                 
52         }
53         
54         @SuppressWarnings("deprecation")
55         @RelatedGetValue(Plant3D.URIs.HasTurnRadius)
56         @GetPropertyValue(value=Plant3D.URIs.HasTurnRadius, name = "Elbow radius")
57         public double getTurnRadius() {
58                 return turnRadius[0];
59         }
60         
61         @SuppressWarnings("deprecation")
62         @RelatedSetValue(Plant3D.URIs.HasTurnRadius)
63         @SetPropertyValue(Plant3D.URIs.HasTurnRadius)
64         public void setTurnRadius(double turnRadius) {
65                 this.turnRadius[0] = turnRadius;
66                 firePropertyChanged(Plant3D.URIs.HasTurnRadius);
67                 firePropertyChanged(Plant3D.URIs.HasTurnRadiusArray);
68         }
69         
70         @RelatedGetValue(Plant3D.URIs.HasTurnRadiusArray)
71     @GetPropertyValue(value=Plant3D.URIs.HasTurnRadiusArray, name = "Elbow radius array")
72     public double[] getTurnRadiusArray() {
73         return turnRadius;
74     }
75     
76     @RelatedSetValue(Plant3D.URIs.HasTurnRadiusArray)
77     @SetPropertyValue(Plant3D.URIs.HasTurnRadiusArray)
78     public void setTurnRadiusArray(double[] turnRadiusArray) {
79         if (turnRadiusArray == null || turnRadiusArray.length == 0)
80             return;
81         this.turnRadius = turnRadiusArray;
82         firePropertyChanged(Plant3D.URIs.HasTurnRadiusArray);
83     }
84         
85         @RelatedGetValue(Plant3D.URIs.HasPipeDiameter)
86         @GetPropertyValue(value=Plant3D.URIs.HasPipeDiameter, name = "Diameter")
87         public double getPipeDiameter() {
88                 return pipeDiameter;
89         }
90         
91         @RelatedSetValue(Plant3D.URIs.HasPipeDiameter)
92         @SetPropertyValue(Plant3D.URIs.HasPipeDiameter)
93         public void setPipeDiameter(double pipeDiameter) {
94                 this.pipeDiameter = pipeDiameter;       
95                 firePropertyChanged(Plant3D.URIs.HasPipeDiameter);
96         }
97         
98         @RelatedElementsAdd(Plant3D.URIs.children)
99         public void addChild(PipelineComponent node) {
100                 addNode(Plant3D.URIs.children,node);
101         }
102         
103         @RelatedElementsGet(Plant3D.URIs.children)
104         public Collection<PipelineComponent> getChild() {
105                 Collection<PipelineComponent> coll = new ArrayList<PipelineComponent>();
106                 for (IG3DNode n : getNodes(Plant3D.URIs.children)) {
107                         coll.add((PipelineComponent)n);
108                 }
109                 return coll;
110         }
111         
112         @RelatedElementsRem(Plant3D.URIs.children)
113         public void remChild(PipelineComponent node) {
114                 removeNode(Plant3D.URIs.children, node);
115         }
116
117         
118         public List<PipelineComponent> getSortedChild() {
119                 List<PipelineComponent> coll = new ArrayList<PipelineComponent>();
120                 for (IG3DNode n : getNodes(Plant3D.URIs.children)) {
121                         coll.add((PipelineComponent)n);
122                 }
123                 Collections.sort(coll, new ComponentComparator());
124                 return coll;
125         }
126         private static String PIPECP = "pipecp";
127         
128         public void addChild(PipeControlPoint node) {
129                 addNode(PIPECP,node);
130         }
131         
132         public void remChild(PipeControlPoint node) {
133                 removeNode(PIPECP, node);
134         }
135         
136         public void deattachChild(PipeControlPoint node) {
137                 deattachNode(PIPECP, node);
138         }
139         
140         public Collection<PipeControlPoint> getControlPoints() {
141                 Collection<PipeControlPoint> coll = new ArrayList<PipeControlPoint>();
142                 for (IG3DNode n : getNodes(PIPECP)) {
143                         coll.add((PipeControlPoint)n);
144                 }
145                 return coll;
146         }
147         
148         
149         public boolean equalSpecs(PipeRun other) {
150                 if (!MathTools.equals(pipeDiameter,other.pipeDiameter))
151                         return false;
152                 if (turnRadius.length != other.turnRadius.length)
153                     return false;
154                 for (int i = 0; i < turnRadius.length; i++) {
155                     if (!MathTools.equals(turnRadius[i],other.turnRadius[i]))
156                         return false;
157                 }
158                 return true;
159         }
160         
161         private class ComponentComparator implements Comparator<PipelineComponent> {
162                 @Override
163                 public int compare(PipelineComponent o1, PipelineComponent o2) {
164                         if (o1 == o2)
165                                 return 0;
166                         int i = 1;
167                         PipelineComponent c = o1.getPrevious();
168                         while (c != null) {
169                                 if (c == o2)
170                                         return i;
171                                 c = c.getPrevious();
172                                 i++;
173                         }
174                         i = -1;
175                         c = o1.getNext();
176                         while (c != null) {
177                                 if (c == o2)
178                                         return i;
179                                 c = c.getNext();
180                                 i--;
181                         }
182                         return 0;
183                         
184                 }
185         }
186         
187 }