diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java index d5e3f8b76..84d1714d2 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java @@ -89,10 +89,14 @@ public abstract class AbstractScaleFigure extends JPanel { return originLocation_px; } - public Point getAutoZoomPoint(){ - return new Point(Math.max(0, originLocation_px.x - borderThickness_px.width), - Math.max(0, - borderThickness_px.height)); - } + /** + * Calculate a point for auto-zooming from a scale-to-fit request. + * + * The return point is intended for a $ScaleScrollPane call to "viewport.scrollRectToVisible(...)" + * + * @return the offset, in pixels, from the (top left) corner of the figure's canvas + */ + public abstract Point getAutoZoomPoint(); /** * Set the scale level of the figure. A scale value of 1.0 is equivalent to 100 % scale. diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java index dc2a5d8fe..333ed702a 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java @@ -71,6 +71,24 @@ public class FinPointFigure extends AbstractScaleFigure { updateFigure(); } + @Override + public Point getAutoZoomPoint(){ + final int finFrontLocationPx = originLocation_px.x + (int)(subjectBounds_m.getX()*scale); + + // from canvas top/left + final Point zoomPointPx = new Point( Math.max(0, originLocation_px.x + (int)(subjectBounds_m.getX()*scale)), + 0 ); + + System.err.println("==>> FinPointFigure.getAutoZoomPoint ==>> " + finset.getName() ); + System.err.println(String.format(" ::ContentBounds: %6.4f, %6.4f", contentBounds_m.getX(), contentBounds_m.getY())); + System.err.println(String.format(" ::SubjectBounds: %6.4f, %6.4f", subjectBounds_m.getX(), subjectBounds_m.getY())); +// System.err.println(String.format(" ::finRootOffset: %d, %d", finFrontOffsetPx, finBottomOffsetPx)); +// System.err.println(String.format(" ::finRootLocation: %d, %d", finFrontLocationPx, 0)); + System.err.println(String.format(" ::ZoomPoint: %d, %d", zoomPointPx.x, zoomPointPx.y)); + + return zoomPointPx; + } + @Override public void paintComponent(Graphics g) { super.paintComponent(g); @@ -378,8 +396,11 @@ public class FinPointFigure extends AbstractScaleFigure { @Override protected void updateCanvasOrigin() { - final int finHeightPx = (int)(finBounds_m.span().y*scale); + final int finHeightPx = (int)(finBounds_m.max.y*scale); final int mountHeightPx = (int)(mountBounds_m.span().y*scale); + // this is non-intuitive: it's an offset _from_ the origin(0,0) _to_ the lower-left of the content -- + // because the canvas is drawn from that lower-left corner of the content, and the fin-front + // is fixed-- by definition-- to the origin. final int finFrontPx = (int)(contentBounds_m.getX()*scale); final int contentHeightPx = (int)(contentBounds_m.getHeight()*scale); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 71a407680..6314b303b 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -89,7 +89,12 @@ public class RocketFigure extends AbstractScaleFigure { updateFigure(); } - + + public Point getAutoZoomPoint(){ + return new Point( Math.max(0, originLocation_px.x - borderThickness_px.width), + Math.max(0, - borderThickness_px.height)); + } + public RocketComponent[] getSelection() { return selection; }