From 228df78fd4d070068cf04780fbb2154d3ebcf196 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Wed, 20 May 2020 09:37:48 -0600 Subject: [PATCH] If a FlightConfiguration has an existing simulation, use it to update the data in the RocketPanel --- .../gui/scalefigure/RocketPanel.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 49059cc5d..615549887 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -682,9 +682,27 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change extraText.setCalculatingData(true); Rocket duplicate = (Rocket) document.getRocket().copy(); - Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate); - simulation.setFlightConfigurationId( document.getSelectedConfiguration().getId()); + // find a Simulation based on the current flight configuration + FlightConfigurationId curID = curConfig.getFlightConfigurationID(); + Simulation simulation = null; + for (Simulation sim : document.getSimulations()) { + if (sim.getFlightConfigurationId().compareTo(curID) == 0) { + simulation = sim; + break; + } + } + + // I *think* every FlightConfiguration has at least one associated simulation; just in case I'm wrong, + // if there isn't one we'll create a new simulation to update the statistics in the panel using the + // default simulation conditions + if (simulation == null) { + System.out.println("creating new simulation"); + simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate); + simulation.setFlightConfigurationId( document.getSelectedConfiguration().getId()); + } else + System.out.println("using pre-existing simulation"); + backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation); backgroundSimulationExecutor.execute(backgroundSimulationWorker); }