+++ /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.util.List;\r
-\r
-import javax.vecmath.AxisAngle4f;\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.layer0.utils.EntityFactory;\r
-import org.simantics.layer0.utils.IEntity;\r
-import org.simantics.processeditor.Activator;\r
-import org.simantics.processeditor.ProcessResource;\r
-import org.simantics.processeditor.common.ControlPointTools;\r
-import org.simantics.processeditor.stubs.DirectedControlPoint;\r
-import org.simantics.processeditor.stubs.PipeControlPoint;\r
-import org.simantics.processeditor.stubs.VariableAngleTurnComponent;\r
-import org.simantics.proconf.g3d.actions.ConstrainedTransformAction;\r
-import org.simantics.proconf.g3d.actions.TranslateActionConstraints;\r
-import org.simantics.proconf.g3d.base.G3DAPI;\r
-import org.simantics.proconf.g3d.base.G3DTools;\r
-import org.simantics.proconf.g3d.base.MathTools;\r
-import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
-import org.simantics.proconf.g3d.gizmo.TransformInlineGizmo;\r
-import org.simantics.proconf.g3d.scenegraph.IGraphicsNode;\r
-import org.simantics.proconf.g3d.stubs.G3DNode;\r
-\r
-\r
-public class TranslateElbowAction extends ConstrainedTransformAction {\r
-\r
- TransformInlineGizmo gizmo;\r
- List<IGraphicsNode> mos;\r
- Vector3d dir;\r
- Vector3d orgPos;\r
- double istep = 10.0;\r
- int decimals = 2;\r
- \r
- private Resource pcpResource;\r
- \r
- public TranslateElbowAction(ThreeDimensionalEditorBase parent) {\r
- super(parent);\r
- gizmo = new TransformInlineGizmo(component.getDisplaySystem().getRenderer());\r
- \r
- \r
- }\r
- \r
- public void init() {\r
- this.setText("Translate directed");\r
- this.setToolTipText("Translate the elbow in connections direction");\r
- this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/translate_d.png"));\r
- }\r
- \r
- \r
- \r
- @Override\r
- public boolean usable(Graph graph, List<Resource> resources) {\r
- // TODO : it should be possible to move multiple components on the same straight\r
- // TODO : checking against elbow and dcp; these are not correct!\r
- if (resources.size() != 1)\r
- return false;\r
- IEntity r = EntityFactory.create(graph,resources.get(0));\r
- if (r.isInstanceOf(ProcessResource.plant3Dresource.VariableAngleTurnComponent)) {\r
- VariableAngleTurnComponent e = new VariableAngleTurnComponent(r);\r
- PipeControlPoint pcp = e.getControlPoint();\r
- PipeControlPoint prev = ControlPointTools.findPreviousEnd(pcp);\r
- PipeControlPoint next = ControlPointTools.findNextEnd(pcp);\r
- DirectedControlPoint dcp = null;\r
- int directedCount = 0;\r
- if (prev != null && prev.isInstanceOf(ProcessResource.plant3Dresource.DirectedControlPoint)) {\r
- directedCount++;\r
- dcp = new DirectedControlPoint(prev);\r
- }\r
- if (next != null && next.isInstanceOf(ProcessResource.plant3Dresource.DirectedControlPoint)) {\r
- directedCount++;\r
- dcp = new DirectedControlPoint(next);\r
- }\r
- if (directedCount == 1) {\r
- orgPos = G3DTools.getVector(dcp.getWorldPosition());\r
- dir = ControlPointTools.getDirectedControlPointDirection(dcp);\r
- pcpResource = pcp.getResource();\r
- return true;\r
- }\r
- } \r
- return false;\r
-\r
- }\r
- \r
- @Override\r
- public void deactivate() {\r
- parent.setGizmo(null);\r
- super.deactivate();\r
- }\r
-\r
- @Override\r
- public void activate() {\r
- parent.setGizmo(gizmo);\r
-\r
- String text = "";\r
- mos = parent.getSelectionAdapter().getSelectedObjects();\r
-// for (IGraphicsNode mo : mos) {\r
-// text += GraphicsNodeTools.getWorldTranslation(mo.getGraphicsNode());//mo.getWorldPosition() + " ";\r
-// }\r
-\r
- mos.iterator().next().getGroup().attachChild(gizmo.getNode());\r
- setInfoText(text); \r
- \r
- Vector3d front = new Vector3d(1.0,0.0,0.0);\r
- Vector3d current = new Vector3d(dir);\r
- float angle = (float)current.angle(front);\r
- AxisAngle4f aa;\r
- if (angle < 0.01 || (Math.PI - angle) < 0.01) {\r
- aa = new AxisAngle4f();\r
- } else {\r
- current.normalize();\r
- Vector3d right = new Vector3d();\r
- right.cross(front, current);\r
-\r
- right.normalize();\r
- if (right.lengthSquared() < 0.01) {\r
- aa = new AxisAngle4f();\r
- } else {\r
- aa = new AxisAngle4f((float) right.x, (float) right.y, (float) right.z, angle);\r
- }\r
- }\r
- gizmo.setRotation(aa);\r
- \r
- updateGizmo();\r
- TranslateActionConstraints.addConstraints(new Resource[]{pcpResource}, detector);\r
- parent.setViewChanged(true);\r
- }\r
- \r
- \r
- \r
- Vector3d getTranslate() {\r
- Vector3d translate = new Vector3d();\r
- Vector3d o = new Vector3d();\r
- Vector3d d = new Vector3d();\r
- parent.createPickRay(o, d);\r
- //Vector3d p = gizmo.getPosition();\r
- if (gizmo.isSelected()) {\r
- double s[] = new double[1];\r
- \r
- Vector3d i1 = new Vector3d();\r
- Vector3d i2 = new Vector3d();\r
- s = new double[2];\r
- MathTools.intersectStraightStraight(orgPos, dir,o, d, i2, i1,s);\r
- translate.set(dir);\r
- if (s[0] < 0.0)\r
- s[0] = 0.0;\r
- \r
- translate.scale(s[0]);\r
- translate.add(orgPos);\r
- \r
- if (useConstraints) {\r
- Vector3d t = new Vector3d(translate);\r
-// FIXME : snapped point may be outside of proper range\r
- Point3d snap = detector.getPointSnap2(t, dir);\r
- if (snap != null) {\r
- translate = new Vector3d(snap);\r
- }\r
- }\r
- \r
- return translate;\r
- }\r
- return null;\r
- }\r
- \r
- Vector3d prevTranslate = new Vector3d();\r
- \r
- @Override\r
- public void doChanges(Graph g) throws Exception {\r
- if (input.mousePressed()) {\r
- //prevTranslate = getTranslate();\r
- \r
- }\r
- if (input.mouseClicked()) {\r
- end();\r
- return;\r
- }\r
- if (!input.mouseDragged()) {\r
- parent.getDefaultAction().update();\r
- return;\r
- } \r
- parent.setViewChanged(true);\r
- \r
- \r
- List<IGraphicsNode> mos = parent.getSelectionAdapter().getSelectedObjects();\r
- Vector3d translate = getTranslate();\r
- \r
- if (translate == null) {\r
- //cameraRotateAction.update();\r
- parent.getDefaultAction().update();\r
- updateGizmo();\r
- return;\r
- }\r
-\r
- String text = "";\r
- for (IGraphicsNode mo : mos) {\r
- G3DNode node = mo.getG3DNode(g);\r
- G3DAPI.setWorldPosition(node, translate);\r
- //G3DTools.setTuple3(node.getW, translation)\r
- //G3DTools.setLocalTranslation(node,translate);\r
- // mo.setLocalTranslation(translate);\r
- text += G3DTools.getVector(node.getWorldPosition()) + " " + translate;// mo.getWorldPosition() + " " +\r
- \r
- }\r
- setInfoText(text);\r
-\r
- updateGizmo();\r
-\r
- }\r
- \r
- protected void updateGizmo() {\r
- gizmo.update(camera.getCameraPos(),component);\r
- }\r
- \r
- public void setInfoText(String text) {\r
- \r
- }\r
-\r
-}
\ No newline at end of file