package fi.vtt.simantics.processeditor.scenegraph; import java.util.ArrayList; import java.util.Collection; import java.util.List; import javax.vecmath.AxisAngle4d; import javax.vecmath.Quat4d; import org.simantics.db.Graph; import org.simantics.db.Resource; import org.simantics.layer0.utils.EntityFactory; import org.simantics.layer0.utils.IEntity; import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase; import org.simantics.proconf.g3d.scenegraph.IGraphicsNode; import org.simantics.proconf.g3d.scenegraph.ShapeNode; import com.jme.math.Quaternion; import com.jme.renderer.ColorRGBA; import com.jme.scene.Geometry; import com.jme.scene.state.MaterialState; import com.jme.scene.state.RenderState; import fi.vtt.simantics.processeditor.ProcessResource; import fi.vtt.simantics.processeditor.common.ControlPointTools; import fi.vtt.simantics.processeditor.common.PipingTools; import fi.vtt.simantics.processeditor.stubs.CodedComponent; import fi.vtt.simantics.processeditor.stubs.PipeControlPoint; import fi.vtt.simantics.processeditor.stubs.Plant3DResource; import fi.vtt.simantics.processeditor.stubs.SizeChangeControlPoint; /** * This is for hard-coded geometries * TODO : we need an extension point for geometries, * so that other code-based geometries can be supported * * * @author Marko Luukkainen * */ public class PipeComponentNode extends ShapeNode { enum Type{ELBOW,STRAIGHT,REDUCER}; Type type; Resource controlPoint; public PipeComponentNode(ThreeDimensionalEditorBase editor, IGraphicsNode parent, Graph graph, Resource resource) { super(editor, parent, graph, resource); CodedComponent component = new CodedComponent(graph,resource); PipeControlPoint cp = component.getControlPoint(); Plant3DResource p3r = ProcessResource.plant3Dresource; controlPoint = cp.getResource(); if (component.isInstanceOf(p3r.Elbow)) { type = Type.ELBOW; } else if (component.isInstanceOf(p3r.Straight)) { type = Type.STRAIGHT; } else if (component.isInstanceOf(p3r.Elbow)) { type = Type.REDUCER; } } @Override public Collection getMaterial() { MaterialState ms = null; ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState(); ms.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.f)); ms.setSpecular(new ColorRGBA(1.f,1.f,1.f,1.f)); ms.setEnabled(true); ms.setShininess(128.f); if (type == Type.ELBOW) { ms.setDiffuse(new ColorRGBA(0.5f,0.5f,0.5f,0.f)); ms.setAmbient(new ColorRGBA(0.5f,0.5f,0.5f,0.f)); } else if (type == Type.STRAIGHT) { ms.setDiffuse(new ColorRGBA(0.75f,0.75f,0.75f,0.f)); ms.setAmbient(new ColorRGBA(0.75f,0.75f,0.75f,0.f)); } else { ms.setDiffuse(new ColorRGBA(0.6f,0.6f,0.6f,0.f)); ms.setAmbient(new ColorRGBA(0.6f,0.6f,0.6f,0.f)); } List states = new ArrayList(); states.add(ms); return states; } @Override public void updateTransform(Graph graph) { if (type == Type.REDUCER) { SizeChangeControlPoint sccp = new SizeChangeControlPoint(graph, controlPoint); Quat4d q = ControlPointTools.getControlPointLocalOrientationQuat(sccp, sccp.getRotationAngle()[0], true); update(q); } if (type != Type.STRAIGHT) { super.updateTransform(graph); } else { transform.setLocalTranslation(0.f,0.f,0.f); transform.setLocalRotation(new Quaternion()); } } }