From e82a7a89b243258350d25e09b51d8dfed1d2436f Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 4 Mar 2022 18:10:44 +0100 Subject: [PATCH] Add helper methods --- .../rocketcomponent/RocketComponent.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 43fad2d51..bcdca0897 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -1623,6 +1623,23 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab checkState(); return parent; } + + /** + * Get all the parent and super-parent components of this component. + * @return parent and super-parents of this component + */ + public final List getParents() { + checkState(); + List result = new LinkedList<>(); + RocketComponent currComp = this; + + while (currComp.parent != null) { + currComp = currComp.parent; + result.add(currComp); + } + + return result; + } /** * Get the root component of the component tree. @@ -1710,6 +1727,26 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab } return result; } + + /** + * Return all the component assemblies that are a parent or super-parent of this component + * @return list of ComponentAssembly components that are a parent or super-parent of this component + */ + public final List getParentAssemblies() { + checkState(); + + List result = new LinkedList<>(); + RocketComponent currComp = this; + + while (currComp.parent != null) { + currComp = currComp.parent; + if (currComp instanceof ComponentAssembly) { + result.add(currComp); + } + } + + return result; + } /**