[fixes #976] Added different display order for side view and back view

This commit is contained in:
Sibo Van Gool 2021-07-10 19:29:39 +02:00
parent 9ac2d2f844
commit c21127f4e3
19 changed files with 82 additions and 35 deletions

View File

@ -45,7 +45,8 @@ public class BodyTube extends SymmetricComponent implements BoxBounded, MotorMou
this.outerRadius = Math.max(radius, 0);
this.length = Math.max(length, 0);
motors = new MotorConfigurationSet(this);
super.displayOrder = 0; // Order for displaying the component in the 2D view
super.displayOrder_side = 0; // Order for displaying the component in the 2D side view
super.displayOrder_back = 0; // Order for displaying the component in the 2D back view
}
public BodyTube(double length, double radius, boolean filled) {

View File

@ -13,7 +13,8 @@ public class Bulkhead extends RadiusRingComponent {
public Bulkhead() {
setOuterRadiusAutomatic(true);
setLength(0.002);
super.displayOrder = 10; // Order for displaying the component in the 2D view
super.displayOrder_side = 10; // Order for displaying the component in the 2D side view
super.displayOrder_back = 10; // Order for displaying the component in the 2D back view
}
@Override

View File

@ -13,7 +13,8 @@ public class CenteringRing extends RadiusRingComponent {
setOuterRadiusAutomatic(true);
setInnerRadiusAutomatic(true);
setLength(0.002);
super.displayOrder = 9; // Order for displaying the component in the 2D view
super.displayOrder_side = 9; // Order for displaying the component in the 2D side view
super.displayOrder_back = 9; // Order for displaying the component in the 2D back view
}
private static final Translator trans = Application.getTranslator();

View File

@ -16,7 +16,8 @@ public class EngineBlock extends ThicknessRingComponent implements AxialPosition
setOuterRadiusAutomatic(true);
setThickness(0.005);
setLength(0.005);
super.displayOrder = 11; // Order for displaying the component in the 2D view
super.displayOrder_side = 11; // Order for displaying the component in the 2D side view
super.displayOrder_back = 11; // Order for displaying the component in the 2D back view
}
@Override

View File

@ -134,7 +134,8 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona
public FinSet() {
super( AxialMethod.BOTTOM);
this.filletMaterial = Application.getPreferences().getDefaultComponentMaterial(this.getClass(), Material.Type.BULK);
super.displayOrder = 4; // Order for displaying the component in the 2D view
super.displayOrder_side = 4; // Order for displaying the component in the 2D side view
super.displayOrder_back = 4; // Order for displaying the component in the 2D back view
}
@Override

View File

@ -49,7 +49,8 @@ public class InnerTube extends ThicknessRingComponent implements AxialPositionab
motors = new MotorConfigurationSet(this);
super.displayOrder = 7; // Order for displaying the component in the 2D view
super.displayOrder_side = 7; // Order for displaying the component in the 2D side view
super.displayOrder_back = 7; // Order for displaying the component in the 2D back view
}

View File

@ -37,7 +37,8 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, B
radius = 0.01 / 2;
thickness = 0.001;
length = 0.03;
super.displayOrder = 6; // Order for displaying the component in the 2D view
super.displayOrder_side = 6; // Order for displaying the component in the 2D side view
super.displayOrder_back = 6; // Order for displaying the component in the 2D back view
}

View File

