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