From 9029e681fb0c47e9041c5527b966a247b23029b3 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Wed, 12 Feb 2020 16:12:57 +0200 Subject: [PATCH] Added a length scaling factor for adding components gitlab #78 Change-Id: Ied89a7f8289aad1e0ca952c4fb51e40df93fc811 --- .../plant3d/actions/AddComponentAction.java | 7 +++++++ .../plant3d/dialog/ComponentSelectionDialog.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 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 d9ee9d70..0ee0f6bc 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java @@ -50,6 +50,8 @@ public class AddComponentAction extends vtkSwtAction { private String libUri; + private double lengthFactor = 1.0; + public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root, String libUri) { super(panel); this.root = root; @@ -60,6 +62,10 @@ public class AddComponentAction extends vtkSwtAction { this.libUri = libUri; } + public void setLengthFactor(double lengthFactor) { + this.lengthFactor = lengthFactor; + } + public void setComponent(PipelineComponent component) { this.component = component; @@ -97,6 +103,7 @@ public class AddComponentAction extends vtkSwtAction { // Set list of already reserved component names dialog.addUsedNames(ComponentUtils.getPipelineComponentNames(root)); + dialog.setLengthFactor(lengthFactor); if (dialog.open() == ComponentSelectionDialog.CANCEL) return; 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 720d88ce..35e761cc 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java @@ -53,6 +53,8 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange private static final String DIALOG = "ComponentSelectionDialog"; //$NON-NLS-1$ private IDialogSettings dialogSettings; + + private double lengthFactor = 1.0; private ResourceManager resourceManager; @@ -126,6 +128,10 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange if (dialogSettings == null) dialogSettings = settings.addNewSection(DIALOG); } + + public void setLengthFactor(double lengthFactor) { + this.lengthFactor = lengthFactor; + } @Override protected IDialogSettings getDialogBoundsSettings() { @@ -317,7 +323,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange @Override public void keyReleased(KeyEvent e) { try { - length = Double.parseDouble(lengthText.getText()); + length = Double.parseDouble(lengthText.getText()) / lengthFactor; } catch (NumberFormatException err) { length = null; } @@ -353,7 +359,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange @Override public void keyReleased(KeyEvent e) { try { - diameter = Double.parseDouble(diameterText.getText()); + diameter = Double.parseDouble(diameterText.getText()) / lengthFactor; } catch (NumberFormatException err) { diameter = null; } @@ -365,7 +371,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange @Override public void keyReleased(KeyEvent e) { try { - turnRadius = Double.parseDouble(turnRadiusText.getText()); + turnRadius = Double.parseDouble(turnRadiusText.getText()) / lengthFactor; } catch (NumberFormatException err) { turnRadius = null; } -- 2.47.1