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

@ -62,11 +62,11 @@ import net.sf.openrocket.util.Reflection;
*/ */
public class ComponentAddButtons extends JPanel implements Scrollable { public class ComponentAddButtons extends JPanel implements Scrollable {
private static final int ROWS = 3; private static final int ROWS = 3;
private static final int MAXCOLS = 6; private static final int MAXCOLS = 6;
private static final String BUTTONPARAM = "grow, sizegroup buttons"; private static final String BUTTONPARAM = "grow, sizegroup buttons";
private static final int GAP = 5; private static final int GAP = 5;
private static final int EXTRASPACE = 0; private static final int EXTRASPACE = 0;
@ -80,15 +80,15 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
private final int width, height; private final int width, height;
public ComponentAddButtons(OpenRocketDocument document, TreeSelectionModel model, public ComponentAddButtons(OpenRocketDocument document, TreeSelectionModel model,
JViewport viewport) { JViewport viewport) {
super(); super();
String constaint = "[min!]"; String constaint = "[min!]";
for (int i=1; i<MAXCOLS; i++) for (int i = 1; i < MAXCOLS; i++)
constaint = constaint + GAP + "[min!]"; constaint = constaint + GAP + "[min!]";
layout = new MigLayout("fill",constaint); layout = new MigLayout("fill", constaint);
setLayout(layout); setLayout(layout);
this.document = document; this.document = document;
this.selectionModel = model; this.selectionModel = model;
@ -99,48 +99,46 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
//////////////////////////////////////////// ////////////////////////////////////////////
addButtonRow("Body components and fin sets",row, addButtonRow("Body components and fin sets", row,
new BodyComponentButton(NoseCone.class,"Nose cone"), new BodyComponentButton(NoseCone.class, "Nose cone"),
new BodyComponentButton(BodyTube.class,"Body tube"), new BodyComponentButton(BodyTube.class, "Body tube"),
new BodyComponentButton(Transition.class,"Transition"), new BodyComponentButton(Transition.class, "Transition"),
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++;
///////////////////////////////////////////// /////////////////////////////////////////////
addButtonRow("Inner component",row, addButtonRow("Inner component", row,
new ComponentButton(InnerTube.class, "Inner tube"), new ComponentButton(InnerTube.class, "Inner tube"),
new ComponentButton(TubeCoupler.class, "Coupler"), new ComponentButton(TubeCoupler.class, "Coupler"),
new ComponentButton(CenteringRing.class, "Centering\nring"), new ComponentButton(CenteringRing.class, "Centering\nring"),
new ComponentButton(Bulkhead.class, "Bulkhead"), new ComponentButton(Bulkhead.class, "Bulkhead"),
new ComponentButton(EngineBlock.class, "Engine\nblock")); new ComponentButton(EngineBlock.class, "Engine\nblock"));
row++; row++;
//////////////////////////////////////////// ////////////////////////////////////////////
addButtonRow("Mass objects",row, addButtonRow("Mass objects", row,
new ComponentButton(Parachute.class, "Parachute"), new ComponentButton(Parachute.class, "Parachute"),
new ComponentButton(Streamer.class, "Streamer"), new ComponentButton(Streamer.class, "Streamer"),
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
int w=0, h=0; int w = 0, h = 0;
for (row=0; row < buttons.length; row++) { for (row = 0; row < buttons.length; row++) {
for (int col=0; col < buttons[row].length; col++) { for (int col = 0; col < buttons[row].length; col++) {
Dimension d = buttons[row][col].getPreferredSize(); Dimension d = buttons[row][col].getPreferredSize();
if (d.width > w) if (d.width > w)
w = d.width; w = d.width;
@ -150,12 +148,12 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
} }
// Set all buttons to maximum size // Set all buttons to maximum size
System.out.println("Setting w="+w+" h="+h); System.out.println("Setting w=" + w + " h=" + h);
width=w; width = w;
height=h; height = h;
Dimension d = new Dimension(width,height); Dimension d = new Dimension(width, height);
for (row=0; row < buttons.length; row++) { for (row = 0; row < buttons.length; row++) {
for (int col=0; col < buttons[row].length; col++) { for (int col = 0; col < buttons[row].length; col++) {
buttons[row][col].setMinimumSize(d); buttons[row][col].setMinimumSize(d);
buttons[row][col].setPreferredSize(d); buttons[row][col].setPreferredSize(d);
buttons[row][col].getComponent(0).validate(); buttons[row][col].getComponent(0).validate();
@ -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) {
@ -176,7 +175,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
}); });
} }
add(new JPanel(),"grow"); add(new JPanel(), "grow");
} }
@ -186,50 +185,50 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
* @param row Row number * @param row Row number
* @param b List of ComponentButtons to place on the row * @param b List of ComponentButtons to place on the row
*/ */
private void addButtonRow(String label, int row, ComponentButton ... b) { private void addButtonRow(String label, int row, ComponentButton... b) {
if (row>0) if (row > 0)
add(new JLabel(label),"span, gaptop unrel, wrap"); add(new JLabel(label), "span, gaptop unrel, wrap");
else else
add(new JLabel(label),"span, gaptop 0, wrap"); add(new JLabel(label), "span, gaptop 0, wrap");
int col=0; int col = 0;
buttons[row] = new ComponentButton[b.length]; buttons[row] = new ComponentButton[b.length];
for (int i=0; i<b.length; i++) { for (int i = 0; i < b.length; i++) {
buttons[row][col] = b[i]; buttons[row][col] = b[i];
if (i < b.length-1) if (i < b.length - 1)
add(b[i],BUTTONPARAM); add(b[i], BUTTONPARAM);
else else
add(b[i],BUTTONPARAM+", wrap"); add(b[i], BUTTONPARAM + ", wrap");
col++; col++;
} }
} }
/** /**
* Flows the buttons in all rows of the panel. If a button would come too close * Flows the buttons in all rows of the panel. If a button would come too close
* to the right edge of the viewport, "newline" is added to its constraints flowing * to the right edge of the viewport, "newline" is added to its constraints flowing
* it to the next line. * it to the next line.
*/ */
private void flowButtons() { private void flowButtons() {
if (viewport==null) if (viewport == null)
return; return;
int w; int w;
Dimension d = viewport.getExtentSize(); Dimension d = viewport.getExtentSize();
for (int row=0; row < buttons.length; row++) { for (int row = 0; row < buttons.length; row++) {
w=0; w = 0;
for (int col=0; col < buttons[row].length; col++) { for (int col = 0; col < buttons[row].length; col++) {
w += GAP+width; w += GAP + width;
String param = BUTTONPARAM+",width "+width+"!,height "+height+"!"; String param = BUTTONPARAM + ",width " + width + "!,height " + height + "!";
if (w+EXTRASPACE > d.width) { if (w + EXTRASPACE > d.width) {
param = param + ",newline"; param = param + ",newline";
w = GAP+width; w = GAP + width;
} }
if (col == buttons[row].length-1) if (col == buttons[row].length - 1)
param = param + ",wrap"; param = param + ",wrap";
layout.setComponentConstraints(buttons[row][col], param); layout.setComponentConstraints(buttons[row][col], param);
} }
@ -238,7 +237,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
} }
/** /**
* Class for a component button. * Class for a component button.
*/ */
@ -248,7 +247,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
/** Only label, no icon. */ /** Only label, no icon. */
public ComponentButton(String text) { public ComponentButton(String text) {
this(text,null,null); this(text, null, null);
} }
/** /**
@ -257,48 +256,48 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
*/ */
public ComponentButton(String text, Icon enabled, Icon disabled) { public ComponentButton(String text, Icon enabled, Icon disabled) {
super(); super();
setLayout(new MigLayout("fill, flowy, insets 0, gap 0","","")); setLayout(new MigLayout("fill, flowy, insets 0, gap 0", "", ""));
add(new JLabel(),"push, sizegroup spacing"); add(new JLabel(), "push, sizegroup spacing");
// Add Icon // Add Icon
if (enabled != null) { if (enabled != null) {
JLabel label = new JLabel(enabled); JLabel label = new JLabel(enabled);
if (disabled != null) if (disabled != null)
label.setDisabledIcon(disabled); label.setDisabledIcon(disabled);
add(label,"growx"); add(label, "growx");
} }
// Add labels // Add labels
String[] l = text.split("\n"); String[] l = text.split("\n");
for (int i=0; i<l.length; i++) { for (int i = 0; i < l.length; i++) {
add(new StyledLabel(l[i],SwingConstants.CENTER,-3.0f),"growx"); add(new StyledLabel(l[i], SwingConstants.CENTER, -3.0f), "growx");
} }
add(new JLabel(),"push, sizegroup spacing"); add(new JLabel(), "push, sizegroup spacing");
valueChanged(null); // Update enabled status valueChanged(null); // Update enabled status
selectionModel.addTreeSelectionListener(this); selectionModel.addTreeSelectionListener(this);
} }
/** /**
* Main constructor that should be used. The generated component type is specified * Main constructor that should be used. The generated component type is specified
* and the text. The icons are fetched based on the component type. * and the text. The icons are fetched based on the component type.
*/ */
public ComponentButton(Class<? extends RocketComponent> c, String text) { public ComponentButton(Class<? extends RocketComponent> c, String text) {
this(text,ComponentIcons.getLargeIcon(c),ComponentIcons.getLargeDisabledIcon(c)); this(text, ComponentIcons.getLargeIcon(c), ComponentIcons.getLargeDisabledIcon(c));
if (c==null) if (c == null)
return; return;
componentClass = c; componentClass = c;
try { try {
constructor = c.getConstructor(); constructor = c.getConstructor();
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Unable to get default "+ throw new IllegalArgumentException("Unable to get default " +
"constructor for class "+c,e); "constructor for class " + c, e);
} }
} }
@ -308,9 +307,9 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
* c is null if there is no selection. The default is to use c.isCompatible(class). * c is null if there is no selection. The default is to use c.isCompatible(class).
*/ */
public boolean isAddable(RocketComponent c) { public boolean isAddable(RocketComponent c) {
if (c==null) if (c == null)
return false; return false;
if (componentClass==null) if (componentClass == null)
return false; return false;
return c.isCompatible(componentClass); return c.isCompatible(componentClass);
} }
@ -345,22 +344,22 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
super.setEnabled(enabled); super.setEnabled(enabled);
Component[] c = getComponents(); Component[] c = getComponents();
for (int i=0; i<c.length; i++) for (int i = 0; i < c.length; i++)
c[i].setEnabled(enabled); c[i].setEnabled(enabled);
} }
/** /**
* Update the enabled status of the button. * Update the enabled status of the button.
*/ */
private void updateEnabled() { private void updateEnabled() {
RocketComponent c=null; RocketComponent c = null;
TreePath p = selectionModel.getSelectionPath(); TreePath p = selectionModel.getSelectionPath();
if (p!=null) if (p != null)
c = (RocketComponent)p.getLastPathComponent(); c = (RocketComponent) p.getLastPathComponent();
setEnabled(isAddable(c)); setEnabled(isAddable(c));
} }
@Override @Override
protected void fireActionPerformed(ActionEvent event) { protected void fireActionPerformed(ActionEvent event) {
@ -369,18 +368,18 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
Integer position = null; Integer position = null;
TreePath p = selectionModel.getSelectionPath(); TreePath p = selectionModel.getSelectionPath();
if (p!= null) if (p != null)
c = (RocketComponent)p.getLastPathComponent(); c = (RocketComponent) p.getLastPathComponent();
Pair<RocketComponent, Integer> pos = getAdditionPosition(c); Pair<RocketComponent, Integer> pos = getAdditionPosition(c);
if (pos==null) { if (pos == null) {
// Cancel addition // Cancel addition
return; return;
} }
c = pos.getU(); c = pos.getU();
position = pos.getV(); position = pos.getV();
if (c == null) { if (c == null) {
// Should not occur // Should not occur
ExceptionHandler.handleErrorCondition("ERROR: Could not place new component."); ExceptionHandler.handleErrorCondition("ERROR: Could not place new component.");
@ -395,13 +394,13 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
RocketComponent component; RocketComponent component;
try { try {
component = (RocketComponent)constructor.newInstance(); component = (RocketComponent) constructor.newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
throw new BugException("Could not construct new instance of class "+ throw new BugException("Could not construct new instance of class " +
constructor,e); constructor, e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new BugException("Could not construct new instance of class "+ throw new BugException("Could not construct new instance of class " +
constructor,e); constructor, e);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
throw Reflection.handleWrappedException(e); throw Reflection.handleWrappedException(e);
} }
@ -409,7 +408,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
// Next undo position is set by opening the configuration dialog // Next undo position is set by opening the configuration dialog
document.addUndoPosition("Add " + component.getComponentName()); document.addUndoPosition("Add " + component.getComponentName());
if (position == null) if (position == null)
c.addChild(component); c.addChild(component);
else else
@ -419,14 +418,13 @@ 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;
} }
} }
ComponentConfigDialog.showDialog(parent, document, component); ComponentConfigDialog.showDialog(parent, document, component);
} }
} }
@ -439,15 +437,15 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
public BodyComponentButton(Class<? extends RocketComponent> c, String text) { public BodyComponentButton(Class<? extends RocketComponent> c, String text) {
super(c, text); super(c, text);
} }
public BodyComponentButton(String text, Icon enabled, Icon disabled) { public BodyComponentButton(String text, Icon enabled, Icon disabled) {
super(text, enabled, disabled); super(text, enabled, disabled);
} }
public BodyComponentButton(String text) { public BodyComponentButton(String text) {
super(text); super(text);
} }
@Override @Override
public boolean isAddable(RocketComponent c) { public boolean isAddable(RocketComponent c) {
if (super.isAddable(c)) if (super.isAddable(c))
@ -462,28 +460,31 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
@Override @Override
public Pair<RocketComponent, Integer> getAdditionPosition(RocketComponent c) { public Pair<RocketComponent, Integer> getAdditionPosition(RocketComponent c) {
if (super.isAddable(c)) // Handled automatically if (super.isAddable(c)) // Handled automatically
return super.getAdditionPosition(c); return super.getAdditionPosition(c);
if (c == null || c instanceof Rocket) { if (c == null || c instanceof Rocket) {
// Add as last body component of the last stage // Add as last body component of the last stage
Rocket rocket = document.getRocket(); Rocket rocket = document.getRocket();
return new Pair<RocketComponent,Integer>(rocket.getChild(rocket.getStageCount()-1), return new Pair<RocketComponent, Integer>(rocket.getChild(rocket.getStageCount() - 1),
null); null);
} }
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
int pos = Prefs.getChoise(Prefs.BODY_COMPONENT_INSERT_POSITION_KEY, 2, 0); int pos = Prefs.getChoise(Prefs.BODY_COMPONENT_INSERT_POSITION_KEY, 2, 0);
if (pos==0) { if (pos == 0) {
if (parent.getChildPosition(c) == parent.getChildCount()-1) if (parent.getChildPosition(c) == parent.getChildCount() - 1)
pos = 2; // Selected component is the last component pos = 2; // Selected component is the last component
else else
pos = askPosition(); pos = askPosition();
} }
@ -494,12 +495,12 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
return null; return null;
case 1: case 1:
// Insert after current position // Insert after current position
return new Pair<RocketComponent,Integer>(parent, parent.getChildPosition(c)+1); return new Pair<RocketComponent, Integer>(parent, parent.getChildPosition(c) + 1);
case 2: case 2:
// Insert at the end of the parent // Insert at the end of the parent
return new Pair<RocketComponent,Integer>(parent, null); return new Pair<RocketComponent, Integer>(parent, null);
default: default:
ExceptionHandler.handleErrorCondition("ERROR: Bad position type: "+pos); ExceptionHandler.handleErrorCondition("ERROR: Bad position type: " + pos);
return null; return null;
} }
} }
@ -509,22 +510,22 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
JPanel panel = new JPanel(new MigLayout()); JPanel panel = new JPanel(new MigLayout());
JCheckBox check = new JCheckBox("Do not ask me again"); JCheckBox check = new JCheckBox("Do not ask me again");
panel.add(check,"wrap"); panel.add(check, "wrap");
panel.add(new StyledLabel("You can change the default operation in the " + panel.add(new StyledLabel("You can change the default operation in the " +
"preferences.",-2)); "preferences.", -2));
int sel = JOptionPane.showOptionDialog(null, // parent component int sel = JOptionPane.showOptionDialog(null, // parent component
new Object[] { new Object[] {
"Insert the component after the current component or as the last " + "Insert the component after the current component or as the last " +
"component?", "component?",
panel }, panel },
"Select component position", // title "Select component position", // title
JOptionPane.DEFAULT_OPTION, // default selections JOptionPane.DEFAULT_OPTION, // default selections
JOptionPane.QUESTION_MESSAGE, // dialog type JOptionPane.QUESTION_MESSAGE, // dialog type
null, // icon null, // icon
options, // options options, // options
options[0]); // initial value options[0]); // initial value
switch (sel) { switch (sel) {
case JOptionPane.CLOSED_OPTION: case JOptionPane.CLOSED_OPTION:
case 2: case 2:
@ -539,7 +540,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
sel = 2; sel = 2;
break; break;
default: default:
ExceptionHandler.handleErrorCondition("ERROR: JOptionPane returned "+sel); ExceptionHandler.handleErrorCondition("ERROR: JOptionPane returned " + sel);
return 0; return 0;
} }
@ -552,7 +553,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
} }
/** /**
* Class for fin sets, that attach only to BodyTubes. * Class for fin sets, that attach only to BodyTubes.
@ -561,33 +562,33 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
public FinButton(Class<? extends RocketComponent> c, String text) { public FinButton(Class<? extends RocketComponent> c, String text) {
super(c, text); super(c, text);
} }
public FinButton(String text, Icon enabled, Icon disabled) { public FinButton(String text, Icon enabled, Icon disabled) {
super(text, enabled, disabled); super(text, enabled, disabled);
} }
public FinButton(String text) { public FinButton(String text) {
super(text); super(text);
} }
@Override @Override
public boolean isAddable(RocketComponent c) { public boolean isAddable(RocketComponent c) {
if (c==null) if (c == null)
return false; return false;
return (c.getClass().equals(BodyTube.class)); return (c.getClass().equals(BodyTube.class));
} }
} }
///////// Scrolling functionality
///////// Scrolling functionality
@Override @Override
public Dimension getPreferredScrollableViewportSize() { public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize(); return getPreferredSize();
} }
@Override @Override
public int getScrollableBlockIncrement(Rectangle visibleRect, public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation, int direction) { int orientation, int direction) {
@ -595,20 +596,20 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
return visibleRect.height * 8 / 10; return visibleRect.height * 8 / 10;
return 10; return 10;
} }
@Override @Override
public boolean getScrollableTracksViewportHeight() { public boolean getScrollableTracksViewportHeight() {
return false; return false;
} }
@Override @Override
public boolean getScrollableTracksViewportWidth() { public boolean getScrollableTracksViewportWidth() {
return true; return true;
} }
@Override @Override
public int getScrollableUnitIncrement(Rectangle visibleRect, public int getScrollableUnitIncrement(Rectangle visibleRect,
int orientation, int direction) { int orientation, int direction) {
@ -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

@ -7,7 +7,7 @@ import java.util.List;
import org.junit.Test; import org.junit.Test;
public class LoggingTest { public class LoggingTest {
@Test @Test
public void testLoggers() { public void testLoggers() {
// Ensure a sane stack trace // Ensure a sane stack trace
@ -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(