[resolves #371] MassCalculator now updates result on FlightConfiguration change

- added check in MassCalculator against last-used FlightConfiguration
- removed dead code
This commit is contained in:
Daniel_M_Williams 2017-10-15 23:37:54 -04:00
parent bd42c7ecde
commit 9c93ada83f
3 changed files with 11 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.Instanceable;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.ParallelStage;
@ -26,7 +27,7 @@ public class MassCalculator implements Monitorable {
private int rocketMassModID = -1;
private int rocketTreeModID = -1;
private FlightConfigurationId configId = FlightConfigurationId.ERROR_FCID;
/*
* Cached data. All CG data is in absolute coordinates. All moments of inertia
@ -321,7 +322,6 @@ public class MassCalculator implements Monitorable {
// if instanced, adjust children's data too.
if ( 1 < component.getInstanceCount() ){
final double curIxx = childrenData.getIxx(); // MOI about x-axis
final double curIyy = childrenData.getIyy(); // MOI about y axis
final double curIzz = childrenData.getIzz(); // MOI about z axis
@ -404,9 +404,11 @@ public class MassCalculator implements Monitorable {
*/
protected final boolean checkCache(FlightConfiguration configuration) {
if (rocketMassModID != configuration.getRocket().getMassModID() ||
rocketTreeModID != configuration.getRocket().getTreeModID()) {
rocketTreeModID != configuration.getRocket().getTreeModID() ||
configId != configuration.getId()) {
rocketMassModID = configuration.getRocket().getMassModID();
rocketTreeModID = configuration.getRocket().getTreeModID();
configId = configuration.getId();
voidMassCache();
return false;
}

View File

@ -18,22 +18,17 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.openrocket.gui.figureelements.FigureElement;
import net.sf.openrocket.gui.rocketfigure.RocketComponentShape;
import net.sf.openrocket.gui.util.ColorConversion;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.simulation.BasicEventSimulationEngine;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
@ -52,8 +47,6 @@ import net.sf.openrocket.util.Transformation;
@SuppressWarnings("serial")
public class RocketFigure extends AbstractScaleFigure {
private static final Logger log = LoggerFactory.getLogger(BasicEventSimulationEngine.class);
private static final String ROCKET_FIGURE_PACKAGE = "net.sf.openrocket.gui.rocketfigure";
private static final String ROCKET_FIGURE_SUFFIX = "Shapes";
@ -108,11 +101,6 @@ public class RocketFigure extends AbstractScaleFigure {
updateFigure();
}
public FlightConfiguration getConfiguration() {
return this.rocket.getSelectedConfiguration();
}
@Override
public Dimension getOrigin() {
return new Dimension((int) translateX, (int) translateY);
@ -456,7 +444,7 @@ public class RocketFigure extends AbstractScaleFigure {
// }
// generate shape for this component, if active
if( this.getConfiguration().isComponentActive( comp )){
if( this.rocket.getSelectedConfiguration().isComponentActive( comp )){
allShapes = addThisShape( allShapes, this.currentViewType, comp, currentLocation, currentTransform);
}

View File

@ -52,6 +52,7 @@ import net.sf.openrocket.gui.simulation.SimulationWorker;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.masscalc.MassCalculator;
import net.sf.openrocket.masscalc.MassData;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
@ -360,10 +361,6 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
return aerodynamicCalculator;
}
public FlightConfiguration getSelectedConfiguration() {
return document.getSelectedConfiguration();
}
/**
* Get the center of pressure figure element.
*
@ -599,7 +596,6 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
extraText.setTheta(cpTheta);
cg = massCalculator.getRocketLaunchMassData( curConfig).getCG();
if (cp.weight > MassCalculator.MIN_MASS){
cpx = cp.x;
@ -638,12 +634,14 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
}
}
MassData emptyInfo = massCalculator.getRocketSpentMassData( curConfig.getRocket().getEmptyConfiguration());
extraText.setCG(cgx);
extraText.setCP(cpx);
extraText.setLength(length);
extraText.setDiameter(diameter);
extraText.setMass(cg.weight);
extraText.setMassWithoutMotors( massCalculator.getRocketSpentMassData( curConfig.getRocket().getEmptyConfiguration() ).getMass() );
extraText.setMassWithoutMotors( emptyInfo.getMass() );
extraText.setWarnings(warnings);
if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) {
@ -784,6 +782,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
extraCG = new CGCaret(0, 0);
extraCP = new CPCaret(0, 0);
extraText = new RocketInfo(curConfig);
updateExtras();
figure.clearRelativeExtra();