From 44a50a069b398c1830f49d4c0af361220b43069d Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 12 Nov 2019 13:26:22 +0200 Subject: [PATCH 01/16] Use FileLocator.toFileURL to get access to image files gitlab #52 Change-Id: I307a0042b7131502452949d79005d24f198c4cca --- .../org/simantics/g3d/tools/PluginTools.java | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/org.simantics.g3d/src/org/simantics/g3d/tools/PluginTools.java b/org.simantics.g3d/src/org/simantics/g3d/tools/PluginTools.java index 296f1a11..7d4fa67b 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/tools/PluginTools.java +++ b/org.simantics.g3d/src/org/simantics/g3d/tools/PluginTools.java @@ -1,39 +1,39 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g3d.tools; - -import java.io.File; -import java.net.URL; - -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.osgi.framework.Bundle; - -public class PluginTools { - - public static String getAbsolutePath(Bundle inBundle, String fullpath) { - IPath path = new Path(fullpath); - URL u = FileLocator.find(inBundle, path, null); - if (u != null) { - try { - u = FileLocator.resolve(u); - if ("file".equals(u.getProtocol())) { - return new File(u.getFile()).getAbsolutePath(); - } - } catch (Exception e) { - } - } - return null; - } - -} +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.tools; + +import java.io.File; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.osgi.framework.Bundle; + +public class PluginTools { + + public static String getAbsolutePath(Bundle inBundle, String fullpath) { + IPath path = new Path(fullpath); + URL u = FileLocator.find(inBundle, path, null); + if (u != null) { + try { + u = FileLocator.toFileURL(u); + if ("file".equals(u.getProtocol())) { + return new File(u.getFile()).getAbsolutePath(); + } + } catch (Exception e) { + } + } + return null; + } + +} -- 2.45.2 From e9091a5c65126eec0d96a75d435fe6ea4cab0412 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Tue, 12 Nov 2019 13:56:26 +0200 Subject: [PATCH 02/16] Disable outline page DEBUG option from product builds gitlab #53 Change-Id: I6d9fff240ed19ac0e5085dc2db0693cea3e32180 --- .../src/org/simantics/plant3d/editor/P3DContentOutlinePage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java index f853a02f..893a0730 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DContentOutlinePage.java @@ -31,7 +31,7 @@ import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint; public class P3DContentOutlinePage extends VTKContentOutlinePage{ - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; protected Menu contextMenu; private LocalResourceManager manager = new LocalResourceManager(JFaceResources.getResources()); -- 2.45.2 From 452ed80b1d0bacd7632d482cef42367a491d4486 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Tue, 12 Nov 2019 14:02:41 +0200 Subject: [PATCH 03/16] Rename of getSubPoint in PipeControlPoint in SCL Change-Id: Ib8d4728bfad6aabb84ef9cbfd999e6f5861c8c5a --- .../scl/Plant3d/Scenegraph/PipelineComponent.scl | 1 + 1 file changed, 1 insertion(+) diff --git a/org.simantics.plant3d/scl/Plant3d/Scenegraph/PipelineComponent.scl b/org.simantics.plant3d/scl/Plant3d/Scenegraph/PipelineComponent.scl index cc75aab2..f56444e2 100644 --- a/org.simantics.plant3d/scl/Plant3d/Scenegraph/PipelineComponent.scl +++ b/org.simantics.plant3d/scl/Plant3d/Scenegraph/PipelineComponent.scl @@ -171,6 +171,7 @@ importJava "org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint" wher isFixed :: PipeControlPoint -> Boolean + @JavaName getChildPoints getSubPoint :: PipeControlPoint -> [PipeControlPoint] getParentPoint :: PipeControlPoint -> Maybe PipeControlPoint -- 2.45.2 From 31fd8b586a816e12d85f361b3fe2f6ebd52e427b Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 12 Nov 2019 15:34:48 +0200 Subject: [PATCH 04/16] Removing components left orphan piperuns in the plant gitlab #35 Change-Id: I428a58bf4e817816f2bb02d00186b41fa40a0527 --- .../plant3d/scenegraph/controlpoint/PipeControlPoint.java | 3 +++ .../plant3d/scenegraph/controlpoint/PipingRules.java | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java index 491a2733..20386b54 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java @@ -1079,6 +1079,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { if (currentNext == null && currentPrev == null) { removeComponent(); pipeRun.remChild(this); + checkRemove(pipeRun); return; } if (currentNext != null && currentPrev != null) { @@ -1350,6 +1351,8 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { pcp._remove(); // This call will recursively call also this method... return true; } + } else if (points.size() == 2) { + } return false; } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java index 3094f7d2..3ab4cca4 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java @@ -1671,7 +1671,11 @@ public class PipingRules { pcps.add(points); PipeControlPoint pcp = points.get(points.size()-1); if (pcp.getChildPoints().size() > 0) { - pipeRun = pcp.getChildPoints().get(0).getPipeRun(); + PipeRun pipeRun2 = pcp.getChildPoints().get(0).getPipeRun(); + if (pipeRun == pipeRun2) + break; + else + pipeRun = pipeRun2; } else { break; } -- 2.45.2 From 96b67feb92c117c72fb823b6fff5f89afa7ee631 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 12 Nov 2019 18:54:47 +0200 Subject: [PATCH 05/16] Editor internal toolbar for Plant3D editor gitlab #54 Change-Id: I68dece53eaad866e10d67e5920248c187a66b1ad --- .../simantics/g3d/vtk/swt/RotateAction.java | 78 ++++++-- .../g3d/vtk/swt/TranslateAction.java | 177 +++++++++++------- org.simantics.g3d/META-INF/MANIFEST.MF | 1 + .../simantics/g3d/toolbar/ToolComposite.java | 31 +++ .../plant3d/actions/RoutePipeAction.java | 122 +++++++++--- .../TranslateFreeVariableLengthAction.java | 5 +- .../actions/TranslateInlineAction.java | 10 +- .../plant3d/editor/Plant3DEditor.java | 28 ++- 8 files changed, 343 insertions(+), 109 deletions(-) create mode 100644 org.simantics.g3d/src/org/simantics/g3d/toolbar/ToolComposite.java diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java index 9cf39eff..f9ea1877 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java @@ -21,8 +21,13 @@ import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; import org.simantics.g3d.math.EulerTools; import org.simantics.g3d.math.EulerTools.Order; import org.simantics.g3d.math.MathTools; @@ -31,6 +36,7 @@ import org.simantics.g3d.preferences.PreferenceConstants; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.structural.IStructuralNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.Activator; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.gizmo.RotateAxisGizmo; @@ -77,6 +83,9 @@ public class RotateAction extends vtkSwtAction{ //AxisAngle4d rotation = new AxisAngle4d(); Quat4d worldOrientation = new Quat4d(); + protected ToolComposite toolComposite; + protected Combo axisCombo; + public void setNode(IG3DNode node) { this.node = node; if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) { @@ -105,12 +114,12 @@ public class RotateAction extends vtkSwtAction{ return node; } - public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { + public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { super(panel); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_rotate_clockwise.png")); setText("Rotate"); this.nodeMap = nodeMap; - + this.toolComposite = toolComposite; steps = 36; angles = new double[steps+1]; @@ -122,10 +131,41 @@ public class RotateAction extends vtkSwtAction{ dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_CROSS); } + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Rotate axis:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("Camera"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + index = c.getSelectionIndex(); + updateLock(); + panel.getComponent().setFocus(); + } + }); + axisCombo.select(index); + + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); + } + public void attach() { if (node == null) return; - + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { public void run() { @@ -139,7 +179,10 @@ public class RotateAction extends vtkSwtAction{ } public void deattach() { - + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + } node = null; nodeMap.commit("Rotate"); deattachUI(); @@ -184,11 +227,19 @@ public class RotateAction extends vtkSwtAction{ if (e.getKeyCode() == KeyEvent.VK_G) { worldCoord = !worldCoord; } - gizmo.setType(index); - panel.refresh(); + + updateLock(); + return true; } + private void updateLock() { + gizmo.setType(index); + if (axisCombo != null) + axisCombo.select(index); + panel.refresh(); + } + @Override public boolean keyReleased(KeyEvent e) { return false; @@ -227,7 +278,7 @@ public class RotateAction extends vtkSwtAction{ private void update() { Vector3d nodePos = node.getWorldPosition(); - System.out.println(nodePos); +// System.out.println(nodePos); gizmo.setPosition(nodePos); if (worldCoord) { gizmo.setRotation(new AxisAngle4d()); @@ -408,7 +459,7 @@ public class RotateAction extends vtkSwtAction{ // intersection point j.set(i2); i.cross(j, axis); - System.out.println("I,J " + i + " " + j); +// System.out.println("I,J " + i + " " + j); double angleI = i2.angle(i); double angleJ = i2.angle(j); prevAngle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); @@ -436,7 +487,7 @@ public class RotateAction extends vtkSwtAction{ taxis = new Vector3d(axis); MathTools.rotate(parentWorldOrientation, axis, axis); } - System.out.println(inputType); +// System.out.println(inputType); if (inputType == InputType.INTERSECT) { double s[] = new double[2]; @@ -446,7 +497,7 @@ public class RotateAction extends vtkSwtAction{ double angleI = i2.angle(i); double angleJ = i2.angle(j); double angle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); - System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); +// System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); if(!worldCoord) axis = taxis; if (useStep) { @@ -475,7 +526,7 @@ public class RotateAction extends vtkSwtAction{ //Quat4d q = MathTools.getQuat(euler); Quat4d q = EulerTools.getQuatFromEuler(order, euler); setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); } else { setOrientation(qrot); } @@ -530,7 +581,7 @@ public class RotateAction extends vtkSwtAction{ //Quat4d q = MathTools.getQuat(euler); Quat4d q = EulerTools.getQuatFromEuler(order, euler); setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); } else { setOrientation(qrot); } @@ -614,8 +665,7 @@ public class RotateAction extends vtkSwtAction{ case Z: return new Vector3d(0.0, 0.0, 1.0); case P: - Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera() - .GetDirectionOfProjection()); + Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera().GetDirectionOfProjection()); axis.normalize(); return axis; default: diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java index 32b97c1b..682112cf 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java @@ -22,13 +22,19 @@ import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.structural.IStructuralNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.Activator; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.gizmo.TranslateAxisGizmo; @@ -57,6 +63,9 @@ public class TranslateAction extends vtkSwtAction{ private Cursor activeCursor;// = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); private Cursor dragCursor;// = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); + protected ToolComposite toolComposite; + protected Combo axisCombo; + public void setNode(IG3DNode node) { this.node = node; if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) { @@ -70,7 +79,7 @@ public class TranslateAction extends vtkSwtAction{ return node; } - public TranslateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { + public TranslateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { super(panel); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_out.png")); setText("Translate"); @@ -78,11 +87,46 @@ public class TranslateAction extends vtkSwtAction{ activeCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND); dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZEALL); + this.toolComposite = toolComposite; + } + + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Translate direction:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("XY"); + axisCombo.add("XZ"); + axisCombo.add("YZ"); + axisCombo.add("Camera"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + index = c.getSelectionIndex(); + updateLock(); + panel.getComponent().setFocus(); + } + }); + axisCombo.select(index); + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); } public void attach() { if (node == null) return; + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { @@ -91,12 +135,13 @@ public class TranslateAction extends vtkSwtAction{ update(); } }); - - - } public void deattach() { + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + } node = null; nodeMap.commit("Translate"); @@ -142,13 +187,19 @@ public class TranslateAction extends vtkSwtAction{ if (e.getKeyCode() == KeyEvent.VK_G) { worldCoord = !worldCoord; } - gizmo.setType(index); + updateLock(); update(); //panel.repaint(); return true; } + private void updateLock() { + gizmo.setType(index); + if (axisCombo != null) + axisCombo.select(index); + panel.refresh(); + } @Override @@ -422,65 +473,65 @@ public class TranslateAction extends vtkSwtAction{ translate.x = s[0]; break; - case Y : - dir = new Vector3d(0.0,1.0,0.0); - if(!worldCoord) - MathTools.rotate(q, dir, dir); - i1 = new Vector3d(); - i2 = new Vector3d(); - s = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); - translate.y = s[0]; - break; - case Z : - dir = new Vector3d(0.0,0.0,1.0); - if(!worldCoord) - MathTools.rotate(q, dir, dir); - i1 = new Vector3d(); - i2 = new Vector3d(); - s = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); - translate.z = s[0]; - break; - case XY : - normal = new Vector3d(0.0,0.0,1.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.x = r.x; - translate.y = r.y; - } - break; - case XZ : - normal = new Vector3d(0.0,1.0,0.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.x = r.x; - translate.z = r.z; - } - break; - case YZ : - normal = new Vector3d(1.0,0.0,0.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.y = r.y; - translate.z = r.z; - } - break; - default : - - return null; + case Y : + dir = new Vector3d(0.0,1.0,0.0); + if(!worldCoord) + MathTools.rotate(q, dir, dir); + i1 = new Vector3d(); + i2 = new Vector3d(); + s = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); + translate.y = s[0]; + break; + case Z : + dir = new Vector3d(0.0,0.0,1.0); + if(!worldCoord) + MathTools.rotate(q, dir, dir); + i1 = new Vector3d(); + i2 = new Vector3d(); + s = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); + translate.z = s[0]; + break; + case XY : + normal = new Vector3d(0.0,0.0,1.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.x = r.x; + translate.y = r.y; + } + break; + case XZ : + normal = new Vector3d(0.0,1.0,0.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.x = r.x; + translate.z = r.z; + } + break; + case YZ : + normal = new Vector3d(1.0,0.0,0.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.y = r.y; + translate.z = r.z; } - translate.sub(offset); - return translate; + break; + default : + + return null; + } + translate.sub(offset); + return translate; } } diff --git a/org.simantics.g3d/META-INF/MANIFEST.MF b/org.simantics.g3d/META-INF/MANIFEST.MF index 7e889b35..d89a00f5 100644 --- a/org.simantics.g3d/META-INF/MANIFEST.MF +++ b/org.simantics.g3d/META-INF/MANIFEST.MF @@ -35,6 +35,7 @@ Export-Package: org.simantics.g3d, org.simantics.g3d.scenegraph.structural, org.simantics.g3d.scl, org.simantics.g3d.shape, + org.simantics.g3d.toolbar, org.simantics.g3d.tools, org.simantics.g3d.ui, org.simantics.g3d.wizard diff --git a/org.simantics.g3d/src/org/simantics/g3d/toolbar/ToolComposite.java b/org.simantics.g3d/src/org/simantics/g3d/toolbar/ToolComposite.java new file mode 100644 index 00000000..2fabeeee --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/toolbar/ToolComposite.java @@ -0,0 +1,31 @@ +package org.simantics.g3d.toolbar; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class ToolComposite extends Composite{ + + public ToolComposite(Composite parent, int style) { + super(parent, style|SWT.BORDER); + RowLayout layout = new RowLayout(); + layout.center = true; + layout.marginBottom = 1; + layout.marginTop = 1; + setLayout(layout); + } + + public void clear() { + Control children[] = getChildren(); + for (Control c : children) + c.dispose(); + relayout(); + } + + public void relayout() { + getParent().layout(true); + layout(true); + } + +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java index 9f523c95..389f3be5 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java @@ -13,11 +13,18 @@ import javax.vecmath.Point3d; import javax.vecmath.Tuple3d; import javax.vecmath.Vector3d; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Label; import org.simantics.db.Resource; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.base.INode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.tools.ConstraintDetector; import org.simantics.g3d.vtk.gizmo.TranslateAxisGizmo; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; @@ -47,7 +54,7 @@ import vtk.vtkTextActor; public class RoutePipeAction extends vtkSwtAction { enum LockType { - X, Y, Z, XY, YZ, XZ, NONE, CUSTOM + X, Y, Z, XY, XZ, YZ, NONE, CUSTOM }; LockType lock = LockType.NONE; @@ -91,11 +98,15 @@ public class RoutePipeAction extends vtkSwtAction { private Set allowed = new HashSet(); - public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root) { - this(panel,root, true); + protected ToolComposite toolComposite; + protected Combo axisCombo; + protected Button cameraButton; + + public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite) { + this(panel,root, toolComposite, true); } - public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, boolean allowBranches) { + public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite, boolean allowBranches) { super(panel); this.root = root; this.allowBranches = allowBranches; @@ -106,6 +117,7 @@ public class RoutePipeAction extends vtkSwtAction { terminalSelectionGizmo = new TerminalSelectionGizmo(panel); constraintPointGizmo = new ConstraintPointGizmo(panel); detector = new org.simantics.g3d.vtk.swt.ConstraintDetector(panel); + this.toolComposite = toolComposite; } public void setComponent(PipelineComponent component) { @@ -120,19 +132,69 @@ public class RoutePipeAction extends vtkSwtAction { setEnabled(allowed.size() > 0); } - public void deattach() { - deactivate(); - startComponent = null; - - deattachUI(); - super.deattach(); - panel.refresh(); - } + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Route direction:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("XY"); + axisCombo.add("XZ"); + axisCombo.add("YZ"); + axisCombo.add("None"); + axisCombo.add("Custom"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + setLockType(LockType.values()[c.getSelectionIndex()],false); + panel.getComponent().setFocus(); + + } + }); + axisCombo.select(lock.ordinal()); + cameraButton = new Button(toolComposite, SWT.TOGGLE); + cameraButton.setText("Camera"); + cameraButton.setSelection(useDefault); + cameraButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setUseDefault(((Button)e.getSource()).getSelection()); + panel.getComponent().setFocus(); + } + }); + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); + } + + public void deattach() { + deactivate(); + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + cameraButton = null; + } + + startComponent = null; + + deattachUI(); + super.deattach(); + panel.refresh(); + } public void attach() { if (startComponent == null) return; - + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { public void run() { @@ -236,19 +298,21 @@ public class RoutePipeAction extends vtkSwtAction { } } if (e.getKeyCode() == KeyEvent.VK_C) { - useDefault = !useDefault; - if (useDefault) - setInfoText("Rotating camera"); - System.out.println("UseDefault " + useDefault); + setUseDefault(!useDefault); } - - - update(); return true; } + private void setUseDefault(boolean b) { + useDefault = b; + if (useDefault) + setInfoText("Rotating camera"); + if (cameraButton != null) + cameraButton.setSelection(useDefault); + } + private void update() { panel.refresh(); @@ -387,6 +451,7 @@ public class RoutePipeAction extends vtkSwtAction { translateAxisGizmo.attach(panel); setPreviousPosition(previousPosition); updateCurrentPoint(); + updateWidget(); } protected void setPreviousPosition(Vector3d v) { @@ -433,6 +498,7 @@ public class RoutePipeAction extends vtkSwtAction { translateAxisGizmo.attach(panel); setPreviousPosition(previousPosition); updateCurrentPoint(); + updateWidget(); } private void activateSplit(PipeControlPoint start) throws Exception{ @@ -482,7 +548,10 @@ public class RoutePipeAction extends vtkSwtAction { } private void setLockType(LockType type, boolean force) { - if (force || (lock != LockType.CUSTOM || !lockForced) ) { + if (type == LockType.CUSTOM && (direction == null || added.size() > 0)) { + // nothing to do.. + } else if (force || (lock != LockType.CUSTOM || !lockForced || added.size() > 0) ) { + lock = type; switch (lock) { @@ -510,7 +579,16 @@ public class RoutePipeAction extends vtkSwtAction { break; } + } + updateWidget(); + } + + private void updateWidget() { + if (axisCombo != null) { + axisCombo.select(lock.ordinal()); + axisCombo.setEnabled(!lockForced || lock != LockType.CUSTOM); + } } @Override @@ -557,7 +635,7 @@ public class RoutePipeAction extends vtkSwtAction { addPoint(); } } else { - throw new RuntimeException("RoutePipeAction initlialization has been failed, no added components found"); + throw new RuntimeException("RoutePipeAction initialization has failed, no added components found"); // // user was selecting position of branch // lastPoint.set(startPoint); // controlPoints.add(new Point3d(startPoint)); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java index b76989e1..c9bdea17 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java @@ -7,6 +7,7 @@ import javax.vecmath.Vector3d; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.IG3DNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; import org.simantics.g3d.vtk.utils.vtkUtil; import org.simantics.plant3d.Activator; @@ -23,8 +24,8 @@ public class TranslateFreeVariableLengthAction extends RoutePipeAction{ private InlineComponent component; - public TranslateFreeVariableLengthAction(InteractiveVtkComposite panel, P3DRootNode root) { - super(panel, root, false); + public TranslateFreeVariableLengthAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite) { + super(panel, root, toolComposite, false); setText("Translate"); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png")); } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java index 3c5886d8..9001d0a7 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java @@ -10,6 +10,7 @@ import org.simantics.g3d.math.MathTools; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.base.INode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; import org.simantics.g3d.vtk.swt.TranslateAction; @@ -27,8 +28,8 @@ public class TranslateInlineAction extends TranslateAction{ private Vector3d e; private Vector3d dir; - public TranslateInlineAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { - super(panel, nodeMap); + public TranslateInlineAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { + super(panel, nodeMap, toolComposite); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png")); } @@ -89,6 +90,11 @@ public class TranslateInlineAction extends TranslateAction{ } } + @Override + protected void createTools(ToolComposite toolComposite) { + + } + @Override public boolean keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 5d755d06..4059d938 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -8,9 +8,12 @@ import java.util.Set; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.layout.FillLayout; @@ -25,6 +28,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.RenderListener; import org.simantics.g3d.scenegraph.base.INode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.action.RemoveAction; import org.simantics.g3d.vtk.common.HoverHighlighter; import org.simantics.g3d.vtk.common.NodeSelectionProvider2; @@ -89,10 +93,12 @@ import vtk.vtkSimpleMotionBlurPass; public class Plant3DEditor extends ResourceEditorPart { private Composite parent; + protected ToolComposite toolComposite; private Resource input; // private InteractiveVtkPanel panel; // private SWTAWTComponent component; private InteractiveVtkComposite panel; + private P3DRootNode rootNode; private IMapping mapping; @@ -117,7 +123,9 @@ public class Plant3DEditor extends ResourceEditorPart { @Override public void createPartControl(Composite parent) { this.parent = parent; - parent.setLayout (new FillLayout ()); + //parent.setLayout (new FillLayout ()); + + // component = new SWTAWTComponent(parent,SWT.NONE) { // // @Override @@ -134,9 +142,17 @@ public class Plant3DEditor extends ResourceEditorPart { IResourceEditorInput rei = (IResourceEditorInput)getEditorInput(); input = rei.getResource(); + toolComposite = new ToolComposite(parent, SWT.BORDER); + toolComposite.setVisible(true); + panel = new InteractiveVtkComposite(parent); + GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(parent); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(getPanel().getComponent()); + + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(toolComposite); + //IActionBars actionBars = getEditorSite().getActionBars(); hookContextMenu(); @@ -246,13 +262,13 @@ public class Plant3DEditor extends ResourceEditorPart { protected void createActions() { focusAction = new FocusAction(panel, cameraAction); - translateAction = new TranslateAction(panel,nodeMap); - translateInlineAction = new TranslateInlineAction(panel, nodeMap); - translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode()); - rotateAction = new RotateAction(panel,nodeMap); + translateAction = new TranslateAction(panel,nodeMap,toolComposite); + translateInlineAction = new TranslateInlineAction(panel, nodeMap,toolComposite); + translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode(), toolComposite); + rotateAction = new RotateAction(panel,nodeMap,toolComposite); removeAction = new RemoveAction(nodeMap); removeSplitAction = new RemoveAndSplitAction(nodeMap); - routePipeAction = new RoutePipeAction(panel,rootNode); + routePipeAction = new RoutePipeAction(panel,rootNode, toolComposite); addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri()); reversePipeRunAction = new ReversePipeRunAction(nodeMap); } -- 2.45.2 From 4dce64449d13ec20bb509954298168bd1dfe160b Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 14 Nov 2019 17:38:15 +0200 Subject: [PATCH 06/16] Loading VTK dlls with plug-in activator. gitlab #50 Change-Id: Iae39a7d1e38e48156a532b5002b7c88edfa1d709 (cherry picked from commit 3523a218827de60e1aa4ce7be126342418ddb054) --- vtk/META-INF/MANIFEST.MF | 3 +++ vtk/src/vtk/Activator.java | 19 +++++++++++++++++++ vtk/src/vtk/vtkJavaDep.java | 31 +++++++++++++++++++------------ vtk/src/vtk/vtkObjectBase.java | 1 - 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 vtk/src/vtk/Activator.java diff --git a/vtk/META-INF/MANIFEST.MF b/vtk/META-INF/MANIFEST.MF index 641b1d16..ac7adfe2 100644 --- a/vtk/META-INF/MANIFEST.MF +++ b/vtk/META-INF/MANIFEST.MF @@ -6,3 +6,6 @@ Bundle-Version: 8.2.0.qualifier Automatic-Module-Name: vtk Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: vtk +Bundle-ActivationPolicy: lazy +Bundle-Activator: vtk.Activator +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.13.0" diff --git a/vtk/src/vtk/Activator.java b/vtk/src/vtk/Activator.java new file mode 100644 index 00000000..98031ca8 --- /dev/null +++ b/vtk/src/vtk/Activator.java @@ -0,0 +1,19 @@ +package vtk; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + @Override + public void start(BundleContext context) throws Exception { + vtkJavaDep.load(); + + } + + @Override + public void stop(BundleContext context) throws Exception { + + } + +} diff --git a/vtk/src/vtk/vtkJavaDep.java b/vtk/src/vtk/vtkJavaDep.java index c482235a..0377199e 100644 --- a/vtk/src/vtk/vtkJavaDep.java +++ b/vtk/src/vtk/vtkJavaDep.java @@ -8,7 +8,6 @@ package vtk; */ public class vtkJavaDep { static String[] libs = new String[] { - "jawt", "vtksys", "vtkCommonCore", "vtkWrappingJava", @@ -121,20 +120,28 @@ public class vtkJavaDep { "vtkIOImportJava", }; + + private static boolean loaded = false; + static void load() { + if (!loaded) { - static { - try { - Class.forName("java.awt.Toolkit"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException(e); - } + try { + Class.forName("java.awt.Toolkit"); + } catch (ClassNotFoundException e) { + throw new IllegalStateException(e); + } + try { + System.loadLibrary("jawt"); + } catch (UnsatisfiedLinkError e) { + // bypass potential load error. If jawt is not really loaded, we will get errors + // with VTK dlls. + } - for (String lib : libs) - System.loadLibrary(lib); - } - - static void load() { + for (String lib : libs) + System.loadLibrary(lib); + loaded = true; + } } } diff --git a/vtk/src/vtk/vtkObjectBase.java b/vtk/src/vtk/vtkObjectBase.java index 5b88cd51..539aa966 100644 --- a/vtk/src/vtk/vtkObjectBase.java +++ b/vtk/src/vtk/vtkObjectBase.java @@ -44,7 +44,6 @@ public class vtkObjectBase public static vtk.vtkJavaMemoryManager JAVA_OBJECT_MANAGER = new vtk.vtkJavaMemoryManagerImpl(); public vtkObjectBase() { - vtkJavaDep.load(); this.vtkId = this.VTKInit(); vtkObjectBase.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this); } -- 2.45.2 From 5ed9e84f079af0000885f74a91845bb298e9a362 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Fri, 15 Nov 2019 13:49:33 +0200 Subject: [PATCH 07/16] Tag user modifiable length With modifiable tag, we can ask for length parameter when we insert new components gitlab #26 Change-Id: Ic98a1b491bb8223d28bdca570af5fc792df3fe6c (cherry picked from commit daa07327bd3222487742965d433ea2f041e5ae73) --- org.simantics.plant3d.ontology/graph/plant3d.pgraph | 7 +++---- .../plant3d/dialog/ComponentSelectionDialog.java | 4 ++-- .../simantics/plant3d/scenegraph/InlineComponent.java | 4 ++++ .../plant3d/scenegraph/PipelineComponent.java | 6 ++++++ .../scenegraph/controlpoint/ControlPointFactory.java | 11 +++++++++++ .../scenegraph/controlpoint/PipeControlPoint.java | 10 ++++++++++ .../org/simantics/plant3d/utils/ComponentUtils.java | 8 +++++--- .../src/org/simantics/plant3d/utils/Item.java | 9 +++++++++ .../src/org/simantics/plant3d/utils/P3DUtil.java | 2 ++ 9 files changed, 52 insertions(+), 9 deletions(-) diff --git a/org.simantics.plant3d.ontology/graph/plant3d.pgraph b/org.simantics.plant3d.ontology/graph/plant3d.pgraph index 5621443e..d6029cc6 100644 --- a/org.simantics.plant3d.ontology/graph/plant3d.pgraph +++ b/org.simantics.plant3d.ontology/graph/plant3d.pgraph @@ -56,15 +56,14 @@ P3D.TurnComponent parameters = new HashMap<>(getParameterMap()); + parameters.put(name, value); + setParameterMap(parameters); + } public abstract void setType(String typeURI) throws Exception; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java index 6b92e447..ff49b93a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java @@ -45,6 +45,7 @@ public class ControlPointFactory { PipeControlPoint pcp = new PipeControlPoint(component); pcp.setType(inst.type); pcp.setFixed(inst.fixed); + pcp.setMod(inst.mod); pcp.setRotate(inst.isRotate); pcp.setReverse(inst.isReverse); switch(inst.type) { @@ -58,6 +59,7 @@ public class ControlPointFactory { sub.parent = pcp; sub.setType(inst.type); sub.setFixed(inst.fixed); + sub.setMod(inst.mod); sub.setSub(true); sub.setDeletable(false); if (inst.isOffset) @@ -78,6 +80,7 @@ public class ControlPointFactory { private static class Instruction { PointType type; boolean fixed; + boolean mod; boolean isOffset; boolean isSizeChange; boolean isRotate; @@ -98,6 +101,7 @@ public class ControlPointFactory { i.isRotate = false; i.isReverse = false; i.type = PointType.INLINE; + i.mod = false; if (graph.isInheritedFrom(res, p3d.Nozzle)) { i.fixed = true; i.isOffset = false; @@ -110,6 +114,11 @@ public class ControlPointFactory { i.fixed = false; } else if (graph.hasStatement(res,p3d.FixedLengthInlineComponent)) { i.fixed = true; + } else if (graph.hasStatement(res,p3d.AdjustableLengthInlineComponent)) { + i.fixed = true; + i.mod = true; + } else { + throw new DatabaseException("Inline component type " + res + " does not have length configuration."); } if (graph.hasStatement(res,p3d.SizeChangeComponent)) { @@ -133,6 +142,8 @@ public class ControlPointFactory { i.fixed = false; } else if (graph.hasStatement(res,p3d.FixedAngleTurnComponent)) { i.fixed = true; + } else { + throw new DatabaseException("Turn component type " + res + " does not have angle configuration."); } } else if (graph.isInheritedFrom(res, p3d.EndComponent)) { i.fixed = false; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java index 20386b54..232b8ab4 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java @@ -36,6 +36,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { private PointType type; private boolean isFixed = true; // In-line: fixed-length Turn: fixed-angle + private boolean isMod = false; // Can user modify fixed value manually private boolean isRotate = false; // rotates around path leg axis. private boolean isReverse = false; // definition direction can be swapped private boolean isDeletable = true; // can be removed by rules @@ -88,6 +89,15 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { public void setFixed(boolean fixed) { this.isFixed = fixed; } + + @GetPropertyValue(name="Mod",tabId="Debug",value="mod") + public boolean isMod() { + return isMod; + } + + public void setMod(boolean isMod) { + this.isMod = isMod; + } @GetPropertyValue(name="Rotate",tabId="Debug",value="rotate") public boolean isRotate() { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 14dce68d..50ede807 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -329,7 +329,7 @@ public class ComponentUtils { PositionType insertPosition = inst.insertPosition; boolean lengthAdjustable = false; if (newComponent instanceof InlineComponent) { - lengthAdjustable = ((InlineComponent)newComponent).isVariableLength(); + lengthAdjustable = ((InlineComponent)newComponent).isVariableLength() || ((InlineComponent)newComponent).isModifialble(); } boolean insertAdjustable = false; if (component instanceof InlineComponent) { @@ -407,11 +407,13 @@ public class ComponentUtils { newComponent.setName(name); pipeRun.addChild(newComponent); - // TODO: these options are not stored into DB. Should they?! - if (newComponent instanceof InlineComponent && ((InlineComponent)newComponent).isVariableLength()) { + + if (newComponent instanceof InlineComponent && ((InlineComponent)newComponent).isVariableLength() ||((InlineComponent)newComponent).isModifialble()) { newPcp.setLength(inst.length); + newComponent.setParameter("length", inst.length); } else if (newComponent instanceof TurnComponent && ((TurnComponent)newComponent).isVariableAngle()) { newPcp.setTurnAngle(inst.angle); + newComponent.setParameter("turnAngle", inst.angle); } newComponent.updateParameters(); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java index e1faef34..799d0727 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java @@ -10,6 +10,7 @@ public class Item { private Type type; private boolean code = false; private boolean variable = false; + private boolean modifiable = false; private boolean sizeChange = false; @@ -52,6 +53,14 @@ public class Item { this.variable = variable; } + public boolean isModifiable() { + return modifiable; + } + + public void setModifiable(boolean modifiable) { + this.modifiable = modifiable; + } + public boolean isSizeChange() { return sizeChange; } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java index cb46546e..55cfead4 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java @@ -207,6 +207,8 @@ public class P3DUtil { if (graph.hasStatement(r, p3d.VariableAngleTurnComponent) || graph.hasStatement(r, p3d.VariableLengthInlineComponent)) item.setVariable(true); + if (graph.hasStatement(r, p3d.AdjustableLengthInlineComponent)) + item.setModifiable(true); if (graph.hasStatement(r, p3d.SizeChangeComponent)) item.setSizeChange(true); return item; -- 2.45.2 From 2a4aa4460d5df9da6b348adb2f5ba8c46b071520 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Fri, 15 Nov 2019 15:44:00 +0200 Subject: [PATCH 08/16] Combo property support for annotated property tabs gitlab #55 Change-Id: I4fde018ed47ccdc9f82e59bac51272ffebd8244b (cherry picked from commit 79528578707a2103753d895b520fdc6439f52d3e) --- ...nnotatedPropertyTabContributorFactory.java | 200 +++++++++++++++--- .../property/ComboPropertyManipulator.java | 89 ++++++++ .../g3d/property/ComboValueProvider.java | 10 + .../property/MethodComboValueProvider.java | 41 ++++ .../annotations/GetComboProperty.java | 23 ++ .../annotations/GetComboPropertyValue.java | 26 +++ .../annotations/SetComboPropertyValue.java | 23 ++ 7 files changed, 378 insertions(+), 34 deletions(-) create mode 100644 org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/property/ComboValueProvider.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/property/MethodComboValueProvider.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboProperty.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboPropertyValue.java create mode 100644 org.simantics.g3d/src/org/simantics/g3d/property/annotations/SetComboPropertyValue.java diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java b/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java index 7e3f8533..65b267cb 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java +++ b/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java @@ -39,6 +39,7 @@ import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener; import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent; +import org.eclipse.jface.viewers.ComboBoxCellEditor; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter; import org.eclipse.jface.viewers.ISelection; @@ -69,8 +70,11 @@ import org.eclipse.ui.IWorkbenchSite; import org.simantics.db.management.ISessionContext; import org.simantics.g3d.property.annotations.CompoundGetPropertyValue; import org.simantics.g3d.property.annotations.CompoundSetPropertyValue; +import org.simantics.g3d.property.annotations.GetComboProperty; +import org.simantics.g3d.property.annotations.GetComboPropertyValue; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.property.annotations.PropertyTabBlacklist; +import org.simantics.g3d.property.annotations.SetComboPropertyValue; import org.simantics.g3d.property.annotations.SetPropertyValue; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.NodeMap; @@ -186,6 +190,35 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri } item.setter = m; + } else if (annotation.annotationType().equals(GetComboPropertyValue.class)) { + GetComboPropertyValue get = (GetComboPropertyValue)annotation; + ComboPropertyItem item = (ComboPropertyItem)items.get(get.value()); + if (item == null) { + item = new ComboPropertyItem(get.value()); + items.put(item.id, item); + } + item.getter = m; + item.manipulatorClass = ComboPropertyManipulator.class; + + item.tabId = get.tabId(); + + item.name = get.name(); + } else if (annotation.annotationType().equals(SetComboPropertyValue.class)) { + SetComboPropertyValue set = (SetComboPropertyValue)annotation; + ComboPropertyItem item = (ComboPropertyItem)items.get(set.value()); + if (item == null) { + item = new ComboPropertyItem(set.value()); + items.put(item.id, item); + } + item.setter = m; + } else if (annotation.annotationType().equals(GetComboProperty.class)) { + GetComboProperty get = (GetComboProperty)annotation; + ComboPropertyItem item = (ComboPropertyItem)items.get(get.value()); + if (item == null) { + item = new ComboPropertyItem(get.value()); + items.put(item.id, item); + } + item.values = m; } } } @@ -249,9 +282,22 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri } } + private static PropertyManipulator createManipulator(ComboPropertyItem item, Object obj) { + try { + MethodComboValueProvider provider = new MethodComboValueProvider(item.getter, item.setter,item.values); + PropertyManipulator manipulator = item.manipulatorClass.getConstructor(ValueProvider.class,Object.class).newInstance(provider,obj); + return manipulator; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + private static interface IPropertyItem { public String getTabId(); public String getName(); + public String getId(); + public boolean editable(); } private static class PropertyItem implements IPropertyItem{ @@ -269,6 +315,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri this.id = id; } + @Override + public String getId() { + return id; + } + @Override public int hashCode() { return id.hashCode(); @@ -283,6 +334,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri public String getName() { return name; } + + @Override + public boolean editable() { + return setter != null; + } } private static class CompoundPropertyItem implements IPropertyItem{ @@ -300,6 +356,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri this.id = id; } + @Override + public String getId() { + return id; + } + @Override public int hashCode() { return id.hashCode(); @@ -314,8 +375,55 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri public String getName() { return name; } + + @Override + public boolean editable() { + return setter != null; + } } + private static class ComboPropertyItem implements IPropertyItem{ + private String id; + private String name; + private String tabId; + private Method getter; + private Method setter; + private Method values; + private Class manipulatorClass; + + + public ComboPropertyItem(String id) { + if (id == null) + throw new NullPointerException(); + this.id = id; + } + + @Override + public String getId() { + return id; + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public String getTabId() { + return tabId; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean editable() { + return setter != null; + } + } + private static class AnnotatedPropertyTabContributor implements PropertyTabContributor { private String id; List items; @@ -345,8 +453,8 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri private static class AnnotatedPropertyTab implements IPropertyTab2, NodeListener { //private String id; List contibutedItems; - List resolvedItems = new ArrayList(); - private Map manipulators = new HashMap(); + List resolvedItems = new ArrayList(); + private Map manipulators = new HashMap(); private TableViewer viewer; @@ -407,7 +515,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri @Override public void selectionChanged(SelectionChangedEvent event) { - PropertyItem item = AdaptationUtils.adaptToSingle(event.getSelection(), PropertyItem.class); + IPropertyItem item = AdaptationUtils.adaptToSingle(event.getSelection(), IPropertyItem.class); selectedItem = item; if (!manipulators.get(selectedItem).getEditMode()) manipulators.get(selectedItem).setEditMode(true); @@ -584,14 +692,18 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri if (item instanceof PropertyItem) { resolvedItems.add((PropertyItem)item); manipulators.put((PropertyItem)item, createManipulator((PropertyItem)item, node)); - } - else { + } else if (item instanceof ComboPropertyItem) { + resolvedItems.add((ComboPropertyItem)item); + manipulators.put((ComboPropertyItem)item, createManipulator((ComboPropertyItem)item, node)); + } else if (item instanceof CompoundPropertyItem) { CompoundPropertyItem compound = (CompoundPropertyItem)item; Map manipulators = createManipulators(compound, node); for (PropertyItem i : manipulators.keySet()) { resolvedItems.add(i); this.manipulators.put(i, manipulators.get(i)); } + } else { + } } @@ -688,7 +800,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri if (viewer.getTable().isDisposed()) return; if (DEBUG)System.out.println("Viewer refresh " + id); - for (PropertyItem item : resolvedItems) + for (IPropertyItem item : resolvedItems) if (!item.equals(selectedItem)) viewer.refresh(item); if (selectedItem != null) @@ -704,7 +816,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri return; } if (DEBUG) System.out.println("Viewer threaded refresh " + id); - for (PropertyItem item : resolvedItems) + for (IPropertyItem item : resolvedItems) if (!item.equals(selectedItem)) viewer.refresh(item); if (selectedItem != null) @@ -713,7 +825,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri } }); } else { - for (PropertyItem item : resolvedItems) { + for (IPropertyItem item : resolvedItems) { delayedUpdate.add(item); } } @@ -729,7 +841,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri } - public PropertyManipulator getManipulator(PropertyItem item) { + public PropertyManipulator getManipulator(IPropertyItem item) { return manipulators.get(item); } @@ -759,10 +871,10 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri @Override protected boolean canEdit(Object element) { - PropertyItem item = (PropertyItem)element; + IPropertyItem item = (IPropertyItem)element; if (tab.getManipulator(item).getValueCount() <= index) return false; - if (item.setter == null) + if (!item.editable()) return false; if (getValue(element) == null) return false; @@ -771,32 +883,52 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri @Override protected CellEditor getCellEditor(Object element) { - - if (tab.getManipulator((PropertyItem)element).getValueCount() <= index) + IPropertyItem item = (IPropertyItem)element; + if (tab.getManipulator(item).getValueCount() <= index) return null; if (editor == null) - editor = new TextCellEditor(viewer.getTable(),SWT.NONE) { - @Override - public void activate() { - tab.setEditing(true); - } - - @Override - public void deactivate() { - super.deactivate(); - tab.setEditing(false); - } - }; + if (item instanceof PropertyItem) + editor = new TextCellEditor(viewer.getTable(),SWT.NONE) { + @Override + public void activate() { + tab.setEditing(true); + } + + @Override + public void deactivate() { + super.deactivate(); + tab.setEditing(false); + } + }; + else if (item instanceof ComboPropertyItem) { + ComboPropertyItem comboPropertyItem = (ComboPropertyItem)item; + ComboPropertyManipulator manipulator = (ComboPropertyManipulator)tab.manipulators.get(comboPropertyItem); + editor = new ComboBoxCellEditor(viewer.getTable(), manipulator.getItems()) { + @Override + public void activate() { + tab.setEditing(true); + } + + @Override + public void deactivate() { + super.deactivate(); + tab.setEditing(false); + } + }; + } if (DEBUG)System.err.println("CELL EDITOR: " + element); return editor; } @Override protected Object getValue(Object element) { - PropertyItem item = (PropertyItem)element; + IPropertyItem item = (IPropertyItem)element; PropertyManipulator manipulator = tab.getManipulator(item);//createManipulator(item, obj); if (manipulator.getValueCount() <= index) return null; + if (manipulator instanceof ComboPropertyManipulator) { + return ((ComboPropertyManipulator)manipulator).getValueIndex(); + } Object value = manipulator.getValue(index); return value; } @@ -804,14 +936,14 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri @Override protected void setValue(Object element, Object value) { - PropertyItem item = (PropertyItem)element; + IPropertyItem item = (IPropertyItem)element; PropertyManipulator manipulator = tab.getManipulator(item);//createManipulator(item, obj); if (manipulator.getValueCount() <= index) throw new IllegalAccessError("Editing value in index " + index + " is not allowed."); if (DEBUG)System.err.println("CELL SET VALUE: " + element + " " + value); - manipulator.setValue((String)value,index); + manipulator.setValue(value.toString(),index); viewer.refresh(item); - nodeMap.commit("Set " + item.id + " value to " + value); + nodeMap.commit("Set " + item.getId() + " value to " + value); } @@ -824,12 +956,12 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri @Override public void update(ViewerCell cell) { - PropertyItem item = (PropertyItem)cell.getElement(); + IPropertyItem item = (IPropertyItem)cell.getElement(); - if (item.name.length() > 0) - cell.setText(item.name); + if (item.getName().length() > 0) + cell.setText(item.getName()); else - cell.setText(item.id); + cell.setText(item.getId()); } @@ -845,7 +977,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri @Override public void update(ViewerCell cell) { - PropertyItem item = (PropertyItem)cell.getElement(); + IPropertyItem item = (IPropertyItem)cell.getElement(); int index = cell.getColumnIndex() -1; PropertyManipulator manipulator = tab.getManipulator(item);//createManipulator(item, object); if (manipulator.getValueCount() <= index) diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java b/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java new file mode 100644 index 00000000..45a3b99a --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java @@ -0,0 +1,89 @@ +package org.simantics.g3d.property; + +import java.util.List; + +public class ComboPropertyManipulator implements PropertyManipulator{ + + ComboValueProvider provider; + Object input; + + boolean editMode; + + public ComboPropertyManipulator(ValueProvider provider, Object input) { + this.provider = (ComboValueProvider)provider; + this.input = input; + } + + @Override + public int getValueCount() { + return 1; + } + + @Override + public String getDescription(int i) { + if (i == 0) + return "Value"; + return null; + } + + @Override + public String getValue(int i) { + try { + Integer value = (Integer)provider.getValue(input); + if (value == null) return null; + return getItems()[value]; + } catch (Exception e) { + return null; + } + } + + @Override + public String setValue(String value, int i) { + try { + provider.setValue(input, Integer.parseInt(value)); + } catch (Exception e) { + return e.getMessage(); + } + return null; + } + + @Override + public boolean getEditMode() { + return editMode; + } + + @Override + public void setEditMode(boolean b) { + editMode = b; + } + + public String[] getItems() { + try { + List vals = provider.getValues(input); + String arr[] = new String[vals.size()]; + for (int i = 0; i < vals.size(); i++) { + arr[i] = vals.get(i).toString(); + } + return arr; + } catch (Exception e) { + return new String[0]; + } + } + + public Integer getValueIndex() { + try { + Integer value = (Integer)provider.getValue(input); + return value; + } catch (Exception e) { + return null; + } + } + + public Integer indexOf(String value) { + String[] items = getItems(); + for (int i = 0; i < items.length; i++) + if (items[i].equals(value)) + return i; + return -1; + } +} diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/ComboValueProvider.java b/org.simantics.g3d/src/org/simantics/g3d/property/ComboValueProvider.java new file mode 100644 index 00000000..30d2e33c --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/ComboValueProvider.java @@ -0,0 +1,10 @@ +package org.simantics.g3d.property; + +import java.util.List; + +public interface ComboValueProvider extends ValueProvider{ + + + public List getValues(Object obj) throws Exception; + +} diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/MethodComboValueProvider.java b/org.simantics.g3d/src/org/simantics/g3d/property/MethodComboValueProvider.java new file mode 100644 index 00000000..c1e21e07 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/MethodComboValueProvider.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.property; + +import java.lang.reflect.Method; +import java.util.List; + +public class MethodComboValueProvider implements ComboValueProvider { + + Method getter; + Method setter; + Method values; + + public MethodComboValueProvider(Method getter, Method setter, Method values) { + this.getter = getter; + this.setter = setter; + this.values = values; + } + + @Override + public Object getValue(Object obj) throws Exception{ + return getter.invoke(obj); + } + @Override + public void setValue(Object obj, Object value) throws Exception { + setter.invoke(obj,value); + } + + public List getValues(Object obj) throws Exception { + return (List)values.invoke(obj); + } +} diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboProperty.java b/org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboProperty.java new file mode 100644 index 00000000..ef019ae1 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboProperty.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.property.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface GetComboProperty { + String value(); +} diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboPropertyValue.java b/org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboPropertyValue.java new file mode 100644 index 00000000..5497b8e5 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/annotations/GetComboPropertyValue.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.property.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface GetComboPropertyValue { + String value(); + String name() default ""; + String tabId() default "Default"; + +} diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/annotations/SetComboPropertyValue.java b/org.simantics.g3d/src/org/simantics/g3d/property/annotations/SetComboPropertyValue.java new file mode 100644 index 00000000..08377372 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/annotations/SetComboPropertyValue.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.property.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface SetComboPropertyValue { + String value(); +} -- 2.45.2 From e96447c877fd9c3a4664c2593cfbae768d0c44d7 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Fri, 15 Nov 2019 15:48:22 +0200 Subject: [PATCH 09/16] Adjust turn component radius with combo box (instead of index value) gitlab #43 Change-Id: I5e5c5193c73bbad93c3eaa12fc58f1bc3a0598b8 (cherry picked from commit eb221ba65b20ba9e8477c653e1c10ae1c2a0a4d0) --- .../plant3d/scenegraph/TurnComponent.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java index cd490a5d..1bf67441 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java @@ -1,12 +1,17 @@ package org.simantics.plant3d.scenegraph; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.vecmath.Vector3d; import org.simantics.g3d.math.MathTools; +import org.simantics.g3d.property.annotations.GetComboProperty; +import org.simantics.g3d.property.annotations.GetComboPropertyValue; import org.simantics.g3d.property.annotations.GetPropertyValue; +import org.simantics.g3d.property.annotations.SetComboPropertyValue; import org.simantics.g3d.property.annotations.SetPropertyValue; import org.simantics.g3d.scenegraph.base.ParentNode; import org.simantics.g3d.tools.NodeTools; @@ -110,15 +115,14 @@ public class TurnComponent extends PipelineComponent { return getControlPoint().getTurnAxis(); } - @GetPropertyValue(name="Turn Radius", value="TurnRadius", tabId = "Default") - public Double getTurnRadius() { + public Double getTurnRadius() { if (turnRadiusIndex != null) return getPipeRun().getTurnRadiusArray()[turnRadiusIndex]; return getPipeRun().getTurnRadiusArray()[0]; } @RelatedGetValue(Plant3D.URIs.HasTurnRadiusIndex) - @GetPropertyValue(name="Turn Radius Index", value=Plant3D.URIs.HasTurnRadiusIndex, tabId = "Default") + @GetComboPropertyValue(name="Turn Radius", value=Plant3D.URIs.HasTurnRadiusIndex, tabId = "Default") public Integer getTurnRadiusIndex() { // TODO: For backwards compatibility, we do not accept null values. @@ -129,7 +133,7 @@ public class TurnComponent extends PipelineComponent { } @RelatedSetValue(Plant3D.URIs.HasTurnRadiusIndex) - @SetPropertyValue(value=Plant3D.URIs.HasTurnRadiusIndex) + @SetComboPropertyValue(value=Plant3D.URIs.HasTurnRadiusIndex) public void setTurnRadiusIndex(Integer turnRadiusIndex) { if (this.turnRadiusIndex == turnRadiusIndex) return; @@ -144,6 +148,15 @@ public class TurnComponent extends PipelineComponent { PipingRules.requestUpdate(getControlPoint()); } + @GetComboProperty(value=Plant3D.URIs.HasTurnRadiusIndex) + public List _getTurnRadii() { + List values = new ArrayList(); + for (double d : getPipeRun().getTurnRadiusArray()) + values.add(d); + return values; + } + + @RelatedGetValue(Plant3D.URIs.HasRotationAngle) @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default") public Double getRotationAngle() { -- 2.45.2 From 8f71b333e7b1d116e55c2d39054aeb90dd93028d Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Fri, 15 Nov 2019 17:32:41 +0200 Subject: [PATCH 10/16] Previous change caused ClassCastExceptions. gitlab #26 Change-Id: I018a488b099be724828f636fe91e6d1e2903f3dc (cherry picked from commit c451ced35ae144dbe52d7f09d8eed128c9e644ee) --- .../plant3d/utils/ComponentUtils.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 50ede807..939d1551 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -408,12 +408,18 @@ public class ComponentUtils { pipeRun.addChild(newComponent); - if (newComponent instanceof InlineComponent && ((InlineComponent)newComponent).isVariableLength() ||((InlineComponent)newComponent).isModifialble()) { - newPcp.setLength(inst.length); - newComponent.setParameter("length", inst.length); - } else if (newComponent instanceof TurnComponent && ((TurnComponent)newComponent).isVariableAngle()) { - newPcp.setTurnAngle(inst.angle); - newComponent.setParameter("turnAngle", inst.angle); + if (newComponent instanceof InlineComponent) { + InlineComponent inlineComponent = (InlineComponent)newComponent; + if (inlineComponent.isVariableLength()|| inlineComponent.isModifialble()) { + newPcp.setLength(inst.length); + newComponent.setParameter("length", inst.length); + } + } else if (newComponent instanceof TurnComponent) { + TurnComponent turnComponent = (TurnComponent)newComponent; + if (turnComponent.isVariableAngle()) { + newPcp.setTurnAngle(inst.angle); + newComponent.setParameter("turnAngle", inst.angle); + } } newComponent.updateParameters(); -- 2.45.2 From df57dcb3ec91ed3393991d6f890776772d742128 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 18 Nov 2019 13:27:16 +0200 Subject: [PATCH 11/16] Creating equipment with predefined nozzles. gitlab #27 Change-Id: I67d32b141c5c526d0215f5af3fd309d64962f49a (cherry picked from commit 9817ec2aa0d2afada7024d2aba0cd7562de317ed) --- .../plant3d/actions/AddEquipmentAction.java | 30 +++- .../plant3d/actions/AddEquipmentAction2.java | 45 +++++ .../dialog/ComponentSelectionDialog.java | 18 +- .../dialog/EquipmentSelectionDialog.java | 156 ++++++++++++++++++ .../plant3d/editor/Plant3DEditor.java | 7 +- .../plant3d/utils/ComponentUtils.java | 26 ++- 6 files changed, 270 insertions(+), 12 deletions(-) create mode 100644 org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java create mode 100644 org.simantics.plant3d/src/org/simantics/plant3d/dialog/EquipmentSelectionDialog.java diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java index ff87c4ea..7efb0f83 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java @@ -1,27 +1,47 @@ package org.simantics.plant3d.actions; import org.eclipse.jface.action.Action; +import org.eclipse.swt.widgets.Display; +import org.simantics.plant3d.dialog.EquipmentSelectionDialog; import org.simantics.plant3d.scenegraph.Equipment; import org.simantics.plant3d.scenegraph.P3DRootNode; import org.simantics.plant3d.utils.ComponentUtils; import org.simantics.plant3d.utils.Item; import org.simantics.utils.ui.ExceptionUtils; +/** + * Action that allows user to choose added Equipment with a dialog. + * + * @author luukkainen + * + */ public class AddEquipmentAction extends Action { P3DRootNode root; - private Item item; - public AddEquipmentAction(P3DRootNode root, Item item) { + private String libUri; + + public AddEquipmentAction(P3DRootNode root, String libUri) { this.root = root; - this.item = item; - setText("Add " + item.getName()); + this.libUri = libUri; + setText("Add equipment"); } @Override public void run() { + EquipmentSelectionDialog dialog = new EquipmentSelectionDialog(Display.getCurrent().getActiveShell(), root); + if (dialog.open() == EquipmentSelectionDialog.CANCEL) + return; + Item item = dialog.getSelected(); + if (item == null) + return; + Item selectedNozzle = dialog.getSelectedNozzle(); try { - Equipment equipment = ComponentUtils.createEquipment(root, item); + Equipment equipment = null; + if (selectedNozzle == null) + equipment = ComponentUtils.createEquipment(root, item); + else + equipment = ComponentUtils.createEquipmentWithNozzles(root, item, selectedNozzle); root.getNodeMap().commit("Add equipment " + equipment.getName()); } catch (Exception e) { ExceptionUtils.logAndShowError("Cannot create equipment",e); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java new file mode 100644 index 00000000..f232937f --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java @@ -0,0 +1,45 @@ +package org.simantics.plant3d.actions; + +import org.eclipse.jface.action.Action; +import org.simantics.plant3d.scenegraph.Equipment; +import org.simantics.plant3d.scenegraph.P3DRootNode; +import org.simantics.plant3d.utils.ComponentUtils; +import org.simantics.plant3d.utils.Item; +import org.simantics.utils.ui.ExceptionUtils; + +/** + * Action that creates given Equipment. + * + * @author luukkainen + * + */ +public class AddEquipmentAction2 extends Action { + + P3DRootNode root; + private Item item; + private Item nozzleItem; + + public AddEquipmentAction2(P3DRootNode root, Item item) { + this(root, item, null); + } + + public AddEquipmentAction2(P3DRootNode root, Item item, Item nozzleItem) { + this.root = root; + this.item = item; + setText("Add " + item.getName()); + } + + @Override + public void run() { + try { + Equipment equipment = null; + if (nozzleItem == null) + equipment = ComponentUtils.createEquipment(root, item); + else + equipment = ComponentUtils.createEquipmentWithNozzles(root, item, nozzleItem); + root.getNodeMap().commit("Add equipment " + equipment.getName()); + } catch (Exception e) { + ExceptionUtils.logAndShowError("Cannot create equipment",e); + } + } +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java index 75b12411..7c124eb0 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java @@ -97,6 +97,18 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange this.libUri = libUri; } + protected List getItems(Class c, String libUri) throws DatabaseException{ + if (InlineComponent.class.equals(c)) { + return P3DUtil.getInlines(libUri); + } else if (TurnComponent.class.equals(c)) { + return P3DUtil.getTurns(libUri); + } else if (EndComponent.class.equals(c)) { + return P3DUtil.getEnds(libUri); + } else { + return null; + } + } + @Override protected Control createDialogArea(Composite parent) { resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); @@ -123,9 +135,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange List turns = null; List inlines = null; try { - ends = P3DUtil.getEnds(libUri); - turns= P3DUtil.getTurns(libUri); - inlines = P3DUtil.getInlines(libUri); + ends = getItems(EndComponent.class, libUri); + turns= getItems(TurnComponent.class, libUri); + inlines = getItems(InlineComponent.class, libUri); } catch (DatabaseException e) { Label label = new Label(composite, SWT.NONE); label.setText("Cannot load pipeline components: " + e.getMessage()); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/EquipmentSelectionDialog.java b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/EquipmentSelectionDialog.java new file mode 100644 index 00000000..99ef9e7c --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/EquipmentSelectionDialog.java @@ -0,0 +1,156 @@ +package org.simantics.plant3d.dialog; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.ExpandBar; +import org.eclipse.swt.widgets.ExpandItem; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.simantics.db.exception.DatabaseException; +import org.simantics.plant3d.ontology.Plant3D; +import org.simantics.plant3d.scenegraph.Equipment; +import org.simantics.plant3d.scenegraph.InlineComponent; +import org.simantics.plant3d.scenegraph.Nozzle; +import org.simantics.plant3d.scenegraph.P3DRootNode; +import org.simantics.plant3d.scenegraph.PipelineComponent; +import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PositionType; +import org.simantics.plant3d.utils.Item; +import org.simantics.plant3d.utils.P3DUtil; +import org.simantics.utils.ui.ExceptionUtils; + +public class EquipmentSelectionDialog extends Dialog implements ISelectionChangedListener{ + + private ResourceManager resourceManager; + private String libUri; + private P3DRootNode root; + + private Item selected; + private Item selectedNozzle; + + ListViewer equipmentViewer; + ListViewer nozzleViewer; + + public EquipmentSelectionDialog(Shell parentShell, P3DRootNode root) { + this(parentShell,root,Plant3D.URIs.Builtin); + } + + public EquipmentSelectionDialog(Shell parentShell, P3DRootNode root, String libUri){ + super(parentShell); + this.root = root; + this.libUri = libUri; + } + + protected List getItems(Class c, String libUri) throws DatabaseException{ + if (Equipment.class.equals(c)) { + return P3DUtil.getEquipments(libUri); + } else if (Nozzle.class.equals(c)) { + return P3DUtil.getNozzles(libUri); + } + return null; + } + + @Override + protected Control createDialogArea(Composite parent) { + resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2,false); + layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + applyDialogFont(composite); + + List equipment = null; + List nozzles = null; + try { + equipment = getItems(Equipment.class, libUri); + nozzles = getItems(Nozzle.class, libUri); + } catch (DatabaseException e) { + Label label = new Label(composite, SWT.NONE); + label.setText("Cannot load equipment data: " + e.getMessage()); + ExceptionUtils.logError(e); + return composite; + } + ExpandBar expandBar = new ExpandBar(composite, SWT.NONE); + + ExpandItem equipmentItem = new ExpandItem(expandBar, SWT.NONE); + + equipmentItem.setText("Equipment"); + equipmentViewer = new ListViewer(expandBar); + equipmentViewer.setLabelProvider(new ComponentLabelProvider()); + equipmentViewer.setContentProvider(new ComponentContentProvider()); + + ExpandItem nozzleItem = new ExpandItem(expandBar, SWT.NONE); + + nozzleItem.setText("Nozzles"); + nozzleViewer = new ListViewer(expandBar); + nozzleViewer.setLabelProvider(new ComponentLabelProvider()); + nozzleViewer.setContentProvider(new ComponentContentProvider()); + + equipmentItem.setControl(equipmentViewer.getList()); + nozzleItem.setControl(nozzleViewer.getList()); + + equipmentViewer.setInput(equipment); + nozzleViewer.setInput(nozzles); + + equipmentItem.setHeight(equipmentViewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y); + nozzleItem.setHeight(nozzleViewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y); + + equipmentViewer.addSelectionChangedListener(this); + nozzleViewer.addSelectionChangedListener(this); + + GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(expandBar); + GridDataFactory.fillDefaults().minSize(500, 500).hint(500, 500).applyTo(composite); + + return composite; + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection sel = (IStructuredSelection)event.getSelection(); + Item i = (Item)sel.getFirstElement(); + if (i != null) { + if (event.getSource() == equipmentViewer) { + selected = i; + } else if (event.getSource() == nozzleViewer) { + selectedNozzle = i; + } + + } else { + if (event.getSource() == equipmentViewer) { + selected = i; + } else if (event.getSource() == nozzleViewer) { + selectedNozzle = i; + } + } + } + + public Item getSelected() { + return selected; + } + + public Item getSelectedNozzle() { + return selectedNozzle; + } + +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 4059d938..9051d44a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -418,9 +418,10 @@ public class Plant3DEditor extends ResourceEditorPart { } try { if (selected.size() == 0) { - for (Item eq : P3DUtil.getEquipments(getLibraryUri())) { - m.add(new AddEquipmentAction(rootNode, eq)); - } + m.add(new AddEquipmentAction(rootNode, getLibraryUri())); +// for (Item eq : P3DUtil.getEquipments(getLibraryUri())) { +// m.add(new AddEquipmentAction(rootNode, eq)); +// } } else if (selected.size() == 1) { IP3DNode node = (IP3DNode)selected.get(0); if (node instanceof Equipment) { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 939d1551..9b6ea189 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -180,6 +180,25 @@ public class ComponentUtils { return equipment; } + public static Equipment createEquipmentWithNozzles(P3DRootNode root, String typeURI, String nozzleTypeUri) throws Exception { + GeometryProvider provider = providers.get(typeURI); + if (provider == null) { + load(typeURI); + provider = providers.get(typeURI); + } + Equipment equipment = root.createEquipment(); + equipment.setType(typeURI); + equipment.setGeometry(provider); + root.addChild(equipment); + + for (int i = 0; i < equipment.numberOfFixedNozzles(); i++) { + createNozzle(root, equipment, new Item(nozzleTypeUri, "Nozzle")); + + } + + return equipment; + } + public static InlineComponent createStraight(P3DRootNode root) throws Exception{ InlineComponent component = root.createInline(); component.setType(Plant3D.URIs.Builtin_Straight); @@ -214,7 +233,12 @@ public class ComponentUtils { return equipment; } - + public static Equipment createEquipmentWithNozzles(P3DRootNode root, Item equipmentType, Item nozzleType) throws Exception { + Equipment equipment = createEquipmentWithNozzles(root, equipmentType.getUri(), nozzleType.getUri()); + String n = root.getUniqueName(equipmentType.getName()); + equipment.setName(n); + return equipment; + } public static Nozzle createDefaultNozzle(P3DRootNode root, Equipment equipment) throws Exception { return createNozzle(root, equipment, new Item(Plant3D.URIs.Builtin_Nozzle, "Nozzle")); -- 2.45.2 From ae719edde86debd17077d766263100682176f668 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 18 Nov 2019 13:40:11 +0200 Subject: [PATCH 12/16] Missing library URI from Equipment selection dialog parameters. gitlab #27 Change-Id: I306467532238c87293d1a9def905e475ec7d3c0a (cherry picked from commit 0493ab7d61ff3049d9e22fba9c062c3983028143) --- .../src/org/simantics/plant3d/actions/AddEquipmentAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java index 7efb0f83..d41dba44 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java @@ -29,7 +29,7 @@ public class AddEquipmentAction extends Action { @Override public void run() { - EquipmentSelectionDialog dialog = new EquipmentSelectionDialog(Display.getCurrent().getActiveShell(), root); + EquipmentSelectionDialog dialog = new EquipmentSelectionDialog(Display.getCurrent().getActiveShell(), root, libUri); if (dialog.open() == EquipmentSelectionDialog.CANCEL) return; Item item = dialog.getSelected(); -- 2.45.2 From 84f0830facd7781f3fe39a777b7ceb3ab2982bd7 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 18 Nov 2019 15:21:40 +0200 Subject: [PATCH 13/16] Adding specified equipment with nozzles did not work Constructor nozzle parameter was not stored... gitlab #27 Change-Id: I4f353edaf1c6a33a6c2c6ce8b377c8b11d55b483 (cherry picked from commit ec0ebd74b66427ce92c64eda89d58a0117137eb6) --- .../src/org/simantics/plant3d/actions/AddEquipmentAction2.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java index f232937f..69ce7739 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java @@ -26,6 +26,7 @@ public class AddEquipmentAction2 extends Action { public AddEquipmentAction2(P3DRootNode root, Item item, Item nozzleItem) { this.root = root; this.item = item; + this.nozzleItem = nozzleItem; setText("Add " + item.getName()); } -- 2.45.2 From 8792531e8f0967aee36cdd405ec0cd3a34f9ab06 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 18 Nov 2019 15:24:56 +0200 Subject: [PATCH 14/16] Ask component rotation angle when adding components gitlab #13 Change-Id: I13cbd9905fe6a0fa123375b44a88b15fe84067e7 (cherry picked from commit 15e688c6d6148fdbda457e5f55bdea4259c97aa8) --- .../plant3d/actions/AddComponentAction.java | 3 ++ .../dialog/ComponentSelectionDialog.java | 42 ++++++++++++++++++- .../plant3d/scenegraph/InlineComponent.java | 15 ++----- .../controlpoint/PipeControlPoint.java | 2 +- .../plant3d/utils/ComponentUtils.java | 19 +++++++++ .../src/org/simantics/plant3d/utils/Item.java | 10 ++++- .../org/simantics/plant3d/utils/P3DUtil.java | 2 + 7 files changed, 77 insertions(+), 16 deletions(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java index 56b0443e..ea25230a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java @@ -83,6 +83,7 @@ public class AddComponentAction extends vtkSwtAction { private Double length; private Double angle; + private Double rotationAngle; private Double diameter; private Double turnRadius; @@ -100,6 +101,7 @@ public class AddComponentAction extends vtkSwtAction { this.lengthAdjustable = dialog.isLenghtAdjustable(); this.length = dialog.getLength(); this.angle = dialog.getAngle(); + this.rotationAngle = dialog.getRotationAngle(); this.diameter = dialog.getDiameter(); this.turnRadius = dialog.getTurnRadius(); allowed = dialog.filterAllowed(); @@ -177,6 +179,7 @@ public class AddComponentAction extends vtkSwtAction { inst.length = length; inst.turnRadius = turnRadius; inst.insertPosition = insertPosition; + inst.rotationAngle = rotationAngle; inst.position = position; ComponentUtils.addComponent(root, component, inst); } catch (Exception e) { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java index 7c124eb0..dd3f4807 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java @@ -62,16 +62,23 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange private Double angle; private Double length; + private Double rotationAngle; + // In-line component private Text lengthText; + // Turn component private Text angleText; + // Rotated In-line, or turn conponent. + private Text rotationAngleText; + // Input for new PipeRun private Double diameter; private Double turnRadius; private Text diameterText; private Text turnRadiusText; + // Position selection private Button startButton; private Button middleButton; private Button endButton; @@ -198,6 +205,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange startButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_start.png"))); middleButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_middle.png"))); endButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_end.png"))); + startButton.setToolTipText("Overlapping insert"); + middleButton.setToolTipText("Cutting insert"); + endButton.setToolTipText("Adding insert"); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(buttonComposite); GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); @@ -232,6 +242,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange label = new Label(composite, SWT.NONE); label.setText("Angle"); angleText = new Text(composite, SWT.SINGLE|SWT.BORDER); + label = new Label(composite, SWT.NONE); + label.setText("Rotation angle"); + rotationAngleText = new Text(composite, SWT.SINGLE|SWT.BORDER); label = new Label(composite, SWT.NONE); label.setText("Diameter"); @@ -242,9 +255,11 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange lengthText.setEnabled(false); angleText.setEnabled(false); + rotationAngleText.setEnabled(false); turnRadiusText.setEnabled(false); diameterText.setEnabled(false); + lengthText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { @@ -269,6 +284,18 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange } }); + rotationAngleText.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + try { + rotationAngle = Double.parseDouble(rotationAngleText.getText()); + } catch (NumberFormatException err) { + rotationAngle = null; + } + validate(); + } + }); + diameterText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { @@ -295,6 +322,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(lengthText); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(angleText); + GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(rotationAngleText); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(diameterText); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(turnRadiusText); @@ -412,11 +440,13 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange if (inlineSplit) { lengthText.setEnabled(false); angleText.setEnabled(false); + rotationAngleText.setEnabled(selected.isRotated()); ok = false; } else { lengthText.setEnabled(true); angleText.setEnabled(false); + rotationAngleText.setEnabled(selected.isRotated()); if (length == null) ok = false; } @@ -425,16 +455,20 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange filterAllowed.add(PositionType.PREVIOUS); lengthText.setEnabled(false); angleText.setEnabled(true); + rotationAngleText.setEnabled(true); if (angle == null) ok = false; } else { - // this should not happen + // this should not happen, since end components should not have variable, or modifiable flag. lengthText.setEnabled(false); angleText.setEnabled(false); + rotationAngleText.setEnabled(false); + } } else { lengthText.setEnabled(false); - angleText.setEnabled(false); + angleText.setEnabled(false); + rotationAngleText.setEnabled(selected.getType() == Type.TURN || selected.isRotated()); } if (selected.isSizeChange()) { @@ -495,6 +529,10 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange return length; } + public Double getRotationAngle() { + return rotationAngle; + } + public Double getDiameter() { return diameter; } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java index aa51073a..a94303ef 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java @@ -86,12 +86,8 @@ public class InlineComponent extends PipelineComponent { if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO) return; controlPoint.setRotationAngle(angle); - try { - PipingRules.requestUpdate(getControlPoint()); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + PipingRules.requestUpdate(getControlPoint()); + } @RelatedGetValue(Plant3D.URIs.IsReversed) @@ -112,12 +108,7 @@ public class InlineComponent extends PipelineComponent { return; } controlPoint.setReversed(reverse); - try { - PipingRules.requestUpdate(getControlPoint()); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + PipingRules.requestUpdate(getControlPoint()); } @Override diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java index 232b8ab4..eae8ec33 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java @@ -398,7 +398,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { @GetPropertyValue(name="Rotation Angle",tabId="Debug",value="rotationAngle") public Double getRotationAngle() { - if (asFixedAngle()) + if (isRotate || asFixedAngle()) return rotationAngle; return null; } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 9b6ea189..0ae36e33 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -275,6 +275,9 @@ public class ComponentUtils { // Variable angle public Double angle; + + // Rotation angle used with turns and rotated inline. + public Double rotationAngle; public String getTypeUri() { return typeUri; @@ -331,6 +334,14 @@ public class ComponentUtils { public void setAngle(Double angle) { this.angle = angle; } + + public Double getRotationAngle() { + return rotationAngle; + } + + public void setRotationAngle(Double rotationAngle) { + this.rotationAngle = rotationAngle; + } } @@ -438,14 +449,19 @@ public class ComponentUtils { newPcp.setLength(inst.length); newComponent.setParameter("length", inst.length); } + if (inst.rotationAngle != null) + ((InlineComponent) newComponent).setRotationAngle(inst.rotationAngle); } else if (newComponent instanceof TurnComponent) { TurnComponent turnComponent = (TurnComponent)newComponent; if (turnComponent.isVariableAngle()) { newPcp.setTurnAngle(inst.angle); newComponent.setParameter("turnAngle", inst.angle); } + if (inst.rotationAngle != null) + ((TurnComponent) newComponent).setRotationAngle(inst.rotationAngle); } + newComponent.updateParameters(); Vector3d v = new Vector3d(dir); @@ -505,6 +521,7 @@ public class ComponentUtils { PipingRules.addSizeChange(true, pipeRun, other, (InlineComponent)newComponent, toPcp, null); } newPcp.setWorldPosition(pos); + // TODO : chicken-egg problem newComponent.updateParameters(); Vector3d v = new Vector3d(dir); @@ -522,6 +539,8 @@ public class ComponentUtils { break; } newPcp.setWorldPosition(pos); + if (inst.rotationAngle != null) + ((InlineComponent) newComponent).setRotationAngle(inst.rotationAngle); } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java index 799d0727..1ce6ed20 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java @@ -12,6 +12,7 @@ public class Item { private boolean variable = false; private boolean modifiable = false; private boolean sizeChange = false; + private boolean rotated = false; public Item(String type, String name) { @@ -68,7 +69,14 @@ public class Item { public void setSizeChange(boolean sizeChange) { this.sizeChange = sizeChange; } - + + public boolean isRotated() { + return rotated; + } + + public void setRotated(boolean rotated) { + this.rotated = rotated; + } @Override diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java index 55cfead4..18d5b2cd 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java @@ -211,6 +211,8 @@ public class P3DUtil { item.setModifiable(true); if (graph.hasStatement(r, p3d.SizeChangeComponent)) item.setSizeChange(true); + if (graph.hasStatement(r, p3d.RotateComponent)) + item.setRotated(true); return item; } -- 2.45.2 From 32d9fe9dcdb8a67a3fb422e721e3f73e18afc08c Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Fri, 22 Nov 2019 12:03:58 +0200 Subject: [PATCH 15/16] Up-to-date ontology class for Plant3D ontology Change-Id: I846a32fa0dadde3b6847dce280217dc5a29289ca --- .../src/org/simantics/plant3d/ontology/Plant3D.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java b/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java index 1ab46e34..c60908ba 100644 --- a/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java +++ b/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java @@ -12,6 +12,7 @@ public class Plant3D { public final Resource Actions; public final Resource Actions_NewPlant; + public final Resource AdjustableLengthInlineComponent; public final Resource Builtin; public final Resource Builtin_BallValve; public final Resource Builtin_BallValveGeometryProvider; @@ -131,6 +132,7 @@ public class Plant3D { public static class URIs { public static final String Actions = "http://www.simantics.org/Plant3D-0.1/Actions"; public static final String Actions_NewPlant = "http://www.simantics.org/Plant3D-0.1/Actions/NewPlant"; + public static final String AdjustableLengthInlineComponent = "http://www.simantics.org/Plant3D-0.1/AdjustableLengthInlineComponent"; public static final String Builtin = "http://www.simantics.org/Plant3D-0.1/Builtin"; public static final String Builtin_BallValve = "http://www.simantics.org/Plant3D-0.1/Builtin/BallValve"; public static final String Builtin_BallValveGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/BallValveGeometryProvider"; @@ -260,6 +262,7 @@ public class Plant3D { public Plant3D(ReadGraph graph) { Actions = getResourceOrNull(graph, URIs.Actions); Actions_NewPlant = getResourceOrNull(graph, URIs.Actions_NewPlant); + AdjustableLengthInlineComponent = getResourceOrNull(graph, URIs.AdjustableLengthInlineComponent); Builtin = getResourceOrNull(graph, URIs.Builtin); Builtin_BallValve = getResourceOrNull(graph, URIs.Builtin_BallValve); Builtin_BallValveGeometryProvider = getResourceOrNull(graph, URIs.Builtin_BallValveGeometryProvider); -- 2.45.2 From 488e24d71d14e60c7da3272e2428a0b23b57c87c Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Fri, 22 Nov 2019 12:40:17 +0200 Subject: [PATCH 16/16] Allow property tab contribution from all INodes. gitlab #56 Change-Id: If6e7bc5138f22378c700c4fb9b4104990a622023 --- .../property/AnnotatedPropertyTabContributorFactory.java | 3 +-- .../simantics/plant3d/property/P3DSelectionProcessor.java | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java b/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java index 65b267cb..73526d1c 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java +++ b/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java @@ -76,7 +76,6 @@ import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.property.annotations.PropertyTabBlacklist; import org.simantics.g3d.property.annotations.SetComboPropertyValue; import org.simantics.g3d.property.annotations.SetPropertyValue; -import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.NodeMapProvider; import org.simantics.g3d.scenegraph.base.INode; @@ -682,7 +681,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri if (nodeMap != null) break; } - n = (IG3DNode)n.getParent(); + n = (INode)n.getParent(); } boolean readOnly = (node instanceof IStructuralNode && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/property/P3DSelectionProcessor.java b/org.simantics.plant3d/src/org/simantics/plant3d/property/P3DSelectionProcessor.java index e48f3320..b78fac4e 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/property/P3DSelectionProcessor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/property/P3DSelectionProcessor.java @@ -19,7 +19,7 @@ import org.simantics.db.management.ISessionContext; import org.simantics.db.request.Read; import org.simantics.g3d.property.PropertyTabContributor; import org.simantics.g3d.property.PropertyTabUtil; -import org.simantics.g3d.scenegraph.IG3DNode; +import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.tools.AdaptationUtils; import org.simantics.g3d.vtk.property.VTKPropertyTabContributor; import org.simantics.objmap.structural.StructuralResource; @@ -43,7 +43,7 @@ public class P3DSelectionProcessor implements SelectionProcessor resourceCollection = AdaptationUtils.adaptToCollection(selection, Resource.class); Collection structuralResourceCollection = AdaptationUtils.adaptToCollection(selection, StructuralResource.class); Collection propCollection = AdaptationUtils.adaptToCollection(selection, vtkProp.class); - Collection nodeCollection = AdaptationUtils.adaptToCollection(selection, IG3DNode.class); + Collection nodeCollection = AdaptationUtils.adaptToCollection(selection, INode.class); boolean readOnly = false; if (resourceCollection.size() == 0 && structuralResourceCollection.size() > 0) { for (StructuralResource sr : structuralResourceCollection) { @@ -55,7 +55,7 @@ public class P3DSelectionProcessor implements SelectionProcessor contributors = PropertyTabUtil.getContributors(node); int i = 100; for (PropertyTabContributor c : contributors) { -- 2.45.2