[refactor] switched 2D figure rendering over to new, simpler system

This commit is contained in:
Daniel_M_Williams 2019-01-20 14:46:57 -05:00
parent 0711cb785b
commit 577b09c4e9
17 changed files with 180 additions and 284 deletions

View File

@ -58,7 +58,7 @@ public class PrintableNoseCone extends AbstractPrintable<NoseCone> {
*/ */
@Override @Override
protected void draw(Graphics2D g2) { protected void draw(Graphics2D g2) {
RocketComponentShape[] compShapes = TransitionShapes.getShapesSide(target, Transformation.rotate_x(0d), new Coordinate(0,0,0), PrintUnit.METERS.toPoints(1)); RocketComponentShape[] compShapes = TransitionShapes.getShapesSide(target, Transformation.IDENTITY, PrintUnit.METERS.toPoints(1));
if (compShapes != null && compShapes.length > 0) { if (compShapes != null && compShapes.length > 0) {
Rectangle r = compShapes[0].shape.getBounds(); Rectangle r = compShapes[0].shape.getBounds();

View File

@ -4,15 +4,12 @@ import java.awt.Shape;
import net.sf.openrocket.rocketcomponent.BodyTube; import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
public class BodyTubeShapes extends RocketComponentShape { public class BodyTubeShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation){
BodyTube tube = (BodyTube)component; BodyTube tube = (BodyTube)component;
@ -20,22 +17,19 @@ public class BodyTubeShapes extends RocketComponentShape {
double radius = tube.getOuterRadius(); double radius = tube.getOuterRadius();
Shape[] s = new Shape[1]; Shape[] s = new Shape[1];
s[0] = TubeShapes.getShapesSide( transformation, componentAbsoluteLocation, length, radius ); s[0] = TubeShapes.getShapesSide( transformation, length, radius );
return RocketComponentShape.toArray(s, component); return RocketComponentShape.toArray(s, component);
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
BodyTube tube = (BodyTube)component; BodyTube tube = (BodyTube)component;
double radius = tube.getOuterRadius(); double radius = tube.getOuterRadius();
Shape[] s = new Shape[1]; Shape[] s = new Shape[1];
s[0] = TubeShapes.getShapesBack( transformation, componentAbsoluteLocation, radius); s[0] = TubeShapes.getShapesBack( transformation, radius);
return RocketComponentShape.toArray(s, component); return RocketComponentShape.toArray(s, component);
} }

View File

@ -6,7 +6,6 @@ import java.util.ArrayList;
import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
@ -15,9 +14,8 @@ import net.sf.openrocket.util.Transformation;
public class FinSetShapes extends RocketComponentShape { public class FinSetShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide(RocketComponent component, public static RocketComponentShape[] getShapesSide( final RocketComponent component,
Transformation transformation, final Transformation transformation){
Coordinate instanceAbsoluteLocation ){
final FinSet finset = (FinSet) component; final FinSet finset = (FinSet) component;
// this supplied transformation includes: // this supplied transformation includes:
@ -47,40 +45,37 @@ public class FinSetShapes extends RocketComponentShape {
ArrayList<RocketComponentShape> shapeList = new ArrayList<>(); ArrayList<RocketComponentShape> shapeList = new ArrayList<>();
// Make fin polygon // Make fin polygon
shapeList.add(new RocketComponentShape(generatePath(instanceAbsoluteLocation, finPoints), finset)); shapeList.add(new RocketComponentShape(generatePath(finPoints), finset));
// Make fin polygon // Make fin polygon
shapeList.add(new RocketComponentShape(generatePath(instanceAbsoluteLocation, tabPoints), finset)); shapeList.add(new RocketComponentShape(generatePath(tabPoints), finset));
// Make fin polygon // Make fin polygon
shapeList.add(new RocketComponentShape(generatePath(instanceAbsoluteLocation, rootPoints), finset)); shapeList.add(new RocketComponentShape(generatePath(rootPoints), finset));
return shapeList.toArray(new RocketComponentShape[0]); return shapeList.toArray(new RocketComponentShape[0]);
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
RocketComponent component,
Transformation transformation,
Coordinate location) {
FinSet finset = (FinSet) component; FinSet finset = (FinSet) component;
Shape[] toReturn; Shape[] toReturn;
if (MathUtil.equals(finset.getCantAngle(), 0)) { if (MathUtil.equals(finset.getCantAngle(), 0)) {
toReturn = uncantedShapesBack(finset, transformation, location); toReturn = uncantedShapesBack(finset, transformation);
} else { } else {
toReturn = cantedShapesBack(finset, transformation, location); toReturn = cantedShapesBack(finset, transformation);
} }
return RocketComponentShape.toArray(toReturn, finset); return RocketComponentShape.toArray(toReturn, finset);
} }
private static Path2D.Float generatePath(final Coordinate c0, final Coordinate[] points){ private static Path2D.Float generatePath(final Coordinate[] points){
Path2D.Float finShape = new Path2D.Float(); Path2D.Float finShape = new Path2D.Float();
for( int i = 0; i < points.length; i++){ for( int i = 0; i < points.length; i++){
Coordinate curPoint = c0.add(points[i]); Coordinate curPoint = points[i];
if (i == 0) if (i == 0)
finShape.moveTo(curPoint.x, curPoint.y); finShape.moveTo(curPoint.x, curPoint.y);
else else
@ -90,8 +85,7 @@ public class FinSetShapes extends RocketComponentShape {
} }
private static Shape[] uncantedShapesBack(FinSet finset, private static Shape[] uncantedShapesBack(FinSet finset,
Transformation transformation, Transformation transformation) {
Coordinate finFront) {
double thickness = finset.getThickness(); double thickness = finset.getThickness();
double height = finset.getSpan(); double height = finset.getSpan();
@ -110,13 +104,13 @@ public class FinSetShapes extends RocketComponentShape {
Coordinate a; Coordinate a;
Path2D.Double p = new Path2D.Double(); Path2D.Double p = new Path2D.Double();
a = finFront.add( c[0] ); a = c[0];
p.moveTo(a.z, a.y); p.moveTo(a.z, a.y);
a = finFront.add( c[1] ); a = c[1];
p.lineTo(a.z, a.y); p.lineTo(a.z, a.y);
a = finFront.add( c[2] ); a = c[2];
p.lineTo(a.z, a.y); p.lineTo(a.z, a.y);
a = finFront.add( c[3] ); a = c[3];
p.lineTo(a.z, a.y); p.lineTo(a.z, a.y);
p.closePath(); p.closePath();
@ -126,8 +120,7 @@ public class FinSetShapes extends RocketComponentShape {
// TODO: LOW: Jagged shapes from back draw incorrectly. // TODO: LOW: Jagged shapes from back draw incorrectly.
private static Shape[] cantedShapesBack(FinSet finset, private static Shape[] cantedShapesBack(FinSet finset,
Transformation transformation, Transformation transformation) {
Coordinate location) {
int i; int i;
int fins = finset.getFinCount(); int fins = finset.getFinCount();
double thickness = finset.getThickness(); double thickness = finset.getThickness();
@ -179,15 +172,15 @@ public class FinSetShapes extends RocketComponentShape {
s = new Shape[fins*2]; s = new Shape[fins*2];
for (int fin=0; fin<fins; fin++) { for (int fin=0; fin<fins; fin++) {
s[2*fin] = makePolygonBack(sidePoints,finset,transformation, location); s[2*fin] = makePolygonBack(sidePoints,finset,transformation);
s[2*fin+1] = makePolygonBack(backPoints,finset,transformation, location); s[2*fin+1] = makePolygonBack(backPoints,finset,transformation);
} }
} else { } else {
s = new Shape[fins]; s = new Shape[fins];
for (int fin=0; fin<fins; fin++) { for (int fin=0; fin<fins; fin++) {
s[fin] = makePolygonBack(sidePoints,finset,transformation, location); s[fin] = makePolygonBack(sidePoints,finset,transformation);
} }
} }
@ -195,11 +188,11 @@ public class FinSetShapes extends RocketComponentShape {
return s; return s;
} }
private static Shape makePolygonBack(Coordinate[] array, FinSet finset, private static Shape makePolygonBack(Coordinate[] array, FinSet finset, final Transformation t) {
Transformation t, Coordinate location) {
Path2D.Float p; Path2D.Float p;
Coordinate compCenter = location; Coordinate compCenter = t.transform(Coordinate.ZERO);
// Make polygon // Make polygon
p = new Path2D.Float(); p = new Path2D.Float();
for (int i=0; i < array.length; i++) { for (int i=0; i < array.length; i++) {

View File

@ -10,32 +10,26 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
public class LaunchLugShapes extends RocketComponentShape { public class LaunchLugShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
RocketComponent component,
Transformation transformation,
Coordinate instanceAbsoluteLocation) {
LaunchLug lug = (LaunchLug)component; LaunchLug lug = (LaunchLug)component;
double length = lug.getLength(); double length = lug.getLength();
double radius = lug.getOuterRadius(); double radius = lug.getOuterRadius();
Shape[] s = new Shape[]{ Shape[] s = new Shape[]{
TubeShapes.getShapesSide( transformation, instanceAbsoluteLocation, length, radius ) TubeShapes.getShapesSide( transformation, length, radius )
}; };
return RocketComponentShape.toArray(s, component); return RocketComponentShape.toArray(s, component);
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
RocketComponent component,
Transformation transformation,
Coordinate instanceAbsoluteLocation) {
LaunchLug lug = (LaunchLug)component; LaunchLug lug = (LaunchLug)component;
double radius = lug.getOuterRadius(); double radius = lug.getOuterRadius();
Shape[] s = new Shape[]{TubeShapes.getShapesBack( transformation, instanceAbsoluteLocation, radius)}; Shape[] s = new Shape[]{TubeShapes.getShapesBack( transformation, radius)};
return RocketComponentShape.toArray(s, component); return RocketComponentShape.toArray(s, component);
} }

View File

@ -8,6 +8,9 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.util.Random; import java.util.Random;
import net.sf.openrocket.rocketcomponent.MassComponent;
import net.sf.openrocket.rocketcomponent.MassObject;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
@ -15,22 +18,19 @@ import net.sf.openrocket.util.Transformation;
public class MassComponentShapes extends RocketComponentShape { public class MassComponentShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType type = ((net.sf.openrocket.rocketcomponent.MassComponent)component).getMassComponentType(); MassComponent.MassComponentType type = ((MassComponent)component).getMassComponentType();
double length = tube.getLength(); double length = tube.getLength();
double radius = tube.getRadius(); double radius = tube.getRadius();
double arc = Math.min(length, 2*radius) * 0.7; double arc = Math.min(length, 2*radius) * 0.7;
Coordinate start = transformation.transform( componentAbsoluteLocation); final Coordinate start = transformation.transform(Coordinate.ZERO);
Shape[] s = new Shape[1];
s[0] = new RoundRectangle2D.Double(start.x, (start.y-radius), length, 2*radius, arc, arc); Shape[] s = {new RoundRectangle2D.Double(start.x, (start.y-radius), length, 2*radius, arc, arc)};
switch (type) { switch (type) {
case ALTIMETER: case ALTIMETER:
@ -61,21 +61,16 @@ public class MassComponentShapes extends RocketComponentShape {
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
double or = tube.getRadius(); double or = tube.getRadius();
Coordinate[] start = new Coordinate[]{transformation.transform( componentAbsoluteLocation )}; final Coordinate start = transformation.transform(Coordinate.ZERO);
Shape[] s = {new Ellipse2D.Double((start.z-or),(start.y-or),2*or,2*or)};
Shape[] s = new Shape[start.length];
for (int i=0; i < start.length; i++) {
s[i] = new Ellipse2D.Double((start[i].z-or),(start[i].y-or),2*or,2*or);
}
return RocketComponentShape.toArray(s, component); return RocketComponentShape.toArray(s, component);
} }

View File

@ -4,48 +4,40 @@ import java.awt.Shape;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import net.sf.openrocket.rocketcomponent.MassObject;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
public class MassObjectShapes extends RocketComponentShape { public class MassObjectShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation, MassObject tube = (MassObject)component;
Coordinate instanceOffset) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
double length = tube.getLength(); double length = tube.getLength();
double radius = tube.getRadius(); double radius = tube.getRadius();
double arc = Math.min(length, 2*radius) * 0.7; double arc = Math.min(length, 2*radius) * 0.7;
Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset));
Shape[] s = new Shape[start.length]; Coordinate start = transformation.transform(Coordinate.ZERO);
for (int i=0; i < start.length; i++) {
s[i] = new RoundRectangle2D.Double(start[i].x,(start[i].y-radius), Shape[] s = {new RoundRectangle2D.Double(start.x, (start.y-radius), length, 2*radius, arc, arc)};
length,2*radius,arc,arc);
}
return RocketComponentShape.toArray(s, component); return RocketComponentShape.toArray(s, component);
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate instanceOffset) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; MassObject tube = (MassObject)component;
double or = tube.getRadius(); double or = tube.getRadius();
Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset)); final Coordinate start = transformation.transform(Coordinate.ZERO);
Shape[] s = {new Ellipse2D.Double((start.z-or), (start.y-or), 2*or, 2*or)};
Shape[] s = new Shape[start.length];
for (int i=0; i < start.length; i++) {
s[i] = new Ellipse2D.Double((start[i].z-or),(start[i].y-or),2*or,2*or);
}
return RocketComponentShape.toArray(s, component); return RocketComponentShape.toArray(s, component);
} }

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.rocketfigure; package net.sf.openrocket.gui.rocketfigure;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
@ -12,36 +13,31 @@ import java.awt.geom.RoundRectangle2D;
public class ParachuteShapes extends RocketComponentShape { public class ParachuteShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
double length = tube.getLength(); double length = tube.getLength();
double radius = tube.getRadius(); double radius = tube.getRadius();
double arc = Math.min(length, 2*radius) * 0.7; double arc = Math.min(length, 2*radius) * 0.7;
Coordinate[] start = new Coordinate[]{transformation.transform( componentAbsoluteLocation)};
Shape[] s = new Shape[start.length]; Coordinate start = transformation.transform( Coordinate.ZERO);
for (int i=0; i < start.length; i++) {
s[i] = new RoundRectangle2D.Double(start[i].x, (start[i].y-radius), length, 2*radius, arc, arc); Shape[] s = new Shape[1];
}
s[0] = new RoundRectangle2D.Double(start.x, (start.y-radius), length, 2*radius, arc, arc);
return RocketComponentShape.toArray( addSymbol(s), component); return RocketComponentShape.toArray( addSymbol(s), component);
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate instanceOffset) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
double or = tube.getRadius(); double or = tube.getRadius();
Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset)); Coordinate[] start = transformation.transform(tube.toAbsolute(Coordinate.ZERO));
Shape[] s = new Shape[start.length]; Shape[] s = new Shape[start.length];
for (int i=0; i < start.length; i++) { for (int i=0; i < start.length; i++) {

View File

@ -14,10 +14,7 @@ import net.sf.openrocket.util.Transformation;
public class RailButtonShapes extends RocketComponentShape { public class RailButtonShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
RocketComponent component,
Transformation transformation,
Coordinate instanceAbsoluteLocation) {
RailButton btn = (RailButton)component; RailButton btn = (RailButton)component;
@ -36,6 +33,11 @@ public class RailButtonShapes extends RocketComponentShape {
final double innerHeightcos = innerHeight*cosr; final double innerHeightcos = innerHeight*cosr;
final double flangeHeightcos = flangeHeight*cosr; final double flangeHeightcos = flangeHeight*cosr;
final Coordinate instanceAbsoluteLocation = transformation.transform(Coordinate.ZERO);
System.err.println(String.format("Generating Shapes for RailButtons..."));
System.err.println(String.format(" @ %s", instanceAbsoluteLocation));
Path2D.Double path = new Path2D.Double(); Path2D.Double path = new Path2D.Double();
{// central pillar {// central pillar
@ -51,7 +53,7 @@ public class RailButtonShapes extends RocketComponentShape {
path.append( new Ellipse2D.Double( lowerLeft.x, (lowerLeft.y+baseHeightcos), drawWidth, drawHeight), false); path.append( new Ellipse2D.Double( lowerLeft.x, (lowerLeft.y+baseHeightcos), drawWidth, drawHeight), false);
} }
{// inner {// inner flange
final double drawWidth = innerDiameter; final double drawWidth = innerDiameter;
final double drawHeight = innerDiameter*sinr; final double drawHeight = innerDiameter*sinr;
final Point2D.Double center = new Point2D.Double( instanceAbsoluteLocation.x, instanceAbsoluteLocation.y + baseHeightcos); final Point2D.Double center = new Point2D.Double( instanceAbsoluteLocation.x, instanceAbsoluteLocation.y + baseHeightcos);
@ -80,12 +82,9 @@ public class RailButtonShapes extends RocketComponentShape {
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate instanceOffset) {
net.sf.openrocket.rocketcomponent.RailButton btn = (net.sf.openrocket.rocketcomponent.RailButton)component; RailButton btn = (RailButton)component;
final double rotation_rad = btn.getAngleOffset(); final double rotation_rad = btn.getAngleOffset();
final double sinr = Math.sin(rotation_rad); final double sinr = Math.sin(rotation_rad);
@ -98,7 +97,8 @@ public class RailButtonShapes extends RocketComponentShape {
final double outerRadius = outerDiameter/2; final double outerRadius = outerDiameter/2;
final double innerDiameter = btn.getInnerDiameter(); final double innerDiameter = btn.getInnerDiameter();
final double innerRadius = innerDiameter/2; final double innerRadius = innerDiameter/2;
Coordinate[] inst = transformation.transform( btn.getLocations());
Coordinate[] inst = {transformation.transform(Coordinate.ZERO)};
Shape[] s = new Shape[inst.length]; Shape[] s = new Shape[inst.length];
for (int i=0; i < inst.length; i++) { for (int i=0; i < inst.length; i++) {

View File

@ -2,19 +2,16 @@ package net.sf.openrocket.gui.rocketfigure;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.rocketcomponent.RingComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
public class RingComponentShapes extends RocketComponentShape { public class RingComponentShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate instanceAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.RingComponent tube = (net.sf.openrocket.rocketcomponent.RingComponent)component; net.sf.openrocket.rocketcomponent.RingComponent tube = (net.sf.openrocket.rocketcomponent.RingComponent)component;
Shape[] s; Shape[] s;
@ -26,24 +23,22 @@ public class RingComponentShapes extends RocketComponentShape {
if ((outerRadius-innerRadius >= 0.0012) && (innerRadius > 0)) { if ((outerRadius-innerRadius >= 0.0012) && (innerRadius > 0)) {
// Draw outer and inner // Draw outer and inner
s = new Shape[] { s = new Shape[] {
TubeShapes.getShapesSide(transformation, instanceAbsoluteLocation, length, outerRadius), TubeShapes.getShapesSide(transformation, length, outerRadius),
TubeShapes.getShapesSide(transformation, instanceAbsoluteLocation, length, innerRadius) TubeShapes.getShapesSide(transformation, length, innerRadius)
}; };
} else { } else {
// Draw only outer // Draw only outer
s = new Shape[] { s = new Shape[] {
TubeShapes.getShapesSide(transformation, instanceAbsoluteLocation, length, outerRadius) TubeShapes.getShapesSide(transformation, length, outerRadius)
}; };
} }
return RocketComponentShape.toArray( s, component); return RocketComponentShape.toArray( s, component);
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation, RingComponent tube = (net.sf.openrocket.rocketcomponent.RingComponent)component;
Coordinate instanceAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.RingComponent tube = (net.sf.openrocket.rocketcomponent.RingComponent)component;
Shape[] s; Shape[] s;
double outerRadius = tube.getOuterRadius(); double outerRadius = tube.getOuterRadius();
@ -51,12 +46,12 @@ public class RingComponentShapes extends RocketComponentShape {
if ((outerRadius-innerRadius >= 0.0012) && (innerRadius > 0)) { if ((outerRadius-innerRadius >= 0.0012) && (innerRadius > 0)) {
s = new Shape[] { s = new Shape[] {
TubeShapes.getShapesBack(transformation, instanceAbsoluteLocation, outerRadius), TubeShapes.getShapesBack(transformation, outerRadius),
TubeShapes.getShapesBack(transformation, instanceAbsoluteLocation, innerRadius) TubeShapes.getShapesBack(transformation, innerRadius)
}; };
}else { }else {
s = new Shape[] { s = new Shape[] {
TubeShapes.getShapesBack(transformation, instanceAbsoluteLocation, outerRadius) TubeShapes.getShapesBack(transformation, outerRadius)
}; };
} }

View File

@ -3,10 +3,8 @@ package net.sf.openrocket.gui.rocketfigure;
import java.awt.Shape; import java.awt.Shape;
import net.sf.openrocket.gui.scalefigure.RocketFigure;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.LineStyle; import net.sf.openrocket.util.LineStyle;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
@ -51,20 +49,15 @@ public class RocketComponentShape {
} }
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate instanceOffset) {
// no-op // no-op
Application.getExceptionHandler().handleErrorCondition("ERROR: RocketComponent.getShapesSide called with " Application.getExceptionHandler().handleErrorCondition("ERROR: RocketComponent.getShapesSide called with "
+ component); + component);
return new RocketComponentShape[0]; return new RocketComponentShape[0];
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component, // no-op
Transformation transformation,
Coordinate instanceOffset) { // no-op
Application.getExceptionHandler().handleErrorCondition("ERROR: RocketComponent.getShapesBack called with " Application.getExceptionHandler().handleErrorCondition("ERROR: RocketComponent.getShapesBack called with "
+component); +component);
return new RocketComponentShape[0]; return new RocketComponentShape[0];

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.rocketfigure; package net.sf.openrocket.gui.rocketfigure;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
@ -11,10 +12,8 @@ import java.awt.geom.RoundRectangle2D;
public class ShockCordShapes extends RocketComponentShape { public class ShockCordShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.MassObject massObj = (net.sf.openrocket.rocketcomponent.MassObject)component; net.sf.openrocket.rocketcomponent.MassObject massObj = (net.sf.openrocket.rocketcomponent.MassObject)component;
@ -22,8 +21,7 @@ public class ShockCordShapes extends RocketComponentShape {
double radius = massObj.getRadius(); double radius = massObj.getRadius();
double arc = Math.min(length, 2*radius) * 0.7; double arc = Math.min(length, 2*radius) * 0.7;
Coordinate start = transformation.transform(Coordinate.ZERO);
Coordinate start = transformation.transform( componentAbsoluteLocation);
Shape[] s = new Shape[1]; Shape[] s = new Shape[1];
s[0] = new RoundRectangle2D.Double(start.x,(start.y-radius), s[0] = new RoundRectangle2D.Double(start.x,(start.y-radius),
length,2*radius,arc,arc); length,2*radius,arc,arc);
@ -32,17 +30,15 @@ public class ShockCordShapes extends RocketComponentShape {
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
double or = tube.getRadius(); double or = tube.getRadius();
Shape[] s = new Shape[1]; Shape[] s = new Shape[1];
Coordinate start = componentAbsoluteLocation; Coordinate start = transformation.transform(Coordinate.ZERO);
s[0] = new Ellipse2D.Double((start.z-or),(start.y-or),2*or,2*or); s[0] = new Ellipse2D.Double((start.z-or),(start.y-or),2*or,2*or);
// Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset)); // Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset));

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.rocketfigure; package net.sf.openrocket.gui.rocketfigure;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
@ -11,10 +12,7 @@ import java.awt.geom.RoundRectangle2D;
public class StreamerShapes extends RocketComponentShape { public class StreamerShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation ) {
net.sf.openrocket.rocketcomponent.MassObject massObj = (net.sf.openrocket.rocketcomponent.MassObject)component; net.sf.openrocket.rocketcomponent.MassObject massObj = (net.sf.openrocket.rocketcomponent.MassObject)component;
@ -23,7 +21,7 @@ public class StreamerShapes extends RocketComponentShape {
double arc = Math.min(length, 2*radius) * 0.7; double arc = Math.min(length, 2*radius) * 0.7;
Shape[] s = new Shape[1]; Shape[] s = new Shape[1];
Coordinate frontCenter = componentAbsoluteLocation; Coordinate frontCenter = transformation.transform(Coordinate.ZERO);
s[0] = new RoundRectangle2D.Double((frontCenter.x),(frontCenter.y-radius), s[0] = new RoundRectangle2D.Double((frontCenter.x),(frontCenter.y-radius),
length,2*radius,arc,arc); length,2*radius,arc,arc);
@ -37,16 +35,14 @@ public class StreamerShapes extends RocketComponentShape {
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component;
double or = tube.getRadius(); double or = tube.getRadius();
Shape[] s = new Shape[1]; Shape[] s = new Shape[1];
Coordinate center = componentAbsoluteLocation; Coordinate center = transformation.transform(Coordinate.ZERO);
s[0] = new Ellipse2D.Double((center.z-or),(center.y-or),2*or,2*or); s[0] = new Ellipse2D.Double((center.z-or),(center.y-or),2*or,2*or);
// Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset)); // Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset));

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.rocketfigure; package net.sf.openrocket.gui.rocketfigure;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.SymmetricComponent; import net.sf.openrocket.rocketcomponent.SymmetricComponent;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
@ -17,10 +18,8 @@ public class SymmetricComponentShapes extends RocketComponentShape {
// TODO: LOW: Uses only first component of cluster (not currently clusterable) // TODO: LOW: Uses only first component of cluster (not currently clusterable)
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
SymmetricComponent c = (SymmetricComponent) component; SymmetricComponent c = (SymmetricComponent) component;
@ -79,7 +78,7 @@ public class SymmetricComponentShapes extends RocketComponentShape {
//System.out.println("here"); //System.out.println("here");
final int len = points.size(); final int len = points.size();
Coordinate nose = componentAbsoluteLocation; Coordinate nose = transformation.transform(Coordinate.ZERO);
// TODO: LOW: curved path instead of linear // TODO: LOW: curved path instead of linear
Path2D.Double path = new Path2D.Double(); Path2D.Double path = new Path2D.Double();

View File

@ -12,24 +12,20 @@ import java.awt.geom.Path2D;
public class TransitionShapes extends RocketComponentShape { public class TransitionShapes extends RocketComponentShape {
// TODO: LOW: Uses only first component of cluster (not currently clusterable). public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
return getShapesSide(component, transformation, 1.0);
public static RocketComponentShape[] getShapesSide(
RocketComponent component,
Transformation transformation,
Coordinate instanceLocation) {
return getShapesSide(component, transformation, instanceLocation, 1.0);
} }
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide(
RocketComponent component, final RocketComponent component,
Transformation transformation, final Transformation transformation,
Coordinate instanceAbsoluteLocation, final double scaleFactor) {
final double scaleFactor) {
Transition transition = (Transition)component; Transition transition = (Transition)component;
final Coordinate instanceAbsoluteLocation = transformation.transform(Coordinate.ZERO);
RocketComponentShape[] mainShapes; RocketComponentShape[] mainShapes;
// Simpler shape for conical transition, others use the method from SymmetricComponent // Simpler shape for conical transition, others use the method from SymmetricComponent
@ -49,27 +45,28 @@ public class TransitionShapes extends RocketComponentShape {
mainShapes = new RocketComponentShape[] { new RocketComponentShape( path, component) }; mainShapes = new RocketComponentShape[] { new RocketComponentShape( path, component) };
} else { } else {
mainShapes = SymmetricComponentShapes.getShapesSide(component, transformation, instanceAbsoluteLocation); mainShapes = SymmetricComponentShapes.getShapesSide(component, transformation);
} }
Shape foreShoulder=null, aftShoulder=null; Shape foreShoulder=null, aftShoulder=null;
int arrayLength = mainShapes.length; int arrayLength = mainShapes.length;
if (transition.getForeShoulderLength() > 0.0005) { if (transition.getForeShoulderLength() > 0.0005) {
Coordinate foreTransitionShoulderCenter = instanceAbsoluteLocation.sub( transition.getForeShoulderLength(), 0, 0); final double shoulderLength = transition.getForeShoulderLength();
final Coordinate frontCenter = foreTransitionShoulderCenter; //transformation.transform( foreTransitionShoulderCenter); final double shoulderRadius = transition.getForeShoulderRadius();
final double length = transition.getForeShoulderLength(); final Transformation offsetTransform = Transformation.getTranslationTransform(-transition.getForeShoulderLength(), 0, 0);
final double radius = transition.getForeShoulderRadius(); final Transformation foreShoulderTransform = transformation.applyTransformation(offsetTransform);
foreShoulder = TubeShapes.getShapesSide( transformation, frontCenter, length, radius); foreShoulder = TubeShapes.getShapesSide( foreShoulderTransform, shoulderLength, shoulderRadius);
arrayLength++; arrayLength++;
} }
if (transition.getAftShoulderLength() > 0.0005) { if (transition.getAftShoulderLength() > 0.0005) {
Coordinate aftTransitionShoulderCenter = instanceAbsoluteLocation.add( transition.getLength(), 0, 0); final double shoulderLength = transition.getAftShoulderLength();
final Coordinate frontCenter = aftTransitionShoulderCenter; //transformation.transform( aftTransitionShoulderCenter ); final double shoulderRadius = transition.getAftShoulderRadius();
final double length = transition.getAftShoulderLength(); final Transformation offsetTransform = Transformation.getTranslationTransform(transition.getLength(), 0, 0);
final double radius = transition.getAftShoulderRadius(); final Transformation aftShoulderTransform = transformation.applyTransformation(offsetTransform);
aftShoulder = TubeShapes.getShapesSide(transformation, frontCenter, length, radius);
aftShoulder = TubeShapes.getShapesSide(aftShoulderTransform, shoulderLength, shoulderRadius);
arrayLength++; arrayLength++;
} }
if (foreShoulder==null && aftShoulder==null) if (foreShoulder==null && aftShoulder==null)
@ -92,17 +89,14 @@ public class TransitionShapes extends RocketComponentShape {
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.Transition transition = (net.sf.openrocket.rocketcomponent.Transition)component; Transition transition = (net.sf.openrocket.rocketcomponent.Transition)component;
double r1 = transition.getForeRadius(); double r1 = transition.getForeRadius();
double r2 = transition.getAftRadius(); double r2 = transition.getAftRadius();
Coordinate center = componentAbsoluteLocation; final Coordinate center = transformation.transform(Coordinate.ZERO);
Shape[] s = new Shape[2]; Shape[] s = new Shape[2];
s[0] = new Ellipse2D.Double((center.z-r1),(center.y-r1),2*r1,2*r1); s[0] = new Ellipse2D.Double((center.z-r1),(center.y-r1),2*r1,2*r1);

View File

@ -4,18 +4,17 @@ import java.awt.Shape;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.TubeFinSet;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Transformation; import net.sf.openrocket.util.Transformation;
public class TubeFinSetShapes extends RocketComponentShape { public class TubeFinSetShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide( public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.TubeFinSet finset = (net.sf.openrocket.rocketcomponent.TubeFinSet)component; TubeFinSet finset = (net.sf.openrocket.rocketcomponent.TubeFinSet)component;
int fins = finset.getFinCount(); int fins = finset.getFinCount();
double length = finset.getLength(); double length = finset.getLength();
@ -47,12 +46,9 @@ public class TubeFinSetShapes extends RocketComponentShape {
} }
public static RocketComponentShape[] getShapesBack( public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.TubeFinSet finset = (net.sf.openrocket.rocketcomponent.TubeFinSet)component; TubeFinSet finset = (net.sf.openrocket.rocketcomponent.TubeFinSet)component;
int fins = finset.getFinCount(); int fins = finset.getFinCount();
double outerradius = finset.getOuterRadius(); double outerradius = finset.getOuterRadius();

View File

@ -10,10 +10,9 @@ import net.sf.openrocket.util.Transformation;
public class TubeShapes extends RocketComponentShape { public class TubeShapes extends RocketComponentShape {
public static Shape getShapesSide( public static Shape getShapesSide( final Transformation transformation, final double length, final double radius ){
Transformation transformation,
Coordinate instanceAbsoluteLocation, final Coordinate instanceAbsoluteLocation = transformation.transform(Coordinate.ZERO);
final double length, final double radius ){
return new Rectangle2D.Double((instanceAbsoluteLocation.x), //x - the X coordinate of the upper-left corner of the newly constructed Rectangle2D return new Rectangle2D.Double((instanceAbsoluteLocation.x), //x - the X coordinate of the upper-left corner of the newly constructed Rectangle2D
(instanceAbsoluteLocation.y-radius), // y - the Y coordinate of the upper-left corner of the newly constructed Rectangle2D (instanceAbsoluteLocation.y-radius), // y - the Y coordinate of the upper-left corner of the newly constructed Rectangle2D
@ -21,10 +20,9 @@ public class TubeShapes extends RocketComponentShape {
2*radius); // h - the height of the newly constructed Rectangle2D 2*radius); // h - the height of the newly constructed Rectangle2D
} }
public static Shape getShapesBack( public static Shape getShapesBack( final Transformation transformation, final double radius ) {
Transformation transformation,
Coordinate instanceAbsoluteLocation, final Coordinate instanceAbsoluteLocation = transformation.transform(Coordinate.ZERO);
final double radius ) {
return new Ellipse2D.Double((instanceAbsoluteLocation.z-radius), (instanceAbsoluteLocation.y-radius), 2*radius, 2*radius); return new Ellipse2D.Double((instanceAbsoluteLocation.z-radius), (instanceAbsoluteLocation.y-radius), 2*radius, 2*radius);
} }

View File

@ -15,22 +15,21 @@ import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map.Entry;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import net.sf.openrocket.gui.figureelements.FigureElement; import net.sf.openrocket.gui.figureelements.FigureElement;
import net.sf.openrocket.gui.rocketfigure.RocketComponentShape; import net.sf.openrocket.gui.rocketfigure.RocketComponentShape;
import net.sf.openrocket.gui.scalefigure.RocketPanel.VIEW_TYPE;
import net.sf.openrocket.gui.util.ColorConversion; import net.sf.openrocket.gui.util.ColorConversion;
import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.InstanceContext;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -192,8 +191,7 @@ public class RocketFigure extends AbstractScaleFigure {
updateCanvasSize(); updateCanvasSize();
updateTransform(); updateTransform();
figureShapes.clear(); updateShapes(this.figureShapes);
updateShapeTree( this.figureShapes, rocket, this.axialRotation, Coordinate.ZERO);
g2.transform(projection); g2.transform(projection);
@ -336,58 +334,27 @@ public class RocketFigure extends AbstractScaleFigure {
return l.toArray(new RocketComponent[0]); return l.toArray(new RocketComponent[0]);
} }
// NOTE: Recursive function private void updateShapes(ArrayList<RocketComponentShape> allShapes) {
private ArrayList<RocketComponentShape> updateShapeTree( // source input
ArrayList<RocketComponentShape> allShapes, // output parameter final FlightConfiguration config = rocket.getSelectedConfiguration();
final RocketComponent comp,
final Transformation parentTransform,
final Coordinate parentLocation){
// allShapes is an output buffer -- it stores all the generated shapes
allShapes.clear();
final int instanceCount = comp.getInstanceCount(); for(Entry<RocketComponent, ArrayList<InstanceContext>> entry: config.getActiveInstances().entrySet() ) {
Coordinate[] instanceLocations = comp.getInstanceLocations(); final RocketComponent comp = entry.getKey();
instanceLocations = parentTransform.transform( instanceLocations );
double[] instanceAngles = comp.getInstanceAngles();
if( instanceLocations.length != instanceAngles.length ){
throw new ArrayIndexOutOfBoundsException(String.format("lengths of location array (%d) and angle arrays (%d) differs! (in: %s) ", instanceLocations.length, instanceAngles.length, comp.getName()));
}
// iterate over the aggregated instances *for the whole* tree. final ArrayList<InstanceContext> contextList = entry.getValue();
for( int index = 0; instanceCount > index ; ++index ){
final double currentAngle = instanceAngles[index];
Transformation currentTransform = parentTransform; for(InstanceContext context: contextList ) {
if( 0.00001 < Math.abs( currentAngle )) { final Transformation currentTransform = this.axialRotation.applyTransformation(context.transform);
Transformation currentAngleTransform = Transformation.rotate_x( currentAngle );
currentTransform = currentAngleTransform.applyTransformation( parentTransform );
}
Coordinate currentLocation = parentLocation.add( instanceLocations[index] ); // generate shape for this component, if active
if( context.active ) {
// if(FinSet.class.isAssignableFrom(comp.getClass())) { allShapes = addThisShape( allShapes, this.currentViewType, comp, currentTransform);
// System.err.println(String.format("@%s: %s -- inst: [%d/%d]", comp.getClass().getSimpleName(), comp.getName(), index+1, instanceCount)); }
// }
// // FlightConfiguration config = this.rocket.getSelectedConfiguration(); }
// // System.err.println(String.format(" -- stage: %d, active: %b, config: (%d) %s", comp.getStageNumber(), config.isComponentActive(comp), config.instanceNumber, config.getId()));
// System.err.println(String.format(" -- %s + %s = %s", parentLocation.toString(), instanceLocations[index].toString(), currentLocation.toString()));
// if( 0.00001 < Math.abs( currentAngle )) {
// System.err.println(String.format(" -- at: %6.4f radians", currentAngle));
// }
// }
// generate shape for this component, if active
if( this.rocket.getSelectedConfiguration().isComponentActive( comp )){
allShapes = addThisShape( allShapes, this.currentViewType, comp, currentLocation, currentTransform);
}
// recurse into component's children
for( RocketComponent child: comp.getChildren() ){
// draw a tree for each instance subcomponent
updateShapeTree( allShapes, child, currentTransform, currentLocation );
}
}
return allShapes;
} }
/** /**
@ -401,12 +368,11 @@ public class RocketFigure extends AbstractScaleFigure {
ArrayList<RocketComponentShape> allShapes, // this is the output parameter ArrayList<RocketComponentShape> allShapes, // this is the output parameter
final RocketPanel.VIEW_TYPE viewType, final RocketPanel.VIEW_TYPE viewType,
final RocketComponent component, final RocketComponent component,
final Coordinate instanceOffset,
final Transformation transformation) { final Transformation transformation) {
Reflection.Method m; Reflection.Method m;
if(( component instanceof Rocket)||( component instanceof ComponentAssembly )){ if(( component instanceof Rocket)||( component instanceof ComponentAssembly )){
// no-op; no shapes here, either. // no-op; no shapes here
return allShapes; return allShapes;
} }
@ -414,12 +380,12 @@ public class RocketFigure extends AbstractScaleFigure {
switch (viewType) { switch (viewType) {
case SideView: case SideView:
m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesSide", m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesSide",
RocketComponent.class, Transformation.class, Coordinate.class); RocketComponent.class, Transformation.class);
break; break;
case BackView: case BackView:
m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesBack", m = Reflection.findMethod(ROCKET_FIGURE_PACKAGE, component, ROCKET_FIGURE_SUFFIX, "getShapesBack",
RocketComponent.class, Transformation.class, Coordinate.class); RocketComponent.class, Transformation.class);
break; break;
default: default:
@ -433,7 +399,7 @@ public class RocketFigure extends AbstractScaleFigure {
} }
RocketComponentShape[] returnValue = (RocketComponentShape[]) m.invokeStatic(component, transformation, instanceOffset); RocketComponentShape[] returnValue = (RocketComponentShape[]) m.invokeStatic(component, transformation);
for ( RocketComponentShape curShape : returnValue ){ for ( RocketComponentShape curShape : returnValue ){
allShapes.add( curShape ); allShapes.add( curShape );
} }
@ -441,7 +407,6 @@ public class RocketFigure extends AbstractScaleFigure {
} }
/** /**
* Gets the bounds of the drawn subject in Model-Space * Gets the bounds of the drawn subject in Model-Space
* *