Add 2D visualization for boosters

This commit is contained in:
SiboVG 2022-07-16 14:41:14 +02:00
parent 9c5d1e9e26
commit b479809b62
3 changed files with 57 additions and 8 deletions

View File

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

View File

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

View File

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