added code to scale view based on Outside / Parallel Stage offsets. Approximate.

This commit is contained in:
Daniel_M_Williams 2015-07-25 11:23:01 -04:00
parent b547084156
commit 28cca8d140
3 changed files with 51 additions and 28 deletions

View File

@ -271,14 +271,12 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY; double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
for (RocketComponent component : this) { for (RocketComponent component : this) {
for (Coordinate c : component.getComponentBounds()) { for (Coordinate coord : component.getComponentBounds()) {
for (Coordinate coord : component.toAbsolute(c)) { cachedBounds.add(coord);
cachedBounds.add(coord); if (coord.x < minX)
if (coord.x < minX) minX = coord.x;
minX = coord.x; if (coord.x > maxX)
if (coord.x > maxX) maxX = coord.x;
maxX = coord.x;
}
} }
} }

View File

@ -252,6 +252,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
/** /**
* Return a collection of bounding coordinates. The coordinates must be such that * Return a collection of bounding coordinates. The coordinates must be such that
* the component is fully enclosed in their convex hull. * the component is fully enclosed in their convex hull.
*
* Note: this function gets the bounds only for this component. Subchildren must be called individually.
* *
* @return a collection of coordinates that bound the component. * @return a collection of coordinates that bound the component.
*/ */
@ -1078,7 +1080,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
} }
public Coordinate getAbsolutePositionVector() { public Coordinate getAbsolutePositionVector() {
if (null == this.parent) { // i.e. root / Rocket instance OR improperly initialized components if (null == this.parent) {
// == improperly initialized components OR the root Rocket instance
return new Coordinate(); return new Coordinate();
} else { } else {
return this.parent.getAbsolutePositionVector().add(this.getRelativePositionVector()); return this.parent.getAbsolutePositionVector().add(this.getRelativePositionVector());
@ -1888,7 +1891,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
/** /**
* Helper method to add rotationally symmetric bounds at the specified coordinates. * Helper method to add four bounds rotated around the given x coordinate at radius 'r', and 90deg between each.
* The X-axis value is <code>x</code> and the radius at the specified position is * The X-axis value is <code>x</code> and the radius at the specified position is
* <code>r</code>. * <code>r</code>.
*/ */

View File

@ -1,5 +1,7 @@
package net.sf.openrocket.rocketcomponent; package net.sf.openrocket.rocketcomponent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
@ -54,28 +56,23 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon
return true; return true;
} }
// not strictly accurate, but this should provide an acceptable estimate for total vehicle size
@Override @Override
public void toDebugTreeNode(final StringBuilder buffer, final String prefix) { public Collection<Coordinate> getComponentBounds() {
Collection<Coordinate> bounds = new ArrayList<Coordinate>(8);
final double WAG_FACTOR = 1.05;
Coordinate center = this.getAbsolutePositionVector();
double startx = center.x - this.length / 2;
double endx = center.x + this.length / 2;
double r = this.getRadialOffset() * WAG_FACTOR;
String thisLabel = this.getName() + " (" + this.getStageNumber() + ")"; if (!this.isCenterline()) {
System.err.println(">> <Stage: " + this.getName() + ">.getComponentBounds(): r=" + r);
buffer.append(String.format("%s %-24s %5.3f %24s %24s", prefix, thisLabel, this.getLength(),
this.getRelativePositionVector(), this.getAbsolutePositionVector()));
if (this.isCenterline()) {
buffer.append("\n");
} else {
buffer.append(String.format(" %4.1f//%s \n", this.getAxialOffset(), this.relativePosition.name()));
Coordinate componentAbsolutePosition = this.getAbsolutePositionVector();
Coordinate[] instanceCoords = new Coordinate[] { componentAbsolutePosition };
instanceCoords = this.shiftCoordinates(instanceCoords);
for (int instance = 0; instance < this.count; instance++) {
Coordinate instanceAbsolutePosition = instanceCoords[instance];
buffer.append(String.format("%s [instance %2d of %2d] %s\n", prefix, instance, count, instanceAbsolutePosition));
}
} }
addBound(bounds, startx, r);
addBound(bounds, endx, r);
return bounds;
} }
/** /**
@ -329,6 +326,31 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon
return buf; return buf;
} }
@Override
public void toDebugTreeNode(final StringBuilder buffer, final String prefix) {
String thisLabel = this.getName() + " (" + this.getStageNumber() + ")";
buffer.append(String.format("%s %-24s %5.3f %24s %24s", prefix, thisLabel, this.getLength(),
this.getRelativePositionVector(), this.getAbsolutePositionVector()));
if (this.isCenterline()) {
buffer.append("\n");
} else {
buffer.append(String.format(" %4.1f//%s \n", this.getAxialOffset(), this.relativePosition.name()));
Coordinate componentAbsolutePosition = this.getAbsolutePositionVector();
Coordinate[] instanceCoords = new Coordinate[] { componentAbsolutePosition };
instanceCoords = this.shiftCoordinates(instanceCoords);
for (int instance = 0; instance < this.count; instance++) {
Coordinate instanceAbsolutePosition = instanceCoords[instance];
buffer.append(String.format("%s [instance %2d of %2d] %s\n", prefix, instance, count, instanceAbsolutePosition));
}
}
}
@Override @Override
public void updateBounds() { public void updateBounds() {
// currently only updates the length // currently only updates the length