[Bugfix] Fixed Motor Ignition Default Loading

- added MotorConfiguration constructor which takes a template
  -- this allows copy-constructing from the default
  -- removed 'name' field: instead, call 'to?Description()'
- condensed & refactored a few debug methods.
This commit is contained in:
Daniel_M_Williams 2016-02-16 21:30:28 -05:00 committed by Daniel_M_Williams
parent d0cb8ab99f
commit a75b1816a4
7 changed files with 64 additions and 56 deletions

View File

@ -64,14 +64,13 @@ class MotorMountHandler extends AbstractElementHandler {
// System.err.println("closing MotorMount element: "+ element);
if (element.equals("motor")) {
// yes, this is confirmed to be the FLIGHT config id == motor instance id.
FlightConfigurationId fcid = new FlightConfigurationId(attributes.get("configid"));
if (!fcid.isValid()) {
warnings.add(Warning.fromString("Illegal motor specification, ignoring."));
return;
}
Motor motor = motorHandler.getMotor(warnings);
MotorConfiguration motorConfig = new MotorConfiguration( mount, fcid);
MotorConfiguration motorConfig = new MotorConfiguration( mount, fcid, mount.getDefaultMotorConfig());
motorConfig.setMotor(motor);
motorConfig.setEjectionDelay(motorHandler.getDelay(warnings));

View File

@ -14,7 +14,7 @@ import net.sf.openrocket.util.Inertia;
*/
public class MotorConfiguration implements FlightConfigurableParameter<MotorConfiguration> {
public static final String EMPTY_DESCRIPTION = "Empty Configuration".intern();
public static final String EMPTY_DESCRIPTION = "Empty Motor Configuration".intern();
protected final MotorMount mount;
protected final FlightConfigurationId fcid;
@ -44,18 +44,30 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
this.motor = null;
ejectionDelay = 0.0;
ignitionEvent = IgnitionEvent.LAUNCH;
ignitionEvent = IgnitionEvent.NEVER;
ignitionDelay = 0.0;
modID++;
}
public MotorConfiguration( final MotorMount _mount, final FlightConfigurationId _fcid, final MotorConfiguration _template ) {
this( _mount, _fcid);
if( null != _template){
ejectionDelay = _template.getEjectionDelay();
ignitionEvent = _template.getIgnitionEvent();
ignitionDelay = _template.getIgnitionDelay();
}
}
public boolean hasIgnitionOverride() {
return ignitionOveride;
}
public String getDescription(){
public String toMotorDescription(){
if( motor == null ){
return EMPTY_DESCRIPTION;
return "<Empty>";
}else{
return this.motor.getDesignation() + "-" + (int)this.getEjectionDelay();
}
@ -67,7 +79,6 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public void setMotor(Motor motor){
this.motor = motor;
updateName();
}
public Motor getMotor() {
@ -119,6 +130,16 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
this.ignitionOveride = true;
}
public int getMotorCount() {
if( mount instanceof InnerTube ){
InnerTube inner = (InnerTube) mount;
return inner.getClusterConfiguration().getClusterCount();
}else{
return 1;
}
}
public Coordinate getOffset( ){
RocketComponent comp = (RocketComponent) mount;
double delta_x = comp.getLength() + mount.getMotorOverhang() - this.motor.getLength();
@ -195,19 +216,26 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public void update(){
}
private void updateName(){
if( null != motor ){
this.name = this.mount.getID() + "-"+ getDescription();
}
public String toDescription(){
return ( this.toMotorDescription()+
" in: "+mount.getDebugName()+
" ign@: "+this.toIgnitionDescription() );
}
public int getMotorCount() {
if( mount instanceof InnerTube ){
InnerTube inner = (InnerTube) mount;
return inner.getClusterConfiguration().getClusterCount();
}else{
return 1;
}
public String toIgnitionDescription(){
return this.ignitionEvent.getName()+" + "+this.ignitionDelay+"s ";
}
public String toDebugDetail( ) {
StringBuilder buf = new StringBuilder();
buf.append(String.format(">> in: %28s::%10s %8s ign@: %12s ",
mount.getDebugName(),
fcid.toShortKey(),
toMotorDescription(),
toIgnitionDescription() ));
return buf.toString();
}

View File

@ -36,27 +36,16 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
@Override
public String toDebug(){
StringBuilder buffer = new StringBuilder();
buffer.append("====== Dumping MotorConfigurationSet for mount ("+this.size()+ " motors)\n");
MotorConfiguration defaultConfig = this.getDefault();
buffer.append(" (Ignition@ "+ defaultConfig.getIgnitionEvent().name +" +"+defaultConfig.getIgnitionDelay()+"sec )\n");
final MotorMount mnt = this.getDefault().getMount();
buffer.append("====== Dumping MotorConfigurationSet: "+this.size()+ " motors in "+mnt.getDebugName()+" \n");
for( FlightConfigurationId loopFCID : this.map.keySet()){
String shortKey = loopFCID.toShortKey();
MotorConfiguration curInstance = this.map.get(loopFCID);
String designation;
if( null == curInstance.getMotor() ){
designation = "<EMPTY>";
MotorConfiguration curConfig = this.map.get(loopFCID);
if( this.isDefault(loopFCID)){
buffer.append( " [DEFAULT] "+curConfig.toDebugDetail()+"\n");
}else{
designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay());
buffer.append( " "+curConfig.toDebugDetail() +"\n");
}
String ignition = curInstance.getIgnitionEvent().name;
double delay = curInstance.getIgnitionDelay();
if( 0 != delay ){
ignition += " +"+delay;
}
buffer.append(String.format(" >> [%10s]= %6s @ %4s\n",
shortKey, designation, ignition ));
}
return buffer.toString();
}

View File

@ -316,7 +316,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
}
if( ! motorConfig.isEmpty()){
buff.append( motorConfig.getDescription());
buff.append( motorConfig.toMotorDescription());
++activeMotorCount;
}
}
@ -397,6 +397,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.motors.put( motorConfig.getID(), motorConfig);
}
}
}
@Override
@ -522,7 +523,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return this.fcid.hashCode();
}
public String toDebug() {
return this.fcid.toDebug()+" (#"+instanceNumber+") "+ getOneLineMotorDescription();
}
@ -544,23 +544,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
// DEBUG / DEVEL
public String toMotorDetail(){
StringBuilder buf = new StringBuilder();
buf.append(String.format("\nDumping %2d Motors for configuration %s: (#: %s)\n",
this.motors.size(), this.getFlightConfigurationID().toFullKey(), this.instanceNumber));
final String fmt = " ..[%-8s] %-12s %-20s\n";
buf.append(String.format(fmt, "Motor Id", "Mtr Desig","Mount"));
buf.append(String.format("\nDumping %2d Motors for configuration %s (%s)(#: %s)\n",
this.motors.size(), this.getName(), this.getFlightConfigurationID().toFullKey(), this.instanceNumber));
for( MotorConfiguration curConfig : this.motors.values() ){
MotorMount mount = curConfig.getMount();
String motorId = curConfig.getID().toString();
String motorDesig;
if( curConfig.isEmpty() ){
motorDesig = "(empty)";
}else{
motorDesig = curConfig.getMotor().getDesignation();
}
String mountName = ((RocketComponent)mount).getName();
buf.append(String.format( fmt, motorId, motorDesig, mountName));
buf.append(" "+curConfig.toDebugDetail()+"\n");
}
buf.append("\n");
return buf.toString();

View File

@ -63,7 +63,7 @@ public interface MotorMount extends ChangeSource, FlightConfigurableComponent {
// duplicate of RocketComponent
public String getID();
public String getName();
public String getDebugName();
// duplicate of RocketComponent
public AxialStage getStage();

View File

@ -847,6 +847,10 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
return id;
}
public final String getDebugName() {
return (name + "/" + id.substring(0,8));
}
/**
* Generate a new ID for this component.
*/

View File

@ -145,7 +145,7 @@ public class MotorClusterState {
public String toDescription(){
return String.format("%32s / %4s - %s",
getMount().getName(), this.motor.getDesignation(), this.currentState.getName());
getMount().getDebugName(), this.motor.getDesignation(), this.currentState.getName());
}