From: kruland2607 Date: Wed, 16 May 2012 06:27:02 +0000 (+0000) Subject: Refactor ExtendedThrustCurveMotor so it extends ThrustCurveMotor instead of delegates... X-Git-Tag: upstream/12.09^2~260 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=3773af05e07d8eaddb73889a6110abd3ba096122;p=debian%2Fopenrocket 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. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@688 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/android/src/net/sf/openrocket/android/MotorDatabaseAdapter.java b/android/src/net/sf/openrocket/android/MotorDatabaseAdapter.java index 72609184..cb027d2b 100644 --- a/android/src/net/sf/openrocket/android/MotorDatabaseAdapter.java +++ b/android/src/net/sf/openrocket/android/MotorDatabaseAdapter.java @@ -33,7 +33,7 @@ public class MotorDatabaseAdapter implements MotorDatabase { try { ExtendedThrustCurveMotor m = mDbHelper.getMotorDao().fetchMotor(manufacturer, designation); if ( m != null ) { - return Collections.singletonList(m.getThrustCurveMotor()); + return Collections.singletonList(m); } } catch ( Exception ex ) { diff --git a/android/src/net/sf/openrocket/android/db/MotorDao.java b/android/src/net/sf/openrocket/android/db/MotorDao.java index 5ea8caec..81e9912d 100644 --- a/android/src/net/sf/openrocket/android/db/MotorDao.java +++ b/android/src/net/sf/openrocket/android/db/MotorDao.java @@ -2,6 +2,7 @@ package net.sf.openrocket.android.db; import net.sf.openrocket.android.motor.ExtendedThrustCurveMotor; 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.Motor; import net.sf.openrocket.motor.ThrustCurveMotor; @@ -93,25 +94,24 @@ public class MotorDao { public long insertOrUpdateMotor(ExtendedThrustCurveMotor mi) throws Exception { ContentValues initialValues = new ContentValues(); - final ThrustCurveMotor tcm = mi.getThrustCurveMotor(); initialValues.put(ID, mi.getId()); - initialValues.put(UNIQUE_NAME, tcm.getManufacturer() + tcm.getDesignation()); - initialValues.put(DIGEST, tcm.getDigest()); - initialValues.put(DESIGNATION, tcm.getDesignation()); - initialValues.put(DELAYS, ConversionUtils.delaysToString(tcm.getStandardDelays())); - initialValues.put(DIAMETER, tcm.getDiameter()); - initialValues.put(TOTAL_IMPULSE, tcm.getTotalImpulseEstimate()); - initialValues.put(AVG_THRUST, tcm.getAverageThrustEstimate()); - initialValues.put(MAX_THRUST, tcm.getMaxThrustEstimate()); - initialValues.put(BURN_TIME, tcm.getBurnTimeEstimate()); - initialValues.put(LENGTH, tcm.getLength()); + initialValues.put(UNIQUE_NAME, mi.getManufacturer() + mi.getDesignation()); + initialValues.put(DIGEST, mi.getDigest()); + initialValues.put(DESIGNATION, mi.getDesignation()); + initialValues.put(DELAYS, ConversionUtils.delaysToString(mi.getStandardDelays())); + initialValues.put(DIAMETER, mi.getDiameter()); + initialValues.put(TOTAL_IMPULSE, mi.getTotalImpulseEstimate()); + initialValues.put(AVG_THRUST, mi.getAverageThrustEstimate()); + initialValues.put(MAX_THRUST, mi.getMaxThrustEstimate()); + initialValues.put(BURN_TIME, mi.getBurnTimeEstimate()); + initialValues.put(LENGTH, mi.getLength()); 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(MANUFACTURER, tcm.getManufacturer().getSimpleName()); - initialValues.put(THRUST_DATA, ConversionUtils.serializeArrayOfDouble(tcm.getThrustPoints())); - initialValues.put(TIME_DATA, ConversionUtils.serializeArrayOfDouble(tcm.getTimePoints())); - initialValues.put(CG_DATA, ConversionUtils.serializeArrayOfCoordinate(tcm.getCGPoints())); + initialValues.put(MANUFACTURER, mi.getManufacturer().getSimpleName()); + initialValues.put(THRUST_DATA, ConversionUtils.serializeArrayOfDouble(mi.getThrustPoints())); + initialValues.put(TIME_DATA, ConversionUtils.serializeArrayOfDouble(mi.getTimePoints())); + initialValues.put(CG_DATA, ConversionUtils.serializeArrayOfCoordinate(mi.getCGPoints())); AndroidLogWrapper.d(MotorDao.class, "insertOrUpdate Motor"); 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 { - ExtendedThrustCurveMotor mi = new ExtendedThrustCurveMotor(); - - mi.setId(mCursor.getLong(mCursor.getColumnIndex(ID))); - mi.setCaseInfo(mCursor.getString(mCursor.getColumnIndex(CASE_INFO))); - mi.setImpulseClass(mCursor.getString(mCursor.getColumnIndex(IMPULSE_CLASS))); - + ExtendedThrustCurveMotor mi; { String digest = mCursor.getString(mCursor.getColumnIndex(DIGEST)); String designation = mCursor.getString(mCursor.getColumnIndex(DESIGNATION)); @@ -222,7 +217,12 @@ public class MotorDao { cgData, 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; @@ -268,6 +268,9 @@ public class MotorDao { } mCursor.moveToFirst(); return hydrateMotor(mCursor); + } catch( Exception ex ) { + LogHelper.getInstance().debug("whoa!", ex); + throw ex; } finally { mCursor.close(); } diff --git a/android/src/net/sf/openrocket/android/motor/BurnPlotFragment.java b/android/src/net/sf/openrocket/android/motor/BurnPlotFragment.java index 53ff9205..c055e556 100644 --- a/android/src/net/sf/openrocket/android/motor/BurnPlotFragment.java +++ b/android/src/net/sf/openrocket/android/motor/BurnPlotFragment.java @@ -98,7 +98,7 @@ public class BurnPlotFragment extends Fragment { renderer.setAxesColor(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.setXLabelsAlign(Align.RIGHT); @@ -122,10 +122,10 @@ public class BurnPlotFragment extends Fragment { 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[] thrustPoints = motor.getThrustCurveMotor().getThrustPoints(); + double[] timePoints = motor.getTimePoints(); + double[] thrustPoints = motor.getThrustPoints(); // We are going to abuse this loop to also compute the Y axis max. int maxy = 0; diff --git a/android/src/net/sf/openrocket/android/motor/ExtendedThrustCurveMotor.java b/android/src/net/sf/openrocket/android/motor/ExtendedThrustCurveMotor.java index 41e4c4fd..cd72be48 100644 --- a/android/src/net/sf/openrocket/android/motor/ExtendedThrustCurveMotor.java +++ b/android/src/net/sf/openrocket/android/motor/ExtendedThrustCurveMotor.java @@ -2,12 +2,16 @@ package net.sf.openrocket.android.motor; import net.sf.openrocket.motor.ThrustCurveMotor; -public class ExtendedThrustCurveMotor { +public class ExtendedThrustCurveMotor extends ThrustCurveMotor { private Long id; private String caseInfo; private String impulseClass; - private ThrustCurveMotor thrustCurveMotor; + + public ExtendedThrustCurveMotor( ThrustCurveMotor tcm ) { + super(tcm); + } + /** * @return the id */ @@ -44,19 +48,6 @@ public class ExtendedThrustCurveMotor { public void setImpulseClass(String 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; - } - - + } diff --git a/android/src/net/sf/openrocket/android/motor/MotorDetailsFragment.java b/android/src/net/sf/openrocket/android/motor/MotorDetailsFragment.java index b1fac2cb..5bd42b9a 100644 --- a/android/src/net/sf/openrocket/android/motor/MotorDetailsFragment.java +++ b/android/src/net/sf/openrocket/android/motor/MotorDetailsFragment.java @@ -3,13 +3,12 @@ package net.sf.openrocket.android.motor; import net.sf.openrocket.R; import net.sf.openrocket.android.db.ConversionUtils; 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.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.EditText; public class MotorDetailsFragment extends DialogFragment { @@ -84,14 +83,13 @@ public class MotorDetailsFragment extends DialogFragment { } private void init( ) { - ThrustCurveMotor tcm = motor.getThrustCurveMotor(); - manuField.setText( tcm.getManufacturer().getDisplayName()); - nameField.setText( tcm.getDesignation() ); - delaysField.setText( ConversionUtils.delaysToString(tcm.getStandardDelays()) ); + manuField.setText( motor.getManufacturer().getDisplayName()); + nameField.setText( motor.getDesignation() ); + delaysField.setText( ConversionUtils.delaysToString(motor.getStandardDelays()) ); caseField.setText( motor.getCaseInfo()); impulseClassField.setText( motor.getImpulseClass()); - diameterField.setText( String.valueOf(tcm.getDiameter()*1000.0) ); - lengthField.setText( String.valueOf(tcm.getLength()*1000.0) ); + diameterField.setText( UnitGroup.UNITS_MOTOR_DIMENSIONS.toString(motor.getDiameter()) ); + lengthField.setText( UnitGroup.UNITS_LENGTH.getUnit("mm").toString(motor.getLength()) ); } private void saveChanges() { diff --git a/android/src/net/sf/openrocket/android/thrustcurve/TCQueryAction.java b/android/src/net/sf/openrocket/android/thrustcurve/TCQueryAction.java index 7516f7f1..52d99a40 100644 --- a/android/src/net/sf/openrocket/android/thrustcurve/TCQueryAction.java +++ b/android/src/net/sf/openrocket/android/thrustcurve/TCQueryAction.java @@ -101,9 +101,7 @@ public abstract class TCQueryAction extends Fragment { DbAdapter mDbHelper = new DbAdapter(getActivity()); mDbHelper.open(); try { - ExtendedThrustCurveMotor m = new ExtendedThrustCurveMotor(); - - m.setThrustCurveMotor( thrustCurveMotor ); + ExtendedThrustCurveMotor m = new ExtendedThrustCurveMotor(thrustCurveMotor); // Convert impulse class. ThrustCurve puts mmx, 1/4a and 1/2a as A. m.setImpulseClass(mi.getImpulse_class());