@ -41,13 +41,15 @@ public class MassComponent extends MassObject {
public MassComponent() {
super();
super.displayOrder = 15; // Order for displaying the component in the 2D view
super.displayOrder_side = 14; // Order for displaying the component in the 2D side view
super.displayOrder_back = 14; // Order for displaying the component in the 2D back view
}
public MassComponent(double length, double radius, double mass) {
super(length, radius);
this.mass = mass;
super.displayOrder = 14; // Order for displaying the component in the 2D view
super.displayOrder_side = 14; // Order for displaying the component in the 2D side view
super.displayOrder_back = 14; // Order for displaying the component in the 2D back view
}

View File

@ -43,7 +43,8 @@ public class NoseCone extends Transition implements InsideColorComponent {
super.setAftRadiusAutomatic(false);
super.setAftRadius(radius);
super.displayOrder = 1; // Order for displaying the component in the 2D view
super.displayOrder_side = 1; // Order for displaying the component in the 2D side view
super.displayOrder_back = 1; // Order for displaying the component in the 2D back view
}

View File

@ -23,7 +23,8 @@ public class Parachute extends RecoveryDevice {
this.diameter = 0.3;
this.lineMaterial = Application.getPreferences().getDefaultComponentMaterial(Parachute.class, Material.Type.LINE);
this.lineLength = 0.3;
super.displayOrder = 12; // Order for displaying the component in the 2D view
super.displayOrder_side = 12; // Order for displaying the component in the 2D side view
super.displayOrder_back = 12; // Order for displaying the component in the 2D back view
}

View File

@ -69,14 +69,16 @@ public class RailButton extends ExternalComponent implements AnglePositionable,
this.setStandoff( 0.002);
this.setInstanceSeparation( this.outerDiameter_m * 6);
this.setMaterial(Databases.findMaterial(Material.Type.BULK, "Delrin"));
super.displayOrder = 5; // Order for displaying the component in the 2D view
super.displayOrder_side = 5; // Order for displaying the component in the 2D side view
super.displayOrder_back = 5; // Order for displaying the component in the 2D back view
}
public RailButton( final double od, final double ht ) {
this();
this.setOuterDiameter( od);
this.setTotalHeight( ht);
super.displayOrder = 5; // Order for displaying the component in the 2D view
super.displayOrder_side = 5; // Order for displaying the component in the 2D side view
super.displayOrder_back = 5; // Order for displaying the component in the 2D back view
}
public RailButton( final double od, final double id, final double ht, final double flangeThickness, final double _standoff ) {
@ -88,7 +90,8 @@ public class RailButton extends ExternalComponent implements AnglePositionable,
this.setStandoff( _standoff);
this.setInstanceSeparation( od*2);
this.setMaterial(Databases.findMaterial(Material.Type.BULK, "Delrin"));
super.displayOrder = 5; // Order for displaying the component in the 2D view
super.displayOrder_side = 5; // Order for displaying the component in the 2D side view
super.displayOrder_back = 5; // Order for displaying the component in the 2D back view
}
private static final RailButton make1010Button(){

View File

@ -129,10 +129,13 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
/**
* This is for determining the order in which the component should be drawn in the 2D views.
* This is for determining the order in which the component should be drawn in the 2D views, both
* in the side view and in the back view.
* Lower values will be placed more in the back, higher values more in the front.
* A high enough init value is picked to not mess with pre-defined values.
*/
protected int displayOrder = 100; // Take a high enough init value to not mess with pre-defined values
protected int displayOrder_side = 100;
protected int displayOrder_back = 100;
//// NOTE !!! All fields must be copied in the method copyFrom()! ////
@ -2020,7 +2023,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
this.name = src.name;
this.comment = src.comment;
this.id = src.id;
this.displayOrder = src.displayOrder;
this.displayOrder_side = src.displayOrder_side;
this.displayOrder_back = src.displayOrder_back;
// Add source components to invalidation tree
for (RocketComponent c : src) {
@ -2236,11 +2240,19 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
return false;
}
public int getDisplayOrder() {
return displayOrder;
public int getDisplayOrder_side() {
return displayOrder_side;
}
public void setDisplayOrder(int displayOrder) {
this.displayOrder = displayOrder;
public void setDisplayOrder_side(int displayOrder_side) {
this.displayOrder_side = displayOrder_side;
}
public int getDisplayOrder_back() {
return displayOrder_back;
}
public void setDisplayOrder_back(int displayOrder_back) {
this.displayOrder_back = displayOrder_back;
}
}

View File

@ -15,7 +15,8 @@ public class ShockCord extends MassObject {
public ShockCord() {
material = Application.getPreferences().getDefaultComponentMaterial(ShockCord.class, Material.Type.LINE);
cordLength = 0.4;
super.displayOrder = 13; // Order for displaying the component in the 2D view
super.displayOrder_side = 13; // Order for displaying the component in the 2D side view
super.displayOrder_back = 13; // Order for displaying the component in the 2D back view
}

View File

@ -21,7 +21,8 @@ public class Streamer extends RecoveryDevice {
public Streamer() {
this.stripLength = 0.5;
this.stripWidth = 0.05;
super.displayOrder = 12; // Order for displaying the component in the 2D view
super.displayOrder_side = 12; // Order for displaying the component in the 2D side view
super.displayOrder_back = 12; // Order for displaying the component in the 2D back view
}

View File

@ -59,7 +59,8 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
this.shapeParameter = 0;
this.clipped = true;
super.displayOrder = 2; // Order for displaying the component in the 2D view
super.displayOrder_side = 2; // Order for displaying the component in the 2D side view
super.displayOrder_back = 2; // Order for displaying the component in the 2D back view
}
//////// Length ////////

View File

@ -13,7 +13,8 @@ public class TubeCoupler extends ThicknessRingComponent implements RadialParent
setOuterRadiusAutomatic(true);
setThickness(0.002);
setLength(0.06);
super.displayOrder = 8; // Order for displaying the component in the 2D view
super.displayOrder_side = 8; // Order for displaying the component in the 2D side view
super.displayOrder_back = 8; // Order for displaying the component in the 2D back view
}
@Override

View File

@ -56,7 +56,8 @@ public class TubeFinSet extends ExternalComponent implements AxialPositionable,
public TubeFinSet() {
super(AxialMethod.BOTTOM);
length = 0.10;
super.displayOrder = 3; // Order for displaying the component in the 2D view
super.displayOrder_side = 3; // Order for displaying the component in the 2D side view
super.displayOrder_back = 3; // Order for displaying the component in the 2D back view
}
public void setLength(double length) {

View File

@ -12,7 +12,7 @@ import net.sf.openrocket.util.Transformation;
/**
* A catch-all, no-operation drawing component.
*/
public class RocketComponentShape implements Comparable<RocketComponentShape> {
public class RocketComponentShape {
final public boolean hasShape;
final public Shape shape;
@ -71,10 +71,4 @@ public class RocketComponentShape implements Comparable<RocketComponentShape> {
}
return toReturn;
}
@Override
public int compareTo(RocketComponentShape o) {
return Integer.compare(o.component.getDisplayOrder(), this.component.getDisplayOrder());
}
}

View File

@ -78,7 +78,10 @@ public class RocketFigure extends AbstractScaleFigure {
* the highest priority, namely being the one where the corresponding RocketComponent has the highest displayOrder
* (declared in RocketComponent, can be overridden in separate components).
*/
private final PriorityQueue<RocketComponentShape> figureShapes = new PriorityQueue<>();
private final PriorityQueue<RocketComponentShape> figureShapes_side = new PriorityQueue<>(
Comparator.comparingInt(o -> -o.component.getDisplayOrder_side()));
private final PriorityQueue<RocketComponentShape> figureShapes_back = new PriorityQueue<>(
Comparator.comparingInt(o -> -o.component.getDisplayOrder_back()));
private final ArrayList<FigureElement> relativeExtra = new ArrayList<FigureElement>();
@ -191,13 +194,23 @@ public class RocketFigure extends AbstractScaleFigure {
Graphics2D g2 = (Graphics2D) g;
AffineTransform baseTransform = g2.getTransform();
PriorityQueue<RocketComponentShape> figureShapes;
if (currentViewType == RocketPanel.VIEW_TYPE.SideView)
figureShapes = figureShapes_side;
else if (currentViewType == RocketPanel.VIEW_TYPE.BackView)
figureShapes = figureShapes_back;
else {
log.warn("Unknown view type for paintComponent");
return;
}
updateSubjectDimensions();
updateCanvasOrigin();
updateCanvasSize();
updateTransform();
updateShapes(this.figureShapes);
updateShapes(figureShapes);
g2.transform(projection);
@ -332,6 +345,15 @@ public class RocketFigure extends AbstractScaleFigure {
LinkedHashSet<RocketComponent> l = new LinkedHashSet<RocketComponent>();
PriorityQueue<RocketComponentShape> figureShapes;
if (currentViewType == RocketPanel.VIEW_TYPE.SideView)
figureShapes = figureShapes_side;
else if (currentViewType == RocketPanel.VIEW_TYPE.BackView)
figureShapes = figureShapes_back;
else {
log.warn("Unknown view type for getComponentsByPoint");
return null;
}
PriorityQueue<RocketComponentShape> figureShapesCopy = new PriorityQueue<>(figureShapes);
while (!figureShapesCopy.isEmpty()) {