Ignore inactive components in CA parameter sweep

This commit is contained in:
SiboVG 2024-08-24 01:42:17 +02:00
parent 32a2fcc849
commit cb7b6ae8d0
3 changed files with 19 additions and 11 deletions

View File

@ -322,14 +322,24 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
public Collection<RocketComponent> getAllComponents() {
List<RocketComponent> traversalOrder = new ArrayList<>();
recurseAllComponentsDepthFirst(this.rocket, traversalOrder);
recurseAllComponentsDepthFirst(this.rocket, traversalOrder, false);
return traversalOrder;
}
private void recurseAllComponentsDepthFirst(RocketComponent comp, List<RocketComponent> traversalOrder) {
public Collection<RocketComponent> getAllActiveComponents() {
List<RocketComponent> traversalOrder = new ArrayList<>();
recurseAllComponentsDepthFirst(this.rocket, traversalOrder, true);
return traversalOrder;
}
private void recurseAllComponentsDepthFirst(RocketComponent comp, List<RocketComponent> traversalOrder,
boolean ignoreInactive) {
if (ignoreInactive && !isComponentActive(comp)) {
return;
}
traversalOrder.add(comp);
for (RocketComponent child : comp.getChildren()) {
recurseAllComponentsDepthFirst(child, traversalOrder);
recurseAllComponentsDepthFirst(child, traversalOrder, ignoreInactive);
}
}
@ -374,7 +384,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
// this method is deprecated because it ignores instancing of parent components
// (e.g. Strapons or pods )
// depending on your context, this may or may not be what you want.
// recommend migrating to either: `getAllComponents` or `getActiveInstances`
// recommend migrating to 'getAllActiveComponents'
@Deprecated
public Collection<RocketComponent> getActiveComponents() {
Queue<RocketComponent> toProcess = new ArrayDeque<>(this.getActiveStages());

View File

@ -3,6 +3,7 @@ package info.openrocket.swing.gui.dialogs.componentanalysis;
import info.openrocket.core.l10n.Translator;
import info.openrocket.core.rocketcomponent.ComponentAssembly;
import info.openrocket.core.rocketcomponent.FinSet;
import info.openrocket.core.rocketcomponent.FlightConfiguration;
import info.openrocket.core.rocketcomponent.Rocket;
import info.openrocket.core.rocketcomponent.RocketComponent;
import info.openrocket.core.simulation.DataType;
@ -94,15 +95,15 @@ public class CADataType implements Comparable<CADataType>, Groupable<CADataTypeG
/**
* Calculate all components that are relevant for a given CADataType.
* @param rocket the rocket to search in
* @param configuration the current flight configuration of the rocket
* @param type the CADataType to search for
* @return a list of all components that are relevant for the given CADataType
*/
public static List<RocketComponent> calculateComponentsForType(Rocket rocket, CADataType type) {
public static List<RocketComponent> calculateComponentsForType(FlightConfiguration configuration, CADataType type) {
List<RocketComponent> components = new ArrayList<>();
// Iterate through all components in the rocket
for (RocketComponent component : rocket.getSelectedConfiguration().getAllComponents()) {
for (RocketComponent component : configuration.getAllActiveComponents()) {
// Check if this component is relevant for the given CADataType
if (isComponentRelevantForType(component, type)) {
components.add(component);

View File

@ -35,8 +35,6 @@ public class ComponentAnalysisPlotExportDialog extends JDialog {
private static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(ComponentAnalysisPlotExportDialog.class);
private final Rocket rocket;
private final JTabbedPane tabbedPane;
JComboBox<CADomainDataType> parameterSelector;
private JButton okButton;
@ -64,7 +62,6 @@ public class ComponentAnalysisPlotExportDialog extends JDialog {
final JPanel contentPanel = new JPanel(new MigLayout("fill, height 500px"));
this.rocket = rocket;
this.parameters = parameters;
this.parameterSweep = new CAParameterSweep(parameters, aerodynamicCalculator, rocket);
this.componentCache = new HashMap<>();
@ -276,7 +273,7 @@ public class ComponentAnalysisPlotExportDialog extends JDialog {
}
if (!componentCache.containsKey(type)) {
List<RocketComponent> components = CADataType.calculateComponentsForType(rocket, type);
List<RocketComponent> components = CADataType.calculateComponentsForType(parameters.getSelectedConfiguration(), type);
componentCache.put(type, components);
}