From b1e173d54ef9fafa173402c44a915bfeb42d59cf Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 17 Jan 2023 01:27:47 +0100 Subject: [PATCH 1/4] Refactor pod/booster shapes --- .../rocketfigure/ComponentAssemblyShapes.java | 56 +++++++++++++++++++ .../gui/rocketfigure/ParallelStageShapes.java | 47 +--------------- .../gui/rocketfigure/PodSetShapes.java | 47 +--------------- .../gui/scalefigure/RocketFigure.java | 4 +- 4 files changed, 62 insertions(+), 92 deletions(-) create mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java new file mode 100644 index 000000000..c4b2cb960 --- /dev/null +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java @@ -0,0 +1,56 @@ +package net.sf.openrocket.gui.rocketfigure; + +import net.sf.openrocket.rocketcomponent.ParallelStage; +import net.sf.openrocket.rocketcomponent.PodSet; +import net.sf.openrocket.rocketcomponent.RocketComponent; +import net.sf.openrocket.util.Color; +import net.sf.openrocket.util.Transformation; + +import java.awt.Shape; + +public class ComponentAssemblyShapes extends RocketComponentShape { + + public static RocketComponentShape[] getShapesSide(final RocketComponent component, final Transformation transformation) { + double radius = getDisplayRadius(component); + + Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(transformation, radius); + RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); + + // Set the color of the shapes + Color color = getColor(component); + for (int i = 0; i < shapes.length - 1; i++) { + shapes[i].setColor(color); + } + + return shapes; + } + + public static RocketComponentShape[] getShapesBack(final RocketComponent component, final Transformation transformation) { + double radius = getDisplayRadius(component); + + Shape[] s = EmptyShapes.getShapesBackWithSelectionSquare(transformation, radius); + RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); + + // Set the color of the shapes + Color color = getColor(component); + for (int i = 0; i < shapes.length - 1; i++) { + shapes[i].setColor(color); + } + + return shapes; + } + + private static double getDisplayRadius(RocketComponent component) { + return component.getRocket().getBoundingRadius() * 0.03; + } + + private static Color getColor(RocketComponent component) { + if (component instanceof PodSet) { + return new Color(160,160,215); + } else if (component instanceof ParallelStage) { + return new Color(198,163,184); + } else { + return new Color(160, 160, 160); + } + } +} diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java index 565a23591..18f27ab4a 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java @@ -1,48 +1,5 @@ package net.sf.openrocket.gui.rocketfigure; -import net.sf.openrocket.rocketcomponent.ParallelStage; -import net.sf.openrocket.rocketcomponent.RocketComponent; -import net.sf.openrocket.util.Color; -import net.sf.openrocket.util.Transformation; - -import java.awt.Shape; - -public class ParallelStageShapes extends RocketComponentShape { - public static final Color boosterColor = new Color(198,163,184); - - public static RocketComponentShape[] getShapesSide(final RocketComponent component, final Transformation transformation) { - ParallelStage booster = (ParallelStage)component; - double radius = getDisplayRadius(booster); - - Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(transformation, radius); - RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); - - // Set the color of the shapes - for (int i = 0; i < shapes.length - 1; i++) { - shapes[i].setColor(boosterColor); - } - shapes[shapes.length - 1].setColor(Color.INVISIBLE); - - return shapes; - } - - public static RocketComponentShape[] getShapesBack(final RocketComponent component, final Transformation transformation) { - ParallelStage booster = (ParallelStage)component; - double radius = getDisplayRadius(booster); - - Shape[] s = EmptyShapes.getShapesBackWithSelectionSquare(transformation, radius); - RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); - - // Set the color of the shapes - for (int i = 0; i < shapes.length - 1; i++) { - shapes[i].setColor(boosterColor); - } - shapes[shapes.length - 1].setColor(Color.INVISIBLE); - - return shapes; - } - - private static double getDisplayRadius(ParallelStage booster) { - return booster.getRocket().getBoundingRadius() * 0.03; - } +public class ParallelStageShapes extends ComponentAssemblyShapes { + // Everything is implemented in ComponentAssemblyShapes.java } diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java index 7ef928f2d..1d2ba4144 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java @@ -1,48 +1,5 @@ package net.sf.openrocket.gui.rocketfigure; -import net.sf.openrocket.rocketcomponent.PodSet; -import net.sf.openrocket.rocketcomponent.RocketComponent; -import net.sf.openrocket.util.Color; -import net.sf.openrocket.util.Transformation; - -import java.awt.Shape; - -public class PodSetShapes extends RocketComponentShape { - public static final Color podsetColor = new Color(160,160,215); - - public static RocketComponentShape[] getShapesSide(final RocketComponent component, final Transformation transformation) { - PodSet podset = (PodSet)component; - double radius = getDisplayRadius(podset); - - Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(transformation, radius); - RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); - - // Set the color of the shapes - for (int i = 0; i < shapes.length - 1; i++) { - shapes[i].setColor(podsetColor); - } - shapes[shapes.length - 1].setColor(Color.INVISIBLE); - - return shapes; - } - - public static RocketComponentShape[] getShapesBack(final RocketComponent component, final Transformation transformation) { - PodSet podset = (PodSet)component; - double radius = getDisplayRadius(podset); - - Shape[] s = EmptyShapes.getShapesBackWithSelectionSquare(transformation, radius); - RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); - - // Set the color of the shapes - for (int i = 0; i < shapes.length - 1; i++) { - shapes[i].setColor(podsetColor); - } - shapes[shapes.length - 1].setColor(Color.INVISIBLE); - - return shapes; - } - - private static double getDisplayRadius(PodSet podset) { - return podset.getRocket().getBoundingRadius() * 0.03; - } +public class PodSetShapes extends ComponentAssemblyShapes { + // Everything is implemented in ComponentAssemblyShapes.java } diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 0f62a28f7..fa195b4c0 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -387,8 +387,8 @@ public class RocketFigure extends AbstractScaleFigure { for (Entry> entry : config.getActiveInstances().entrySet()) { final RocketComponent comp = entry.getKey(); - // Only draw podsets when they are selected - if ((comp instanceof PodSet || comp instanceof ParallelStage) && preferences.isShowMarkers()) { + // Only draw pod sets and boosters when they are selected + if (preferences.isShowMarkers() && (comp instanceof PodSet || comp instanceof ParallelStage)) { boolean selected = false; // Check if component is in the selection From 738905d6d8248f2d3dc6b763346c73692b2a8f47 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 17 Jan 2023 22:48:28 +0100 Subject: [PATCH 2/4] Refactoring --- .../rocketcomponent/FlightConfiguration.java | 2 +- .../sf/openrocket/rocketcomponent/InstanceMap.java | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 307b1e2d4..271e1fb59 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -427,7 +427,7 @@ public class FlightConfiguration implements FlightConfigurableParameter()); + public void emplace(final RocketComponent component, int number, final Transformation transform) { + if (!containsKey(component)) { + put(component, new ArrayList<>()); } - final InstanceContext context = new InstanceContext(component, number, xform); - get(key).add(context); + final InstanceContext context = new InstanceContext(component, number, transform); + get(component).add(context); } public List getInstanceContexts(final RocketComponent key) { From 3d02766d41ab987a1a508fa8564af305138d240c Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 18 Jan 2023 00:13:04 +0100 Subject: [PATCH 3/4] [#1980] Render booster markers even if no children --- .../rocketcomponent/FlightConfiguration.java | 19 +++++++++++++++++-- .../gui/scalefigure/RocketFigure.java | 9 +++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 271e1fb59..44089a499 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -67,6 +67,7 @@ public class FlightConfiguration implements FlightConfigurableParameter preloadStageActiveness = null; final private Collection activeMotors = new ConcurrentLinkedQueue(); final private InstanceMap activeInstances = new InstanceMap(); + final private InstanceMap extraRenderInstances = new InstanceMap(); // Extra instances to be rendered, besides the active instances private int boundsModID = -1; private BoundingBox cachedBoundsAerodynamic = new BoundingBox(); // Bounding box of all aerodynamic components @@ -288,7 +289,7 @@ public class FlightConfiguration implements FlightConfigurableParameter 0 && + return stage != null && stage.getChildCount() > 0 && // Stages with no children are marked as inactive stages.get(stageNumber) != null && stages.get(stageNumber).active; } @@ -398,6 +399,15 @@ public class FlightConfiguration implements FlightConfigurableParameter> entry : config.getActiveInstances().entrySet()) { + addShapesFromInstanceEntries(allShapes, config.getActiveInstances().entrySet()); + addShapesFromInstanceEntries(allShapes, config.getExtraRenderInstances().entrySet()); + } + + private void addShapesFromInstanceEntries(PriorityQueue allShapes, Set>> entries) { + for (Entry> entry : entries) { final RocketComponent comp = entry.getKey(); // Only draw pod sets and boosters when they are selected @@ -409,7 +414,7 @@ public class RocketFigure extends AbstractScaleFigure { } } } - + /** * Gets the shapes required to draw the component. * From 08b9afb6ca60af7bdc9269ca6e11d6476bfec2fa Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 18 Jan 2023 00:20:01 +0100 Subject: [PATCH 4/4] Refactor again --- .../gui/rocketfigure/ComponentAssemblyShapes.java | 10 ++++++++++ .../gui/rocketfigure/ParallelStageShapes.java | 5 ----- .../sf/openrocket/gui/rocketfigure/PodSetShapes.java | 5 ----- 3 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java delete mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java index c4b2cb960..da8250474 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java @@ -1,5 +1,6 @@ package net.sf.openrocket.gui.rocketfigure; +import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.ParallelStage; import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.RocketComponent; @@ -11,6 +12,11 @@ import java.awt.Shape; public class ComponentAssemblyShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesSide(final RocketComponent component, final Transformation transformation) { + // Ignore normal stages + if (component instanceof AxialStage && !(component instanceof ParallelStage)) { + return null; + } + double radius = getDisplayRadius(component); Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(transformation, radius); @@ -26,6 +32,10 @@ public class ComponentAssemblyShapes extends RocketComponentShape { } public static RocketComponentShape[] getShapesBack(final RocketComponent component, final Transformation transformation) { + // Ignore normal stages + if (component instanceof AxialStage && !(component instanceof ParallelStage)) { + return null; + } double radius = getDisplayRadius(component); Shape[] s = EmptyShapes.getShapesBackWithSelectionSquare(transformation, radius); diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java deleted file mode 100644 index 18f27ab4a..000000000 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.sf.openrocket.gui.rocketfigure; - -public class ParallelStageShapes extends ComponentAssemblyShapes { - // Everything is implemented in ComponentAssemblyShapes.java -} diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java deleted file mode 100644 index 1d2ba4144..000000000 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.sf.openrocket.gui.rocketfigure; - -public class PodSetShapes extends ComponentAssemblyShapes { - // Everything is implemented in ComponentAssemblyShapes.java -}