Refactor RASAero motor conversion
This commit is contained in:
parent
b6af7220c6
commit
a7c63260c5
@ -2,6 +2,8 @@ package net.sf.openrocket.file.rasaero;
|
||||
|
||||
import net.sf.openrocket.logging.WarningSet;
|
||||
import net.sf.openrocket.motor.Manufacturer;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.ExternalComponent;
|
||||
import net.sf.openrocket.rocketcomponent.FinSet;
|
||||
@ -10,6 +12,7 @@ import net.sf.openrocket.util.Color;
|
||||
import net.sf.openrocket.util.MathUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.openrocket.file.rasaero.export.RASAeroSaver.RASAeroExportException;
|
||||
@ -371,6 +374,29 @@ public class RASAeroCommonConstants {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an OpenRocket motor as a RASAero motor.
|
||||
* @param motors list of available RASAero motors
|
||||
* @param ORMotor OpenRocket motor
|
||||
* @return a RASAero String representation of a motor
|
||||
*/
|
||||
public static String OPENROCKET_TO_RASAERO_MOTOR(List<ThrustCurveMotor> motors, Motor ORMotor, WarningSet warnings) {
|
||||
if (!(ORMotor instanceof ThrustCurveMotor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (ThrustCurveMotor motor : motors) {
|
||||
if (ORMotor.getDesignation().equals(motor.getDesignation()) &&
|
||||
((ThrustCurveMotor) ORMotor).getManufacturer().matches(motor.getManufacturer().getDisplayName())) {
|
||||
return motor.getDesignation() +
|
||||
" (" + OPENROCKET_TO_RASAERO_MANUFACTURER(motor.getManufacturer()) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
warnings.add(String.format("Could not find RASAero motor for '%s'", ORMotor.getDesignation()));
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String OPENROCKET_TO_RASAERO_MANUFACTURER(Manufacturer manufacturer) {
|
||||
if (manufacturer.matches("AeroTech")) {
|
||||
return "AT";
|
||||
|
@ -139,7 +139,7 @@ public class SimulationDTO {
|
||||
switch (stageNr) {
|
||||
// Sustainer
|
||||
case 0:
|
||||
setSustainerEngine(getRASAeroMotor(motors, motorConfig.getMotor(), warnings));
|
||||
setSustainerEngine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motorConfig.getMotor(), warnings));
|
||||
setSustainerLaunchWt(stage.getSectionMass() * RASAeroCommonConstants.OPENROCKET_TO_RASAERO_WEIGHT);
|
||||
|
||||
// Calculate CG of sustainer
|
||||
@ -151,7 +151,7 @@ public class SimulationDTO {
|
||||
break;
|
||||
// Booster 1
|
||||
case 1:
|
||||
setBooster1Engine(getRASAeroMotor(motors, motorConfig.getMotor(), warnings));
|
||||
setBooster1Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motorConfig.getMotor(), warnings));
|
||||
|
||||
// Aggregate mass of sustainer and booster 1
|
||||
setBooster1LaunchWt(rocket.getChild(0).getSectionMass() + stage.getSectionMass()
|
||||
@ -171,7 +171,7 @@ public class SimulationDTO {
|
||||
break;
|
||||
// Booster 2
|
||||
case 2:
|
||||
setBooster2Engine(getRASAeroMotor(motors, motorConfig.getMotor(), warnings));
|
||||
setBooster2Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motorConfig.getMotor(), warnings));
|
||||
|
||||
// Aggregate mass of sustainer, booster 1 and booster 2
|
||||
setBooster2LaunchWt(rocket.getChild(0).getSectionMass() + rocket.getChild(1).getSectionMass() +
|
||||
@ -196,29 +196,6 @@ public class SimulationDTO {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an OpenRocket motor as a RASAero motor.
|
||||
* @param motors list of available RASAero motors
|
||||
* @param ORMotor OpenRocket motor
|
||||
* @return a RASAero String representation of a motor
|
||||
*/
|
||||
private String getRASAeroMotor(List<ThrustCurveMotor> motors, Motor ORMotor, WarningSet warnings) {
|
||||
if (!(ORMotor instanceof ThrustCurveMotor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (ThrustCurveMotor motor : motors) {
|
||||
if (ORMotor.getDesignation().equals(motor.getDesignation()) &&
|
||||
((ThrustCurveMotor) ORMotor).getManufacturer().matches(motor.getManufacturer().getDisplayName())) {
|
||||
return motor.getDesignation() +
|
||||
" (" + RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MANUFACTURER(motor.getManufacturer()) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
warnings.add(String.format("Could not find RASAero motor for '%s'", ORMotor.getDesignation()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getSustainerEngine() {
|
||||
return sustainerEngine;
|
||||
|
Loading…
x
Reference in New Issue
Block a user