[fix] FinPointFigure now auto-scales correctly

- auto-zooms on startup
- ScaleSelector Text updates with +/- buttons
- adjusts fin-point drawing code
This commit is contained in:
Daniel_M_Williams 2018-07-04 17:15:25 -04:00
parent 87b1f99a9b
commit b63ea3b3cc
5 changed files with 31 additions and 33 deletions

View File

@ -254,7 +254,9 @@ public class FreeformFinSetConfig extends FinSetConfig {
}
});
ScaleSelector selector = new ScaleSelector(figurePane);
// fit on first start-up
figurePane.setFitting(true);
panel.setLayout(new MigLayout("fill, gap 5!","", "[nogrid, fill, sizegroup display, growprio 200]5![sizegroup text, growprio 5]5![sizegroup buttons, align top, growprio 5]0!"));
// first row: main display

View File

@ -39,6 +39,7 @@ public abstract class AbstractScaleFigure extends JPanel {
protected double scale = -1;
protected static final Dimension borderThickness_px = new Dimension(DEFAULT_BORDER_PIXELS_WIDTH, DEFAULT_BORDER_PIXELS_HEIGHT);
// pixel offset from the the subject's origin to the canvas's upper-left-corner.
protected Dimension originLocation_px = new Dimension(0,0);
// ======= whatever this figure is drawing, in real-space coordinates: meters
@ -99,6 +100,8 @@ public abstract class AbstractScaleFigure extends JPanel {
this.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM);
this.scale = baseScale * userScale;
this.fireChangeEvent();
}
/**
@ -111,9 +114,6 @@ public abstract class AbstractScaleFigure extends JPanel {
return;
updateSubjectDimensions();
updateCanvasOrigin();
updateCanvasSize();
updateTransform();
// dimensions within the viewable area, which are available to draw
final int drawable_width_px = newBounds.width - 2 * borderThickness_px.width;
@ -147,7 +147,6 @@ public abstract class AbstractScaleFigure extends JPanel {
setPreferredSize(preferredFigureSize_px);
setMinimumSize(preferredFigureSize_px);
revalidate();
}
protected void updateTransform(){

View File

@ -36,9 +36,6 @@ public class FinPointFigure extends AbstractScaleFigure {
private final static Logger log = LoggerFactory.getLogger(FinPointFigure.class);
private static final float MINIMUM_CANVAS_SIZE_METERS = 0.01f; // i.e. 1 cm
private static final Color GRID_LINE_COLOR = new Color( 137, 137, 137, 32);
private static final float GRID_LINE_BASE_WIDTH = 0.001f;
@ -53,6 +50,8 @@ public class FinPointFigure extends AbstractScaleFigure {
private final FreeformFinSet finset;
private int modID = -1;
protected Rectangle2D finBounds_m = null;
protected Rectangle2D mountBounds_m = null;
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
@ -66,7 +65,7 @@ public class FinPointFigure extends AbstractScaleFigure {
setBackground(Color.WHITE);
setOpaque(true);
updateTransform();
updateFigure();
}
@Override
@ -315,40 +314,33 @@ public class FinPointFigure extends AbstractScaleFigure {
@Override
protected void updateSubjectDimensions(){
// update subject bounds
BoundingBox newBounds = new BoundingBox();
// update subject (i.e. Fin) bounds
finBounds_m = new BoundingBox().update(finset.getFinPoints()).toRectangle();
// NOTE: the fin's forward root is pinned at 0,0
finBounds_m.setRect(0, 0, finBounds_m.getWidth(), finBounds_m.getHeight());
// subsequent updates can only increase the size of the bounds, so this is the minimum size.
newBounds.update( MINIMUM_CANVAS_SIZE_METERS);
SymmetricComponent parent = (SymmetricComponent)this.finset.getParent();
// N.B.: (0,0) is the fin front-- where it meets the parent body.
SymmetricComponent parent = (SymmetricComponent)this.finset.getParent();
mountBounds_m = new BoundingBox().update(parent.getComponentBounds()).toRectangle();
final double xFinFront = finset.asPositionValue(AxialMethod.TOP); //<< in body frame
// update to bound the parent body:
final double xParentFront = -xFinFront;
newBounds.update( xParentFront);
final double xParentBack = -xFinFront + parent.getLength();
newBounds.update( xParentBack );
final double yParentCenterline = -parent.getRadius(xFinFront); // from parent centerline to fin front.
newBounds.update( yParentCenterline );
final double xParent = -xFinFront;
final double yParent = -parent.getRadius(xFinFront); // from parent centerline to fin front.
final double rParent = Math.max(parent.getForeRadius(), parent.getAftRadius());
mountBounds_m.setRect(xParent, yParent, mountBounds_m.getWidth(), rParent);
// in 99% of fins, this bound is redundant, buuuuut just in case.
final double yParentMax = yParentCenterline + Math.max( parent.getForeRadius(), parent.getAftRadius());
newBounds.update( yParentMax );
// update to bounds the fin points:
newBounds.update( finset.getFinPoints());
subjectBounds_m = newBounds.toRectangle();
subjectBounds_m = new BoundingBox().update(finBounds_m).update(mountBounds_m).toRectangle();
}
@Override
protected void updateCanvasOrigin() {
originLocation_px.width = borderThickness_px.width - (int)(subjectBounds_m.getX()*scale);
originLocation_px.height = borderThickness_px.height + (int)(subjectBounds_m.getY()*scale);
// the negative sign is to compensate for the mount's negative location.
originLocation_px.width = borderThickness_px.width - (int)(mountBounds_m.getX()*scale);
originLocation_px.height = borderThickness_px.height + (int)(subjectBounds_m.getHeight()*scale);
}
}

View File

@ -108,6 +108,7 @@ public class RocketFigure extends AbstractScaleFigure {
this.selection = selection;
}
updateFigure();
fireChangeEvent();
}
@ -125,6 +126,7 @@ public class RocketFigure extends AbstractScaleFigure {
this.rotation = rot;
this.axialRotation = Transformation.rotate_x(rotation);
updateFigure();
fireChangeEvent();
}
@ -140,6 +142,7 @@ public class RocketFigure extends AbstractScaleFigure {
return;
this.currentViewType = type;
updateFigure();
fireChangeEvent();
}

View File

@ -50,6 +50,7 @@ public class ScaleSelector extends JPanel {
final double oldScale = scrollPane.getUserScale();
final double newScale = getNextLargerScale(oldScale);
scrollPane.setScaling(newScale);
setZoomText();
}
});
add(button, "gap");
@ -102,6 +103,7 @@ public class ScaleSelector extends JPanel {
double scale = scrollPane.getUserScale();
scale = getNextSmallerScale(scale);
scrollPane.setScaling(scale);
setZoomText();
}
});
add(button, "gapleft rel");