]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java
0bd028307343513f88d7eb32f7717bfc929419ee
[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.childen)
81         public void addChild(PipelineComponent node) {
82                 addNode(Plant3D.URIs.childen,node);
83         }
84         
85         @RelatedElementsGet(Plant3D.URIs.childen)
86         public Collection<PipelineComponent> getChild() {
87                 Collection<PipelineComponent> coll = new ArrayList<PipelineComponent>();
88                 for (IG3DNode n : getNodes(Plant3D.URIs.childen)) {
89                         coll.add((PipelineComponent)n);
90                 }
91                 return coll;
92         }
93         
94         @RelatedElementsRem(Plant3D.URIs.childen)
95         public void remChild(PipelineComponent node) {
96                 removeNode(Plant3D.URIs.childen, node);
97         }
98
99         
100         public List<PipelineComponent> getSortedChild() {
101                 List<PipelineComponent> coll = new ArrayList<PipelineComponent>();
102                 for (IG3DNode n : getNodes(Plant3D.URIs.childen)) {
103                         coll.add((PipelineComponent)n);
104                 }
105                 Collections.sort(coll, new ComponentComparator());
106                 return coll;
107         }
108         public void addChild(PipeControlPoint node) {
109                 addNode("pipecp",node);
110         }
111         
112         public void remChild(PipeControlPoint node) {
113                 removeNode("pipecp", node);
114         }
115         
116         public void deattachChild(PipeControlPoint node) {
117                 deattachNode("pipecp", node);
118         }
119         
120         public Collection<PipeControlPoint> getControlPoints() {
121                 Collection<PipeControlPoint> coll = new ArrayList<PipeControlPoint>();
122                 for (IG3DNode n : getNodes("pipecp")) {
123                         coll.add((PipeControlPoint)n);
124                 }
125                 return coll;
126         }
127         
128         public boolean equalSpecs(PipeRun other) {
129                 if (!MathTools.equals(pipeDiameter,other.pipeDiameter))
130                         return false;
131                 if (!MathTools.equals(turnRadius,other.turnRadius))
132                         return false;
133                 return true;
134         }
135         
136         private class ComponentComparator implements Comparator<PipelineComponent> {
137                 @Override
138                 public int compare(PipelineComponent o1, PipelineComponent o2) {
139                         if (o1 == o2)
140                                 return 0;
141                         int i = 1;
142                         PipelineComponent c = o1.getPrevious();
143                         while (c != null) {
144                                 if (c == o2)
145                                         return i;
146                                 c = c.getPrevious();
147                                 i++;
148                         }
149                         i = -1;
150                         c = o1.getNext();
151                         while (c != null) {
152                                 if (c == o2)
153                                         return i;
154                                 c = c.getNext();
155                                 i--;
156                         }
157                         return 0;
158                         
159                 }
160         }
161 }