[#1893] Add rocket top view
This commit is contained in:
parent
88bf25e41d
commit
a2b6c63f0b
@ -49,6 +49,7 @@ RocketActions.MoveDownAct.Movedown = Move down
|
|||||||
RocketActions.MoveDownAct.ttip.Movedown = Move this component downwards.
|
RocketActions.MoveDownAct.ttip.Movedown = Move this component downwards.
|
||||||
|
|
||||||
! RocketPanel
|
! RocketPanel
|
||||||
|
RocketPanel.FigTypeAct.TopView = Top view
|
||||||
RocketPanel.FigTypeAct.SideView = Side view
|
RocketPanel.FigTypeAct.SideView = Side view
|
||||||
RocketPanel.FigTypeAct.BackView = Back view
|
RocketPanel.FigTypeAct.BackView = Back view
|
||||||
RocketPanel.FigTypeAct.Figure3D = 3D Figure
|
RocketPanel.FigTypeAct.Figure3D = 3D Figure
|
||||||
|
@ -58,9 +58,10 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
private static final String ROCKET_FIGURE_PACKAGE = "net.sf.openrocket.gui.rocketfigure";
|
private static final String ROCKET_FIGURE_PACKAGE = "net.sf.openrocket.gui.rocketfigure";
|
||||||
private static final String ROCKET_FIGURE_SUFFIX = "Shapes";
|
private static final String ROCKET_FIGURE_SUFFIX = "Shapes";
|
||||||
|
|
||||||
public static final int VIEW_SIDE=0;
|
public static final int VIEW_SIDE = 0;
|
||||||
public static final int VIEW_BACK=1;
|
public static final int VIEW_TOP = 1;
|
||||||
|
public static final int VIEW_BACK = 2;
|
||||||
|
|
||||||
// Width for drawing normal and selected components
|
// Width for drawing normal and selected components
|
||||||
public static final double NORMAL_WIDTH = 1.0;
|
public static final double NORMAL_WIDTH = 1.0;
|
||||||
@ -130,10 +131,6 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Transformation getRotateTransformation() {
|
|
||||||
return axialRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRotation(double rot) {
|
public void setRotation(double rot) {
|
||||||
if (MathUtil.equals(rotation, rot))
|
if (MathUtil.equals(rotation, rot))
|
||||||
return;
|
return;
|
||||||
@ -142,6 +139,14 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
updateFigure();
|
updateFigure();
|
||||||
fireChangeEvent();
|
fireChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Transformation getFigureRotation() {
|
||||||
|
if (currentViewType == RocketPanel.VIEW_TYPE.TopView) {
|
||||||
|
return this.axialRotation.applyTransformation(Transformation.rotate_x(-Math.PI / 2));
|
||||||
|
} else {
|
||||||
|
return this.axialRotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public RocketPanel.VIEW_TYPE getType() {
|
public RocketPanel.VIEW_TYPE getType() {
|
||||||
@ -149,7 +154,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setType(final RocketPanel.VIEW_TYPE type) {
|
public void setType(final RocketPanel.VIEW_TYPE type) {
|
||||||
if (type != RocketPanel.VIEW_TYPE.BackView && type != RocketPanel.VIEW_TYPE.SideView) {
|
if (type != RocketPanel.VIEW_TYPE.BackView && type != RocketPanel.VIEW_TYPE.SideView && type != RocketPanel.VIEW_TYPE.TopView) {
|
||||||
throw new IllegalArgumentException("Illegal type: " + type);
|
throw new IllegalArgumentException("Illegal type: " + type);
|
||||||
}
|
}
|
||||||
if (this.currentViewType == type)
|
if (this.currentViewType == type)
|
||||||
@ -201,7 +206,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
AffineTransform baseTransform = g2.getTransform();
|
AffineTransform baseTransform = g2.getTransform();
|
||||||
|
|
||||||
PriorityQueue<RocketComponentShape> figureShapes;
|
PriorityQueue<RocketComponentShape> figureShapes;
|
||||||
if (currentViewType == RocketPanel.VIEW_TYPE.SideView)
|
if (currentViewType == RocketPanel.VIEW_TYPE.SideView || currentViewType == RocketPanel.VIEW_TYPE.TopView)
|
||||||
figureShapes = figureShapes_side;
|
figureShapes = figureShapes_side;
|
||||||
else if (currentViewType == RocketPanel.VIEW_TYPE.BackView)
|
else if (currentViewType == RocketPanel.VIEW_TYPE.BackView)
|
||||||
figureShapes = figureShapes_back;
|
figureShapes = figureShapes_back;
|
||||||
@ -300,11 +305,11 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
// System.err.println(String.format(" mount instance: %s => %s", curMountLocation.toString(), curMotorLocation.toString() ));
|
// System.err.println(String.format(" mount instance: %s => %s", curMountLocation.toString(), curMotorLocation.toString() ));
|
||||||
|
|
||||||
// rotate by figure's axial rotation:
|
// rotate by figure's axial rotation:
|
||||||
curMotorLocation = this.axialRotation.transform(curMotorLocation);
|
curMotorLocation = getFigureRotation().transform(curMotorLocation);
|
||||||
|
|
||||||
{
|
{
|
||||||
Shape s;
|
Shape s;
|
||||||
if (currentViewType == RocketPanel.VIEW_TYPE.SideView) {
|
if (currentViewType == RocketPanel.VIEW_TYPE.SideView || currentViewType == RocketPanel.VIEW_TYPE.TopView) {
|
||||||
s = new Rectangle2D.Double(curMotorLocation.x,
|
s = new Rectangle2D.Double(curMotorLocation.x,
|
||||||
(curMotorLocation.y - motorRadius),
|
(curMotorLocation.y - motorRadius),
|
||||||
motorLength,
|
motorLength,
|
||||||
@ -354,7 +359,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
LinkedHashSet<RocketComponent> l = new LinkedHashSet<RocketComponent>();
|
LinkedHashSet<RocketComponent> l = new LinkedHashSet<RocketComponent>();
|
||||||
|
|
||||||
PriorityQueue<RocketComponentShape> figureShapes;
|
PriorityQueue<RocketComponentShape> figureShapes;
|
||||||
if (currentViewType == RocketPanel.VIEW_TYPE.SideView)
|
if (currentViewType == RocketPanel.VIEW_TYPE.SideView || currentViewType == RocketPanel.VIEW_TYPE.TopView)
|
||||||
figureShapes = figureShapes_side;
|
figureShapes = figureShapes_side;
|
||||||
else if (currentViewType == RocketPanel.VIEW_TYPE.BackView)
|
else if (currentViewType == RocketPanel.VIEW_TYPE.BackView)
|
||||||
figureShapes = figureShapes_back;
|
figureShapes = figureShapes_back;
|
||||||
@ -399,7 +404,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
final ArrayList<InstanceContext> contextList = entry.getValue();
|
final ArrayList<InstanceContext> contextList = entry.getValue();
|
||||||
|
|
||||||
for (InstanceContext context : contextList) {
|
for (InstanceContext context : contextList) {
|
||||||
final Transformation currentTransform = this.axialRotation.applyTransformation(context.transform);
|
final Transformation currentTransform = getFigureRotation().applyTransformation(context.transform);
|
||||||
allShapes = addThisShape(allShapes, this.currentViewType, comp, currentTransform);
|
allShapes = addThisShape(allShapes, this.currentViewType, comp, currentTransform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -432,9 +437,10 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
// Find the appropriate method
|
// Find the appropriate method
|
||||||
switch (viewType) {
|
switch (viewType) {
|
||||||
case SideView:
|
case SideView:
|
||||||
|
case TopView:
|
||||||
m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesSide",
|
m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesSide",
|
||||||
RocketComponent.class, Transformation.class);
|
RocketComponent.class, Transformation.class);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BackView:
|
case BackView:
|
||||||
m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesBack",
|
m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesBack",
|
||||||
@ -503,6 +509,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
switch (currentViewType) {
|
switch (currentViewType) {
|
||||||
case SideView:
|
case SideView:
|
||||||
|
case TopView:
|
||||||
subjectBounds_m = new Rectangle2D.Double(bounds.min.x, -maxR, bounds.span().x, 2 * maxR);
|
subjectBounds_m = new Rectangle2D.Double(bounds.min.x, -maxR, bounds.span().x, 2 * maxR);
|
||||||
break;
|
break;
|
||||||
case BackView:
|
case BackView:
|
||||||
@ -528,9 +535,8 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
if (currentViewType == RocketPanel.VIEW_TYPE.BackView){
|
if (currentViewType == RocketPanel.VIEW_TYPE.BackView){
|
||||||
final int newOriginX = mid_x;
|
final int newOriginX = mid_x;
|
||||||
final int newOriginY = borderThickness_px.height + getHeight() / 2;
|
final int newOriginY = borderThickness_px.height + getHeight() / 2;
|
||||||
|
|
||||||
originLocation_px = new Point(newOriginX, newOriginY);
|
originLocation_px = new Point(newOriginX, newOriginY);
|
||||||
}else if (currentViewType == RocketPanel.VIEW_TYPE.SideView){
|
} else if (currentViewType == RocketPanel.VIEW_TYPE.SideView || currentViewType == RocketPanel.VIEW_TYPE.TopView) {
|
||||||
final int newOriginX = mid_x - (subjectWidth / 2) - (int)(subjectBounds_m.getMinX() * scale);
|
final int newOriginX = mid_x - (subjectWidth / 2) - (int)(subjectBounds_m.getMinX() * scale);
|
||||||
final int newOriginY = Math.max(getHeight(), subjectHeight + 2*borderThickness_px.height )/ 2;
|
final int newOriginY = Math.max(getHeight(), subjectHeight + 2*borderThickness_px.height )/ 2;
|
||||||
originLocation_px = new Point(newOriginX, newOriginY);
|
originLocation_px = new Point(newOriginX, newOriginY);
|
||||||
|
@ -93,6 +93,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
|
|
||||||
public enum VIEW_TYPE {
|
public enum VIEW_TYPE {
|
||||||
SideView(false, RocketFigure.VIEW_SIDE),
|
SideView(false, RocketFigure.VIEW_SIDE),
|
||||||
|
TopView(false, RocketFigure.VIEW_TOP),
|
||||||
BackView(false, RocketFigure.VIEW_BACK),
|
BackView(false, RocketFigure.VIEW_BACK),
|
||||||
Figure3D(true, RocketFigure3d.TYPE_FIGURE),
|
Figure3D(true, RocketFigure3d.TYPE_FIGURE),
|
||||||
Unfinished(true, RocketFigure3d.TYPE_UNFINISHED),
|
Unfinished(true, RocketFigure3d.TYPE_UNFINISHED),
|
||||||
@ -773,7 +774,8 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
figure3d.setCP(new Coordinate(Double.NaN, Double.NaN));
|
figure3d.setCP(new Coordinate(Double.NaN, Double.NaN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) {
|
if (length > 0 &&
|
||||||
|
((figure.getType() == RocketPanel.VIEW_TYPE.TopView) || (figure.getType() == RocketPanel.VIEW_TYPE.SideView))) {
|
||||||
extraCP.setPosition(cpx, cpy);
|
extraCP.setPosition(cpx, cpy);
|
||||||
extraCG.setPosition(cgx, cgy);
|
extraCG.setPosition(cgx, cgy);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user