From 719576cc622af7a9b29706a1888be788af3f4cd6 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Tue, 4 Jun 2019 08:37:26 -0600 Subject: [PATCH 1/5] bunch of changes along the way to fixing length calculation --- .../rocketcomponent/AxialStage.java | 4 +- .../openrocket/rocketcomponent/BodyTube.java | 42 +++------------- .../rocketcomponent/ComponentAssembly.java | 20 +++++--- .../rocketcomponent/InternalComponent.java | 10 ++++ .../openrocket/rocketcomponent/LaunchLug.java | 15 ++++-- .../rocketcomponent/MassObject.java | 4 +- .../rocketcomponent/ParallelStage.java | 27 ---------- .../sf/openrocket/rocketcomponent/PodSet.java | 3 +- .../rocketcomponent/RailButton.java | 12 ++++- .../rocketcomponent/RingComponent.java | 5 +- .../rocketcomponent/RocketComponent.java | 10 ++-- .../sf/openrocket/rocketcomponent/Sleeve.java | 4 +- .../rocketcomponent/SymmetricComponent.java | 15 ++++-- .../rocketcomponent/Transition.java | 21 +++++++- .../rocketcomponent/TubeFinSet.java | 16 +++--- .../net/sf/openrocket/util/BoundingBox.java | 5 ++ .../figure3d/geometry/ComponentRenderer.java | 50 ++++++++++++++++++- 17 files changed, 159 insertions(+), 104 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java b/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java index a5607615e..b6a5488c8 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java @@ -59,7 +59,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC * {@inheritDoc} * not strictly accurate, but this should provide an acceptable estimate for total vehicle size */ - @Override + /* @Override public Collection getComponentBounds() { Collection bounds = new ArrayList(8); Coordinate[] instanceLocations = this.getInstanceLocations(); @@ -72,7 +72,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC return bounds; } - + */ /** * Check whether the given type can be added to this component. A Stage allows * only BodyComponents to be added. diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index be4d06a9a..486ee6f52 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -10,6 +10,7 @@ import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfigurationSet; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -304,44 +305,15 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial * * Currently the points are simply a rectangular box around the body tube. */ - @Override + /* @Override public Collection getComponentBounds() { - Collection bounds = new ArrayList(8); - double x_min_shape = 0; - double x_max_shape = this.length; - double r_max_shape = getOuterRadius(); + Collection bounds = new ArrayList(2); + + addBoundingBox(bounds, 0, length, getOuterRadius()); - Coordinate[] locs = this.getLocations(); - // not strictly accurate, but this should provide an acceptable estimate for total vehicle size - double x_min_inst = Double.MAX_VALUE; - double x_max_inst = Double.MIN_VALUE; - double r_max_inst = 0.0; - - // refactor: get component inherent bounds - for (Coordinate cur : locs) { - double x_cur = cur.x; - double r_cur = MathUtil.hypot(cur.y, cur.z); - if (x_min_inst > x_cur) { - x_min_inst = x_cur; - } - if (x_max_inst < x_cur) { - x_max_inst = x_cur; - } - if (r_cur > r_max_inst) { - r_max_inst = r_cur; - } - } - - // combine the position bounds with the inherent shape bounds - double x_min = x_min_shape + x_min_inst; - double x_max = x_max_shape + x_max_inst; - double r_max = r_max_shape + r_max_inst; - - addBoundingBox(bounds, x_min, x_max, r_max); return bounds; - } - - + }*/ + /** * Check whether the given type can be added to this component. BodyTubes allow any * InternalComponents or ExternalComponents, excluding BodyComponents, to be added. diff --git a/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java b/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java index 24468aeb3..3aec4aea7 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java +++ b/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.AxialPositionable; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; @@ -46,14 +47,6 @@ public abstract class ComponentAssembly extends RocketComponent implements Axia public double getAxialOffset() { return getAxialOffset( this.axialMethod ); } - - /** - * Null method (ComponentAssembly has no bounds of itself). - */ - @Override - public Collection getComponentBounds() { - return Collections.emptyList(); - } /** * Null method (ComponentAssembly has no mass of itself). @@ -107,6 +100,17 @@ public abstract class ComponentAssembly extends RocketComponent implements Axia } return outerRadius; } + + /** + * We'll find the bounding box of a component by iterating an + * InstanceMap, not by performing a treewalk of the component. + * So, anything subclassed from a ComponentAssembly will just + * return an empty bounding box + */ + @Override + public BoundingBox getBoundingBox() { + return new BoundingBox(); + } /** * Components have no aerodynamic effect, so return false. diff --git a/core/src/net/sf/openrocket/rocketcomponent/InternalComponent.java b/core/src/net/sf/openrocket/rocketcomponent/InternalComponent.java index f108eddf2..f19304a1c 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InternalComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InternalComponent.java @@ -2,6 +2,7 @@ package net.sf.openrocket.rocketcomponent; import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.AxialPositionable; +import net.sf.openrocket.util.BoundingBox; /** * A component internal to the rocket. Internal components have no effect on the @@ -35,6 +36,15 @@ public abstract class InternalComponent extends RocketComponent implements Axial return false; } + /** + * An internal component can't extend beyond the bounding box established by external components + * Return an empty bounding box to simplify methods calling us. + */ + @Override + public BoundingBox getBoundingBox() { + return new BoundingBox(); + } + /** * Is massive. * @return true diff --git a/core/src/net/sf/openrocket/rocketcomponent/LaunchLug.java b/core/src/net/sf/openrocket/rocketcomponent/LaunchLug.java index 0824a3aef..924de3678 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/LaunchLug.java +++ b/core/src/net/sf/openrocket/rocketcomponent/LaunchLug.java @@ -8,6 +8,7 @@ import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.preset.ComponentPreset.Type; import net.sf.openrocket.rocketcomponent.position.*; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -187,12 +188,16 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, C return length * Math.PI * (MathUtil.pow2(radius) - MathUtil.pow2(radius - thickness)); } - @Override + /* @Override public Collection getComponentBounds() { - ArrayList set = new ArrayList(); - addBound(set, 0, radius); - addBound(set, length, radius); - return set; + ArrayList bounds = new ArrayList(2); + addBoundingBox(bounds, 0, length, radius); + return bounds; + } + */ + @Override + public BoundingBox getBoundingBox() { + return new BoundingBox(0, length, radius); } @Override diff --git a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java index b018919d2..faecf63c4 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java @@ -133,13 +133,13 @@ public abstract class MassObject extends InternalComponent { public final double getRotationalUnitInertia() { return pow2(radius) / 2; } - + /* @Override public final Collection getComponentBounds() { Collection c = new ArrayList(); addBound(c, 0, radius); addBound(c, length, radius); return c; - } + }*/ } diff --git a/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java b/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java index daf79abda..0cfd8b071 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java @@ -44,33 +44,6 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo return trans.get("BoosterSet.BoosterSet"); } - // not strictly accurate, but this should provide an acceptable estimate for total vehicle size - @Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(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. diff --git a/core/src/net/sf/openrocket/rocketcomponent/PodSet.java b/core/src/net/sf/openrocket/rocketcomponent/PodSet.java index e22fc51aa..26d3c7f67 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/PodSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/PodSet.java @@ -46,7 +46,7 @@ public class PodSet extends ComponentAssembly implements RingInstanceable { // not strictly accurate, but this should provide an acceptable estimate for total vehicle size - @Override + /* @Override public Collection getComponentBounds() { Collection bounds = new ArrayList(8); double x_min = Double.MAX_VALUE; @@ -71,6 +71,7 @@ public class PodSet extends ComponentAssembly implements RingInstanceable { return bounds; } + */ /** * Check whether the given type can be added to this component. A Stage allows diff --git a/core/src/net/sf/openrocket/rocketcomponent/RailButton.java b/core/src/net/sf/openrocket/rocketcomponent/RailButton.java index df6ea275a..ff0f619db 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RailButton.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RailButton.java @@ -11,6 +11,7 @@ import net.sf.openrocket.rocketcomponent.position.AnglePositionable; import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.AxialPositionable; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -232,6 +233,13 @@ public class RailButton extends ExternalComponent implements AnglePositionable, public Type getPresetType() { return ComponentPreset.Type.RAIL_BUTTON; } + + @Override + public BoundingBox getBoundingBox() { + final double r = outerDiameter_m / 2.0; + return new BoundingBox(new Coordinate(-r, -r, 0), + new Coordinate(r, r, totalHeight_m)); + } @Override public void componentChanged(ComponentChangeEvent e) { @@ -287,7 +295,7 @@ public class RailButton extends ExternalComponent implements AnglePositionable, public String getPatternName(){ return (this.getInstanceCount() + "-Line"); } - + /* @Override public Collection getComponentBounds() { final double r = outerDiameter_m / 2.0; @@ -302,7 +310,7 @@ public class RailButton extends ExternalComponent implements AnglePositionable, set.add(new Coordinate(-r, totalHeight_m, -r)); return set; } - + */ @Override public Coordinate getComponentCG() { // Math.PI and density are assumed constant through calculation, and thus may be factored out. diff --git a/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java index 5dbf4d5ba..4cf2f7349 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java @@ -162,13 +162,13 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } - @Override + /* @Override public Collection getComponentBounds() { List bounds = new ArrayList(); addBound(bounds, 0, getOuterRadius()); addBound(bounds, length, getOuterRadius()); return bounds; - } + }*/ @Override public Coordinate getComponentCG() { @@ -195,7 +195,6 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi getMaterial().getDensity()) * getInstanceCount(); } - @Override public double getLongitudinalUnitInertia() { return ringLongitudinalUnitInertia(getOuterRadius(), getInnerRadius(), getLength()); diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index fc20dc813..1d5794736 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -19,6 +19,7 @@ import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.RadiusMethod; import net.sf.openrocket.util.ArrayList; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.Color; @@ -222,14 +223,13 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab /** - * Return a collection of bounding coordinates. The coordinates must be such that - * the component is fully enclosed in their convex hull. + * Return bounding box of component. * * Note: this function gets the bounds only for this component. Subchildren must be called individually. * * @return a collection of coordinates that bound the component. */ - public abstract Collection getComponentBounds(); + public abstract BoundingBox getBoundingBox(); /** * Return true if the component may have an aerodynamic effect on the rocket. @@ -1902,7 +1902,9 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab /** - * Helper method to add two points on opposite corners of a box around the rocket centerline. This box will be (x_max - x_min) long, and 2*r wide/high. + * Helper method to add two points on opposite corners of a box + * around the component centerline. This box will be (x_max - + * x_min) long, and 2*r wide/high. */ protected static final void addBoundingBox(Collection bounds, double x_min, double x_max, double r) { bounds.add(new Coordinate(x_min, -r, -r)); diff --git a/core/src/net/sf/openrocket/rocketcomponent/Sleeve.java b/core/src/net/sf/openrocket/rocketcomponent/Sleeve.java index aafff5422..86a5d9191 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Sleeve.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Sleeve.java @@ -2,6 +2,7 @@ package net.sf.openrocket.rocketcomponent; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -82,9 +83,6 @@ public class Sleeve extends RingComponent { thickness = t; fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } - - - @Override public void setInnerRadiusAutomatic(boolean auto) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java index a530bfe94..5c937f44e 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java @@ -8,6 +8,7 @@ import java.util.List; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.rocketcomponent.position.AxialMethod; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -138,7 +139,7 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial /** * Adds component bounds at a number of points between 0...length. */ - @Override + /* @Override public Collection getComponentBounds() { List list = new ArrayList(20); for (int n = 0; n <= 5; n++) { @@ -147,10 +148,18 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial addBound(list, x, r); } return list; + }*/ + + /** + * Are there any components whose max diameter isn't at either the + * fore or aft end? I don't know of any. + */ + @Override + public BoundingBox getBoundingBox() { + return new BoundingBox(0, getLength(), + Math.max(getForeRadius(), getAftRadius())); } - - @Override protected void loadFromPreset(ComponentPreset preset) { if ( preset.has(ComponentPreset.THICKNESS) ) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/Transition.java b/core/src/net/sf/openrocket/rocketcomponent/Transition.java index d89f6de69..179a3897d 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Transition.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Transition.java @@ -10,6 +10,7 @@ import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.preset.ComponentPreset.Type; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -435,7 +436,7 @@ public class Transition extends SymmetricComponent { - @Override +/* @Override public Collection getComponentBounds() { Collection bounds = super.getComponentBounds(); if (foreShoulderLength > 0.001) @@ -443,6 +444,24 @@ public class Transition extends SymmetricComponent { if (aftShoulderLength > 0.001) addBound(bounds, getLength() + aftShoulderLength, aftShoulderRadius); return bounds; + }*/ + + /** + * bounding box of transition + * + * It's tempting to ignore the shoulders (if any) on the grounds + * that they will be covered by the fore and aft body tubes, but + * including them won't cause any errors + * + * we will assume the maximum radius will occur at either the fore + * or aft end -- this is true for the transitions that are + * currently allowed, but could conceivably change in the future + */ + @Override + public BoundingBox getBoundingBox() { + return new BoundingBox(-getForeShoulderLength(), + getLength() + getAftShoulderLength(), + Math.max(getForeRadius(), getAftRadius())); } @Override diff --git a/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java index aa9ad73ab..85db37d74 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java @@ -10,6 +10,7 @@ import net.sf.openrocket.preset.ComponentPreset.Type; import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.AxialPositionable; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.Transformation; @@ -305,15 +306,18 @@ public class TubeFinSet extends ExternalComponent implements AxialPositionable { return false; } - @Override + /* @Override public Collection getComponentBounds() { - List bounds = new ArrayList(); - double r = getBodyRadius(); - - addBound(bounds, 0, 2 * (r + outerRadius)); - addBound(bounds, length, 2 * (r + outerRadius)); + List bounds = new ArrayList(2); + + addBoundingBox(bounds, 0, length, outerRadius); return bounds; + }*/ + + @Override + public BoundingBox getBoundingBox() { + return new BoundingBox(0, length, outerRadius); } /** diff --git a/core/src/net/sf/openrocket/util/BoundingBox.java b/core/src/net/sf/openrocket/util/BoundingBox.java index 6d5f46eb8..79220ce2e 100644 --- a/core/src/net/sf/openrocket/util/BoundingBox.java +++ b/core/src/net/sf/openrocket/util/BoundingBox.java @@ -17,6 +17,11 @@ public class BoundingBox { this.min = _min.clone(); this.max = _max.clone(); } + + public BoundingBox(double xmin, double xmax, double rad) { + min = new Coordinate(xmin, -rad, -rad); + max = new Coordinate(xmax, rad, rad); + } public void clear() { min = Coordinate.MAX.setWeight( 0.0); diff --git a/swing/src/net/sf/openrocket/gui/figure3d/geometry/ComponentRenderer.java b/swing/src/net/sf/openrocket/gui/figure3d/geometry/ComponentRenderer.java index a0f44b54d..cd8229381 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/geometry/ComponentRenderer.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/geometry/ComponentRenderer.java @@ -25,6 +25,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.Transition.Shape; import net.sf.openrocket.rocketcomponent.TubeFinSet; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Transformation; @@ -121,12 +122,57 @@ public class ComponentRenderer { } else if ( c instanceof ParallelStage ) { } else if ( c instanceof PodSet ) { } else { - renderOther(gl, c); + renderBoundingBox(gl, c); } } + /** + * If I don't have a method to render an object, I'll render its bounding box + */ + private void renderBoundingBox(GL2 gl, RocketComponent c) { + BoundingBox box = c.getBoundingBox(); + + // rectangle at forward end + gl.glBegin(GL.GL_LINES); + gl.glVertex3d(box.min.x, box.min.y, box.min.z); + gl.glVertex3d(box.min.x, box.max.y, box.min.z); + gl.glVertex3d(box.min.x, box.max.y, box.max.z); + gl.glVertex3d(box.min.x, box.max.x, box.min.z); + gl.glEnd(); + + // rectangle at aft end + gl.glBegin(GL.GL_LINES); + gl.glVertex3d(box.max.x, box.min.y, box.min.z); + gl.glVertex3d(box.max.x, box.max.y, box.min.z); + gl.glVertex3d(box.max.x, box.max.y, box.max.z); + gl.glVertex3d(box.max.x, box.max.x, box.min.z); + gl.glEnd(); + + // connect forward and aft rectangles + gl.glBegin(GL.GL_LINES); + gl.glVertex3d(box.min.x, box.min.y, box.min.z); + gl.glVertex3d(box.max.x, box.min.y, box.min.z); + gl.glEnd(); + + gl.glBegin(GL.GL_LINES); + gl.glVertex3d(box.min.x, box.max.y, box.min.z); + gl.glVertex3d(box.max.x, box.max.y, box.min.z); + gl.glEnd(); + + gl.glBegin(GL.GL_LINES); + gl.glVertex3d(box.min.x, box.min.y, box.max.z); + gl.glVertex3d(box.max.x, box.min.y, box.max.z); + gl.glEnd(); + + gl.glBegin(GL.GL_LINES); + gl.glVertex3d(box.min.x, box.max.y, box.max.z); + gl.glVertex3d(box.max.x, box.max.y, box.max.z); + gl.glEnd(); + } + + /* private void renderOther(GL2 gl, RocketComponent c) { gl.glBegin(GL.GL_LINES); for (Coordinate cc : c.getComponentBounds()) { @@ -137,7 +183,7 @@ public class ComponentRenderer { } gl.glEnd(); } - + */ private void renderTransition(GL2 gl, Transition t, Surface which) { if (which == Surface.OUTSIDE || which == Surface.INSIDE) { From 1b188e20bebc42996bd81aaf8739fe0336997a76 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 10 Jun 2019 17:03:58 -0600 Subject: [PATCH 2/5] finished first draft of fixing lengths --- core/src/net/sf/openrocket/rocketcomponent/FinSet.java | 4 ++-- .../sf/openrocket/rocketcomponent/FlightConfiguration.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 52ba40843..a183f4f31 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -723,7 +723,7 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab * * Currently the points are simply a rectangular box around the body tube. */ - @Override + /*@Override public Collection getComponentBounds() { Collection bounds = new ArrayList(8); @@ -756,7 +756,7 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab addBoundingBox(bounds, x_min, x_max, r_max); return bounds; - } + }*/ @Override public void componentChanged(ComponentChangeEvent e) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 4bb7fdc8d..0b807d972 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -529,7 +529,7 @@ public class FlightConfiguration implements FlightConfigurableParameter Date: Mon, 17 Jun 2019 15:19:08 -0600 Subject: [PATCH 3/5] This is a much bigger commit than I like to make, and will result in a much bigger PR than I like as well. All I can do is apologize... Fixes length calculation in RocketPanel. (1) Finished switching over from deprecated getBounds() function to getBoundingBox(). getBounds() function is removed. (2) 3D rendering code had its own getBounds(). Switched this over to RocketComponent:getBoundingBox() as well (3) Made getBoundingBox() consistently get the bounding box relative to the component. Implementations for some components were calculating box relative to start of rocket (4) Used InstanceMap to iterate through all instances of components in creating bounding box. --- .../aerodynamics/BarrowmanCalculator.java | 4 +- .../rocketcomponent/AxialStage.java | 18 ------ .../openrocket/rocketcomponent/BodyTube.java | 16 ----- .../sf/openrocket/rocketcomponent/FinSet.java | 47 ++------------- .../rocketcomponent/FlightConfiguration.java | 48 +++++++-------- .../rocketcomponent/InstanceMap.java | 2 +- .../openrocket/rocketcomponent/LaunchLug.java | 9 +-- .../rocketcomponent/MassObject.java | 9 --- .../sf/openrocket/rocketcomponent/PodSet.java | 28 --------- .../rocketcomponent/RailButton.java | 17 +----- .../rocketcomponent/RingComponent.java | 8 --- .../rocketcomponent/RocketUtils.java | 26 --------- .../rocketcomponent/SymmetricComponent.java | 15 ----- .../rocketcomponent/Transition.java | 12 ---- .../rocketcomponent/TubeFinSet.java | 9 --- .../simulation/SimulationStatus.java | 6 +- .../net/sf/openrocket/util/BoundingBox.java | 10 +++- openrocket.log | 1 - .../gui/figure3d/RocketFigure3d.java | 56 +++--------------- .../gui/figure3d/RocketRenderer.java | 2 +- .../gui/figure3d/photo/PhotoPanel.java | 58 +++---------------- .../gui/figureelements/RocketInfo.java | 4 -- .../gui/scalefigure/RocketFigure.java | 2 +- .../gui/scalefigure/RocketPanel.java | 15 +---- 24 files changed, 61 insertions(+), 361 deletions(-) delete mode 100644 core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java delete mode 100644 openrocket.log diff --git a/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java b/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java index 4667476c8..c4ac8c874 100644 --- a/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java +++ b/core/src/net/sf/openrocket/aerodynamics/BarrowmanCalculator.java @@ -2,7 +2,6 @@ package net.sf.openrocket.aerodynamics; import static net.sf.openrocket.util.MathUtil.pow2; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; @@ -23,6 +22,7 @@ import net.sf.openrocket.rocketcomponent.InstanceMap; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.SymmetricComponent; +import net.sf.openrocket.util.ArrayList; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.PolyInterpolator; @@ -96,7 +96,6 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator { // Calculate non-axial force data AerodynamicForces total = calculateNonAxialForces(configuration, conditions, map, warnings); - // Calculate friction data total.setFrictionCD(calculateFrictionDrag(configuration, conditions, map, warnings)); total.setPressureCD(calculatePressureDrag(configuration, conditions, map, warnings)); @@ -174,7 +173,6 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator { if (calcMap == null) buildCalcMap(configuration); - if( ! isContinuous( configuration.getRocket() ) ){ warnings.add( Warning.DIAMETER_DISCONTINUITY); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java b/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java index b6a5488c8..0e80fbf9b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java @@ -55,24 +55,6 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC separations.reset(fcid); } - /** - * {@inheritDoc} - * not strictly accurate, but this should provide an acceptable estimate for total vehicle size - */ - /* @Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(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. diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 486ee6f52..b2a9f134b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -297,22 +297,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial private static double getFilledVolume(double r, double l) { return Math.PI * r * r * l; } - - - /** - * Adds bounding coordinates to the given set. The body tube will fit within the - * convex hull of the points. - * - * Currently the points are simply a rectangular box around the body tube. - */ - /* @Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(2); - - addBoundingBox(bounds, 0, length, getOuterRadius()); - - return bounds; - }*/ /** * Check whether the given type can be added to this component. BodyTubes allow any diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index a183f4f31..e63bf15d5 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -709,54 +709,17 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab BoundingBox singleFinBounds= new BoundingBox().update(getFinPoints()); final double finLength = singleFinBounds.max.x; final double finHeight = singleFinBounds.max.y; - + + /* BoundingBox compBox = new BoundingBox().update(getComponentLocations()); BoundingBox finSetBox = new BoundingBox( compBox.min.sub( 0, finHeight, finHeight ), compBox.max.add( finLength, finHeight, finHeight )); return finSetBox; + */ + + return new BoundingBox(0.0, finLength, finHeight); } - - /** - * Adds bounding coordinates to the given set. The body tube will fit within the - * convex hull of the points. - * - * Currently the points are simply a rectangular box around the body tube. - */ - /*@Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(8); - - // should simply return this component's bounds in this component's body frame. - - double x_min = Double.MAX_VALUE; - double x_max = Double.MIN_VALUE; - double r_max = 0.0; - - for (Coordinate point : getFinPoints()) { - double hypot = MathUtil.hypot(point.y, point.z); - double x_cur = point.x; - if (x_min > x_cur) { - x_min = x_cur; - } - if (x_max < x_cur) { - x_max = x_cur; - } - if (r_max < hypot) { - r_max = hypot; - } - } - - Coordinate location = this.getLocations()[0]; - x_max += location.x; - - if( parent instanceof SymmetricComponent){ - r_max += ((SymmetricComponent)parent).getRadius(0); - } - - addBoundingBox(bounds, x_min, x_max, r_max); - return bounds; - }*/ @Override public void componentChanged(ComponentChangeEvent e) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 0b807d972..f3b3e3e74 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -63,7 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter motors = new HashMap(); private int boundsModID = -1; - private BoundingBox cachedBounds = new BoundingBox(); + private BoundingBox cachedBoundingBox = new BoundingBox(); private double cachedLength = -1; private int refLengthModID = -1; @@ -501,18 +501,6 @@ public class FlightConfiguration implements FlightConfigurableParameterCollection containing coordinates bounding the rocket. - * - * @deprecated Migrate to .getBoundingBox(), when practical. - */ - @Deprecated - public Collection getBounds() { - return getBoundingBox().toCollection(); - } - /** * Return the bounding box of the current configuration. * @@ -520,22 +508,34 @@ public class FlightConfiguration implements FlightConfigurableParameter> entry: imap.entrySet() ) { + final RocketComponent comp = entry.getKey(); + if (this.isComponentActive(comp)) { + + // iterate across all componenent instances + final ArrayList contextList = entry.getValue(); + + for(InstanceContext context: contextList ) { + BoundingBox instanceBox = new BoundingBox(context.transform.transform(comp.getBoundingBox().min), + context.transform.transform(comp.getBoundingBox().max)); + bounds.update(instanceBox); + } + } } boundsModID = rocket.getModID(); cachedLength = bounds.span().x; - cachedBounds.update( bounds ); + cachedBoundingBox.update( bounds ); } /** @@ -546,7 +546,7 @@ public class FlightConfiguration implements FlightConfigurableParameter getComponentBounds() { - ArrayList bounds = new ArrayList(2); - addBoundingBox(bounds, 0, length, radius); - return bounds; - } - */ + @Override public BoundingBox getBoundingBox() { return new BoundingBox(0, length, radius); diff --git a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java index faecf63c4..9af0c8ae3 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java @@ -133,13 +133,4 @@ public abstract class MassObject extends InternalComponent { public final double getRotationalUnitInertia() { return pow2(radius) / 2; } - /* - @Override - public final Collection getComponentBounds() { - Collection c = new ArrayList(); - addBound(c, 0, radius); - addBound(c, length, radius); - return c; - }*/ - } diff --git a/core/src/net/sf/openrocket/rocketcomponent/PodSet.java b/core/src/net/sf/openrocket/rocketcomponent/PodSet.java index 26d3c7f67..2e3a72275 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/PodSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/PodSet.java @@ -45,34 +45,6 @@ public class PodSet extends ComponentAssembly implements RingInstanceable { } - // not strictly accurate, but this should provide an acceptable estimate for total vehicle size - /* @Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(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. diff --git a/core/src/net/sf/openrocket/rocketcomponent/RailButton.java b/core/src/net/sf/openrocket/rocketcomponent/RailButton.java index ff0f619db..ab39d492b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RailButton.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RailButton.java @@ -295,22 +295,7 @@ public class RailButton extends ExternalComponent implements AnglePositionable, public String getPatternName(){ return (this.getInstanceCount() + "-Line"); } - /* - @Override - public Collection getComponentBounds() { - final double r = outerDiameter_m / 2.0; - ArrayList set = new ArrayList(); - set.add(new Coordinate(r, totalHeight_m, r)); - set.add(new Coordinate(r, totalHeight_m, -r)); - set.add(new Coordinate(r, 0, r)); - set.add(new Coordinate(r, 0, -r)); - set.add(new Coordinate(-r, 0, r)); - set.add(new Coordinate(-r, 0, -r)); - set.add(new Coordinate(-r, totalHeight_m, r)); - set.add(new Coordinate(-r, totalHeight_m, -r)); - return set; - } - */ + @Override public Coordinate getComponentCG() { // Math.PI and density are assumed constant through calculation, and thus may be factored out. diff --git a/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java index 4cf2f7349..0365a76a3 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java @@ -162,14 +162,6 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } - /* @Override - public Collection getComponentBounds() { - List bounds = new ArrayList(); - addBound(bounds, 0, getOuterRadius()); - addBound(bounds, length, getOuterRadius()); - return bounds; - }*/ - @Override public Coordinate getComponentCG() { Coordinate cg = Coordinate.ZERO; diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java b/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java deleted file mode 100644 index f875c2b76..000000000 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.sf.openrocket.rocketcomponent; - -import java.util.Collection; - -import net.sf.openrocket.util.Coordinate; - -public abstract class RocketUtils { - - public static double getLength(Rocket rocket) { - double length = 0; - Collection bounds = rocket.getSelectedConfiguration().getBounds(); - if (!bounds.isEmpty()) { - double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY; - for (Coordinate c : bounds) { - if (c.x < minX) - minX = c.x; - if (c.x > maxX) - maxX = c.x; - } - length = maxX - minX; - } - return length; - } - - -} diff --git a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java index 5c937f44e..e4f0fe36f 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java @@ -134,21 +134,6 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); clearPreset(); } - - - /** - * Adds component bounds at a number of points between 0...length. - */ - /* @Override - public Collection getComponentBounds() { - List list = new ArrayList(20); - for (int n = 0; n <= 5; n++) { - double x = n * length / 5; - double r = getRadius(x); - addBound(list, x, r); - } - return list; - }*/ /** * Are there any components whose max diameter isn't at either the diff --git a/core/src/net/sf/openrocket/rocketcomponent/Transition.java b/core/src/net/sf/openrocket/rocketcomponent/Transition.java index 179a3897d..ada0e9fb1 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Transition.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Transition.java @@ -434,18 +434,6 @@ public class Transition extends SymmetricComponent { return Math.max(getRadius(x) - thickness, 0); } - - -/* @Override - public Collection getComponentBounds() { - Collection bounds = super.getComponentBounds(); - if (foreShoulderLength > 0.001) - addBound(bounds, -foreShoulderLength, foreShoulderRadius); - if (aftShoulderLength > 0.001) - addBound(bounds, getLength() + aftShoulderLength, aftShoulderRadius); - return bounds; - }*/ - /** * bounding box of transition * diff --git a/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java index 85db37d74..4f6b23aa0 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java @@ -305,15 +305,6 @@ public class TubeFinSet extends ExternalComponent implements AxialPositionable { // TODO Auto-generated method stub return false; } - - /* @Override - public Collection getComponentBounds() { - List bounds = new ArrayList(2); - - addBoundingBox(bounds, 0, length, outerRadius); - - return bounds; - }*/ @Override public BoundingBox getBoundingBox() { diff --git a/core/src/net/sf/openrocket/simulation/SimulationStatus.java b/core/src/net/sf/openrocket/simulation/SimulationStatus.java index 9ea75832d..1420b4166 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationStatus.java +++ b/core/src/net/sf/openrocket/simulation/SimulationStatus.java @@ -127,11 +127,7 @@ public class SimulationStatus implements Monitorable { } } if (!Double.isNaN(lugPosition)) { - double maxX = 0; - for (Coordinate c : this.configuration.getBounds()) { - if (c.x > maxX) - maxX = c.x; - } + double maxX = this.configuration.getBoundingBox().max.x; if (maxX >= lugPosition) { length = Math.max(0, length - (maxX - lugPosition)); } diff --git a/core/src/net/sf/openrocket/util/BoundingBox.java b/core/src/net/sf/openrocket/util/BoundingBox.java index 79220ce2e..2b456cac6 100644 --- a/core/src/net/sf/openrocket/util/BoundingBox.java +++ b/core/src/net/sf/openrocket/util/BoundingBox.java @@ -118,8 +118,14 @@ public class BoundingBox { update_z_max(other.max.z); return this; } - - public Coordinate span() { return max.sub( min ); } + + public Coordinate span() { + Coordinate tmp = max.sub( min ); + return new Coordinate(Math.max(tmp.x, 0.0), + Math.max(tmp.y, 0.0), + Math.max(tmp.z, 0.0), + Math.max(tmp.weight, 0.0)); + } public Coordinate[] toArray() { return new Coordinate[] { this.min, this.max }; diff --git a/openrocket.log b/openrocket.log deleted file mode 100644 index d5c1f8088..000000000 --- a/openrocket.log +++ /dev/null @@ -1 +0,0 @@ -Error: Unable to access jarfile OpenRocket.jar diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java index 8b01b734e..6d74f4a37 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java @@ -49,6 +49,7 @@ import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Preferences; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -468,64 +469,21 @@ public class RocketFigure3d extends JPanel implements GLEventListener { redrawExtras = true; } - @SuppressWarnings("unused") - private static class Bounds { - double xMin, xMax, xSize; - double yMin, yMax, ySize; - double zMin, zMax, zSize; - double rMax; - } - - private Bounds cachedBounds = null; - - /** - * Calculates the bounds for the current configuration - * - * @return - */ - private Bounds calculateBounds() { - if (cachedBounds != null) { - return cachedBounds; - } else { - final Bounds b = new Bounds(); - final FlightConfiguration configuration = rkt.getSelectedConfiguration(); - final Collection bounds = configuration.getBounds(); - for (Coordinate c : bounds) { - b.xMax = Math.max(b.xMax, c.x); - b.xMin = Math.min(b.xMin, c.x); - - b.yMax = Math.max(b.yMax, c.y); - b.yMin = Math.min(b.yMin, c.y); - - b.zMax = Math.max(b.zMax, c.z); - b.zMin = Math.min(b.zMin, c.z); - - double r = MathUtil.hypot(c.y, c.z); - b.rMax = Math.max(b.rMax, r); - } - b.xSize = b.xMax - b.xMin; - b.ySize = b.yMax - b.yMin; - b.zSize = b.zMax - b.zMin; - cachedBounds = b; - return b; - } - } - private void setupView(final GL2 gl, final GLU glu) { gl.glLoadIdentity(); gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION, lightPosition, 0); - // Get the bounds - final Bounds b = calculateBounds(); + // Get the bounding box + final BoundingBox b = rkt.getSelectedConfiguration().getBoundingBox(); // Calculate the distance needed to fit the bounds in both the X and Y // direction // Add 10% for space around it. - final double dX = (b.xSize * 1.2 / 2.0) + final double dX = (b.max.x * 1.2 / 2.0) / Math.tan(Math.toRadians(fovX / 2.0)); - final double dY = (b.rMax * 2.0 * 1.2 / 2.0) + final double dY = (b.max.y * 2.0 * 1.2 / 2.0) / Math.tan(Math.toRadians(fovY / 2.0)); // Move back the greater of the 2 distances @@ -535,7 +493,8 @@ public class RocketFigure3d extends JPanel implements GLEventListener { gl.glRotated(roll * (180.0 / Math.PI), 1, 0, 0); // Center the rocket in the view. - gl.glTranslated(-b.xMin - b.xSize / 2.0, 0, 0); + // gl.glTranslated(-b.xMin - b.xSize / 2.0, 0, 0); + gl.glTranslated((b.min.x - b.max.x) / 2.0, 0, 0); //Change to LEFT Handed coordinates gl.glScaled(1, 1, -1); @@ -554,7 +513,6 @@ public class RocketFigure3d extends JPanel implements GLEventListener { */ public void updateFigure() { log.debug("3D Figure Updated"); - cachedBounds = null; if (canvas != null) { ((GLAutoDrawable) canvas).invoke(true, new GLRunnable() { @Override diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java b/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java index d4f6f54ea..42f657060 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java @@ -2,7 +2,6 @@ package net.sf.openrocket.gui.figure3d; import java.awt.Point; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Set; @@ -28,6 +27,7 @@ import net.sf.openrocket.rocketcomponent.InstanceContext; import net.sf.openrocket.rocketcomponent.InstanceMap; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RocketComponent; +import net.sf.openrocket.util.ArrayList; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Transformation; diff --git a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java index 7e92db8b4..d6212c616 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java @@ -52,6 +52,7 @@ import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Preferences; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.Color; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -92,7 +93,6 @@ public class PhotoPanel extends JPanel implements GLEventListener { @Override public boolean run(final GLAutoDrawable drawable) { PhotoPanel.this.configuration = doc.getSelectedConfiguration(); - cachedBounds = null; rr = new RealisticRenderer(doc); rr.init(drawable); @@ -246,11 +246,11 @@ public class PhotoPanel extends JPanel implements GLEventListener { draw(drawable, 0); if (p.isMotionBlurred()) { - Bounds b = calculateBounds(); + BoundingBox b = configuration.getBoundingBox(); float m = .6f; int c = 10; - float d = (float) b.xSize / 25.0f; + float d = (float) (b.max.x - b.min.x) / 25.0f; gl.glAccum(GL2.GL_LOAD, m); @@ -391,11 +391,11 @@ public class PhotoPanel extends JPanel implements GLEventListener { gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_SPECULAR, new float[] { color[0], color[1], color[2], 1 }, 0); - Bounds b = calculateBounds(); + BoundingBox b = configuration.getBoundingBox(); gl.glLightf(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_QUADRATIC_ATTENUATION, 20f); gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_POSITION, - new float[] { (float) (b.xMax + .1f), 0, 0, 1 }, 0); + new float[] { (float) (b.max.x + .1f), 0, 0, 1 }, 0); gl.glEnable(GLLightingFunc.GL_LIGHT2); } else { gl.glDisable(GLLightingFunc.GL_LIGHT2); @@ -478,56 +478,14 @@ public class PhotoPanel extends JPanel implements GLEventListener { ratio = (double) w / (double) h; } - @SuppressWarnings("unused") - private static class Bounds { - double xMin, xMax, xSize; - double yMin, yMax, ySize; - double zMin, zMax, zSize; - double rMax; - } - - private Bounds cachedBounds = null; - - /** - * Calculates the bounds for the current configuration - * - * @return - */ - private Bounds calculateBounds() { - if (cachedBounds != null) { - return cachedBounds; - } else { - final Bounds b = new Bounds(); - final Collection bounds = configuration.getBounds(); - for (Coordinate c : bounds) { - b.xMax = Math.max(b.xMax, c.x); - b.xMin = Math.min(b.xMin, c.x); - - b.yMax = Math.max(b.yMax, c.y); - b.yMin = Math.min(b.yMin, c.y); - - b.zMax = Math.max(b.zMax, c.z); - b.zMin = Math.min(b.zMin, c.z); - - double r = MathUtil.hypot(c.y, c.z); - b.rMax = Math.max(b.rMax, r); - } - b.xSize = b.xMax - b.xMin; - b.ySize = b.yMax - b.yMin; - b.zSize = b.zMax - b.zMin; - cachedBounds = b; - return b; - } - } - private void setupModel(final GL2 gl) { - // Get the bounds - final Bounds b = calculateBounds(); gl.glRotated(-p.getPitch() * (180.0 / Math.PI), 0, 0, 1); gl.glRotated(p.getYaw() * (180.0 / Math.PI), 0, 1, 0); gl.glRotated(p.getRoll() * (180.0 / Math.PI), 1, 0, 0); + // Center the rocket in the view. - gl.glTranslated(-b.xMin - b.xSize / 2.0, 0, 0); + final BoundingBox b = configuration.getBoundingBox(); + gl.glTranslated((b.min.x - b.max.x) / 2.0, 0, 0); } } diff --git a/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java b/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java index 212d50ef5..70d098089 100644 --- a/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java +++ b/swing/src/net/sf/openrocket/gui/figureelements/RocketInfo.java @@ -61,10 +61,6 @@ public class RocketInfo implements FigureElement { private float line = 0; private float x1, x2, y1, y2; - - - - public RocketInfo(FlightConfiguration configuration) { this.configuration = configuration; this.stabilityUnits = UnitGroup.stabilityUnits(configuration); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 5775390a1..700426068 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -14,7 +14,6 @@ import java.awt.geom.Ellipse2D; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; -import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Map.Entry; @@ -34,6 +33,7 @@ import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.ArrayList; import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 33a014531..eb534701c 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -67,12 +67,12 @@ import net.sf.openrocket.simulation.listeners.SimulationListener; import net.sf.openrocket.simulation.listeners.system.ApogeeEndListener; import net.sf.openrocket.simulation.listeners.system.InterruptListener; import net.sf.openrocket.startup.Application; -import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.Chars; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.StateChangeListener; +import net.sf.openrocket.unit.UnitGroup; /** @@ -607,18 +607,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change figure3d.setCP(cp); // Length bound is assumed to be tight - double length = 0; - Collection bounds = curConfig.getBounds(); - if (!bounds.isEmpty()) { - double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY; - for (Coordinate c : bounds) { - if (c.x < minX) - minX = c.x; - if (c.x > maxX) - maxX = c.x; - } - length = maxX - minX; - } + double length = curConfig.getLength(); double diameter = Double.NaN; for (RocketComponent c : curConfig.getCoreComponents()) { From 934cccb811d96c4efd18379fe33f62bd2d4d9690 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 17 Jun 2019 15:28:50 -0600 Subject: [PATCH 4/5] Was thinking about getting rid of RocketUtils since it's only used by android app; there's no harm in leaving it... --- .../openrocket/android/rocket/#Overview.java# | 146 ++++++++++++++++++ .../openrocket/android/rocket/.#Overview.java | 1 + .../rocketcomponent/RocketUtils.java | 13 ++ 3 files changed, 160 insertions(+) create mode 100644 android/src/net/sf/openrocket/android/rocket/#Overview.java# create mode 120000 android/src/net/sf/openrocket/android/rocket/.#Overview.java create mode 100644 core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java diff --git a/android/src/net/sf/openrocket/android/rocket/#Overview.java# b/android/src/net/sf/openrocket/android/rocket/#Overview.java# new file mode 100644 index 000000000..236b3e8b3 --- /dev/null +++ b/android/src/net/sf/openrocket/android/rocket/#Overview.java# @@ -0,0 +1,146 @@ +package net.sf.openrocket.android.rocket; + +import net.sf.openrocket.R; +import net.sf.openrocket.aerodynamics.AerodynamicCalculator; +import net.sf.openrocket.aerodynamics.BarrowmanCalculator; +import net.sf.openrocket.aerodynamics.FlightConditions; +import net.sf.openrocket.aerodynamics.WarningSet; +import net.sf.openrocket.android.CurrentRocketHolder; +import net.sf.openrocket.android.util.AndroidLogWrapper; +import net.sf.openrocket.document.OpenRocketDocument; +import net.sf.openrocket.masscalc.BasicMassCalculator; +import net.sf.openrocket.masscalc.MassCalculator; +import net.sf.openrocket.masscalc.MassCalculator.MassCalcType; +import net.sf.openrocket.rocketcomponent.Configuration; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.unit.Unit; +import net.sf.openrocket.unit.UnitGroup; +import net.sf.openrocket.util.Coordinate; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.TextView; + +public class Overview extends Fragment +implements SharedPreferences.OnSharedPreferenceChangeListener +{ + + /* Calculation of CP and CG */ + private AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator(); + private MassCalculator massCalculator = new BasicMassCalculator(); + + private MotorConfigSpinner configurationSpinner; + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + AndroidLogWrapper.d(Overview.class, "Created View"); + View v = inflater.inflate(R.layout.rocket_overview, container, false); + configurationSpinner = (MotorConfigSpinner) v.findViewById(R.id.openrocketviewerConfigurationSpinner); + + return v; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + prefs.registerOnSharedPreferenceChangeListener(this); + + } + + @Override + public void onResume() { + super.onResume(); + setup(); + + } + + @Override + public void onDestroy() { + super.onDestroy(); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + prefs.unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) { + if ( this.isVisible() ) { + setup(); + } + } + + private void setup() { + final OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument(); + Rocket rocket = rocketDocument.getRocket(); + + // Find the index of the default configuration so we can preselect it. + Configuration defaultConfiguration = rocketDocument.getDefaultConfiguration(); + configurationSpinner.createAdapter(rocket); + AndroidLogWrapper.d(Overview.class, "configurationSpinner = " + configurationSpinner); + + if ( defaultConfiguration != null ) { + configurationSpinner.setSelectedConfiguration(defaultConfiguration.getMotorConfigurationID()); + } + configurationSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { + + /* (non-Javadoc) + * @see android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View, int, long) + */ + @Override + public void onItemSelected(AdapterView arg0, View arg1, + int arg2, long arg3) { + + String selectedConfigId = rocketDocument.getRocket().getMotorConfigurationIDs()[arg2]; + Configuration config = new Configuration(rocketDocument.getRocket()); + config.setMotorConfigurationID(selectedConfigId); + Coordinate cp = aerodynamicCalculator.getWorstCP(config, + new FlightConditions(config), + new WarningSet()); + + Coordinate cg = massCalculator.getCG(config, MassCalcType.LAUNCH_MASS); + + Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit(); + Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit(); + Unit stabilityUnit = UnitGroup.stabilityUnits(config).getDefaultUnit(); + + ((TextView)getActivity().findViewById(R.id.openrocketviewerCP)).setText(lengthUnit.toStringUnit(cp.x)); + ((TextView)getActivity().findViewById(R.id.openrocketviewerCG)).setText(lengthUnit.toStringUnit(cg.x)); + ((TextView)getActivity().findViewById(R.id.openrocketviewerLiftOffWeight)).setText(massUnit.toStringUnit(cg.weight)); + ((TextView)getActivity().findViewById(R.id.openrocketviewerStabilityMargin)).setText(stabilityUnit.toStringUnit(cp.x-cg.x)); + + } + + /* (non-Javadoc) + * @see android.widget.AdapterView.OnItemSelectedListener#onNothingSelected(android.widget.AdapterView) + */ + @Override + public void onNothingSelected(AdapterView arg0) { + ((TextView)getActivity().findViewById(R.id.openrocketviewerCP)).setText(""); + ((TextView)getActivity().findViewById(R.id.openrocketviewerCG)).setText(""); + ((TextView)getActivity().findViewById(R.id.openrocketviewerLiftOffWeight)).setText(""); + ((TextView)getActivity().findViewById(R.id.openrocketviewerStabilityMargin)).setText(""); + } + + }); + + Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit(); + Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit(); + + Coordinate cg = RocketUtils.getCG(rocket, MassCalcType.NO_MOTORS); + double length = RocketUtils.getLength(rocket); + ((TextView)getActivity().findViewById(R.id.openrocketviewerDesigner)).setText(rocket.getDesigner()); + ((TextView)getActivity().findViewById(R.id.openrocketviewerLength)).setText(lengthUnit.toStringUnit(length)); + ((TextView)getActivity().findViewById(R.id.openrocketviewerMass)).setText(massUnit.toStringUnit(cg.weight)); + ((TextView)getActivity().findViewById(R.id.openrocketviewerStageCount)).setText(String.valueOf(rocket.getStageCount())); + } + +} diff --git a/android/src/net/sf/openrocket/android/rocket/.#Overview.java b/android/src/net/sf/openrocket/android/rocket/.#Overview.java new file mode 120000 index 000000000..5efc10d5f --- /dev/null +++ b/android/src/net/sf/openrocket/android/rocket/.#Overview.java @@ -0,0 +1 @@ +joseph@snowball.10017:1560187057 \ No newline at end of file diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java b/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java new file mode 100644 index 000000000..6776e83c1 --- /dev/null +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketUtils.java @@ -0,0 +1,13 @@ +// this class is only used by the Android application +package net.sf.openrocket.rocketcomponent; + +import java.util.Collection; + +import net.sf.openrocket.util.Coordinate; + +public abstract class RocketUtils { + + public static double getLength(Rocket rocket) { + return rocket.getSelectedConfiguration().getLength(); + } +} From ffef415ed56cc86e40aefe3a8c3baf214b9ebdfc Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 17 Jun 2019 15:31:09 -0600 Subject: [PATCH 5/5] Added an emacs work file by accident. Removing it here --- .../openrocket/android/rocket/#Overview.java# | 146 ------------------ .../openrocket/android/rocket/.#Overview.java | 1 - 2 files changed, 147 deletions(-) delete mode 100644 android/src/net/sf/openrocket/android/rocket/#Overview.java# delete mode 120000 android/src/net/sf/openrocket/android/rocket/.#Overview.java diff --git a/android/src/net/sf/openrocket/android/rocket/#Overview.java# b/android/src/net/sf/openrocket/android/rocket/#Overview.java# deleted file mode 100644 index 236b3e8b3..000000000 --- a/android/src/net/sf/openrocket/android/rocket/#Overview.java# +++ /dev/null @@ -1,146 +0,0 @@ -package net.sf.openrocket.android.rocket; - -import net.sf.openrocket.R; -import net.sf.openrocket.aerodynamics.AerodynamicCalculator; -import net.sf.openrocket.aerodynamics.BarrowmanCalculator; -import net.sf.openrocket.aerodynamics.FlightConditions; -import net.sf.openrocket.aerodynamics.WarningSet; -import net.sf.openrocket.android.CurrentRocketHolder; -import net.sf.openrocket.android.util.AndroidLogWrapper; -import net.sf.openrocket.document.OpenRocketDocument; -import net.sf.openrocket.masscalc.BasicMassCalculator; -import net.sf.openrocket.masscalc.MassCalculator; -import net.sf.openrocket.masscalc.MassCalculator.MassCalcType; -import net.sf.openrocket.rocketcomponent.Configuration; -import net.sf.openrocket.rocketcomponent.Rocket; -import net.sf.openrocket.unit.Unit; -import net.sf.openrocket.unit.UnitGroup; -import net.sf.openrocket.util.Coordinate; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.TextView; - -public class Overview extends Fragment -implements SharedPreferences.OnSharedPreferenceChangeListener -{ - - /* Calculation of CP and CG */ - private AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator(); - private MassCalculator massCalculator = new BasicMassCalculator(); - - private MotorConfigSpinner configurationSpinner; - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - AndroidLogWrapper.d(Overview.class, "Created View"); - View v = inflater.inflate(R.layout.rocket_overview, container, false); - configurationSpinner = (MotorConfigSpinner) v.findViewById(R.id.openrocketviewerConfigurationSpinner); - - return v; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); - prefs.registerOnSharedPreferenceChangeListener(this); - - } - - @Override - public void onResume() { - super.onResume(); - setup(); - - } - - @Override - public void onDestroy() { - super.onDestroy(); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); - prefs.unregisterOnSharedPreferenceChangeListener(this); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) { - if ( this.isVisible() ) { - setup(); - } - } - - private void setup() { - final OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument(); - Rocket rocket = rocketDocument.getRocket(); - - // Find the index of the default configuration so we can preselect it. - Configuration defaultConfiguration = rocketDocument.getDefaultConfiguration(); - configurationSpinner.createAdapter(rocket); - AndroidLogWrapper.d(Overview.class, "configurationSpinner = " + configurationSpinner); - - if ( defaultConfiguration != null ) { - configurationSpinner.setSelectedConfiguration(defaultConfiguration.getMotorConfigurationID()); - } - configurationSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { - - /* (non-Javadoc) - * @see android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View, int, long) - */ - @Override - public void onItemSelected(AdapterView arg0, View arg1, - int arg2, long arg3) { - - String selectedConfigId = rocketDocument.getRocket().getMotorConfigurationIDs()[arg2]; - Configuration config = new Configuration(rocketDocument.getRocket()); - config.setMotorConfigurationID(selectedConfigId); - Coordinate cp = aerodynamicCalculator.getWorstCP(config, - new FlightConditions(config), - new WarningSet()); - - Coordinate cg = massCalculator.getCG(config, MassCalcType.LAUNCH_MASS); - - Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit(); - Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit(); - Unit stabilityUnit = UnitGroup.stabilityUnits(config).getDefaultUnit(); - - ((TextView)getActivity().findViewById(R.id.openrocketviewerCP)).setText(lengthUnit.toStringUnit(cp.x)); - ((TextView)getActivity().findViewById(R.id.openrocketviewerCG)).setText(lengthUnit.toStringUnit(cg.x)); - ((TextView)getActivity().findViewById(R.id.openrocketviewerLiftOffWeight)).setText(massUnit.toStringUnit(cg.weight)); - ((TextView)getActivity().findViewById(R.id.openrocketviewerStabilityMargin)).setText(stabilityUnit.toStringUnit(cp.x-cg.x)); - - } - - /* (non-Javadoc) - * @see android.widget.AdapterView.OnItemSelectedListener#onNothingSelected(android.widget.AdapterView) - */ - @Override - public void onNothingSelected(AdapterView arg0) { - ((TextView)getActivity().findViewById(R.id.openrocketviewerCP)).setText(""); - ((TextView)getActivity().findViewById(R.id.openrocketviewerCG)).setText(""); - ((TextView)getActivity().findViewById(R.id.openrocketviewerLiftOffWeight)).setText(""); - ((TextView)getActivity().findViewById(R.id.openrocketviewerStabilityMargin)).setText(""); - } - - }); - - Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit(); - Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit(); - - Coordinate cg = RocketUtils.getCG(rocket, MassCalcType.NO_MOTORS); - double length = RocketUtils.getLength(rocket); - ((TextView)getActivity().findViewById(R.id.openrocketviewerDesigner)).setText(rocket.getDesigner()); - ((TextView)getActivity().findViewById(R.id.openrocketviewerLength)).setText(lengthUnit.toStringUnit(length)); - ((TextView)getActivity().findViewById(R.id.openrocketviewerMass)).setText(massUnit.toStringUnit(cg.weight)); - ((TextView)getActivity().findViewById(R.id.openrocketviewerStageCount)).setText(String.valueOf(rocket.getStageCount())); - } - -} diff --git a/android/src/net/sf/openrocket/android/rocket/.#Overview.java b/android/src/net/sf/openrocket/android/rocket/.#Overview.java deleted file mode 120000 index 5efc10d5f..000000000 --- a/android/src/net/sf/openrocket/android/rocket/.#Overview.java +++ /dev/null @@ -1 +0,0 @@ -joseph@snowball.10017:1560187057 \ No newline at end of file