From e7e96ca715c39e4da7edc0772b4e038aded31c03 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 3 Mar 2022 02:50:53 +0100 Subject: [PATCH] [#1204] Fix overrideCGX slider length --- .../configdialog/RocketComponentConfig.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java index 55b4dce42..c963aa6a2 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java @@ -6,7 +6,6 @@ import java.awt.Container; import java.awt.event.*; import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -340,15 +339,30 @@ public class RocketComponentConfig extends JPanel { // Calculate suitable length for slider DoubleModel length; if (component instanceof ComponentAssembly) { - double l = 0; - Iterator iterator = component.iterator(false); + double minL = Double.MAX_VALUE; + double maxL = Double.MIN_VALUE; + while (iterator.hasNext()) { RocketComponent c = iterator.next(); - if (c.getAxialMethod() == AxialMethod.AFTER) - l += c.getLength(); + + double compPos = c.getAxialOffset(AxialMethod.ABSOLUTE); + if (compPos < minL) { + minL = compPos; + } + + double compLen = c.getLength(); + if (c instanceof FinSet) { + compLen = ((FinSet) c).getInstanceBoundingBox().span().x; + } + if (compPos + compLen > maxL) { + maxL = compPos + compLen; + } } - length = new DoubleModel(l); + length = new DoubleModel(maxL - minL); + } else if (component instanceof FinSet) { + double compLen = ((FinSet) component).getInstanceBoundingBox().span().x; + length = new DoubleModel(compLen); } else { length = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0); }