From 32a2fcc849ef10515a01c86ee7956574e8f7ac7b Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 24 Aug 2024 01:30:15 +0200 Subject: [PATCH] Only add CADataTypes that have a component tied to it --- .../componentanalysis/CAPlotPanel.java | 6 ++--- .../ComponentAnalysisPlotExportDialog.java | 23 +++++++++++++++++-- .../openrocket/swing/gui/plot/PlotPanel.java | 4 ++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/swing/src/main/java/info/openrocket/swing/gui/dialogs/componentanalysis/CAPlotPanel.java b/swing/src/main/java/info/openrocket/swing/gui/dialogs/componentanalysis/CAPlotPanel.java index 6bf10d523..e480e33ee 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/dialogs/componentanalysis/CAPlotPanel.java +++ b/swing/src/main/java/info/openrocket/swing/gui/dialogs/componentanalysis/CAPlotPanel.java @@ -42,10 +42,10 @@ public class CAPlotPanel extends PlotPanel> componentCache; private boolean isCacheValid; @@ -69,6 +70,8 @@ public class ComponentAnalysisPlotExportDialog extends JDialog { this.componentCache = new HashMap<>(); this.isCacheValid = false; + this.types = getValidTypes(); + // ======== Top panel ======== addTopPanel(contentPanel); @@ -76,11 +79,11 @@ public class ComponentAnalysisPlotExportDialog extends JDialog { this.tabbedPane = new JTabbedPane(); //// Plot data - this.plotTab = CAPlotPanel.create(this); + this.plotTab = CAPlotPanel.create(this, types); this.tabbedPane.addTab(trans.get("CAPlotExportDialog.tab.Plot"), this.plotTab); //// Export data - this.exportTab = CAExportPanel.create(CADataType.ALL_TYPES); + this.exportTab = CAExportPanel.create(types); this.tabbedPane.addTab(trans.get("CAPlotExportDialog.tab.Export"), this.exportTab); contentPanel.add(tabbedPane, "grow, wrap"); @@ -280,6 +283,22 @@ public class ComponentAnalysisPlotExportDialog extends JDialog { isCacheValid = true; } + /** + * Returns the valid types for the current rocket, i.e. types that have at least once component bound to it. + * @return all valid Component Analysis types for the current rocket + */ + private CADataType[] getValidTypes() { + List validTypes = new ArrayList<>(); + List components; + for (CADataType type : CADataType.ALL_TYPES) { + components = getComponentsForType(type); + if (!components.isEmpty()) { + validTypes.add(type); + } + } + return validTypes.toArray(new CADataType[0]); + } + /** * Run the parameter sweep and return the data branch. * @return the data branch containing the results of the parameter sweep diff --git a/swing/src/main/java/info/openrocket/swing/gui/plot/PlotPanel.java b/swing/src/main/java/info/openrocket/swing/gui/plot/PlotPanel.java index 6d63b8a6c..f4d299be3 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/plot/PlotPanel.java +++ b/swing/src/main/java/info/openrocket/swing/gui/plot/PlotPanel.java @@ -46,8 +46,8 @@ public class PlotPanel, private C defaultConfiguration; // Data types for the x and y axis + plot configuration - private final T[] typesX; - private final T[] typesY; + protected final T[] typesX; + protected final T[] typesY; protected C configuration; private final JComboBox configurationSelector;