Only add CADataTypes that have a component tied to it

This commit is contained in:
SiboVG 2024-08-24 01:30:15 +02:00
parent 3598efd773
commit 32a2fcc849
3 changed files with 26 additions and 7 deletions

View File

@ -42,10 +42,10 @@ public class CAPlotPanel extends PlotPanel<CADataType, CADataBranch, CADataTypeG
updatePlots(); updatePlots();
} }
public static CAPlotPanel create(ComponentAnalysisPlotExportDialog parent) { public static CAPlotPanel create(ComponentAnalysisPlotExportDialog parent, CADataType[] typesY) {
CADomainDataType[] typesX = new CADomainDataType[] { parent.getSelectedParameter() }; CADomainDataType[] typesX = new CADomainDataType[] { parent.getSelectedParameter() };
return new CAPlotPanel(parent, typesX, CADataType.ALL_TYPES); return new CAPlotPanel(parent, typesX, typesY);
} }
@Override @Override
@ -66,7 +66,7 @@ public class CAPlotPanel extends PlotPanel<CADataType, CADataBranch, CADataTypeG
@Override @Override
protected CAPlotTypeSelector createSelector(int i, CADataType type, Unit unit, int axis) { protected CAPlotTypeSelector createSelector(int i, CADataType type, Unit unit, int axis) {
return new CAPlotTypeSelector(parent, i, type, unit, axis, List.of(CADataType.ALL_TYPES), return new CAPlotTypeSelector(parent, i, type, unit, axis, List.of(typesY),
parent.getComponentsForType(type), configuration); parent.getComponentsForType(type), configuration);
} }

View File

@ -54,6 +54,7 @@ public class ComponentAnalysisPlotExportDialog extends JDialog {
private final CAParameters parameters; private final CAParameters parameters;
private final CAParameterSweep parameterSweep; private final CAParameterSweep parameterSweep;
private final CADataType[] types;
private final Map<CADataType, List<RocketComponent>> componentCache; private final Map<CADataType, List<RocketComponent>> componentCache;
private boolean isCacheValid; private boolean isCacheValid;
@ -69,6 +70,8 @@ public class ComponentAnalysisPlotExportDialog extends JDialog {
this.componentCache = new HashMap<>(); this.componentCache = new HashMap<>();
this.isCacheValid = false; this.isCacheValid = false;
this.types = getValidTypes();
// ======== Top panel ======== // ======== Top panel ========
addTopPanel(contentPanel); addTopPanel(contentPanel);
@ -76,11 +79,11 @@ public class ComponentAnalysisPlotExportDialog extends JDialog {
this.tabbedPane = new JTabbedPane(); this.tabbedPane = new JTabbedPane();
//// Plot data //// Plot data
this.plotTab = CAPlotPanel.create(this); this.plotTab = CAPlotPanel.create(this, types);
this.tabbedPane.addTab(trans.get("CAPlotExportDialog.tab.Plot"), this.plotTab); this.tabbedPane.addTab(trans.get("CAPlotExportDialog.tab.Plot"), this.plotTab);
//// Export data //// Export data
this.exportTab = CAExportPanel.create(CADataType.ALL_TYPES); this.exportTab = CAExportPanel.create(types);
this.tabbedPane.addTab(trans.get("CAPlotExportDialog.tab.Export"), this.exportTab); this.tabbedPane.addTab(trans.get("CAPlotExportDialog.tab.Export"), this.exportTab);
contentPanel.add(tabbedPane, "grow, wrap"); contentPanel.add(tabbedPane, "grow, wrap");
@ -280,6 +283,22 @@ public class ComponentAnalysisPlotExportDialog extends JDialog {
isCacheValid = true; 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<CADataType> validTypes = new ArrayList<>();
List<RocketComponent> 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. * Run the parameter sweep and return the data branch.
* @return the data branch containing the results of the parameter sweep * @return the data branch containing the results of the parameter sweep

View File

@ -46,8 +46,8 @@ public class PlotPanel<T extends DataType & Groupable<G>,
private C defaultConfiguration; private C defaultConfiguration;
// Data types for the x and y axis + plot configuration // Data types for the x and y axis + plot configuration
private final T[] typesX; protected final T[] typesX;
private final T[] typesY; protected final T[] typesY;
protected C configuration; protected C configuration;
private final JComboBox<C> configurationSelector; private final JComboBox<C> configurationSelector;