[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:
parent
87b1f99a9b
commit
b63ea3b3cc
@ -254,6 +254,8 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
ScaleSelector selector = new ScaleSelector(figurePane);
|
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!"));
|
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!"));
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
protected double scale = -1;
|
protected double scale = -1;
|
||||||
|
|
||||||
protected static final Dimension borderThickness_px = new Dimension(DEFAULT_BORDER_PIXELS_WIDTH, DEFAULT_BORDER_PIXELS_HEIGHT);
|
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);
|
protected Dimension originLocation_px = new Dimension(0,0);
|
||||||
|
|
||||||
// ======= whatever this figure is drawing, in real-space coordinates: meters
|
// ======= 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.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM);
|
||||||
|
|
||||||
this.scale = baseScale * userScale;
|
this.scale = baseScale * userScale;
|
||||||
|
|
||||||
|
this.fireChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,9 +114,6 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
updateSubjectDimensions();
|
updateSubjectDimensions();
|
||||||
updateCanvasOrigin();
|
|
||||||
updateCanvasSize();
|
|
||||||
updateTransform();
|
|
||||||
|
|
||||||
// dimensions within the viewable area, which are available to draw
|
// dimensions within the viewable area, which are available to draw
|
||||||
final int drawable_width_px = newBounds.width - 2 * borderThickness_px.width;
|
final int drawable_width_px = newBounds.width - 2 * borderThickness_px.width;
|
||||||
@ -147,7 +147,6 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
|
|
||||||
setPreferredSize(preferredFigureSize_px);
|
setPreferredSize(preferredFigureSize_px);
|
||||||
setMinimumSize(preferredFigureSize_px);
|
setMinimumSize(preferredFigureSize_px);
|
||||||
revalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateTransform(){
|
protected void updateTransform(){
|
||||||
|
@ -36,9 +36,6 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(FinPointFigure.class);
|
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 Color GRID_LINE_COLOR = new Color( 137, 137, 137, 32);
|
||||||
private static final float GRID_LINE_BASE_WIDTH = 0.001f;
|
private static final float GRID_LINE_BASE_WIDTH = 0.001f;
|
||||||
|
|
||||||
@ -53,6 +50,8 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
private final FreeformFinSet finset;
|
private final FreeformFinSet finset;
|
||||||
private int modID = -1;
|
private int modID = -1;
|
||||||
|
|
||||||
|
protected Rectangle2D finBounds_m = null;
|
||||||
|
protected Rectangle2D mountBounds_m = null;
|
||||||
|
|
||||||
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
|
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
|
||||||
|
|
||||||
@ -66,7 +65,7 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
setBackground(Color.WHITE);
|
setBackground(Color.WHITE);
|
||||||
setOpaque(true);
|
setOpaque(true);
|
||||||
|
|
||||||
updateTransform();
|
updateFigure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -315,40 +314,33 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateSubjectDimensions(){
|
protected void updateSubjectDimensions(){
|
||||||
// update subject bounds
|
// update subject (i.e. Fin) bounds
|
||||||
BoundingBox newBounds = new BoundingBox();
|
finBounds_m = new BoundingBox().update(finset.getFinPoints()).toRectangle();
|
||||||
|
|
||||||
// subsequent updates can only increase the size of the bounds, so this is the minimum size.
|
// NOTE: the fin's forward root is pinned at 0,0
|
||||||
newBounds.update( MINIMUM_CANVAS_SIZE_METERS);
|
finBounds_m.setRect(0, 0, finBounds_m.getWidth(), finBounds_m.getHeight());
|
||||||
|
|
||||||
SymmetricComponent parent = (SymmetricComponent)this.finset.getParent();
|
SymmetricComponent parent = (SymmetricComponent)this.finset.getParent();
|
||||||
|
mountBounds_m = new BoundingBox().update(parent.getComponentBounds()).toRectangle();
|
||||||
|
|
||||||
// N.B.: (0,0) is the fin front-- where it meets the parent body.
|
|
||||||
final double xFinFront = finset.asPositionValue(AxialMethod.TOP); //<< in body frame
|
final double xFinFront = finset.asPositionValue(AxialMethod.TOP); //<< in body frame
|
||||||
|
|
||||||
// update to bound the parent body:
|
// update to bound the parent body:
|
||||||
final double xParentFront = -xFinFront;
|
final double xParent = -xFinFront;
|
||||||
newBounds.update( xParentFront);
|
final double yParent = -parent.getRadius(xFinFront); // from parent centerline to fin front.
|
||||||
final double xParentBack = -xFinFront + parent.getLength();
|
final double rParent = Math.max(parent.getForeRadius(), parent.getAftRadius());
|
||||||
newBounds.update( xParentBack );
|
mountBounds_m.setRect(xParent, yParent, mountBounds_m.getWidth(), rParent);
|
||||||
final double yParentCenterline = -parent.getRadius(xFinFront); // from parent centerline to fin front.
|
|
||||||
newBounds.update( yParentCenterline );
|
|
||||||
|
|
||||||
// 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:
|
subjectBounds_m = new BoundingBox().update(finBounds_m).update(mountBounds_m).toRectangle();
|
||||||
newBounds.update( finset.getFinPoints());
|
|
||||||
|
|
||||||
subjectBounds_m = newBounds.toRectangle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateCanvasOrigin() {
|
protected void updateCanvasOrigin() {
|
||||||
originLocation_px.width = borderThickness_px.width - (int)(subjectBounds_m.getX()*scale);
|
// the negative sign is to compensate for the mount's negative location.
|
||||||
originLocation_px.height = borderThickness_px.height + (int)(subjectBounds_m.getY()*scale);
|
originLocation_px.width = borderThickness_px.width - (int)(mountBounds_m.getX()*scale);
|
||||||
|
originLocation_px.height = borderThickness_px.height + (int)(subjectBounds_m.getHeight()*scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
}
|
}
|
||||||
updateFigure();
|
updateFigure();
|
||||||
|
fireChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -125,6 +126,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
this.rotation = rot;
|
this.rotation = rot;
|
||||||
this.axialRotation = Transformation.rotate_x(rotation);
|
this.axialRotation = Transformation.rotate_x(rotation);
|
||||||
updateFigure();
|
updateFigure();
|
||||||
|
fireChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -140,6 +142,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
return;
|
return;
|
||||||
this.currentViewType = type;
|
this.currentViewType = type;
|
||||||
updateFigure();
|
updateFigure();
|
||||||
|
fireChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ public class ScaleSelector extends JPanel {
|
|||||||
final double oldScale = scrollPane.getUserScale();
|
final double oldScale = scrollPane.getUserScale();
|
||||||
final double newScale = getNextLargerScale(oldScale);
|
final double newScale = getNextLargerScale(oldScale);
|
||||||
scrollPane.setScaling(newScale);
|
scrollPane.setScaling(newScale);
|
||||||
|
setZoomText();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(button, "gap");
|
add(button, "gap");
|
||||||
@ -102,6 +103,7 @@ public class ScaleSelector extends JPanel {
|
|||||||
double scale = scrollPane.getUserScale();
|
double scale = scrollPane.getUserScale();
|
||||||
scale = getNextSmallerScale(scale);
|
scale = getNextSmallerScale(scale);
|
||||||
scrollPane.setScaling(scale);
|
scrollPane.setScaling(scale);
|
||||||
|
setZoomText();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(button, "gapleft rel");
|
add(button, "gapleft rel");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user