package org.simantics.plant3d.scenegraph; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.property.annotations.PropertyTabBlacklist; import org.simantics.g3d.property.annotations.SetPropertyValue; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.vtk.common.VtkView; import org.simantics.objmap.graph.annotations.GraphType; import org.simantics.objmap.graph.annotations.RelatedElementsAdd; import org.simantics.objmap.graph.annotations.RelatedElementsGet; import org.simantics.objmap.graph.annotations.RelatedElementsRem; import org.simantics.objmap.graph.annotations.RelatedGetValue; import org.simantics.objmap.graph.annotations.RelatedSetValue; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint; import vtk.vtkProp3D; import vtk.vtkRenderer; @GraphType(Plant3D.URIs.PipeRun) @PropertyTabBlacklist("Transform") public class PipeRun extends P3DParentNode { private double pipeDiameter = 0.1; private double turnRadius = 0.2; @Override public void update(vtkRenderer ren) { } @Override public void visualize(VtkView panel) { } @Override public Collection getActors() { return Collections.EMPTY_LIST; } @Override public void stopVisualize() { } @RelatedGetValue(Plant3D.URIs.HasTurnRadius) @GetPropertyValue(value=Plant3D.URIs.HasTurnRadius, name = "Elbow radius") public double getTurnRadius() { return turnRadius; } @RelatedSetValue(Plant3D.URIs.HasTurnRadius) @SetPropertyValue(Plant3D.URIs.HasTurnRadius) public void setTurnRadius(double turnRadius) { this.turnRadius = turnRadius; firePropertyChanged(Plant3D.URIs.HasTurnRadius); } @RelatedGetValue(Plant3D.URIs.HasPipeDiameter) @GetPropertyValue(value=Plant3D.URIs.HasPipeDiameter, name = "Diameter") public double getPipeDiameter() { return pipeDiameter; } @RelatedSetValue(Plant3D.URIs.HasPipeDiameter) @SetPropertyValue(Plant3D.URIs.HasPipeDiameter) public void setPipeDiameter(double pipeDiameter) { this.pipeDiameter = pipeDiameter; firePropertyChanged(Plant3D.URIs.HasPipeDiameter); } @RelatedElementsAdd(Plant3D.URIs.children) public void addChild(PipelineComponent node) { addNode(Plant3D.URIs.children,node); } @RelatedElementsGet(Plant3D.URIs.children) public Collection getChild() { Collection coll = new ArrayList(); for (IG3DNode n : getNodes(Plant3D.URIs.children)) { coll.add((PipelineComponent)n); } return coll; } @RelatedElementsRem(Plant3D.URIs.children) public void remChild(PipelineComponent node) { removeNode(Plant3D.URIs.children, node); } public List getSortedChild() { List coll = new ArrayList(); for (IG3DNode n : getNodes(Plant3D.URIs.children)) { coll.add((PipelineComponent)n); } Collections.sort(coll, new ComponentComparator()); return coll; } public void addChild(PipeControlPoint node) { addNode("pipecp",node); } public void remChild(PipeControlPoint node) { removeNode("pipecp", node); } public void deattachChild(PipeControlPoint node) { deattachNode("pipecp", node); } public Collection getControlPoints() { Collection coll = new ArrayList(); for (IG3DNode n : getNodes("pipecp")) { coll.add((PipeControlPoint)n); } return coll; } public boolean equalSpecs(PipeRun other) { if (!MathTools.equals(pipeDiameter,other.pipeDiameter)) return false; if (!MathTools.equals(turnRadius,other.turnRadius)) return false; return true; } private class ComponentComparator implements Comparator { @Override public int compare(PipelineComponent o1, PipelineComponent o2) { if (o1 == o2) return 0; int i = 1; PipelineComponent c = o1.getPrevious(); while (c != null) { if (c == o2) return i; c = c.getPrevious(); i++; } i = -1; c = o1.getNext(); while (c != null) { if (c == o2) return i; c = c.getNext(); i--; } return 0; } } }