CyberShadow
Newbie
Joined: Apr 15, 2023
Post Count: 3
Status:
Offline
|
|
Re: Move selection by an exact distance
|
Thank you!
I also submitted the following patch, which I think makes sense regardless (though, as these things go, no idea if it arrived anywhere or not):
From ae3f3435dde25fee5f9213c9c0333d78c641a49c Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev <git@cy.md> Date: Sat, 15 Apr 2023 22:20:06 +0000 Subject: [PATCH] Made the arrow keys move the selection by distances aligned to user units
Arrow keys move selected items by a distance which depends on the zoom level (scale), however this can be a little arbitrary.
Since the user operates on a grid with length values based in a real-world system of measurements, it's usually more useful to allow operating in terms of those values. In practical terms, this means that users are more likely to find useful to move an item by 1 cm, as opposed to e.g. 1.025641025 cm.
Make the arrow keys do this, by using a function which calculates a scale value such that a unit distance will be greater than a pixel but aligned to the user's preferred system of measurements. --- .../sweethome3d/swing/PlanComponent.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/src/com/eteks/sweethome3d/swing/PlanComponent.java b/src/com/eteks/sweethome3d/swing/PlanComponent.java index 7d91535..ed75adb 100644 --- a/src/com/eteks/sweethome3d/swing/PlanComponent.java +++ b/src/com/eteks/sweethome3d/swing/PlanComponent.java @@ -1595,7 +1595,7 @@ public class PlanComponent extends JComponent implements PlanView, Scrollable, P } public void actionPerformed(ActionEvent ev) { - controller.moveSelection(this.dx / getScale(), this.dy / getScale()); + controller.moveSelection(this.dx / getAlignedScale(), this.dy / getAlignedScale()); } } // Toggle magnetism action @@ -5584,6 +5584,40 @@ public class PlanComponent extends JComponent implements PlanView, Scrollable, P return this.scale; } + private static final float[] metricScaleSteps = { + 0.01f, 0.025f, 0.05f, + 0.1f, 0.25f, 0.5f, + 1f, 2.5f, 5f, + 10f, 25f, 50f, + 100f, 250f, 500f, + 1000f, 2500f, 5000f, + 10000f, 25000f, 50000f + }; + + private static final float[] imperialScaleSteps = { + 2.54f / 12 / 12, 2.54f / 12 / 4, 2.54f / 12 / 2, + 2.54f / 12, 2.54f / 4, 2.54f / 2, + 2.54f, 2.54f * 3, 2.54f * 6, + 2.54f * 12, 2.54f * 12 * 3, 2.54f * 12 * 6, + 2.54f * 12 * 12, 2.54f * 12 * 12 * 3, 2.54f * 12 * 12 * 6, + 2.54f * 12 * 12 * 12, 2.54f * 12 * 12 * 12 * 3, 2.54f * 12 * 12 * 12 * 6, + 2.54f * 12 * 12 * 12 * 12 + }; + + /** + * Returns a scale value close to getScale(), but aligned to the user's preferred measurement units. + */ + public float getAlignedScale() { + LengthUnit lengthUnit = this.preferences.getLengthUnit(); + float[] scaleSteps = lengthUnit.isMetric() ? metricScaleSteps : imperialScaleSteps; + float pixelLength = getPixelLength(); + for (int i = 0; i < scaleSteps.length; i++) { + if (scaleSteps >= pixelLength) + return 1 / scaleSteps / this.resolutionScale; + } + return this.scale; + } + /** * Sets the scale used to display the plan. * If this component is displayed in a viewport the view position is updated -- 2.40.0
|