bug fixes

This commit is contained in:
Sampo Niskanen 2010-07-19 11:28:15 +00:00
parent 429aa68ff8
commit ccadafeba8
5 changed files with 169 additions and 162 deletions

View File

@ -1,3 +1,11 @@
2010-07-19 Sampo Niskanen
* Small bug fixes
2010-07-18 Sampo Niskanen
* Major refactoring of simulation code
2010-03-21 Sampo Niskanen 2010-03-21 Sampo Niskanen
* Released version 1.1.0 * Released version 1.1.0

View File

@ -107,8 +107,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
new FinButton(TrapezoidFinSet.class, "Trapezoidal"), // TODO: MEDIUM: freer fin placing new FinButton(TrapezoidFinSet.class, "Trapezoidal"), // TODO: MEDIUM: freer fin placing
new FinButton(EllipticalFinSet.class, "Elliptical"), new FinButton(EllipticalFinSet.class, "Elliptical"),
new FinButton(FreeformFinSet.class, "Freeform"), new FinButton(FreeformFinSet.class, "Freeform"),
new FinButton(LaunchLug.class,"Launch lug") new FinButton(LaunchLug.class, "Launch lug"));
);
row++; row++;
@ -132,8 +131,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
new ComponentButton(ShockCord.class, "Shock cord"), new ComponentButton(ShockCord.class, "Shock cord"),
// new ComponentButton("Motor clip"), // new ComponentButton("Motor clip"),
// new ComponentButton("Payload"), // new ComponentButton("Payload"),
new ComponentButton(MassComponent.class,"Mass\ncomponent") new ComponentButton(MassComponent.class, "Mass\ncomponent"));
);
// Get maximum button size // Get maximum button size
@ -166,6 +164,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
if (viewport != null) { if (viewport != null) {
viewport.addChangeListener(new ChangeListener() { viewport.addChangeListener(new ChangeListener() {
private int oldWidth = -1; private int oldWidth = -1;
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
Dimension d = ComponentAddButtons.this.viewport.getExtentSize(); Dimension d = ComponentAddButtons.this.viewport.getExtentSize();
if (d.width != oldWidth) { if (d.width != oldWidth) {
@ -419,8 +418,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
selectionModel.setSelectionPath(ComponentTreeModel.makeTreePath(component)); selectionModel.setSelectionPath(ComponentTreeModel.makeTreePath(component));
JFrame parent = null; JFrame parent = null;
for (Component comp = ComponentAddButtons.this; comp != null; for (Component comp = ComponentAddButtons.this; comp != null; comp = comp.getParent()) {
comp = comp.getParent()) {
if (comp instanceof JFrame) { if (comp instanceof JFrame) {
parent = (JFrame) comp; parent = (JFrame) comp;
break; break;
@ -476,7 +474,10 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
if (!(c instanceof BodyComponent)) if (!(c instanceof BodyComponent))
return null; return null;
RocketComponent parent = c.getParent(); RocketComponent parent = c.getParent();
assert(parent != null); if (parent == null) {
throw new BugException("Component " + c.getComponentName() + " is the root component, " +
"componentClass=" + componentClass);
}
// Check whether to insert between or at the end. // Check whether to insert between or at the end.
// 0 = ask, 1 = in between, 2 = at the end // 0 = ask, 1 = in between, 2 = at the end
@ -616,4 +617,3 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
} }
} }

View File

@ -25,6 +25,7 @@ import javax.swing.JProgressBar;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.Simulation; import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.dialogs.DetailDialog; import net.sf.openrocket.gui.dialogs.DetailDialog;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.rocketcomponent.Configuration; import net.sf.openrocket.rocketcomponent.Configuration;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
@ -35,6 +36,7 @@ import net.sf.openrocket.simulation.exception.SimulationException;
import net.sf.openrocket.simulation.exception.SimulationLaunchException; import net.sf.openrocket.simulation.exception.SimulationLaunchException;
import net.sf.openrocket.simulation.listeners.AbstractSimulationListener; import net.sf.openrocket.simulation.listeners.AbstractSimulationListener;
import net.sf.openrocket.simulation.listeners.SimulationListener; import net.sf.openrocket.simulation.listeners.SimulationListener;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.Unit; import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.GUIUtil; import net.sf.openrocket.util.GUIUtil;
@ -43,6 +45,8 @@ import net.sf.openrocket.util.Prefs;
public class SimulationRunDialog extends JDialog { public class SimulationRunDialog extends JDialog {
private static final LogHelper log = Application.getLogger();
/** Update the dialog status every this many ms */ /** Update the dialog status every this many ms */
private static final long UPDATE_MS = 200; private static final long UPDATE_MS = 200;
@ -174,7 +178,6 @@ public class SimulationRunDialog extends JDialog {
private void updateProgress() { private void updateProgress() {
System.out.println("updateProgress() called");
int index; int index;
for (index = 0; index < simulations.length; index++) { for (index = 0; index < simulations.length; index++) {
if (!simulationDone[index]) if (!simulationDone[index])
@ -183,7 +186,7 @@ public class SimulationRunDialog extends JDialog {
if (index >= simulations.length) { if (index >= simulations.length) {
// Everything is done, close the dialog // Everything is done, close the dialog
System.out.println("Everything done."); log.debug("Everything done.");
this.dispose(); this.dispose();
return; return;
} }
@ -195,15 +198,15 @@ public class SimulationRunDialog extends JDialog {
} }
progress /= simulationWorkers.length; progress /= simulationWorkers.length;
progressBar.setValue(progress); progressBar.setValue(progress);
System.out.println("Progressbar value " + progress); log.debug("Progressbar value " + progress);
// Update the simulation fields // Update the simulation fields
simLabel.setText("Running " + simulations[index].getName()); simLabel.setText("Running " + simulations[index].getName());
if (simulationStatuses[index] == null) { if (simulationStatuses[index] == null) {
log.debug("No simulation status data available, setting empty labels");
timeLabel.setText(""); timeLabel.setText("");
altLabel.setText(""); altLabel.setText("");
velLabel.setText(""); velLabel.setText("");
System.out.println("Empty labels, how sad.");
return; return;
} }
@ -217,7 +220,6 @@ public class SimulationRunDialog extends JDialog {
u = UnitGroup.UNITS_VELOCITY.getDefaultUnit(); u = UnitGroup.UNITS_VELOCITY.getDefaultUnit();
velLabel.setText(u.toStringUnit(simulationStatuses[index].getRocketVelocity().z) + " (max. " + velLabel.setText(u.toStringUnit(simulationStatuses[index].getRocketVelocity().z) + " (max. " +
u.toStringUnit(simulationMaxVelocity[index]) + ")"); u.toStringUnit(simulationMaxVelocity[index]) + ")");
System.out.println("Set interesting labels.");
} }
@ -299,7 +301,7 @@ public class SimulationRunDialog extends JDialog {
// 1. time = 0 ... burnoutTimeEstimate // 1. time = 0 ... burnoutTimeEstimate
if (simulationStage == -2 && status.getSimulationTime() < burnoutTimeEstimate) { if (simulationStage == -2 && status.getSimulationTime() < burnoutTimeEstimate) {
System.out.println("Method 1: t=" + status.getSimulationTime() + " est=" + burnoutTimeEstimate); log.debug("Method 1: t=" + status.getSimulationTime() + " est=" + burnoutTimeEstimate);
setSimulationProgress(MathUtil.map(status.getSimulationTime(), 0, burnoutTimeEstimate, setSimulationProgress(MathUtil.map(status.getSimulationTime(), 0, burnoutTimeEstimate,
0.0, BURNOUT_PROGRESS)); 0.0, BURNOUT_PROGRESS));
updateProgress(); updateProgress();
@ -309,13 +311,12 @@ public class SimulationRunDialog extends JDialog {
if (simulationStage == -2) { if (simulationStage == -2) {
simulationStage++; simulationStage++;
burnoutVelocity = MathUtil.max(status.getRocketVelocity().z, 0.1); burnoutVelocity = MathUtil.max(status.getRocketVelocity().z, 0.1);
System.out.println("CHANGING to Method 2, vel=" + burnoutVelocity); log.debug("CHANGING to Method 2, vel=" + burnoutVelocity);
} }
// 2. z-velocity from burnout velocity to zero // 2. z-velocity from burnout velocity to zero
if (simulationStage == -1 && status.getRocketVelocity().z >= 0) { if (simulationStage == -1 && status.getRocketVelocity().z >= 0) {
System.out.println("Method 2: vel=" + status.getRocketVelocity().z + " burnout=" + log.debug("Method 2: vel=" + status.getRocketVelocity().z + " burnout=" + burnoutVelocity);
burnoutVelocity);
setSimulationProgress(MathUtil.map(status.getRocketVelocity().z, burnoutVelocity, 0, setSimulationProgress(MathUtil.map(status.getRocketVelocity().z, burnoutVelocity, 0,
BURNOUT_PROGRESS, APOGEE_PROGRESS)); BURNOUT_PROGRESS, APOGEE_PROGRESS));
updateProgress(); updateProgress();
@ -325,11 +326,12 @@ public class SimulationRunDialog extends JDialog {
if (simulationStage == -1 && status.getRocketVelocity().z < 0) { if (simulationStage == -1 && status.getRocketVelocity().z < 0) {
simulationStage++; simulationStage++;
apogeeAltitude = MathUtil.max(status.getRocketPosition().z, 1); apogeeAltitude = MathUtil.max(status.getRocketPosition().z, 1);
log.debug("CHANGING to Method 3, apogee=" + apogeeAltitude);
} }
// 3. z-position from apogee to zero // 3. z-position from apogee to zero
// TODO: MEDIUM: several stages // TODO: MEDIUM: several stages
System.out.println("Method 3: alt=" + status.getRocketPosition().z + " apogee=" + apogeeAltitude); log.debug("Method 3: alt=" + status.getRocketPosition().z + " apogee=" + apogeeAltitude);
setSimulationProgress(MathUtil.map(status.getRocketPosition().z, setSimulationProgress(MathUtil.map(status.getRocketPosition().z,
apogeeAltitude, 0, APOGEE_PROGRESS, 1.0)); apogeeAltitude, 0, APOGEE_PROGRESS, 1.0));
updateProgress(); updateProgress();
@ -341,7 +343,7 @@ public class SimulationRunDialog extends JDialog {
@Override @Override
protected void simulationDone() { protected void simulationDone() {
simulationDone[index] = true; simulationDone[index] = true;
System.out.println("DONE, setting progress"); log.debug("Simulation done");
setSimulationProgress(1.0); setSimulationProgress(1.0);
updateProgress(); updateProgress();
} }
@ -425,10 +427,9 @@ public class SimulationRunDialog extends JDialog {
private void setSimulationProgress(double p) { private void setSimulationProgress(double p) {
progress = Math.max(progress, (int) (100 * p + 0.5)); int exact = Math.max(progress, (int) (100 * p + 0.5));
progress = MathUtil.clamp(progress, 0, 100); progress = MathUtil.clamp(exact, 0, 100);
System.out.println("Setting progress to " + progress + " (real " + log.debug("Setting progress to " + progress + " (real " + exact + ")");
((int) (100 * p + 0.5)) + ")");
super.setProgress(progress); super.setProgress(progress);
} }
@ -448,7 +449,7 @@ public class SimulationRunDialog extends JDialog {
case APOGEE: case APOGEE:
simulationStage = 0; simulationStage = 0;
apogeeAltitude = status.getRocketPosition().z; apogeeAltitude = status.getRocketPosition().z;
System.out.println("APOGEE, setting progress"); log.debug("APOGEE, setting progress");
setSimulationProgress(APOGEE_PROGRESS); setSimulationProgress(APOGEE_PROGRESS);
publish(status); publish(status);
break; break;
@ -458,7 +459,7 @@ public class SimulationRunDialog extends JDialog {
break; break;
case SIMULATION_END: case SIMULATION_END:
System.out.println("END, setting progress"); log.debug("END, setting progress");
setSimulationProgress(1.0); setSimulationProgress(1.0);
break; break;
} }

View File

@ -479,9 +479,7 @@ public class Prefs {
//// Background flight data computation //// Background flight data computation
public static boolean computeFlightInBackground() { public static boolean computeFlightInBackground() {
// TODO: CRITICAL: Revert return PREFNODE.getBoolean("backgroundFlight", true);
return false;
// return PREFNODE.getBoolean("backgroundFlight", true);
} }
public static Simulation getBackgroundSimulation(Rocket rocket) { public static Simulation getBackgroundSimulation(Rocket rocket) {

View File

@ -31,7 +31,7 @@ public class LoggingTest {
List<LogLine> logs = log4.getLogs(); List<LogLine> logs = log4.getLogs();
assertEquals(4, logs.size()); assertEquals(4, logs.size());
assertTrue(logs.get(0).toString(), logs.get(0).toString().matches( assertTrue(logs.get(0).toString(), logs.get(0).toString().matches(
" *[0-9]+ +[0-9]+\\.[0-9]+ +DEBUG \\(LoggingTest.java:[0-9]+\\) two")); " *[0-9]+ +[0-9]+\\.[0-9]+ +DEBUG \\(-\\) two"));
assertTrue(logs.get(1).toString(), logs.get(1).toString().matches( assertTrue(logs.get(1).toString(), logs.get(1).toString().matches(
" *[0-9]+ +[0-9]+\\.[0-9]+ +INFO \\(LoggingTest.java:[0-9]+\\) three")); " *[0-9]+ +[0-9]+\\.[0-9]+ +INFO \\(LoggingTest.java:[0-9]+\\) three"));
assertTrue(logs.get(2).toString(), logs.get(2).toString().matches( assertTrue(logs.get(2).toString(), logs.get(2).toString().matches(