Merge pull request #1984 from SiboVG/issue-1981

[#1981] Update pod/booster marker position based on axial method & Correct for pod/booster marker radius offset
This commit is contained in:
Sibo Van Gool 2023-01-20 00:56:50 +01:00 committed by GitHub
commit 55e03f97d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,11 @@
package net.sf.openrocket.gui.rocketfigure; package net.sf.openrocket.gui.rocketfigure;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.rocketcomponent.ParallelStage; import net.sf.openrocket.rocketcomponent.ParallelStage;
import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.PodSet;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.util.Color; import net.sf.openrocket.util.Color;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
@ -17,9 +19,22 @@ public class ComponentAssemblyShapes extends RocketComponentShape {
return null; return null;
} }
double radius = getDisplayRadius(component); ComponentAssembly assembly = (ComponentAssembly) component;
Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(transformation, radius); // Update the marker location based on the axial method. The axial method changes the "reference point" of the component.
Transformation correctedTransform = transformation;
if (assembly.getAxialMethod() == AxialMethod.BOTTOM) {
correctedTransform = transformation.applyTransformation(new Transformation(assembly.getLength(), 0, 0));
} else if (assembly.getAxialMethod() == AxialMethod.MIDDLE) {
correctedTransform = transformation.applyTransformation(new Transformation(assembly.getLength() / 2, 0, 0));
}
// 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));
double markerRadius = getDisplayRadius(component);
Shape[] s = EmptyShapes.getShapesSideWithSelectionSquare(correctedTransform, markerRadius);
RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component); RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component);
// Set the color of the shapes // Set the color of the shapes
@ -36,9 +51,15 @@ public class ComponentAssemblyShapes extends RocketComponentShape {
if (component instanceof AxialStage && !(component instanceof ParallelStage)) { if (component instanceof AxialStage && !(component instanceof ParallelStage)) {
return null; 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); RocketComponentShape[] shapes = RocketComponentShape.toArray(s, component);
// Set the color of the shapes // Set the color of the shapes
@ -50,6 +71,11 @@ public class ComponentAssemblyShapes extends RocketComponentShape {
return shapes; 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) { private static double getDisplayRadius(RocketComponent component) {
return component.getRocket().getBoundingRadius() * 0.03; return component.getRocket().getBoundingRadius() * 0.03;
} }