Clean up some code in DesignReport

Clean up some of the code in DesignReport, including some
refactoring TODOs in the addMotorData method.

Signed-off-by: Billy Olsen <billy.olsen@gmail.com>
This commit is contained in:
Billy Olsen 2020-03-14 20:16:43 -07:00
parent ca64e9e82a
commit d5598d7380

View File

@ -29,6 +29,7 @@ import net.sf.openrocket.gui.figureelements.RocketInfo;
import net.sf.openrocket.gui.scalefigure.RocketPanel; import net.sf.openrocket.gui.scalefigure.RocketPanel;
import net.sf.openrocket.masscalc.MassCalculator; import net.sf.openrocket.masscalc.MassCalculator;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
@ -162,7 +163,7 @@ public class DesignReport {
PrintUtilities.addText(document, PrintUtilities.BIG_BOLD, ROCKET_DESIGN); PrintUtilities.addText(document, PrintUtilities.BIG_BOLD, ROCKET_DESIGN);
Rocket rocket = rocketDocument.getRocket(); Rocket rocket = rocketDocument.getRocket();
final FlightConfiguration configuration = rocket.getSelectedConfiguration();//.clone(); final FlightConfiguration configuration = rocket.getSelectedConfiguration();
configuration.setAllStages(); configuration.setAllStages();
PdfContentByte canvas = writer.getDirectContent(); PdfContentByte canvas = writer.getDirectContent();
@ -190,7 +191,6 @@ public class DesignReport {
canvas.newlineShowText(STAGES); canvas.newlineShowText(STAGES);
canvas.showText("" + rocket.getStageCount()); canvas.showText("" + rocket.getStageCount());
if (configuration.hasMotors()) { if (configuration.hasMotors()) {
if (configuration.getStageCount() > 1) { if (configuration.getStageCount() > 1) {
canvas.newlineShowText(MASS_WITH_MOTORS); canvas.newlineShowText(MASS_WITH_MOTORS);
@ -361,11 +361,19 @@ public class DesignReport {
if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) { if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) {
MotorMount mount = (MotorMount) c; MotorMount mount = (MotorMount) c;
// TODO: refactor this... it's redundant with containing if, and could probably be simplified MotorConfiguration motorConfig = mount.getMotorConfig(motorId);
if (mount.isMotorMount() && (mount.getMotorConfig(motorId) != null) &&(null != mount.getMotorConfig(motorId).getMotor())) { if (null == motorConfig) {
Motor motor = mount.getMotorConfig(motorId).getMotor(); log.warn("Unable to find motorConfig for motorId {}", motorId);
int motorCount = mount.getMotorCount(); continue;
}
Motor motor = motorConfig.getMotor();
if (null == motor) {
log.warn("Motor instance is null for motorId {}", motorId);
continue;
}
int motorCount = mount.getMotorCount();
int border = Rectangle.NO_BORDER; int border = Rectangle.NO_BORDER;
if (topBorder) { if (topBorder) {
@ -411,7 +419,6 @@ public class DesignReport {
totalTTW += ttw * motorCount; totalTTW += ttw * motorCount;
} }
} }
}
if (totalMotorCount > 1) { if (totalMotorCount > 1) {
int border = Rectangle.TOP; int border = Rectangle.TOP;