<TextView\r
android:layout_width="match_parent"\r
android:layout_height="match_parent"\r
- android:text="Comment" />\r
+ android:text="Lift off weight" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerLiftOffWeight"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
\r
<TextView\r
android:layout_width="match_parent"\r
android:text="" />\r
\r
<TextView\r
- android:id="@+id/openrocketviewerComment"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:text="CP" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerCP"\r
android:layout_width="match_parent"\r
android:layout_height="wrap_content"\r
android:text="" />\r
- </LinearLayout>\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:text="Stability margin" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerStabilityMargin"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ </LinearLayout>\r
\r
<pl.polidea.treeview.TreeViewList\r
android:id="@+id/openrocketviewerComponentTree"\r
import java.io.File;\r
\r
import net.sf.openrocket.R;\r
+import net.sf.openrocket.aerodynamics.AerodynamicCalculator;\r
+import net.sf.openrocket.aerodynamics.BarrowmanCalculator;\r
+import net.sf.openrocket.aerodynamics.FlightConditions;\r
+import net.sf.openrocket.aerodynamics.WarningSet;\r
import net.sf.openrocket.android.Application;\r
import net.sf.openrocket.android.PreferencesActivity;\r
import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;\r
import net.sf.openrocket.android.simulation.SimulationViewer;\r
import net.sf.openrocket.document.OpenRocketDocument;\r
import net.sf.openrocket.document.Simulation;\r
+import net.sf.openrocket.masscalc.BasicMassCalculator;\r
+import net.sf.openrocket.masscalc.MassCalculator;\r
import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;\r
+import net.sf.openrocket.rocketcomponent.Configuration;\r
import net.sf.openrocket.rocketcomponent.Rocket;\r
import net.sf.openrocket.rocketcomponent.RocketComponent;\r
import net.sf.openrocket.rocketcomponent.RocketUtils;\r
private Spinner configurationSpinner;\r
private TreeViewList componentTree;\r
private ListView simulationList;\r
+ \r
+ /* Calculation of CP and CG */\r
+ private AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();\r
+ private MassCalculator massCalculator = new BasicMassCalculator();\r
+\r
+ OpenRocketDocument rocketDocument;\r
+ Configuration rocketConfiguration;\r
\r
private Application app;\r
\r
\r
private void updateContents() {\r
\r
- OpenRocketDocument rocketDocument = app.getRocketDocument();\r
+ rocketDocument = app.getRocketDocument();\r
+ rocketConfiguration = rocketDocument.getDefaultConfiguration();\r
Rocket rocket = rocketDocument.getRocket();\r
\r
setTitle(rocket.getName());\r
}\r
\r
configurationSpinner.setAdapter(spinnerAdapter);\r
+ configurationSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {\r
+\r
+ /* (non-Javadoc)\r
+ * @see android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View, int, long)\r
+ */\r
+ @Override\r
+ public void onItemSelected(AdapterView<?> arg0, View arg1,\r
+ int arg2, long arg3) {\r
+\r
+ String selectedConfigId = rocketDocument.getRocket().getMotorConfigurationIDs()[arg2];\r
+ rocketConfiguration.setMotorConfigurationID(selectedConfigId);\r
+ Coordinate cp = aerodynamicCalculator.getWorstCP(rocketConfiguration,\r
+ new FlightConditions(rocketConfiguration),\r
+ new WarningSet());\r
+ \r
+ Coordinate cg = massCalculator.getCG(rocketConfiguration, MassCalcType.LAUNCH_MASS);\r
+\r
+ Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
+ Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
+ Unit stabilityUnit = UnitGroup.stabilityUnits(rocketConfiguration).getDefaultUnit();\r
+\r
+ ((TextView)findViewById(R.id.openrocketviewerCP)).setText(lengthUnit.toStringUnit(cp.x));\r
+ ((TextView)findViewById(R.id.openrocketviewerCG)).setText(lengthUnit.toStringUnit(cg.x));\r
+ ((TextView)findViewById(R.id.openrocketviewerLiftOffWeight)).setText(massUnit.toStringUnit(cg.weight));\r
+ ((TextView)findViewById(R.id.openrocketviewerStabilityMargin)).setText(stabilityUnit.toStringUnit(cp.x-cg.x));\r
+\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see android.widget.AdapterView.OnItemSelectedListener#onNothingSelected(android.widget.AdapterView)\r
+ */\r
+ @Override\r
+ public void onNothingSelected(AdapterView<?> arg0) {\r
+ ((TextView)findViewById(R.id.openrocketviewerCP)).setText("");\r
+ ((TextView)findViewById(R.id.openrocketviewerCG)).setText("");\r
+ ((TextView)findViewById(R.id.openrocketviewerLiftOffWeight)).setText("");\r
+ ((TextView)findViewById(R.id.openrocketviewerStabilityMargin)).setText("");\r
+ }\r
+ \r
+ });\r
\r
- Unit LengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
- Unit MassUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
+ Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
+ Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
\r
Coordinate cg = RocketUtils.getCG(rocket, MassCalcType.NO_MOTORS);\r
double length = RocketUtils.getLength(rocket);\r
((TextView)findViewById(R.id.openrocketviewerDesigner)).setText(rocket.getDesigner());\r
- ((TextView)findViewById(R.id.openrocketviewerCG)).setText(LengthUnit.toStringUnit(cg.x) );\r
- ((TextView)findViewById(R.id.openrocketviewerLength)).setText(LengthUnit.toStringUnit(length));\r
- ((TextView)findViewById(R.id.openrocketviewerMass)).setText(MassUnit.toStringUnit(cg.weight));\r
+ ((TextView)findViewById(R.id.openrocketviewerLength)).setText(lengthUnit.toStringUnit(length));\r
+ ((TextView)findViewById(R.id.openrocketviewerMass)).setText(massUnit.toStringUnit(cg.weight));\r
((TextView)findViewById(R.id.openrocketviewerStageCount)).setText(String.valueOf(rocket.getStageCount()));\r
- ((TextView)findViewById(R.id.openrocketviewerComment)).setText(rocket.getComment());\r
\r
+ \r
ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_2,rocketDocument.getSimulations()) {\r
\r
@Override\r