1 package org.simantics.processeditor.scenegraph;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
5 import java.util.List;
\r
7 import javax.vecmath.AxisAngle4d;
\r
8 import javax.vecmath.Quat4d;
\r
10 import org.simantics.db.Graph;
\r
11 import org.simantics.db.Resource;
\r
12 import org.simantics.layer0.utils.EntityFactory;
\r
13 import org.simantics.layer0.utils.IEntity;
\r
14 import org.simantics.processeditor.ProcessResource;
\r
15 import org.simantics.processeditor.common.ControlPointTools;
\r
16 import org.simantics.processeditor.common.PipingTools;
\r
17 import org.simantics.processeditor.stubs.CodedComponent;
\r
18 import org.simantics.processeditor.stubs.PipeControlPoint;
\r
19 import org.simantics.processeditor.stubs.Plant3DResource;
\r
20 import org.simantics.processeditor.stubs.SizeChangeControlPoint;
\r
21 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
22 import org.simantics.proconf.g3d.scenegraph.IGraphicsNode;
\r
23 import org.simantics.proconf.g3d.scenegraph.ShapeNode;
\r
25 import com.jme.math.Quaternion;
\r
26 import com.jme.renderer.ColorRGBA;
\r
27 import com.jme.scene.Geometry;
\r
28 import com.jme.scene.state.MaterialState;
\r
29 import com.jme.scene.state.RenderState;
\r
34 * This is for hard-coded geometries
\r
35 * TODO : we need an extension point for geometries,
\r
36 * so that other code-based geometries can be supported
\r
39 * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>
\r
42 public class PipeComponentNode extends ShapeNode {
\r
44 enum Type{ELBOW,STRAIGHT,REDUCER};
\r
47 Resource controlPoint;
\r
50 public PipeComponentNode(ThreeDimensionalEditorBase editor, IGraphicsNode parent, Graph graph, Resource resource) {
\r
51 super(editor, parent, graph, resource);
\r
52 CodedComponent component = new CodedComponent(graph,resource);
\r
53 PipeControlPoint cp = component.getControlPoint();
\r
54 Plant3DResource p3r = ProcessResource.plant3Dresource;
\r
55 controlPoint = cp.getResource();
\r
57 if (component.isInstanceOf(p3r.Elbow)) {
\r
59 } else if (component.isInstanceOf(p3r.Straight)) {
\r
60 type = Type.STRAIGHT;
\r
61 } else if (component.isInstanceOf(p3r.Elbow)) {
\r
62 type = Type.REDUCER;
\r
69 public Collection<RenderState> getMaterial() {
\r
70 MaterialState ms = null;
\r
71 ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();
\r
72 ms.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.f));
\r
73 ms.setSpecular(new ColorRGBA(1.f,1.f,1.f,1.f));
\r
74 ms.setEnabled(true);
\r
75 ms.setShininess(128.f);
\r
76 if (type == Type.ELBOW) {
\r
77 ms.setDiffuse(new ColorRGBA(0.5f,0.5f,0.5f,0.f));
\r
78 ms.setAmbient(new ColorRGBA(0.5f,0.5f,0.5f,0.f));
\r
79 } else if (type == Type.STRAIGHT) {
\r
80 ms.setDiffuse(new ColorRGBA(0.75f,0.75f,0.75f,0.f));
\r
81 ms.setAmbient(new ColorRGBA(0.75f,0.75f,0.75f,0.f));
\r
83 ms.setDiffuse(new ColorRGBA(0.6f,0.6f,0.6f,0.f));
\r
84 ms.setAmbient(new ColorRGBA(0.6f,0.6f,0.6f,0.f));
\r
86 List<RenderState> states = new ArrayList<RenderState>();
\r
93 public void updateTransform(Graph graph) {
\r
94 if (type == Type.REDUCER) {
\r
95 SizeChangeControlPoint sccp = new SizeChangeControlPoint(graph, controlPoint);
\r
96 Quat4d q = ControlPointTools.getControlPointLocalOrientationQuat(sccp, sccp.getRotationAngle()[0], true);
\r
99 if (type != Type.STRAIGHT) {
\r
100 super.updateTransform(graph);
\r
102 transform.setLocalTranslation(0.f,0.f,0.f);
\r
103 transform.setLocalRotation(new Quaternion());
\r