+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.processeditor.actions;\r
-\r
-import java.awt.event.MouseEvent;\r
-import java.util.List;\r
-\r
-import javax.vecmath.Point3d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.simantics.db.Graph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.proconf.g3d.actions.InteractiveAction;\r
-import org.simantics.proconf.g3d.base.MathTools;\r
-import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
-import org.simantics.proconf.g3d.base.VecmathJmeTools;\r
-\r
-import com.jme.math.Vector3f;\r
-import com.jme.renderer.ColorRGBA;\r
-import com.jme.scene.Line;\r
-import com.jme.scene.state.MaterialState;\r
-import com.jme.util.geom.BufferUtils;\r
-\r
-public class SelectSplitPointAction extends InteractiveAction {\r
- \r
- Point3d start;\r
- Point3d end;\r
- Vector3d dir;\r
- \r
- Line line;\r
- \r
- boolean activated;\r
- \r
- SplitPointListener listener;\r
- \r
- public SelectSplitPointAction(ThreeDimensionalEditorBase parent, SplitPointListener listener) {\r
- super(parent);\r
- this.listener = listener;\r
- }\r
- \r
- \r
- public void setSplit(Point3d start, Point3d end) {\r
- this.start = start;\r
- this.end = end;\r
- dir = new Vector3d(end);\r
- dir.sub(start);\r
- }\r
- \r
- \r
- @Override\r
- public void activate() {\r
- if (start == null) throw new RuntimeException("Starting split action without information about range");\r
- \r
-// start = new Point3d();\r
-// end = new Point3d();\r
-// PipingTools.getStraightPipeEnds(PipingTools.getPipeline(straight),\r
-// straight, startStart, startEnd);\r
- \r
- line = new Line();\r
- MaterialState ms = parent.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();\r
- ms.setEmissive(new ColorRGBA(1.f,1.f,1.f,1.f));\r
- line.setRenderState(ms);\r
- parent.getRenderingComponent().getNoShadowRoot().attachChild(line);\r
- activated = true;\r
- \r
- }\r
- \r
- @Override\r
- public boolean usable(Graph graph, List<Resource> resources) {\r
-// if (resources.size() != 1)\r
-// return false;\r
-// IEntity entity = EntityFactory.create(graph, resources.get(0));\r
-// if (entity.isInstanceOf(ProcessResource.plant3Dresource.VariableLengthInlineComponent)) {\r
-// return true;\r
-// }\r
- // This is not a standalone action\r
- return false;\r
- }\r
- \r
- @Override\r
- public void deactivate() {\r
- line.removeFromParent();\r
- activated = false;\r
- start = null;\r
- end = null;\r
- dir = null;\r
- \r
- }\r
- \r
- public boolean active() {\r
- return activated;\r
- }\r
- \r
- @Override\r
- public void update() {\r
- if (!activated) {\r
- return;\r
- }\r
- if (input.mouseClicked() && input.clickButton() == MouseEvent.BUTTON3) {\r
- listener.setSplitPoint(null);\r
- activated = false;\r
- return;\r
- }\r
- Vector3d o = new Vector3d();\r
- Vector3d d = new Vector3d();\r
- parent.createPickRay(o, d);\r
-\r
- Vector3d normal = parent.getCamera().getUnNormalizedHeading();\r
- normal.normalize();\r
- normal.negate();\r
- // reference point for selection line\r
- Vector3d point = new Vector3d(start);\r
- Vector3d currentPoint = new Vector3d();\r
- MathTools.intersectStraightPlane(o, d, point, normal, currentPoint);\r
- Point3d startPoint = new Point3d();\r
- double mu[] = new double[2];\r
- MathTools.intersectStraightStraight(start, dir, o, d, startPoint,\r
- new Point3d(), mu);\r
- // startPoint of branch must be between pipe ends\r
- // TODO : take account sizes of elbows (or other components)\r
- if (mu[0] < 0.0)\r
- startPoint.set(start);\r
- else if (mu[0] > 1.0)\r
- startPoint.set(end);\r
-\r
- Vector3f verts[] = new Vector3f[2];\r
- verts[0] = VecmathJmeTools.get(startPoint);\r
- verts[1] = VecmathJmeTools.get(currentPoint);\r
- line.reconstruct(BufferUtils.createFloatBuffer(verts), null, null, null);\r
-\r
- parent.setViewChanged(true);\r
- if (input.mouseClicked() && input.clickButton() == MouseEvent.BUTTON1) {\r
- listener.setSplitPoint(new Point3d(startPoint));\r
- }\r
- \r
- }\r
-}\r