From fcc3de10daf6407d4b25746156ce73003a79e728 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 18 Jan 2023 00:39:02 +0100 Subject: [PATCH 1/2] [#1981] Update pod/booster marker position based on axial method --- .../gui/rocketfigure/ComponentAssemblyShapes.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java index da8250474..05727dae1 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java @@ -1,9 +1,11 @@ package net.sf.openrocket.gui.rocketfigure; import net.sf.openrocket.rocketcomponent.AxialStage; +import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.ParallelStage; import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.RocketComponent; +import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.util.Color; import net.sf.openrocket.util.Transformation; @@ -17,9 +19,19 @@ public class ComponentAssemblyShapes extends RocketComponentShape { return null; } + ComponentAssembly assembly = (ComponentAssembly) component; + + // Update the marker location based on the axial method. The axial method changes the "reference point" of the component. + Transformation newTransform = transformation; + if (assembly.getAxialMethod() == AxialMethod.BOTTOM) { + newTransform = transformation.applyTransformation(new Transformation(assembly.getLength(), 0, 0)); + } else if (assembly.getAxialMethod() == AxialMethod.MIDDLE) { + newTransform = transformation.applyTransformation(new Transformation(assembly.getLength() / 2, 0, 0)); + } + double radius = getDisplayRadius(component); - Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(transformation, radius); + Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(newTransform, radius); RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); // Set the color of the shapes From 8a04eed0a2043e37c5aabd886a1bfc78cdd5c9d0 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 18 Jan 2023 02:32:08 +0100 Subject: [PATCH 2/2] [#1981] Correct for pod/booster marker radius offset --- .../rocketfigure/ComponentAssemblyShapes.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java index 05727dae1..5dd94d4d0 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ComponentAssemblyShapes.java @@ -22,16 +22,19 @@ public class ComponentAssemblyShapes extends RocketComponentShape { ComponentAssembly assembly = (ComponentAssembly) component; // Update the marker location based on the axial method. The axial method changes the "reference point" of the component. - Transformation newTransform = transformation; + Transformation correctedTransform = transformation; if (assembly.getAxialMethod() == AxialMethod.BOTTOM) { - newTransform = transformation.applyTransformation(new Transformation(assembly.getLength(), 0, 0)); + correctedTransform = transformation.applyTransformation(new Transformation(assembly.getLength(), 0, 0)); } else if (assembly.getAxialMethod() == AxialMethod.MIDDLE) { - newTransform = transformation.applyTransformation(new Transformation(assembly.getLength() / 2, 0, 0)); + correctedTransform = transformation.applyTransformation(new Transformation(assembly.getLength() / 2, 0, 0)); } - double radius = getDisplayRadius(component); + // Correct the radius to be at the "reference point" dictated by the component's radius offset. + double boundingRadius = assembly.getBoundingRadius(); + correctedTransform = correctedTransform.applyTransformation(new Transformation(0, -boundingRadius, 0)); - Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(newTransform, radius); + double markerRadius = getDisplayRadius(component); + Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(correctedTransform, markerRadius); RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); // Set the color of the shapes @@ -48,9 +51,15 @@ public class ComponentAssemblyShapes extends RocketComponentShape { if (component instanceof AxialStage && !(component instanceof ParallelStage)) { return null; } - double radius = getDisplayRadius(component); - Shape[] s = EmptyShapes.getShapesBackWithSelectionSquare(transformation, radius); + ComponentAssembly assembly = (ComponentAssembly) component; + + // Correct the radius to be at the "reference point" dictated by the component's radius offset. + double boundingRadius = assembly.getBoundingRadius(); + Transformation correctedTransform = transformation.applyTransformation(new Transformation(0, -boundingRadius, 0)); + + double markerRadius = getDisplayRadius(component); + Shape[] s = EmptyShapes.getShapesBackWithSelectionSquare(correctedTransform, markerRadius); RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); // Set the color of the shapes @@ -62,6 +71,11 @@ public class ComponentAssemblyShapes extends RocketComponentShape { return shapes; } + /** + * Returns the radius of the marker (i.e. the marker size), based on the rocket size. + * @param component this component + * @return the radius to draw the marker with + */ private static double getDisplayRadius(RocketComponent component) { return component.getRocket().getBoundingRadius() * 0.03; }