From 5b0cd95cba6964b83a8bdcb0f34c582c8880c00a Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 18 Oct 2020 12:20:37 -0400 Subject: [PATCH] [fixes# 786] Updates config when drawing extras on 2D RocketFigure --- .../gui/figureelements/RocketInfo.java | 28 ++++++++++--------- .../sf/openrocket/gui/print/DesignReport.java | 2 +- .../gui/scalefigure/RocketPanel.java | 8 +++--- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java b/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java index 212d50ef5..9ec5600c3 100644 --- a/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java +++ b/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java @@ -41,12 +41,12 @@ public class RocketInfo implements FigureElement { private final Caret cpCaret = new CPCaret(0,0); private final Caret cgCaret = new CGCaret(0,0); - private final FlightConfiguration configuration; private final UnitGroup stabilityUnits; + private FlightConfiguration configuration; private double cg = 0, cp = 0; private double length = 0, diameter = 0; - private double mass = 0; + private double massWithMotors = 0; private double aoa = Double.NaN; private double theta = Double.NaN; private double mach = Application.getPreferences().getDefaultMach(); @@ -111,11 +111,11 @@ public class RocketInfo implements FigureElement { public void setDiameter(double diameter) { this.diameter = diameter; } - - public void setMass(double mass) { - this.mass = mass; + + public void setMassWithMotors(double mass) { + this.massWithMotors = mass; } - + public void setMassWithoutMotors(double mass) { this.massWithoutMotors = mass; } @@ -175,11 +175,10 @@ public class RocketInfo implements FigureElement { if( configuration.hasMotors() ) { //// Mass with motors massTextWithMotors = trans.get("RocketInfo.massWithMotors") + " "; - massTextWithMotors += UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(mass); + massTextWithMotors += UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(massWithMotors); GlyphVector massLineWithMotors = createText(massTextWithMotors); g2.drawGlyphVector(massLineWithMotors, x1, y1+3*line); } - } @@ -254,8 +253,8 @@ public class RocketInfo implements FigureElement { * * @return the mass */ - public double getMass() { - return mass; + public double getMassWithMotors() { + return massWithMotors; } /** @@ -265,8 +264,8 @@ public class RocketInfo implements FigureElement { * * @return the mass */ - public String getMass(Unit u) { - return u.toStringUnit(mass); + public String getMassWithMotors(Unit u) { + return u.toStringUnit(massWithMotors); } /** @@ -450,5 +449,8 @@ public class RocketInfo implements FigureElement { float size=(float) (Application.getPreferences().getRocketInfoFontSize()-2.0); return (SMALLFONT.deriveFont(size)).createGlyphVector(g2.getFontRenderContext(), text); } - + + public void setCurrentConfig(FlightConfiguration newConfig) { + this.configuration = newConfig; + } } diff --git a/swing/src/net/sf/openrocket/gui/print/DesignReport.java b/swing/src/net/sf/openrocket/gui/print/DesignReport.java index 626b7a227..5f09daad5 100644 --- a/swing/src/net/sf/openrocket/gui/print/DesignReport.java +++ b/swing/src/net/sf/openrocket/gui/print/DesignReport.java @@ -253,7 +253,7 @@ public class DesignReport { } else { canvas.newlineShowText(MASS_EMPTY); } - canvas.showText(text.getMass(UnitGroup.UNITS_MASS.getDefaultUnit())); + canvas.showText(text.getMassWithMotors(UnitGroup.UNITS_MASS.getDefaultUnit())); canvas.newlineShowText(STABILITY); canvas.showText(text.getStability()); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 49059cc5d..8c4638881 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -573,6 +573,8 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change FlightConditions conditions = new FlightConditions(curConfig); warnings.clear(); + extraText.setCurrentConfig(curConfig); + if (!Double.isNaN(cpMach)) { conditions.setMach(cpMach); extraText.setMach(cpMach); @@ -601,15 +603,13 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change cp = aerodynamicCalculator.getWorstCP(curConfig, conditions, warnings); } extraText.setTheta(cpTheta); - - cg = MassCalculator.calculateLaunch( curConfig).getCM(); - if (cp.weight > MathUtil.EPSILON){ cpx = cp.x; // map the 3D value into the 2D Display Panel cpy = cp.y * Math.cos(rotation) + cp.z*Math.sin(rotation); } + cg = MassCalculator.calculateLaunch( curConfig).getCM(); if (cg.weight > MassCalculator.MIN_MASS){ cgx = cg.x; // map the 3D value into the 2D Display Panel @@ -636,7 +636,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change extraText.setCP(cpx); extraText.setLength(length); extraText.setDiameter(diameter); - extraText.setMass(cg.weight); + extraText.setMassWithMotors(cg.weight); extraText.setMassWithoutMotors( emptyInfo.getMass() ); extraText.setWarnings(warnings);