From 0e93ca7c25d24a5fbad8abc32e7cb895d6dcb177 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 20 Mar 2023 23:48:03 +0100 Subject: [PATCH] Use multi-comp fin splitting --- .../sf/openrocket/rocketcomponent/FinSet.java | 39 +++++++++++++++++++ .../gui/configdialog/FinSetConfig.java | 17 +------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 83bc3b553..ece537bcd 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -1421,6 +1421,45 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } + /** + * Split the fin set into individual fins. + * @return A list of the new fin sets. + */ + public List splitFins() { + RocketComponent parent = getParent(); + int index = parent.getChildPosition(this); + int count = getFinCount(); + double base = getBaseRotation(); + + List splitFins = null; // List of all the split fins + + if (count > 1) { + parent.removeChild(index); + splitFins = new ArrayList<>(); + for (int i = 0; i < count; i++) { + FinSet copy = (FinSet) this.copy(); + copy.setFinCount(1); + copy.setBaseRotation(base + i * 2 * Math.PI / count); + copy.setName(copy.getName() + " #" + (i + 1)); + copy.setOverrideMass(getOverrideMass() / getFinCount()); + parent.addChild(copy, index + i); + + splitFins.add(copy); + } + } + + // Split fins for children + for (RocketComponent listener : configListeners) { + if (listener instanceof FinSet) { + ((FinSet) listener).splitFins(); + this.removeConfigListener(listener); + } + } + + return splitFins; + } + + // for debugging. You can safely delete this method public static String getPointDescr( final Coordinate[] points, final String name, final String indent){ return getPointDescr(Arrays.asList(points), name, indent); diff --git a/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java index 42e231cd8..f4455bef6 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java @@ -109,23 +109,8 @@ public abstract class FinSetConfig extends RocketComponentConfig { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - RocketComponent parent = component.getParent(); - int index = parent.getChildPosition(component); - int count = ((FinSet) component).getFinCount(); - double base = ((FinSet) component).getBaseRotation(); - if (count <= 1) - return; - document.addUndoPosition("Split fin set"); - parent.removeChild(index); - for (int i = 0; i < count; i++) { - FinSet copy = (FinSet) component.copy(); - copy.setFinCount(1); - copy.setBaseRotation(base + i * 2 * Math.PI / count); - copy.setName(copy.getName() + " #" + (i + 1)); - copy.setOverrideMass(((FinSet) component).getOverrideMass()/((FinSet) component).getFinCount()); - parent.addChild(copy, index + i); - } + ((FinSet) component).splitFins(); } });