1 package fi.vtt.simantics.processeditor.actions;
\r
3 import java.awt.event.MouseEvent;
\r
4 import java.util.List;
\r
6 import javax.vecmath.Point3d;
\r
7 import javax.vecmath.Vector3d;
\r
9 import org.simantics.db.Graph;
\r
10 import org.simantics.db.Resource;
\r
11 import org.simantics.proconf.g3d.actions.InteractiveAction;
\r
12 import org.simantics.proconf.g3d.base.MathTools;
\r
13 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
14 import org.simantics.proconf.g3d.base.VecmathJmeTools;
\r
16 import com.jme.math.Vector3f;
\r
17 import com.jme.renderer.ColorRGBA;
\r
18 import com.jme.scene.Line;
\r
19 import com.jme.scene.state.MaterialState;
\r
20 import com.jme.util.geom.BufferUtils;
\r
22 public class SelectSplitPointAction extends InteractiveAction {
\r
32 SplitPointListener listener;
\r
34 public SelectSplitPointAction(ThreeDimensionalEditorBase parent, SplitPointListener listener) {
\r
36 this.listener = listener;
\r
40 public void setSplit(Point3d start, Point3d end) {
\r
43 dir = new Vector3d(end);
\r
49 public void activate() {
\r
50 if (start == null) throw new RuntimeException("Starting split action without information about range");
\r
52 // start = new Point3d();
\r
53 // end = new Point3d();
\r
54 // PipingTools.getStraightPipeEnds(PipingTools.getPipeline(straight),
\r
55 // straight, startStart, startEnd);
\r
58 MaterialState ms = parent.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();
\r
59 ms.setEmissive(new ColorRGBA(1.f,1.f,1.f,1.f));
\r
60 line.setRenderState(ms);
\r
61 parent.getRenderingComponent().getNoShadowRoot().attachChild(line);
\r
67 public boolean usable(Graph graph, List<Resource> resources) {
\r
68 // if (resources.size() != 1)
\r
70 // IEntity entity = EntityFactory.create(graph, resources.get(0));
\r
71 // if (entity.isInstanceOf(ProcessResource.plant3Dresource.VariableLengthInlineComponent)) {
\r
74 // This is not a standalone action
\r
79 public void deactivate() {
\r
80 line.removeFromParent();
\r
88 public boolean active() {
\r
93 public void update() {
\r
97 if (input.mouseClicked() && input.clickButton() == MouseEvent.BUTTON3) {
\r
98 listener.setSplitPoint(null);
\r
102 Vector3d o = new Vector3d();
\r
103 Vector3d d = new Vector3d();
\r
104 parent.createPickRay(o, d);
\r
106 Vector3d normal = parent.getCamera().getUnNormalizedHeading();
\r
107 normal.normalize();
\r
109 // reference point for selection line
\r
110 Vector3d point = new Vector3d(start);
\r
111 Vector3d currentPoint = new Vector3d();
\r
112 MathTools.intersectStraightPlane(o, d, point, normal, currentPoint);
\r
113 Point3d startPoint = new Point3d();
\r
114 double mu[] = new double[2];
\r
115 MathTools.intersectStraightStraight(start, dir, o, d, startPoint,
\r
116 new Point3d(), mu);
\r
117 // startPoint of branch must be between pipe ends
\r
118 // TODO : take account sizes of elbows (or other components)
\r
120 startPoint.set(start);
\r
121 else if (mu[0] > 1.0)
\r
122 startPoint.set(end);
\r
124 Vector3f verts[] = new Vector3f[2];
\r
125 verts[0] = VecmathJmeTools.get(startPoint);
\r
126 verts[1] = VecmathJmeTools.get(currentPoint);
\r
127 line.reconstruct(BufferUtils.createFloatBuffer(verts), null, null, null);
\r
129 parent.setViewChanged(true);
\r
130 if (input.mouseClicked() && input.clickButton() == MouseEvent.BUTTON1) {
\r
131 listener.setSplitPoint(new Point3d(startPoint));
\r