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.actions;
\r
13 import java.awt.event.MouseEvent;
\r
14 import java.util.List;
\r
16 import javax.vecmath.Point3d;
\r
17 import javax.vecmath.Vector3d;
\r
19 import org.simantics.db.Graph;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.proconf.g3d.actions.InteractiveAction;
\r
22 import org.simantics.proconf.g3d.base.MathTools;
\r
23 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
24 import org.simantics.proconf.g3d.base.VecmathJmeTools;
\r
26 import com.jme.math.Vector3f;
\r
27 import com.jme.renderer.ColorRGBA;
\r
28 import com.jme.scene.Line;
\r
29 import com.jme.scene.state.MaterialState;
\r
30 import com.jme.util.geom.BufferUtils;
\r
32 public class SelectSplitPointAction extends InteractiveAction {
\r
42 SplitPointListener listener;
\r
44 public SelectSplitPointAction(ThreeDimensionalEditorBase parent, SplitPointListener listener) {
\r
46 this.listener = listener;
\r
50 public void setSplit(Point3d start, Point3d end) {
\r
53 dir = new Vector3d(end);
\r
59 public void activate() {
\r
60 if (start == null) throw new RuntimeException("Starting split action without information about range");
\r
62 // start = new Point3d();
\r
63 // end = new Point3d();
\r
64 // PipingTools.getStraightPipeEnds(PipingTools.getPipeline(straight),
\r
65 // straight, startStart, startEnd);
\r
68 MaterialState ms = parent.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();
\r
69 ms.setEmissive(new ColorRGBA(1.f,1.f,1.f,1.f));
\r
70 line.setRenderState(ms);
\r
71 parent.getRenderingComponent().getNoShadowRoot().attachChild(line);
\r
77 public boolean usable(Graph graph, List<Resource> resources) {
\r
78 // if (resources.size() != 1)
\r
80 // IEntity entity = EntityFactory.create(graph, resources.get(0));
\r
81 // if (entity.isInstanceOf(ProcessResource.plant3Dresource.VariableLengthInlineComponent)) {
\r
84 // This is not a standalone action
\r
89 public void deactivate() {
\r
90 line.removeFromParent();
\r
98 public boolean active() {
\r
103 public void update() {
\r
107 if (input.mouseClicked() && input.clickButton() == MouseEvent.BUTTON3) {
\r
108 listener.setSplitPoint(null);
\r
112 Vector3d o = new Vector3d();
\r
113 Vector3d d = new Vector3d();
\r
114 parent.createPickRay(o, d);
\r
116 Vector3d normal = parent.getCamera().getUnNormalizedHeading();
\r
117 normal.normalize();
\r
119 // reference point for selection line
\r
120 Vector3d point = new Vector3d(start);
\r
121 Vector3d currentPoint = new Vector3d();
\r
122 MathTools.intersectStraightPlane(o, d, point, normal, currentPoint);
\r
123 Point3d startPoint = new Point3d();
\r
124 double mu[] = new double[2];
\r
125 MathTools.intersectStraightStraight(start, dir, o, d, startPoint,
\r
126 new Point3d(), mu);
\r
127 // startPoint of branch must be between pipe ends
\r
128 // TODO : take account sizes of elbows (or other components)
\r
130 startPoint.set(start);
\r
131 else if (mu[0] > 1.0)
\r
132 startPoint.set(end);
\r
134 Vector3f verts[] = new Vector3f[2];
\r
135 verts[0] = VecmathJmeTools.get(startPoint);
\r
136 verts[1] = VecmathJmeTools.get(currentPoint);
\r
137 line.reconstruct(BufferUtils.createFloatBuffer(verts), null, null, null);
\r
139 parent.setViewChanged(true);
\r
140 if (input.mouseClicked() && input.clickButton() == MouseEvent.BUTTON1) {
\r
141 listener.setSplitPoint(new Point3d(startPoint));
\r