1 /*******************************************************************************
\r
2 * Copyright (c) 2007- VTT Technical Research Centre of Finland.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.scenegraph;
\r
13 import java.util.ArrayList;
\r
14 import java.util.Collection;
\r
15 import java.util.List;
\r
17 import javax.vecmath.AxisAngle4d;
\r
18 import javax.vecmath.Quat4d;
\r
20 import org.simantics.db.Graph;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.layer0.utils.EntityFactory;
\r
23 import org.simantics.layer0.utils.IEntity;
\r
24 import org.simantics.processeditor.ProcessResource;
\r
25 import org.simantics.processeditor.common.ControlPointTools;
\r
26 import org.simantics.processeditor.common.PipingTools;
\r
27 import org.simantics.processeditor.stubs.CodedComponent;
\r
28 import org.simantics.processeditor.stubs.PipeControlPoint;
\r
29 import org.simantics.processeditor.stubs.Plant3DResource;
\r
30 import org.simantics.processeditor.stubs.SizeChangeControlPoint;
\r
31 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
32 import org.simantics.proconf.g3d.scenegraph.IGraphicsNode;
\r
33 import org.simantics.proconf.g3d.scenegraph.ShapeNode;
\r
35 import com.jme.math.Quaternion;
\r
36 import com.jme.renderer.ColorRGBA;
\r
37 import com.jme.scene.Geometry;
\r
38 import com.jme.scene.state.MaterialState;
\r
39 import com.jme.scene.state.RenderState;
\r
44 * This is for hard-coded geometries
\r
45 * TODO : we need an extension point for geometries,
\r
46 * so that other code-based geometries can be supported
\r
49 * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>
\r
52 public class PipeComponentNode extends ShapeNode {
\r
54 enum Type{ELBOW,STRAIGHT,REDUCER};
\r
57 Resource controlPoint;
\r
60 public PipeComponentNode(ThreeDimensionalEditorBase editor, IGraphicsNode parent, Graph graph, Resource resource) {
\r
61 super(editor, parent, graph, resource);
\r
62 CodedComponent component = new CodedComponent(graph,resource);
\r
63 PipeControlPoint cp = component.getControlPoint();
\r
64 Plant3DResource p3r = ProcessResource.plant3Dresource;
\r
65 controlPoint = cp.getResource();
\r
67 if (component.isInstanceOf(p3r.Elbow)) {
\r
69 } else if (component.isInstanceOf(p3r.Straight)) {
\r
70 type = Type.STRAIGHT;
\r
71 } else if (component.isInstanceOf(p3r.Elbow)) {
\r
72 type = Type.REDUCER;
\r
79 public Collection<RenderState> getMaterial() {
\r
80 MaterialState ms = null;
\r
81 ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();
\r
82 ms.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.f));
\r
83 ms.setSpecular(new ColorRGBA(1.f,1.f,1.f,1.f));
\r
84 ms.setEnabled(true);
\r
85 ms.setShininess(128.f);
\r
86 if (type == Type.ELBOW) {
\r
87 ms.setDiffuse(new ColorRGBA(0.5f,0.5f,0.5f,0.f));
\r
88 ms.setAmbient(new ColorRGBA(0.5f,0.5f,0.5f,0.f));
\r
89 } else if (type == Type.STRAIGHT) {
\r
90 ms.setDiffuse(new ColorRGBA(0.75f,0.75f,0.75f,0.f));
\r
91 ms.setAmbient(new ColorRGBA(0.75f,0.75f,0.75f,0.f));
\r
93 ms.setDiffuse(new ColorRGBA(0.6f,0.6f,0.6f,0.f));
\r
94 ms.setAmbient(new ColorRGBA(0.6f,0.6f,0.6f,0.f));
\r
96 List<RenderState> states = new ArrayList<RenderState>();
\r
103 public void updateTransform(Graph graph) {
\r
104 if (type == Type.REDUCER) {
\r
105 SizeChangeControlPoint sccp = new SizeChangeControlPoint(graph, controlPoint);
\r
106 Quat4d q = ControlPointTools.getControlPointLocalOrientationQuat(sccp, sccp.getRotationAngle()[0], true);
\r
109 if (type != Type.STRAIGHT) {
\r
110 super.updateTransform(graph);
\r
112 transform.setLocalTranslation(0.f,0.f,0.f);
\r
113 transform.setLocalRotation(new Quaternion());
\r