Export RASAero motor with designation from RASAero database
This commit is contained in:
parent
be7d9c4e54
commit
6b4c18e0d8
@ -2,6 +2,8 @@ package net.sf.openrocket.file.motor;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@ -28,7 +30,10 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
||||
protected Charset getDefaultCharset() {
|
||||
return CHARSET;
|
||||
}
|
||||
|
||||
|
||||
public List<ThrustCurveMotor.Builder> load(InputStream stream, String filename, boolean removeDelayFromDesignation) throws IOException {
|
||||
return load(new InputStreamReader(stream, getDefaultCharset()), filename, removeDelayFromDesignation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a <code>Motor</code> from a RASP file specified by the <code>Reader</code>.
|
||||
@ -38,11 +43,11 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
||||
* is calculated from the thrust curve by assuming a constant exhaust velocity.
|
||||
*
|
||||
* @param reader the source of the file.
|
||||
* @param removeDelayFromDesignation if true, the motor delay will be left out of the motor designation (e.g. "B6" instead of "B6-0")
|
||||
* @return a list of the {@link Motor} objects defined in the file.
|
||||
* @throws IOException if an I/O error occurs or if the file format is illegal.
|
||||
*/
|
||||
@Override
|
||||
public List<ThrustCurveMotor.Builder> load(Reader reader, String filename) throws IOException {
|
||||
public List<ThrustCurveMotor.Builder> load(Reader reader, String filename, boolean removeDelayFromDesignation) throws IOException {
|
||||
List<ThrustCurveMotor.Builder> motors = new ArrayList<>();
|
||||
BufferedReader in = new BufferedReader(reader);
|
||||
|
||||
@ -153,7 +158,7 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
||||
delayArray[i] = delays.get(i);
|
||||
}
|
||||
motors.add(createRASPMotor(manufacturer, designation, comment,
|
||||
length, diameter, delayArray, propW, totalW, time, thrust));
|
||||
length, diameter, delayArray, propW, totalW, time, thrust, removeDelayFromDesignation));
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
@ -164,6 +169,11 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
||||
|
||||
return motors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThrustCurveMotor.Builder> load(Reader reader, String filename) throws IOException {
|
||||
return load(reader, filename, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -172,7 +182,7 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
||||
*/
|
||||
private static ThrustCurveMotor.Builder createRASPMotor(String manufacturer, String designation,
|
||||
String comment, double length, double diameter, double[] delays,
|
||||
double propW, double totalW, List<Double> time, List<Double> thrust)
|
||||
double propW, double totalW, List<Double> time, List<Double> thrust, boolean removeDelayFromDesignation)
|
||||
throws IOException {
|
||||
|
||||
// Add zero time/thrust if necessary
|
||||
@ -188,8 +198,10 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
||||
thrustArray[i] = thrust.get(i);
|
||||
cgArray[i] = new Coordinate(length / 2, 0, 0, mass.get(i));
|
||||
}
|
||||
|
||||
designation = removeDelay(designation);
|
||||
|
||||
if (removeDelayFromDesignation) {
|
||||
designation = removeDelay(designation);
|
||||
}
|
||||
|
||||
// Create the motor digest from data available in RASP files
|
||||
MotorDigest motorDigest = new MotorDigest();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.sf.openrocket.file.rasaero;
|
||||
|
||||
import net.sf.openrocket.file.motor.AbstractMotorLoader;
|
||||
import net.sf.openrocket.logging.WarningSet;
|
||||
import net.sf.openrocket.motor.Manufacturer;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
@ -389,27 +390,24 @@ public class RASAeroCommonConstants {
|
||||
|
||||
/**
|
||||
* Format an OpenRocket motor as a RASAero motor.
|
||||
* @param motors list of available RASAero motors
|
||||
* @param RASAeroMotors list of available RASAero motors
|
||||
* @param ORMotor OpenRocket motor
|
||||
* @param motorConfig motor configuration of the selected motor
|
||||
* @return a RASAero String representation of a motor
|
||||
*/
|
||||
public static String OPENROCKET_TO_RASAERO_MOTOR(List<ThrustCurveMotor> motors, Motor ORMotor, MotorConfiguration motorConfig,
|
||||
public static String OPENROCKET_TO_RASAERO_MOTOR(List<ThrustCurveMotor> RASAeroMotors, Motor ORMotor,
|
||||
WarningSet warnings) {
|
||||
if (!(ORMotor instanceof ThrustCurveMotor) || motorConfig == null) {
|
||||
if (!(ORMotor instanceof ThrustCurveMotor)) {
|
||||
log.debug("RASAero motor not found: not a thrust curve motor");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (ThrustCurveMotor motor : motors) {
|
||||
if (ORMotor.getDesignation().equals(motor.getDesignation()) &&
|
||||
((ThrustCurveMotor) ORMotor).getManufacturer().matches(motor.getManufacturer().getDisplayName())) {
|
||||
String motorName = motor.getDesignation();
|
||||
if (motorConfig.getEjectionDelay() == 0) {
|
||||
motorName += "-0";
|
||||
}
|
||||
log.debug(String.format("RASAero motor found: %s", motorName));
|
||||
return motorName + " (" + OPENROCKET_TO_RASAERO_MANUFACTURER(motor.getManufacturer()) + ")";
|
||||
for (ThrustCurveMotor RASAeroMotor : RASAeroMotors) {
|
||||
String RASAeroDesignation = AbstractMotorLoader.removeDelay(RASAeroMotor.getDesignation());
|
||||
if (ORMotor.getDesignation().equals(RASAeroDesignation) &&
|
||||
((ThrustCurveMotor) ORMotor).getManufacturer().matches(RASAeroMotor.getManufacturer().getDisplayName())) {
|
||||
String motorName = RASAeroMotor.getDesignation();
|
||||
log.debug(String.format("RASAero RASAeroMotor found: %s", motorName));
|
||||
return motorName + " (" + OPENROCKET_TO_RASAERO_MANUFACTURER(RASAeroMotor.getManufacturer()) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.sf.openrocket.file.rasaero;
|
||||
|
||||
import net.sf.openrocket.file.motor.GeneralMotorLoader;
|
||||
import net.sf.openrocket.file.motor.RASPMotorLoader;
|
||||
import net.sf.openrocket.logging.WarningSet;
|
||||
import net.sf.openrocket.database.motor.ThrustCurveMotorSet;
|
||||
import net.sf.openrocket.file.motor.AbstractMotorLoader;
|
||||
@ -69,23 +70,23 @@ public abstract class RASAeroMotorsLoader {
|
||||
public static List<ThrustCurveMotor> loadAllRASAeroMotors(WarningSet warnings) throws RuntimeException {
|
||||
List<ThrustCurveMotor> RASAeroMotors = new ArrayList<>();
|
||||
|
||||
GeneralMotorLoader loader = new GeneralMotorLoader();
|
||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||
String fileName = "RASAero_Motors.eng";
|
||||
InputStream is = classloader.getResourceAsStream("datafiles/thrustcurves/RASAero/" + fileName);
|
||||
if (is == null) {
|
||||
throw new RuntimeException("Could not find " + fileName);
|
||||
}
|
||||
try {
|
||||
List<ThrustCurveMotor.Builder> motors = loader.load(is, fileName);
|
||||
for (ThrustCurveMotor.Builder builder : motors) {
|
||||
RASAeroMotors.add(builder.build());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
warnings.add("Error during motor loading: " + e.getMessage());
|
||||
}
|
||||
RASPMotorLoader loader = new RASPMotorLoader();
|
||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||
String fileName = "RASAero_Motors.eng";
|
||||
InputStream is = classloader.getResourceAsStream("datafiles/thrustcurves/RASAero/" + fileName);
|
||||
if (is == null) {
|
||||
throw new RuntimeException("Could not find " + fileName);
|
||||
}
|
||||
try {
|
||||
List<ThrustCurveMotor.Builder> motors = loader.load(is, fileName, false);
|
||||
for (ThrustCurveMotor.Builder builder : motors) {
|
||||
RASAeroMotors.add(builder.build());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
warnings.add("Error during motor loading: " + e.getMessage());
|
||||
}
|
||||
|
||||
return RASAeroMotors;
|
||||
return RASAeroMotors;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,7 +180,7 @@ public class SimulationDTO {
|
||||
switch (stageNr) {
|
||||
// Sustainer
|
||||
case 0:
|
||||
setSustainerEngine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, motorConfig, warnings));
|
||||
setSustainerEngine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, warnings));
|
||||
|
||||
// Calculate mass & CG of sustainer
|
||||
CGCalcConfig.setOnlyStage(0);
|
||||
@ -202,7 +202,7 @@ public class SimulationDTO {
|
||||
break;
|
||||
// Booster 1
|
||||
case 1:
|
||||
setBooster1Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, motorConfig, warnings));
|
||||
setBooster1Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, warnings));
|
||||
|
||||
// Calculate mass & CG of sustainer + booster 1 combined
|
||||
CGCalcConfig.setOnlyStage(0);
|
||||
@ -234,7 +234,7 @@ public class SimulationDTO {
|
||||
break;
|
||||
// Booster 2
|
||||
case 2:
|
||||
setBooster2Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, motorConfig, warnings));
|
||||
setBooster2Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, warnings));
|
||||
|
||||
// Calculate mass & CG of sustainer + booster 1 + booster 2 combined
|
||||
CGCalcConfig.setOnlyStage(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user