Refactor pod/booster shapes

This commit is contained in:
SiboVG 2023-01-17 01:27:47 +01:00
parent 16f7e6ab54
commit b1e173d54e
4 changed files with 62 additions and 92 deletions

View File

@ -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);
}
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -387,8 +387,8 @@ public class RocketFigure extends AbstractScaleFigure {
for (Entry<RocketComponent, ArrayList<InstanceContext>> 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