package org.simantics.plant3d.scenegraph; import java.util.HashMap; import java.util.Map; import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.objmap.graph.annotations.DynamicGraphType; import org.simantics.objmap.graph.annotations.GetType; import org.simantics.objmap.graph.annotations.RelatedGetObj; import org.simantics.objmap.graph.annotations.RelatedGetValue; import org.simantics.objmap.graph.annotations.RelatedSetObj; import org.simantics.objmap.graph.annotations.RelatedSetValue; import org.simantics.objmap.graph.annotations.SetType; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory; import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint; @DynamicGraphType(Plant3D.URIs.Nozzle) public class Nozzle extends PipelineComponent { private String type; private PipeControlPoint controlPoint; @GetType(Plant3D.URIs.Nozzle) public String getType() { return type; } @SetType(Plant3D.URIs.Nozzle) public void setType(String type) throws Exception{ this.type = type; _createCP(); } private int id = 0; @RelatedGetValue(Plant3D.URIs.HasNozzleId) @GetPropertyValue(name="Nozzle ID", value=Plant3D.URIs.HasNozzleId, tabId="Default") public int getNozzleId() { return id; } @RelatedSetValue(Plant3D.URIs.HasNozzleId) public void setNozzleId(int id) { if (id == this.id) return; this.id = id; firePropertyChanged(Plant3D.URIs.HasNozzleId); } private boolean fixed = false; @RelatedGetValue(Plant3D.URIs.IsFixedNozzle) @GetPropertyValue(name="Fixed", value=Plant3D.URIs.IsFixedNozzle, tabId="Default") public boolean isFixed() { return fixed; } @RelatedSetValue(Plant3D.URIs.IsFixedNozzle) public void setFixed(boolean fixed) { if (fixed == this.fixed) return; this.fixed = fixed; firePropertyChanged(Plant3D.URIs.IsFixedNozzle); } private void _createCP() throws Exception{ if (controlPoint != null) return; if (getPipeRun() != null) { controlPoint = ControlPointFactory.create(this); // TODO : these should not be needed. controlPoint.setDeletable(false); controlPoint.setFixed(true); } } @RelatedSetObj(Plant3D.URIs.HasPipeRun) @Override public void setPipeRun(PipeRun pipeRun) { super.setPipeRun(pipeRun); try { _createCP(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } firePropertyChanged(Plant3D.URIs.HasPipeRun); } @RelatedGetObj(Plant3D.URIs.HasPipeRun) @Override public PipeRun getPipeRun() { return super.getPipeRun(); } @Override public PipeControlPoint getControlPoint() { return controlPoint; } @Override public void setPosition(Vector3d position) { super.setPosition(position); updateCP(); } @Override public void setOrientation(Quat4d orientation) { super.setOrientation(orientation); updateCP(); } private void updateCP() { if (controlPoint == null) return; if (controlPoint.getPipeRun() == null) return; controlPoint._setWorldPosition(getWorldPosition()); controlPoint._setWorldOrientation(getWorldOrientation()); } @Override public Map updateParameterMap() { Map map = new HashMap(); PipeRun pipeRun = getPipeRun(); if (pipeRun != null) { //map.put("length", pipeRun.getPipeDiameter() * 2.0); map.put("radius", pipeRun.getPipeDiameter() * 0.5); } return map; } @Override protected double[] getColor() { return new double[]{0.7,0.7,0.7}; } @Override protected double[] getSelectedColor() { return new double[]{0.5,0,0.5}; } public boolean isConnected() { PipeControlPoint pcp = getControlPoint(); return (pcp.getNext() != null || pcp.getPrevious() != null); } public boolean isNextConnected() { PipeControlPoint pcp = getControlPoint(); return (pcp.getNext() != null); } public boolean isPrevConnected() { PipeControlPoint pcp = getControlPoint(); return (pcp.getNext() != null); } }