From b479809b62843467e3af9836d88fded840a7f176 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 16 Jul 2022 14:41:14 +0200 Subject: [PATCH] Add 2D visualization for boosters --- .../gui/rocketfigure/ParallelStageShapes.java | 49 +++++++++++++++++++ .../gui/rocketfigure/PodSetShapes.java | 3 +- .../gui/scalefigure/RocketFigure.java | 13 +++-- 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java new file mode 100644 index 000000000..f8b1f58e4 --- /dev/null +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ParallelStageShapes.java @@ -0,0 +1,49 @@ +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(220, 185, 185); + 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; + } +} diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java index ebe8641c9..308e34929 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/PodSetShapes.java @@ -8,7 +8,8 @@ import net.sf.openrocket.util.Transformation; import java.awt.Shape; public class PodSetShapes extends RocketComponentShape { - public static final Color podsetColor = new Color(160, 160, 160); // Normal color for the podset shape + //public static final Color podsetColor = new Color(180, 180, 225); + public static final Color podsetColor = new Color(160,160,215); public static RocketComponentShape[] getShapesSide(final RocketComponent component, final Transformation transformation) { PodSet podset = (PodSet)component; diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 60f011d9a..39c18e025 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -17,7 +17,8 @@ import java.awt.geom.Rectangle2D; import java.util.*; import java.util.Map.Entry; -import net.sf.openrocket.gui.rocketfigure.PodSetShapes; +import net.sf.openrocket.rocketcomponent.AxialStage; +import net.sf.openrocket.rocketcomponent.ParallelStage; import net.sf.openrocket.rocketcomponent.PodSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +29,6 @@ import net.sf.openrocket.gui.util.ColorConversion; import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorConfiguration; -import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.InstanceContext; import net.sf.openrocket.rocketcomponent.MotorMount; @@ -382,17 +382,16 @@ public class RocketFigure extends AbstractScaleFigure { final RocketComponent comp = entry.getKey(); // Only draw podsets when they are selected - if (comp instanceof PodSet) { + if (comp instanceof PodSet || comp instanceof ParallelStage) { boolean selected = false; // Check if component is in the selection - for (int j = 0; j < selection.length; j++) { - if (comp == selection[j]) { + for (RocketComponent component : selection) { + if (comp == component) { selected = true; break; } } - if (!selected) continue; } @@ -424,7 +423,7 @@ public class RocketFigure extends AbstractScaleFigure { final net.sf.openrocket.util.Color color) { Reflection.Method m; - if(( component instanceof Rocket)||( component instanceof ComponentAssembly && !(component instanceof PodSet))){ + if ((component instanceof Rocket) || (component instanceof AxialStage && !(component instanceof ParallelStage))){ // no-op; no shapes here return allShapes; }