Refactor ExtendedThrustCurveMotor so it extends ThrustCurveMotor instead of delegates to a member variable. This is so when rockets are deserialized from orc files, the ThrustCurveMotors in the Rocket are actually ExtendedThrustCurveMotors. We will use this in the motor configuration editor system.

This commit is contained in:
Kevin Ruland 2012-05-16 06:27:02 +00:00
parent 672239535a
commit 4fa4217665
6 changed files with 45 additions and 55 deletions

View File

@ -33,7 +33,7 @@ public class MotorDatabaseAdapter implements MotorDatabase {
try { try {
ExtendedThrustCurveMotor m = mDbHelper.getMotorDao().fetchMotor(manufacturer, designation); ExtendedThrustCurveMotor m = mDbHelper.getMotorDao().fetchMotor(manufacturer, designation);
if ( m != null ) { if ( m != null ) {
return Collections.singletonList(m.getThrustCurveMotor()); return Collections.singletonList(m);
} }
} catch ( Exception ex ) { } catch ( Exception ex ) {

View File

@ -2,6 +2,7 @@ package net.sf.openrocket.android.db;
import net.sf.openrocket.android.motor.ExtendedThrustCurveMotor; import net.sf.openrocket.android.motor.ExtendedThrustCurveMotor;
import net.sf.openrocket.android.util.AndroidLogWrapper; import net.sf.openrocket.android.util.AndroidLogWrapper;
import net.sf.openrocket.android.util.AndroidLogWrapper.LogHelper;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.motor.ThrustCurveMotor;
@ -93,25 +94,24 @@ public class MotorDao {
public long insertOrUpdateMotor(ExtendedThrustCurveMotor mi) throws Exception { public long insertOrUpdateMotor(ExtendedThrustCurveMotor mi) throws Exception {
ContentValues initialValues = new ContentValues(); ContentValues initialValues = new ContentValues();
final ThrustCurveMotor tcm = mi.getThrustCurveMotor();
initialValues.put(ID, mi.getId()); initialValues.put(ID, mi.getId());
initialValues.put(UNIQUE_NAME, tcm.getManufacturer() + tcm.getDesignation()); initialValues.put(UNIQUE_NAME, mi.getManufacturer() + mi.getDesignation());
initialValues.put(DIGEST, tcm.getDigest()); initialValues.put(DIGEST, mi.getDigest());
initialValues.put(DESIGNATION, tcm.getDesignation()); initialValues.put(DESIGNATION, mi.getDesignation());
initialValues.put(DELAYS, ConversionUtils.delaysToString(tcm.getStandardDelays())); initialValues.put(DELAYS, ConversionUtils.delaysToString(mi.getStandardDelays()));
initialValues.put(DIAMETER, tcm.getDiameter()); initialValues.put(DIAMETER, mi.getDiameter());
initialValues.put(TOTAL_IMPULSE, tcm.getTotalImpulseEstimate()); initialValues.put(TOTAL_IMPULSE, mi.getTotalImpulseEstimate());
initialValues.put(AVG_THRUST, tcm.getAverageThrustEstimate()); initialValues.put(AVG_THRUST, mi.getAverageThrustEstimate());
initialValues.put(MAX_THRUST, tcm.getMaxThrustEstimate()); initialValues.put(MAX_THRUST, mi.getMaxThrustEstimate());
initialValues.put(BURN_TIME, tcm.getBurnTimeEstimate()); initialValues.put(BURN_TIME, mi.getBurnTimeEstimate());
initialValues.put(LENGTH, tcm.getLength()); initialValues.put(LENGTH, mi.getLength());
initialValues.put(CASE_INFO, mi.getCaseInfo()); initialValues.put(CASE_INFO, mi.getCaseInfo());
initialValues.put(TYPE, tcm.getMotorType().name()); initialValues.put(TYPE, mi.getMotorType().name());
initialValues.put(IMPULSE_CLASS, mi.getImpulseClass()); initialValues.put(IMPULSE_CLASS, mi.getImpulseClass());
initialValues.put(MANUFACTURER, tcm.getManufacturer().getSimpleName()); initialValues.put(MANUFACTURER, mi.getManufacturer().getSimpleName());
initialValues.put(THRUST_DATA, ConversionUtils.serializeArrayOfDouble(tcm.getThrustPoints())); initialValues.put(THRUST_DATA, ConversionUtils.serializeArrayOfDouble(mi.getThrustPoints()));
initialValues.put(TIME_DATA, ConversionUtils.serializeArrayOfDouble(tcm.getTimePoints())); initialValues.put(TIME_DATA, ConversionUtils.serializeArrayOfDouble(mi.getTimePoints()));
initialValues.put(CG_DATA, ConversionUtils.serializeArrayOfCoordinate(tcm.getCGPoints())); initialValues.put(CG_DATA, ConversionUtils.serializeArrayOfCoordinate(mi.getCGPoints()));
AndroidLogWrapper.d(MotorDao.class, "insertOrUpdate Motor"); AndroidLogWrapper.d(MotorDao.class, "insertOrUpdate Motor");
long rv = mDb.insertWithOnConflict(DATABASE_TABLE, null, initialValues, SQLiteDatabase.CONFLICT_REPLACE); long rv = mDb.insertWithOnConflict(DATABASE_TABLE, null, initialValues, SQLiteDatabase.CONFLICT_REPLACE);
@ -183,12 +183,7 @@ public class MotorDao {
} }
private ExtendedThrustCurveMotor hydrateMotor(Cursor mCursor) throws Exception { private ExtendedThrustCurveMotor hydrateMotor(Cursor mCursor) throws Exception {
ExtendedThrustCurveMotor mi = new ExtendedThrustCurveMotor(); ExtendedThrustCurveMotor mi;
mi.setId(mCursor.getLong(mCursor.getColumnIndex(ID)));
mi.setCaseInfo(mCursor.getString(mCursor.getColumnIndex(CASE_INFO)));
mi.setImpulseClass(mCursor.getString(mCursor.getColumnIndex(IMPULSE_CLASS)));
{ {
String digest = mCursor.getString(mCursor.getColumnIndex(DIGEST)); String digest = mCursor.getString(mCursor.getColumnIndex(DIGEST));
String designation = mCursor.getString(mCursor.getColumnIndex(DESIGNATION)); String designation = mCursor.getString(mCursor.getColumnIndex(DESIGNATION));
@ -222,7 +217,12 @@ public class MotorDao {
cgData, cgData,
digest digest
); );
mi.setThrustCurveMotor(tcm); mi = new ExtendedThrustCurveMotor(tcm);
mi.setId(mCursor.getLong(mCursor.getColumnIndex(ID)));
mi.setCaseInfo(mCursor.getString(mCursor.getColumnIndex(CASE_INFO)));
mi.setImpulseClass(mCursor.getString(mCursor.getColumnIndex(IMPULSE_CLASS)));
} }
return mi; return mi;
@ -268,6 +268,9 @@ public class MotorDao {
} }
mCursor.moveToFirst(); mCursor.moveToFirst();
return hydrateMotor(mCursor); return hydrateMotor(mCursor);
} catch( Exception ex ) {
LogHelper.getInstance().debug("whoa!", ex);
throw ex;
} finally { } finally {
mCursor.close(); mCursor.close();
} }

View File

@ -98,7 +98,7 @@ public class BurnPlotFragment extends Fragment {
renderer.setAxesColor(Color.LTGRAY); renderer.setAxesColor(Color.LTGRAY);
renderer.setLabelsColor(Color.LTGRAY); renderer.setLabelsColor(Color.LTGRAY);
renderer.setChartTitle(motor.getThrustCurveMotor().getManufacturer() + " " + motor.getThrustCurveMotor().getDesignation()); renderer.setChartTitle(motor.getManufacturer() + " " + motor.getDesignation());
renderer.setXTitle("time (s)"); renderer.setXTitle("time (s)");
renderer.setXLabelsAlign(Align.RIGHT); renderer.setXLabelsAlign(Align.RIGHT);
@ -122,10 +122,10 @@ public class BurnPlotFragment extends Fragment {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYSeries series = new XYSeries(motor.getThrustCurveMotor().getDesignation(), 0); XYSeries series = new XYSeries(motor.getDesignation(), 0);
double[] timePoints = motor.getThrustCurveMotor().getTimePoints(); double[] timePoints = motor.getTimePoints();
double[] thrustPoints = motor.getThrustCurveMotor().getThrustPoints(); double[] thrustPoints = motor.getThrustPoints();
// We are going to abuse this loop to also compute the Y axis max. // We are going to abuse this loop to also compute the Y axis max.
int maxy = 0; int maxy = 0;

View File

@ -2,12 +2,16 @@ package net.sf.openrocket.android.motor;
import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.motor.ThrustCurveMotor;
public class ExtendedThrustCurveMotor { public class ExtendedThrustCurveMotor extends ThrustCurveMotor {
private Long id; private Long id;
private String caseInfo; private String caseInfo;
private String impulseClass; private String impulseClass;
private ThrustCurveMotor thrustCurveMotor;
public ExtendedThrustCurveMotor( ThrustCurveMotor tcm ) {
super(tcm);
}
/** /**
* @return the id * @return the id
*/ */
@ -44,19 +48,6 @@ public class ExtendedThrustCurveMotor {
public void setImpulseClass(String impulseClass) { public void setImpulseClass(String impulseClass) {
this.impulseClass = impulseClass; this.impulseClass = impulseClass;
} }
/**
* @return the thrustCurveMotor
*/
public ThrustCurveMotor getThrustCurveMotor() {
return thrustCurveMotor;
}
/**
* @param thrustCurveMotor the thrustCurveMotor to set
*/
public void setThrustCurveMotor(ThrustCurveMotor thrustCurveMotor) {
this.thrustCurveMotor = thrustCurveMotor;
}
} }

View File

@ -3,13 +3,12 @@ package net.sf.openrocket.android.motor;
import net.sf.openrocket.R; import net.sf.openrocket.R;
import net.sf.openrocket.android.db.ConversionUtils; import net.sf.openrocket.android.db.ConversionUtils;
import net.sf.openrocket.android.db.DbAdapter; import net.sf.openrocket.android.db.DbAdapter;
import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.unit.UnitGroup;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
public class MotorDetailsFragment extends DialogFragment { public class MotorDetailsFragment extends DialogFragment {
@ -84,14 +83,13 @@ public class MotorDetailsFragment extends DialogFragment {
} }
private void init( ) { private void init( ) {
ThrustCurveMotor tcm = motor.getThrustCurveMotor(); manuField.setText( motor.getManufacturer().getDisplayName());
manuField.setText( tcm.getManufacturer().getDisplayName()); nameField.setText( motor.getDesignation() );
nameField.setText( tcm.getDesignation() ); delaysField.setText( ConversionUtils.delaysToString(motor.getStandardDelays()) );
delaysField.setText( ConversionUtils.delaysToString(tcm.getStandardDelays()) );
caseField.setText( motor.getCaseInfo()); caseField.setText( motor.getCaseInfo());
impulseClassField.setText( motor.getImpulseClass()); impulseClassField.setText( motor.getImpulseClass());
diameterField.setText( String.valueOf(tcm.getDiameter()*1000.0) ); diameterField.setText( UnitGroup.UNITS_MOTOR_DIMENSIONS.toString(motor.getDiameter()) );
lengthField.setText( String.valueOf(tcm.getLength()*1000.0) ); lengthField.setText( UnitGroup.UNITS_LENGTH.getUnit("mm").toString(motor.getLength()) );
} }
private void saveChanges() { private void saveChanges() {

View File

@ -101,9 +101,7 @@ public abstract class TCQueryAction extends Fragment {
DbAdapter mDbHelper = new DbAdapter(getActivity()); DbAdapter mDbHelper = new DbAdapter(getActivity());
mDbHelper.open(); mDbHelper.open();
try { try {
ExtendedThrustCurveMotor m = new ExtendedThrustCurveMotor(); ExtendedThrustCurveMotor m = new ExtendedThrustCurveMotor(thrustCurveMotor);
m.setThrustCurveMotor( thrustCurveMotor );
// Convert impulse class. ThrustCurve puts mmx, 1/4a and 1/2a as A. // Convert impulse class. ThrustCurve puts mmx, 1/4a and 1/2a as A.
m.setImpulseClass(mi.getImpulse_class()); m.setImpulseClass(mi.getImpulse_class());