From: Marko Luukkainen Date: Mon, 18 Nov 2019 13:24:56 +0000 (+0200) Subject: Ask component rotation angle when adding components X-Git-Tag: v1.43.0~116^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=8792531e8f0967aee36cdd405ec0cd3a34f9ab06;p=simantics%2F3d.git Ask component rotation angle when adding components gitlab #13 Change-Id: I13cbd9905fe6a0fa123375b44a88b15fe84067e7 (cherry picked from commit 15e688c6d6148fdbda457e5f55bdea4259c97aa8) --- 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; }