Merge branch 'unstable' into flight-warning-event

This commit is contained in:
JoePfeiffer 2024-08-19 15:51:57 -06:00
commit 1c0710e240
7 changed files with 131 additions and 55 deletions

View File

@ -20,6 +20,7 @@ import info.openrocket.core.material.Material;
import info.openrocket.core.models.atmosphere.AtmosphericModel; import info.openrocket.core.models.atmosphere.AtmosphericModel;
import info.openrocket.core.models.atmosphere.ExtendedISAModel; import info.openrocket.core.models.atmosphere.ExtendedISAModel;
import info.openrocket.core.preset.ComponentPreset; import info.openrocket.core.preset.ComponentPreset;
import info.openrocket.core.rocketcomponent.FlightConfiguration;
import info.openrocket.core.rocketcomponent.MassObject; import info.openrocket.core.rocketcomponent.MassObject;
import info.openrocket.core.rocketcomponent.Rocket; import info.openrocket.core.rocketcomponent.Rocket;
import info.openrocket.core.rocketcomponent.RocketComponent; import info.openrocket.core.rocketcomponent.RocketComponent;
@ -101,8 +102,10 @@ public abstract class ApplicationPreferences implements ChangeSource, ORPreferen
public static final String ROCKET_INFO_FONT_SIZE = "RocketInfoFontSize"; public static final String ROCKET_INFO_FONT_SIZE = "RocketInfoFontSize";
// Preferences Related to Simulations // Preferences related to flight configurations
public static final String DEFAULT_FLIGHT_CONFIG_NAME = "DefaultFlightConfigName";
// Preferences Related to Simulations
public static final String CONFIRM_DELETE_SIMULATION = "ConfirmDeleteSimulation"; public static final String CONFIRM_DELETE_SIMULATION = "ConfirmDeleteSimulation";
public static final String AUTO_RUN_SIMULATIONS = "AutoRunSimulations"; public static final String AUTO_RUN_SIMULATIONS = "AutoRunSimulations";
public static final String LAUNCH_ROD_LENGTH = "LaunchRodLength"; public static final String LAUNCH_ROD_LENGTH = "LaunchRodLength";
@ -258,6 +261,18 @@ public abstract class ApplicationPreferences implements ChangeSource, ORPreferen
} }
/*
* ******************************************************************************************
*/
public String getDefaultFlightConfigName() {
return getString(DEFAULT_FLIGHT_CONFIG_NAME, FlightConfiguration.DEFAULT_CONFIG_NAME);
}
public void setDefaultFlightConfigName(String name) {
putString(DEFAULT_FLIGHT_CONFIG_NAME, name);
}
/* /*
* ****************************************************************************************** * ******************************************************************************************
*/ */

View File

