]> gerrit.simantics Code Review - simantics/3d.git/blob
f94799cf560ac6917f6eff5a7a8f1faf5b9b3e78
[simantics/3d.git] /
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.scenegraph;\r
12 \r
13 import java.util.ArrayList;\r
14 import java.util.Collection;\r
15 import java.util.List;\r
16 \r
17 import javax.vecmath.AxisAngle4d;\r
18 import javax.vecmath.Quat4d;\r
19 \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
34 \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
40 \r
41 \r
42 \r
43 /**\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
47  * \r
48  * \r
49  * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>\r
50  *\r
51  */\r
52 public class PipeComponentNode extends ShapeNode {\r
53         \r
54         enum Type{ELBOW,STRAIGHT,REDUCER};\r
55         \r
56         Type type;\r
57         Resource controlPoint;\r
58 \r
59         \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
66                 \r
67                 if (component.isInstanceOf(p3r.Elbow)) {\r
68                         type = Type.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
73                 }\r
74         \r
75         \r
76         }\r
77         \r
78         @Override\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
92         } else {\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
95         } \r
96                 List<RenderState> states = new ArrayList<RenderState>();\r
97                 states.add(ms);\r
98                 return states;\r
99         }\r
100         \r
101         \r
102         @Override\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
107                         update(q);\r
108                 } \r
109                 if (type != Type.STRAIGHT) {\r
110                         super.updateTransform(graph);\r
111                 } else {\r
112                         transform.setLocalTranslation(0.f,0.f,0.f);\r
113                         transform.setLocalRotation(new Quaternion());\r
114                 }\r
115         }\r
116 \r
117 }\r