Fixing various issues

This commit is contained in:
Sampo Niskanen 2012-02-19 08:23:22 +00:00
parent b1891e1dc1
commit 88f359c25f
10 changed files with 337 additions and 289 deletions

View File

@ -1,3 +1,7 @@
2012-02-16 Sampo Niskanen
* [BUG] Freeze when dropping component on child component
2012-02-10 Sampo Niskanen
* Configurable stage separation events

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -36,4 +36,5 @@ The following file format versions exist:
1.4: Introduced with OpenRocket 1.1.10. Adds the launchrodvelocity and
deploymentvelocity attributes to <flightdata> element. The motor
digesting algorithm was changed.
digesting algorithm was changed. Adds <separationevent> and
<separationdelay> elements to stage components (except sustainer).

View File

@ -34,3 +34,4 @@ help-license.png
help-log.png
help-about.png
help-bug.png
help-tours.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

View File

@ -360,7 +360,6 @@ public class RockSimMotorLoader extends AbstractMotorLoader {
if (!calculateCG) {
motorDigest.update(DataType.CG_PER_TIME, toArray(cg));
}
// FIXME: Should this use CG_SPECIFIC ???
motorDigest.update(DataType.FORCE_PER_TIME, thrustArray);
final String digest = motorDigest.getDigest();

View File

@ -1,5 +1,62 @@
package net.sf.openrocket.gui.main;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
@ -48,38 +105,6 @@ import net.sf.openrocket.util.MemoryManagement.MemoryData;
import net.sf.openrocket.util.Reflection;
import net.sf.openrocket.util.TestRockets;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
public class BasicFrame extends JFrame {
private static final LogHelper log = Application.getLogger();
@ -652,7 +677,7 @@ public class BasicFrame extends JFrame {
// Guided tours
item = new JMenuItem(trans.get("main.menu.help.tours"), KeyEvent.VK_L);
// TODO: Icon
item.setIcon(Icons.HELP_TOURS);
item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.help.tours.desc"));
item.addActionListener(new ActionListener() {
@Override
@ -666,22 +691,6 @@ public class BasicFrame extends JFrame {
menu.addSeparator();
//// License
item = new JMenuItem(trans.get("main.menu.help.license"), KeyEvent.VK_L);
item.setIcon(Icons.HELP_LICENSE);
item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.help.license.desc"));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
log.user("License selected");
new LicenseDialog(BasicFrame.this).setVisible(true);
}
});
menu.add(item);
menu.addSeparator();
//// Bug report
item = new JMenuItem(trans.get("main.menu.help.bugReport"), KeyEvent.VK_B);
item.setIcon(Icons.HELP_BUG_REPORT);
@ -710,6 +719,21 @@ public class BasicFrame extends JFrame {
menu.addSeparator();
//// License
item = new JMenuItem(trans.get("main.menu.help.license"), KeyEvent.VK_L);
item.setIcon(Icons.HELP_LICENSE);
item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.help.license.desc"));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
log.user("License selected");
new LicenseDialog(BasicFrame.this).setVisible(true);
}
});
menu.add(item);
//// About
item = new JMenuItem(trans.get("main.menu.help.about"), KeyEvent.VK_A);
item.setIcon(Icons.HELP_ABOUT);
@ -770,10 +794,10 @@ public class BasicFrame extends JFrame {
int sel = JOptionPane.showOptionDialog(BasicFrame.this, new Object[] {
"Input text key to generate random rocket:",
field
}, "Generate random test rocket", JOptionPane.DEFAULT_OPTION,
}, "Generate random test rocket", JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE, null, new Object[] {
"Random", "OK"
}, "OK");
}, "OK");
Rocket r;
if (sel == 0) {
@ -1212,14 +1236,14 @@ public class BasicFrame extends JFrame {
return true;
}
/**
* "Save" action. If the design is new, then this is identical to "Save As", with a default file filter for .ork.
* If the rocket being edited previously was opened from a .ork file, then it will be saved immediately to the same
* file. But clicking on 'Save' for an existing design file with a .rkt will bring up a confirmation dialog because
* it's potentially a destructive write (loss of some fidelity if it's truly an original Rocksim generated file).
*
* @return true if the file was saved, false otherwise
*/
/**
* "Save" action. If the design is new, then this is identical to "Save As", with a default file filter for .ork.
* If the rocket being edited previously was opened from a .ork file, then it will be saved immediately to the same
* file. But clicking on 'Save' for an existing design file with a .rkt will bring up a confirmation dialog because
* it's potentially a destructive write (loss of some fidelity if it's truly an original Rocksim generated file).
*
* @return true if the file was saved, false otherwise
*/
private boolean saveAction() {
File file = document.getFile();
if (file == null) {
@ -1229,44 +1253,44 @@ public class BasicFrame extends JFrame {
log.info("Saving document to " + file);
if (FileHelper.ROCKSIM_DESIGN_FILTER.accept(file)) {
return saveAsRocksim(file);
return saveAsRocksim(file);
}
return saveAs(file);
}
/**
* "Save As" action.
*
* Never should a .rkt file contain an OpenRocket content, or an .ork file contain a Rocksim design. Regardless of
* what extension the user has chosen, it would violate the Principle of Least Astonishment to do otherwise
* (and we want to make doing the wrong thing really hard to do). So always force the appropriate extension.
*
* This can result in some odd looking filenames (MyDesign.rkt.ork, MyDesign.rkt.ork.rkt, etc.) if the user is
* not paying attention, but the user can control that by modifying the filename in the dialog.
*
* @return true if the file was saved, false otherwise
*/
/**
* "Save As" action.
*
* Never should a .rkt file contain an OpenRocket content, or an .ork file contain a Rocksim design. Regardless of
* what extension the user has chosen, it would violate the Principle of Least Astonishment to do otherwise
* (and we want to make doing the wrong thing really hard to do). So always force the appropriate extension.
*
* This can result in some odd looking filenames (MyDesign.rkt.ork, MyDesign.rkt.ork.rkt, etc.) if the user is
* not paying attention, but the user can control that by modifying the filename in the dialog.
*
* @return true if the file was saved, false otherwise
*/
private boolean saveAsAction() {
File file = null;
StorageOptionChooser storageChooser =
new StorageOptionChooser(document, document.getDefaultStorageOptions());
final JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(FileHelper.OPENROCKET_DESIGN_FILTER);
chooser.addChoosableFileFilter(FileHelper.ROCKSIM_DESIGN_FILTER);
chooser.addChoosableFileFilter(FileHelper.OPENROCKET_DESIGN_FILTER);
chooser.addChoosableFileFilter(FileHelper.ROCKSIM_DESIGN_FILTER);
//Force the file filter to match the file extension that was opened. Will default to OR if the file is null.
if (FileHelper.ROCKSIM_DESIGN_FILTER.accept(document.getFile())) {
chooser.setFileFilter(FileHelper.ROCKSIM_DESIGN_FILTER);
}
else {
chooser.setFileFilter(FileHelper.OPENROCKET_DESIGN_FILTER);
}
//Force the file filter to match the file extension that was opened. Will default to OR if the file is null.
if (FileHelper.ROCKSIM_DESIGN_FILTER.accept(document.getFile())) {
chooser.setFileFilter(FileHelper.ROCKSIM_DESIGN_FILTER);
}
else {
chooser.setFileFilter(FileHelper.OPENROCKET_DESIGN_FILTER);
}
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
chooser.setAccessory(storageChooser);
if (document.getFile() != null) {
chooser.setSelectedFile(document.getFile());
}
}
int option = chooser.showSaveDialog(BasicFrame.this);
if (option != JFileChooser.APPROVE_OPTION) {
@ -1283,44 +1307,44 @@ public class BasicFrame extends JFrame {
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
storageChooser.storeOptions(document.getDefaultStorageOptions());
if (chooser.getFileFilter().equals(FileHelper.ROCKSIM_DESIGN_FILTER)) {
return saveAsRocksim(file);
}
else {
file = FileHelper.forceExtension(file, "ork");
return FileHelper.confirmWrite(file, this) && saveAs(file);
}
if (chooser.getFileFilter().equals(FileHelper.ROCKSIM_DESIGN_FILTER)) {
return saveAsRocksim(file);
}
else {
file = FileHelper.forceExtension(file, "ork");
return FileHelper.confirmWrite(file, this) && saveAs(file);
}
}
/**
* Perform the writing of the design to the given file in Rocksim format.
*
* @param file the chosen file
*
* @return true if the file was written
*/
private boolean saveAsRocksim(File file) {
file = FileHelper.forceExtension(file, "rkt");
if (!FileHelper.confirmWrite(file, this)) {
return false;
}
/**
* Perform the writing of the design to the given file in Rocksim format.
*
* @param file the chosen file
*
* @return true if the file was written
*/
private boolean saveAsRocksim(File file) {
file = FileHelper.forceExtension(file, "rkt");
if (!FileHelper.confirmWrite(file, this)) {
return false;
}
try {
new RocksimSaver().save(file, document);
return true;
} catch (IOException e) {
return false;
}
}
try {
new RocksimSaver().save(file, document);
return true;
} catch (IOException e) {
return false;
}
}
/**
* Perform the writing of the design to the given file in OpenRocket format.
*
* @param file the chosen file
*
* @return true if the file was written
*/
private boolean saveAs(File file) {
/**
* Perform the writing of the design to the given file in OpenRocket format.
*
* @param file the chosen file
*
* @return true if the file was written
*/
private boolean saveAs(File file) {
log.info("Saving document as " + file);
boolean saved = false;

View File

@ -32,6 +32,7 @@ public class ComponentTreeTransferHandler extends TransferHandler {
private final OpenRocketDocument document;
/**
* Sole constructor.
*
@ -89,6 +90,17 @@ public class ComponentTreeTransferHandler extends TransferHandler {
boolean allowed = data.destParent.isCompatible(data.child);
log.verbose("Checking validity of drag-drop " + data.toString() + " allowed:" + allowed);
// Ensure we're not dropping a component onto a child component
RocketComponent path = data.destParent;
while (path != null) {
if (path.equals(data.child)) {
log.verbose("Drop would cause cycle in tree, disallowing.");
allowed = false;
break;
}
path = path.getParent();
}
// If drag-dropping to another rocket always copy
if (support.getDropAction() == MOVE && data.srcParent.getRoot() != data.destParent.getRoot()) {
support.setDropAction(COPY);
@ -98,7 +110,6 @@ public class ComponentTreeTransferHandler extends TransferHandler {
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {

View File

@ -62,9 +62,10 @@ public class Icons {
public static final Icon EDIT_SCALE = loadImageIcon("pix/icons/edit-scale.png", "Scale");
public static final Icon HELP_ABOUT = loadImageIcon("pix/icons/help-about.png", "About");
public static final Icon HELP_LICENSE = loadImageIcon("pix/icons/help-license.png", "License");
public static final Icon HELP_BUG_REPORT = loadImageIcon("pix/icons/help-bug.png", "Bug report");
public static final Icon HELP_DEBUG_LOG = loadImageIcon("pix/icons/help-log.png", "Debug log");
public static final Icon HELP_LICENSE = loadImageIcon("pix/icons/help-license.png", "License");
public static final Icon HELP_TOURS = loadImageIcon("pix/icons/help-tours.png", "Guided tours");
public static final Icon ZOOM_IN = loadImageIcon("pix/icons/zoom-in.png", "Zoom in");
public static final Icon ZOOM_OUT = loadImageIcon("pix/icons/zoom-out.png", "Zoom out");

View File

@ -690,7 +690,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
if (preset.getComponentClass() != this.getClass()) {
throw new IllegalArgumentException("Attempting to load preset of type " + preset.getComponentClass()
+ " into component of type " + this.getClass());
+ " into component of type " + this.getClass());
}
RocketComponent root = getRoot();
@ -840,39 +840,39 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
}
/**
* Determine position relative to given position argument. Note: This is a side-effect free method. No state
* is modified.
*
* @param thePosition the relative position to be used as the basis for the computation
* @param relativeTo the position is computed relative the the given component
*
* @return double position of the component relative to the parent, with respect to <code>position</code>
*/
public double asPositionValue (Position thePosition, RocketComponent relativeTo) {
double result = this.position;
if (relativeTo != null) {
double thisPos = this.toRelative(Coordinate.NUL, relativeTo)[0].x;
/**
* Determine position relative to given position argument. Note: This is a side-effect free method. No state
* is modified.
*
* @param thePosition the relative position to be used as the basis for the computation
* @param relativeTo the position is computed relative the the given component
*
* @return double position of the component relative to the parent, with respect to <code>position</code>
*/
public double asPositionValue(Position thePosition, RocketComponent relativeTo) {
double result = this.position;
if (relativeTo != null) {
double thisPos = this.toRelative(Coordinate.NUL, relativeTo)[0].x;
switch (thePosition) {
case ABSOLUTE:
result = this.toAbsolute(Coordinate.NUL)[0].x;
break;
case TOP:
result = thisPos;
break;
case MIDDLE:
result = thisPos - (relativeTo.length - this.length) / 2;
break;
case BOTTOM:
result = thisPos - (relativeTo.length - this.length);
break;
default:
throw new BugException("Unknown position type: " + thePosition);
}
}
return result;
}
switch (thePosition) {
case ABSOLUTE:
result = this.toAbsolute(Coordinate.NUL)[0].x;
break;
case TOP:
result = thisPos;
break;
case MIDDLE:
result = thisPos - (relativeTo.length - this.length) / 2;
break;
case BOTTOM:
result = thisPos - (relativeTo.length - this.length);
break;
default:
throw new BugException("Unknown position type: " + thePosition);
}
}
return result;
}
/**
* Get the position value of the component. The exact meaning of the value is
@ -1138,10 +1138,18 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
*/
public void addChild(RocketComponent component, int index) {
checkState();
if (component.parent != null) {
throw new IllegalArgumentException("component " + component.getComponentName() +
" is already in a tree");
}
// Ensure that the no loops are created in component tree [A -> X -> Y -> B, B.addChild(A)]
if (this.getRoot().equals(component)) {
throw new IllegalStateException("Component " + component.getComponentName() +
" is a parent of " + this.getComponentName() + ", attempting to create cycle in tree.");
}
if (!isCompatible(component)) {
throw new IllegalStateException("Component " + component.getComponentName() +
" not currently compatible with component " + getComponentName());
@ -1156,7 +1164,6 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
fireAddRemoveEvent(component);
}
/**
* Removes a child from the rocket component tree.
*
@ -1703,7 +1710,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
protected static final double ringMass(double outerRadius, double innerRadius,
double length, double density) {
return Math.PI * (MathUtil.pow2(outerRadius) - MathUtil.pow2(innerRadius)) *
length * density;
length * density;
}
protected static final double ringLongitudinalUnitInertia(double outerRadius,