@ -10,6 +10,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import info.openrocket.core.formatting.RocketDescriptor; import info.openrocket.core.formatting.RocketDescriptor;
import info.openrocket.core.preferences.ApplicationPreferences;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -33,6 +34,7 @@ import info.openrocket.core.util.Transformation;
*/ */
public class FlightConfiguration implements FlightConfigurableParameter<FlightConfiguration>, Monitorable { public class FlightConfiguration implements FlightConfigurableParameter<FlightConfiguration>, Monitorable {
private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class); private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class);
private static final ApplicationPreferences prefs = Application.getPreferences();
private String configurationName; private String configurationName;
public static String DEFAULT_CONFIG_NAME = "[{motors}]"; public static String DEFAULT_CONFIG_NAME = "[{motors}]";
@ -105,7 +107,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.fcid = _fcid; this.fcid = _fcid;
} }
this.rocket = rocket; this.rocket = rocket;
this.configurationName = DEFAULT_CONFIG_NAME; this.configurationName = getDefaultName();
this.configurationInstanceId = configurationInstanceCount++; this.configurationInstanceId = configurationInstanceCount++;
updateStages(); updateStages();
@ -578,11 +580,19 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
public boolean isNameOverridden() { public boolean isNameOverridden() {
return (!DEFAULT_CONFIG_NAME.equals(this.configurationName)); return (!getDefaultName().equals(this.configurationName));
}
private String getDefaultName() {
String name = prefs.getDefaultFlightConfigName();
if (name == null) {
name = DEFAULT_CONFIG_NAME;
}
return name;
} }
/** /**
* Return the name of this configuration, with DEFAULT_CONFIG_NAME replaced by a * Return the name of this configuration, with the default flight config name replaced by a
* one line motor description. * one line motor description.
* If configurationName is null, the one line motor description is returned. * If configurationName is null, the one line motor description is returned.
* *
@ -590,20 +600,20 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
*/ */
public String getName() { public String getName() {
if (configurationName == null) { if (configurationName == null) {
configurationName = DEFAULT_CONFIG_NAME; configurationName = getDefaultName();
} }
return descriptor.format(configurationName, rocket, fcid); return descriptor.format(configurationName, rocket, fcid);
} }
/** /**
* Return the raw configuration name, without replacing DEFAULT_CONFIG_NAME. * Return the raw configuration name, without replacing the default flight config name.
* If the configurationName is null, DEFAULT_CONFIG_NAME is returned. * If the configurationName is null, the default flight config name is returned.
* *
* @return raw flight configuration name * @return raw flight configuration name
*/ */
public String getNameRaw() { public String getNameRaw() {
if (configurationName == null) { if (configurationName == null) {
return DEFAULT_CONFIG_NAME; return getDefaultName();
} }
return configurationName; return configurationName;
} }
@ -920,7 +930,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
public void setName(final String newName) { public void setName(final String newName) {
if ((newName == null) || (newName.isEmpty())) { if ((newName == null) || (newName.isEmpty())) {
this.configurationName = DEFAULT_CONFIG_NAME; this.configurationName = getDefaultName();
return; return;
} else if (!this.getId().isValid()) { } else if (!this.getId().isValid()) {
return; return;

View File

@ -251,6 +251,9 @@ edtmotorconfdlg.tbl.Separationheader = Separation
! Rename FlightConfiguration Dialog ! Rename FlightConfiguration Dialog
RenameConfigDialog.title = Rename Configuration RenameConfigDialog.title = Rename Configuration
RenameConfigDialog.lbl.name = Name for flight configuration: RenameConfigDialog.lbl.name = Name for flight configuration:
RenameConfigDialog.but.saveDefault = Save as default
RenameConfigDialog.dlg.saveDefault.msg = This change will only affect new flight configurations.
RenameConfigDialog.dlg.saveDefault.title = Save as default
RenameConfigDialog.but.reset = Reset to default RenameConfigDialog.but.reset = Reset to default
RenameConfigDialog.lbl.infoMotors = The text '<b>{motors}</b>' will be replaced with the <b>motor designation(s).</b><br><pre>\te.g. '{motors} \u2192 'M1350-0'</pre> RenameConfigDialog.lbl.infoMotors = The text '<b>{motors}</b>' will be replaced with the <b>motor designation(s).</b><br><pre>\te.g. '{motors} \u2192 'M1350-0'</pre>
RenameConfigDialog.lbl.infoManufacturers = The text '<b>{manufacturers}</b>' will be replaced with the <b>motor manufacturer(s).</b><br><pre>\te.g. '{manufacturers}' \u2192 'AeroTech'</pre> RenameConfigDialog.lbl.infoManufacturers = The text '<b>{manufacturers}</b>' will be replaced with the <b>motor manufacturer(s).</b><br><pre>\te.g. '{manufacturers}' \u2192 'AeroTech'</pre>

View File

@ -6,16 +6,16 @@ description: |
OpenRocket is a free, fully featured model rocket simulator that allows you OpenRocket is a free, fully featured model rocket simulator that allows you
to design and simulate your rockets before actually building and flying them. to design and simulate your rockets before actually building and flying them.
The main features include The main features include:
* Six-degree-of-freedom flight simulation * Six-degree-of-freedom flight simulation
* Automatic design optimization * Automatic design optimization
* Realtime simulated altitude, velocity and acceleration display * Realtime simulated altitude, velocity and acceleration display
* Staging and clustering support * Staging and clustering support
* Cross-platform (Java-based) * Cross-platform (Java-based)
* Read more about it on the OpenRocket.info. * Read more about it on OpenRocket.info
license: GPL-3.0 license: GPL-3.0
base: core22 base: core18
confinement: strict confinement: strict
plugs: plugs:
@ -37,7 +37,6 @@ architectures:
apps: apps:
openrocket: openrocket:
extensions: [gnome]
command: bin/launcher command: bin/launcher
plugs: plugs:
- home - home
@ -47,43 +46,23 @@ apps:
- dot-java-user-prefs-openrocket - dot-java-user-prefs-openrocket
- dot-openrocket - dot-openrocket
environment: environment:
JAVA_HOME: "$SNAP/usr/lib/jvm/java-17-openjdk-$CRAFT_TARGET_ARCH" JAVA_HOME: "$SNAP/usr/lib/jvm/java-17-openjdk-$SNAP_ARCH"
parts: parts:
openrocket: openrocket:
plugin: ant plugin: gradle
build-packages:
- ant
- ant-contrib
- ant-optional
- openjdk-17-jdk
- openjdk-17-jre
source: . source: .
source-type: git build-packages:
ant-build-targets: - openjdk-17-jdk
- clean
- check
- unittest
- jar
override-pull: | override-pull: |
# Override the pull in order to set the version and the grade.
# In the future, the releases can be annotated tags and snapcraft
# will use those for the version numbers.
#
# This can be extended to other parts of OpenRocket (to use the
# git describe --tags command) but the build should be updated at
# the same time so its consistent across all artifacts. Will defer
# that to a later pull request.
#
# Until then, just use the build.version value
craftctl default craftctl default
VERSION=$(cat core/resources/build.properties | awk -F'=' '/build\.version/ { print $2 }') version=$(grep 'version =' build.gradle | awk '{print $3}' | tr -d "'")
craftctl set version="$VERSION" craftctl set version="$version"
override-build: | override-build: |
craftctl default craftctl default
mv swing/build/jar/OpenRocket.jar $CRAFT_PART_INSTALL/OpenRocket.jar mkdir -p $CRAFT_PART_INSTALL/bin
cp build/libs/OpenRocket-*.jar $CRAFT_PART_INSTALL/OpenRocket.jar
stage-packages: stage-packages:
- openjdk-17-jdk
- openjdk-17-jre - openjdk-17-jre
- ca-certificates - ca-certificates
- ca-certificates-java - ca-certificates-java
@ -95,6 +74,6 @@ parts:
launcher: launcher:
plugin: dump plugin: dump
source: snap/local source: snap/local
source-type: local
organize: organize:
'launcher': 'bin/' launcher: bin/launcher

View File

@ -9,10 +9,12 @@ import java.awt.event.ActionListener;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import info.openrocket.core.l10n.Translator; import info.openrocket.core.l10n.Translator;
import info.openrocket.core.preferences.ApplicationPreferences;
import info.openrocket.core.rocketcomponent.FlightConfigurationId; import info.openrocket.core.rocketcomponent.FlightConfigurationId;
import info.openrocket.core.rocketcomponent.Rocket; import info.openrocket.core.rocketcomponent.Rocket;
import info.openrocket.core.startup.Application; import info.openrocket.core.startup.Application;
@ -26,6 +28,7 @@ import info.openrocket.swing.gui.theme.UITheme;
public class RenameConfigDialog extends JDialog { public class RenameConfigDialog extends JDialog {
private static final long serialVersionUID = -5423008694485357248L; private static final long serialVersionUID = -5423008694485357248L;
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static final ApplicationPreferences prefs = Application.getPreferences();
private static Color dimTextColor; private static Color dimTextColor;
@ -55,6 +58,17 @@ public class RenameConfigDialog extends JDialog {
} }
}); });
panel.add(okButton); panel.add(okButton);
JButton saveAsDefaultButton = new JButton(trans.get("RenameConfigDialog.but.saveDefault"));
saveAsDefaultButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(RenameConfigDialog.this, trans.get("RenameConfigDialog.dlg.saveDefault.msg"),
trans.get("RenameConfigDialog.dlg.saveDefault.title"), JOptionPane.INFORMATION_MESSAGE);
prefs.setDefaultFlightConfigName(textbox.getText());
}
});
panel.add(saveAsDefaultButton);
JButton resetToDefaultButton = new JButton(trans.get("RenameConfigDialog.but.reset")); JButton resetToDefaultButton = new JButton(trans.get("RenameConfigDialog.but.reset"));
resetToDefaultButton.addActionListener(new ActionListener() { resetToDefaultButton.addActionListener(new ActionListener() {

View File

@ -113,13 +113,14 @@ public class SimulationPlot {
} }
void setShowBranch(int branch) { void setShowBranch(int branch) {
int series = branch + branchCount-1;
XYPlot plot = (XYPlot) chart.getPlot(); XYPlot plot = (XYPlot) chart.getPlot();
int datasetcount = plot.getDatasetCount(); int datasetcount = plot.getDatasetCount();
for (int i = 0; i < datasetcount; i++) { for (int i = 0; i < datasetcount; i++) {
int seriescount = ((XYSeriesCollection) plot.getDataset(i)).getSeriesCount(); int seriescount = ((XYSeriesCollection) plot.getDataset(i)).getSeriesCount();
XYItemRenderer r = ((XYPlot) chart.getPlot()).getRenderer(i); XYItemRenderer r = ((XYPlot) chart.getPlot()).getRenderer(i);
for (int j = 0; j < seriescount; j++) { for (int j = 0; j < seriescount; j++) {
boolean show = (branch < 0) || (j % branchCount == branch); boolean show = (branch < 0) || (j % (2*branchCount-1) == series);
r.setSeriesVisible(j, show); r.setSeriesVisible(j, show);
} }
} }
@ -207,14 +208,65 @@ public class SimulationPlot {
// Store data in provided units // Store data in provided units
List<Double> plotx = thisBranch.get(domainType); List<Double> plotx = thisBranch.get(domainType);
List<Double> ploty = thisBranch.get(type); List<Double> ploty = thisBranch.get(type);
XYSeries series = new XYSeries(seriesCount++, false, true);
series.setDescription(name);
int pointCount = plotx.size(); int pointCount = plotx.size();
for (int j = 0; j < pointCount; j++) {
series.add(domainUnit.toUnit(plotx.get(j)), unit.toUnit(ploty.get(j))); // For a single-stage rocket, there is no need to disambiguate stages
if (branchCount == 1) {
XYSeries series = new XYSeries(seriesCount++, false, true);
series.setDescription(name);
for (int j = 0; j < pointCount; j++) {
series.add(domainUnit.toUnit(plotx.get(j)), unit.toUnit(ploty.get(j)));
}
data[axis].addSeries(series);
}
// For a multi-stage rocket, the stages must be distinguished on the plot
else {
int numStages = branchCount;
int breakpoint = 0;
while (numStages > 0) {
// Create series for this portion of the main rocket flight
XYSeries currentSeries = new XYSeries(seriesCount++, false, true);
StringBuilder str = new StringBuilder();
// Add name of each stage that is still connected to main rocket to the string above
for (int j = 0; j < numStages; j++) {
FlightDataBranch currentBranch = simulation.getSimulatedData().getBranch(j);
str.append(currentBranch.getName());
if(j < numStages-1) {
str.append(" + ");
}
}
// Set the label for the current series
currentSeries.setDescription(str + ": " + name);
// Create list of y-value data for the branch after this series
// This is used to find the stage separation point and stop the current series plot there
List<Double> plotyNext = null;
if (numStages > 1) {
plotyNext = simulation.getSimulatedData().getBranch(numStages - 1).get(type);
}
else {
breakpoint = 0; // Start sustainer stage-plotting from the beginning
}
for (int j = breakpoint; j < pointCount; j++) {
if ( plotyNext != null && !ploty.get(j).equals(plotyNext.get(j)) ) {
if (j != 0) {breakpoint = j - 1;}
break;
}
currentSeries.add(domainUnit.toUnit(plotx.get(j)), unit.toUnit(ploty.get(j)));
}
// Add newly created series to the data
data[axis].addSeries(currentSeries);
// Decrement number of stages connected to main rocket (after separation of current stage)
numStages--;
}
} }
data[axis].addSeries(series);
} }
// Secondary branches // Secondary branches
for (int branchIndex = 1; branchIndex < branchCount; branchIndex++) { for (int branchIndex = 1; branchIndex < branchCount; branchIndex++) {
FlightDataBranch thisBranch = simulation.getSimulatedData().getBranch(branchIndex); FlightDataBranch thisBranch = simulation.getSimulatedData().getBranch(branchIndex);
@ -310,7 +362,8 @@ public class SimulationPlot {
// Add data and map to the axis // Add data and map to the axis
plot.setDataset(axisno, data[axisno]); plot.setDataset(axisno, data[axisno]);
ModifiedXYItemRenderer r = new ModifiedXYItemRenderer(branchCount); // Number of Series = (Number of Branches * 2) - 1
ModifiedXYItemRenderer r = new ModifiedXYItemRenderer(2*branchCount-1);
renderers.add(r); renderers.add(r);
r.setDefaultToolTipGenerator(tooltipGenerator); r.setDefaultToolTipGenerator(tooltipGenerator);
plot.setRenderer(axisno, r); plot.setRenderer(axisno, r);
@ -327,11 +380,12 @@ public class SimulationPlot {
} }
// Update the cumulative count for the next axis // Update the cumulative count for the next axis
cumulativeSeriesCount += data[axisno].getSeriesCount(); cumulativeSeriesCount += data[axisno].getSeriesCount() / branchCount;
// Now we pull the colors for the legend. // Now we pull the colors for the legend.
for (int j = 0; j < data[axisno].getSeriesCount(); j += branchCount) { for (int j = 0; j < data[axisno].getSeriesCount(); j += (2*branchCount-1)) {
String name = data[axisno].getSeries(j).getDescription(); String[] description = data[axisno].getSeries(j).getDescription().split(": ");
String name = description[description.length-1]; // Get data type and units from description
this.legendItems.lineLabels.add(name); this.legendItems.lineLabels.add(name);
Paint linePaint = r.lookupSeriesPaint(j); Paint linePaint = r.lookupSeriesPaint(j);
this.legendItems.linePaints.add(linePaint); this.legendItems.linePaints.add(linePaint);

View File

@ -372,12 +372,13 @@ public class SimulationConfigDialog extends JDialog {
if (plot != null) { if (plot != null) {
plot.setVisible(true); plot.setVisible(true);
} }
closeDialog();
return; return;
} else if (tabIdx == EXPORT_IDX) { } else if (tabIdx == EXPORT_IDX) {
if (exportTab == null || exportTab.doExport()) { if (exportTab == null) {
closeDialog(); closeDialog();
return;
} }
exportTab.doExport();
return; return;
} }