[refactor] ComponentAssembly components no longer have bounds -- it's calculated from individual components, on a per-instance basis.
This commit is contained in:
parent
0a9df5cc64
commit
7b81f763c7
@ -54,25 +54,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
|
||||
public void reset( final FlightConfigurationId fcid){
|
||||
separations.reset(fcid);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* not strictly accurate, but this should provide an acceptable estimate for total vehicle size
|
||||
*/
|
||||
@Override
|
||||
public Collection<Coordinate> getComponentBounds() {
|
||||
Collection<Coordinate> bounds = new ArrayList<Coordinate>(8);
|
||||
Coordinate[] instanceLocations = this.getInstanceLocations();
|
||||
double x_min = instanceLocations[0].x;
|
||||
double x_max = x_min + this.length;
|
||||
double r_max = 0;
|
||||
|
||||
addBound(bounds, x_min, r_max);
|
||||
addBound(bounds, x_max, r_max);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given type can be added to this component. A Stage allows
|
||||
* only BodyComponents to be added.
|
||||
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sf.openrocket.util.BoundingBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -22,7 +23,7 @@ import net.sf.openrocket.util.Coordinate;
|
||||
*
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
*/
|
||||
public abstract class ComponentAssembly extends RocketComponent implements AxialPositionable {
|
||||
public abstract class ComponentAssembly extends RocketComponent implements AxialPositionable, BoxBounded {
|
||||
private static final Logger log = LoggerFactory.getLogger(ComponentAssembly.class);
|
||||
|
||||
/**
|
||||
@ -54,7 +55,7 @@ public abstract class ComponentAssembly extends RocketComponent implements Axia
|
||||
public Collection<Coordinate> getComponentBounds() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Null method (ComponentAssembly has no mass of itself).
|
||||
*/
|
||||
@ -70,7 +71,9 @@ public abstract class ComponentAssembly extends RocketComponent implements Axia
|
||||
public double getComponentMass() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public BoundingBox getInstanceBoundingBox (){ return new BoundingBox(); }
|
||||
|
||||
/**
|
||||
* Null method (ComponentAssembly has no mass of itself).
|
||||
*/
|
||||
|
@ -581,7 +581,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
componentBounds = instanceBounds.transform(context.transform);
|
||||
}
|
||||
}else if ((component instanceof AxialStage) || (component instanceof BodyTube) || (component instanceof PodSet)) {
|
||||
}else if (component instanceof BodyTube) {
|
||||
// Legacy Case #1:
|
||||
// These components do not need the transform performed in
|
||||
// order to provide the proper coordinates for length calculation.
|
||||
@ -593,7 +593,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
// Legacy Case #2:
|
||||
// These components do not implement
|
||||
Collection<Coordinate> instanceCoordinates = component.getComponentBounds();
|
||||
|
||||
for (InstanceContext context : contexts) {
|
||||
/*
|
||||
* If the instance is not active in the current context, then
|
||||
|
@ -3,11 +3,13 @@ package net.sf.openrocket.rocketcomponent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.rocketcomponent.position.AngleMethod;
|
||||
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
|
||||
import net.sf.openrocket.rocketcomponent.position.RadiusMethod;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.BoundingBox;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
|
||||
@ -43,35 +45,7 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
|
||||
//// Stage
|
||||
return trans.get("PodSet.PodSet");
|
||||
}
|
||||
|
||||
|
||||
// not strictly accurate, but this should provide an acceptable estimate for total vehicle size
|
||||
@Override
|
||||
public Collection<Coordinate> getComponentBounds() {
|
||||
Collection<Coordinate> bounds = new ArrayList<Coordinate>(8);
|
||||
double x_min = Double.MAX_VALUE;
|
||||
double x_max = Double.MIN_VALUE;
|
||||
double r_max = 0;
|
||||
|
||||
Coordinate[] instanceLocations = this.getComponentLocations();
|
||||
|
||||
for (Coordinate currentInstanceLocation : instanceLocations) {
|
||||
if (x_min > (currentInstanceLocation.x)) {
|
||||
x_min = currentInstanceLocation.x;
|
||||
}
|
||||
if (x_max < (currentInstanceLocation.x + this.length)) {
|
||||
x_max = currentInstanceLocation.x + this.length;
|
||||
}
|
||||
if (r_max < (this.getRadiusOffset())) {
|
||||
r_max = this.getRadiusOffset();
|
||||
}
|
||||
}
|
||||
addBound(bounds, x_min, r_max);
|
||||
addBound(bounds, x_max, r_max);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given type can be added to this component. A Stage allows
|
||||
* only BodyComponents to be added.
|
||||
@ -85,7 +59,6 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
|
||||
return BodyComponent.class.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getInstanceAngleIncrement(){
|
||||
return angleSeparation;
|
||||
|
@ -45,30 +45,30 @@ public abstract class AbstractScaleFigure extends JPanel {
|
||||
// size of the visible region
|
||||
protected Dimension visibleBounds_px = new Dimension(0,0);
|
||||
|
||||
// ======= whatever this figure is drawing, in real-space coordinates: meters
|
||||
protected Rectangle2D subjectBounds_m = null;
|
||||
|
||||
// combines the translation and scale in one place:
|
||||
// which frames does this transform between ?
|
||||
protected AffineTransform projection = null;
|
||||
// ======= whatever this figure is drawing, in real-space coordinates: meters
|
||||
protected Rectangle2D subjectBounds_m = null;
|
||||
|
||||
// combines the translation and scale in one place:
|
||||
// which frames does this transform between ?
|
||||
protected AffineTransform projection = null;
|
||||
|
||||
protected final List<EventListener> listeners = new LinkedList<EventListener>();
|
||||
|
||||
|
||||
public AbstractScaleFigure() {
|
||||
// produces a pixels-per-meter scale factor
|
||||
//
|
||||
// dots dots inch
|
||||
// ---- = ------ * -----
|
||||
// meter inch meter
|
||||
//
|
||||
this.baseScale = GUIUtil.getDPI() * INCHES_PER_METER;
|
||||
this.userScale = 1.0;
|
||||
this.scale = baseScale * userScale;
|
||||
|
||||
this.setPreferredSize(new Dimension(100,100));
|
||||
setSize(100,100);
|
||||
|
||||
// produces a pixels-per-meter scale factor
|
||||
//
|
||||
// dots dots inch
|
||||
// ---- = ------ * -----
|
||||
// meter inch meter
|
||||
//
|
||||
this.baseScale = GUIUtil.getDPI() * INCHES_PER_METER;
|
||||
this.userScale = 1.0;
|
||||
this.scale = baseScale * userScale;
|
||||
|
||||
this.setPreferredSize(new Dimension(100,100));
|
||||
setSize(100,100);
|
||||
|
||||
setBackground(Color.WHITE);
|
||||
setOpaque(true);
|
||||
}
|
||||
@ -77,28 +77,28 @@ public abstract class AbstractScaleFigure extends JPanel {
|
||||
return userScale;
|
||||
}
|
||||
|
||||
public double getAbsoluteScale() {
|
||||
return scale;
|
||||
}
|
||||
public double getAbsoluteScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public Dimension getSubjectOrigin() {
|
||||
public Dimension getSubjectOrigin() {
|
||||
return originLocation_px;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the scale level of the figure. A scale value of 1.0 is equivalent to 100 % scale.
|
||||
* Smaller scales display the subject smaller.
|
||||
*
|
||||
* If the figure would be smaller than the 'visibleBounds', then the figure is grown to match,
|
||||
* and the figures internal contents are centered according to the figure's origin.
|
||||
*
|
||||
*
|
||||
* @param newScaleRequest the scale level
|
||||
* @param visibleBounds the visible bounds upon the Figure
|
||||
*/
|
||||
public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) {
|
||||
if (MathUtil.equals(this.userScale, newScaleRequest, 0.01)){
|
||||
return;}
|
||||
if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest)) {
|
||||
if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) {
|
||||
return;}
|
||||
|
||||
this.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM);
|
||||
@ -115,21 +115,21 @@ public abstract class AbstractScaleFigure extends JPanel {
|
||||
* @param visibleBounds the visible bounds to scale this figure to.
|
||||
*/
|
||||
public void scaleTo(Dimension visibleBounds) {
|
||||
if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight())
|
||||
return;
|
||||
|
||||
updateSubjectDimensions();
|
||||
|
||||
// dimensions within the viewable area, which are available to draw
|
||||
if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight())
|
||||
return;
|
||||
|
||||
updateSubjectDimensions();
|
||||
|
||||
// dimensions within the viewable area, which are available to draw
|
||||
final int drawable_width_px = visibleBounds.width - 2 * borderThickness_px.width;
|
||||
final int drawable_height_px = visibleBounds.height - 2 * borderThickness_px.height;
|
||||
|
||||
if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) {
|
||||
final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale);
|
||||
final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale);
|
||||
final double minScale = Math.min(height_scale, width_scale);
|
||||
|
||||
scaleTo(minScale, visibleBounds);
|
||||
if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) {
|
||||
final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale);
|
||||
final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale);
|
||||
final double minScale = Math.min(height_scale, width_scale);
|
||||
|
||||
scaleTo(minScale, visibleBounds);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user