Fix NPE
This commit is contained in:
parent
e68fbafde9
commit
3ff98a01d2
@ -4,7 +4,6 @@
|
|||||||
package net.sf.openrocket.gui.print;
|
package net.sf.openrocket.gui.print;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -31,12 +30,13 @@ import net.sf.openrocket.unit.UnitGroup;
|
|||||||
import net.sf.openrocket.util.Chars;
|
import net.sf.openrocket.util.Chars;
|
||||||
import net.sf.openrocket.util.Coordinate;
|
import net.sf.openrocket.util.Coordinate;
|
||||||
|
|
||||||
|
import org.uispec4j.utils.Utils;
|
||||||
|
|
||||||
import com.itextpdf.text.Document;
|
import com.itextpdf.text.Document;
|
||||||
import com.itextpdf.text.DocumentException;
|
import com.itextpdf.text.DocumentException;
|
||||||
import com.itextpdf.text.Element;
|
import com.itextpdf.text.Element;
|
||||||
import com.itextpdf.text.Paragraph;
|
import com.itextpdf.text.Paragraph;
|
||||||
import com.itextpdf.text.Rectangle;
|
import com.itextpdf.text.Rectangle;
|
||||||
import com.itextpdf.text.pdf.BaseFont;
|
|
||||||
import com.itextpdf.text.pdf.DefaultFontMapper;
|
import com.itextpdf.text.pdf.DefaultFontMapper;
|
||||||
import com.itextpdf.text.pdf.PdfContentByte;
|
import com.itextpdf.text.pdf.PdfContentByte;
|
||||||
import com.itextpdf.text.pdf.PdfPCell;
|
import com.itextpdf.text.pdf.PdfPCell;
|
||||||
@ -80,9 +80,9 @@ public class DesignReport {
|
|||||||
* The logger.
|
* The logger.
|
||||||
*/
|
*/
|
||||||
private static final LogHelper log = Application.getLogger();
|
private static final LogHelper log = Application.getLogger();
|
||||||
public static final double SCALE_FUDGE_FACTOR = 0.4d;
|
public static final double SCALE_FUDGE_FACTOR = 0.4d;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The OR Document.
|
* The OR Document.
|
||||||
*/
|
*/
|
||||||
private OpenRocketDocument rocketDocument;
|
private OpenRocketDocument rocketDocument;
|
||||||
@ -97,10 +97,10 @@ public class DesignReport {
|
|||||||
*/
|
*/
|
||||||
protected Document document;
|
protected Document document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The figure rotation.
|
* The figure rotation.
|
||||||
*/
|
*/
|
||||||
private double rotation = 0d;
|
private double rotation = 0d;
|
||||||
|
|
||||||
/** The displayed strings. */
|
/** The displayed strings. */
|
||||||
private static final String STAGES = "Stages: ";
|
private static final String STAGES = "Stages: ";
|
||||||
@ -133,13 +133,13 @@ public class DesignReport {
|
|||||||
*
|
*
|
||||||
* @param theRocDoc the OR document
|
* @param theRocDoc the OR document
|
||||||
* @param theIDoc the iText document
|
* @param theIDoc the iText document
|
||||||
* @param figureRotation the angle the figure is rotated on the screen; printed report will mimic
|
* @param figureRotation the angle the figure is rotated on the screen; printed report will mimic
|
||||||
*/
|
*/
|
||||||
public DesignReport(OpenRocketDocument theRocDoc, Document theIDoc, Double figureRotation) {
|
public DesignReport(OpenRocketDocument theRocDoc, Document theIDoc, Double figureRotation) {
|
||||||
document = theIDoc;
|
document = theIDoc;
|
||||||
rocketDocument = theRocDoc;
|
rocketDocument = theRocDoc;
|
||||||
panel = new RocketPanel(rocketDocument);
|
panel = new RocketPanel(rocketDocument);
|
||||||
rotation = figureRotation;
|
rotation = figureRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,7 +163,7 @@ public class DesignReport {
|
|||||||
PdfContentByte canvas = writer.getDirectContent();
|
PdfContentByte canvas = writer.getDirectContent();
|
||||||
|
|
||||||
final PrintFigure figure = new PrintFigure(configuration);
|
final PrintFigure figure = new PrintFigure(configuration);
|
||||||
figure.setRotation(rotation);
|
figure.setRotation(rotation);
|
||||||
|
|
||||||
FigureElement cp = panel.getExtraCP();
|
FigureElement cp = panel.getExtraCP();
|
||||||
FigureElement cg = panel.getExtraCG();
|
FigureElement cg = panel.getExtraCG();
|
||||||
@ -218,7 +218,7 @@ public class DesignReport {
|
|||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
String[] motorIds = rocket.getMotorConfigurationIDs();
|
String[] motorIds = rocket.getMotorConfigurationIDs();
|
||||||
List<Simulation> simulations = rocketDocument.getSimulations();
|
List<Simulation> simulations = rocketDocument.getSimulations();
|
||||||
|
|
||||||
for (int j = 0; j < motorIds.length; j++) {
|
for (int j = 0; j < motorIds.length; j++) {
|
||||||
String motorId = motorIds[j];
|
String motorId = motorIds[j];
|
||||||
@ -233,7 +233,7 @@ public class DesignReport {
|
|||||||
if (j > 1) {
|
if (j > 1) {
|
||||||
leading = 25;
|
leading = 25;
|
||||||
}
|
}
|
||||||
FlightData flight = findSimulation(motorId, simulations);
|
FlightData flight = findSimulation(motorId, simulations);
|
||||||
addFlightData(flight, rocket, motorId, parent, leading);
|
addFlightData(flight, rocket, motorId, parent, leading);
|
||||||
addMotorData(rocket, motorId, parent);
|
addMotorData(rocket, motorId, parent);
|
||||||
document.add(parent);
|
document.add(parent);
|
||||||
@ -258,8 +258,8 @@ public class DesignReport {
|
|||||||
* @return the scale of the diagram
|
* @return the scale of the diagram
|
||||||
*/
|
*/
|
||||||
private double paintRocketDiagram(final int thePageImageableWidth, final int thePageImageableHeight,
|
private double paintRocketDiagram(final int thePageImageableWidth, final int thePageImageableHeight,
|
||||||
final PdfContentByte theCanvas, final PrintFigure theFigure,
|
final PdfContentByte theCanvas, final PrintFigure theFigure,
|
||||||
final FigureElement theCp, final FigureElement theCg) {
|
final FigureElement theCp, final FigureElement theCg) {
|
||||||
theFigure.clearAbsoluteExtra();
|
theFigure.clearAbsoluteExtra();
|
||||||
theFigure.clearRelativeExtra();
|
theFigure.clearRelativeExtra();
|
||||||
theFigure.addRelativeExtra(theCp);
|
theFigure.addRelativeExtra(theCp);
|
||||||
@ -277,14 +277,14 @@ public class DesignReport {
|
|||||||
|
|
||||||
final DefaultFontMapper mapper = new DefaultFontMapper();
|
final DefaultFontMapper mapper = new DefaultFontMapper();
|
||||||
Graphics2D g2d = theCanvas.createGraphics(thePageImageableWidth, thePageImageableHeight * 2, mapper);
|
Graphics2D g2d = theCanvas.createGraphics(thePageImageableWidth, thePageImageableHeight * 2, mapper);
|
||||||
final double halfFigureHeight = SCALE_FUDGE_FACTOR * theFigure.getFigureHeightPx()/2;
|
final double halfFigureHeight = SCALE_FUDGE_FACTOR * theFigure.getFigureHeightPx() / 2;
|
||||||
int y = PrintUnit.POINTS_PER_INCH;
|
int y = PrintUnit.POINTS_PER_INCH;
|
||||||
//If the y dimension is negative, then it will potentially be drawn off the top of the page. Move the origin
|
//If the y dimension is negative, then it will potentially be drawn off the top of the page. Move the origin
|
||||||
//to allow for this.
|
//to allow for this.
|
||||||
if (theFigure.getDimensions().getY() < 0.0d) {
|
if (theFigure.getDimensions().getY() < 0.0d) {
|
||||||
y += (int)halfFigureHeight;
|
y += (int) halfFigureHeight;
|
||||||
}
|
}
|
||||||
g2d.translate(20, y);
|
g2d.translate(20, y);
|
||||||
|
|
||||||
g2d.scale(SCALE_FUDGE_FACTOR, SCALE_FUDGE_FACTOR);
|
g2d.scale(SCALE_FUDGE_FACTOR, SCALE_FUDGE_FACTOR);
|
||||||
theFigure.paint(g2d);
|
theFigure.paint(g2d);
|
||||||
@ -385,9 +385,9 @@ public class DesignReport {
|
|||||||
|
|
||||||
final Unit motorUnit = UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit();
|
final Unit motorUnit = UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit();
|
||||||
motorTable.addCell(ITextHelper.createCell(motorUnit.toString(motor.getDiameter()) +
|
motorTable.addCell(ITextHelper.createCell(motorUnit.toString(motor.getDiameter()) +
|
||||||
"/" +
|
"/" +
|
||||||
motorUnit.toString(motor.getLength()) + " " +
|
motorUnit.toString(motor.getLength()) + " " +
|
||||||
motorUnit.toString(), border));
|
motorUnit.toString(), border));
|
||||||
|
|
||||||
// Sum up total count
|
// Sum up total count
|
||||||
totalMotorCount += motorCount;
|
totalMotorCount += motorCount;
|
||||||
@ -407,11 +407,11 @@ public class DesignReport {
|
|||||||
motorTable.addCell(ITextHelper.createCell("", border));
|
motorTable.addCell(ITextHelper.createCell("", border));
|
||||||
motorTable.addCell(ITextHelper.createCell("", border));
|
motorTable.addCell(ITextHelper.createCell("", border));
|
||||||
motorTable.addCell(ITextHelper.createCell(
|
motorTable.addCell(ITextHelper.createCell(
|
||||||
UnitGroup.UNITS_IMPULSE.getDefaultUnit().toStringUnit(totalImpulse), border));
|
UnitGroup.UNITS_IMPULSE.getDefaultUnit().toStringUnit(totalImpulse), border));
|
||||||
motorTable.addCell(ITextHelper.createCell(
|
motorTable.addCell(ITextHelper.createCell(
|
||||||
ttwFormat.format(totalTTW) + ":1", border));
|
ttwFormat.format(totalTTW) + ":1", border));
|
||||||
motorTable.addCell(ITextHelper.createCell(
|
motorTable.addCell(ITextHelper.createCell(
|
||||||
UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(totalPropMass), border));
|
UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(totalPropMass), border));
|
||||||
motorTable.addCell(ITextHelper.createCell("", border));
|
motorTable.addCell(ITextHelper.createCell("", border));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -426,7 +426,7 @@ public class DesignReport {
|
|||||||
/**
|
/**
|
||||||
* Add the flight data for a simulation configuration to the table.
|
* Add the flight data for a simulation configuration to the table.
|
||||||
*
|
*
|
||||||
* @param flight the flight data for a single simulation
|
* @param flight the flight data for a single simulation
|
||||||
* @param theRocket the rocket
|
* @param theRocket the rocket
|
||||||
* @param motorId a motor configuration id
|
* @param motorId a motor configuration id
|
||||||
* @param parent the parent to which the simulation flight data will be added
|
* @param parent the parent to which the simulation flight data will be added
|
||||||
@ -434,7 +434,7 @@ public class DesignReport {
|
|||||||
*/
|
*/
|
||||||
private void addFlightData(final FlightData flight, final Rocket theRocket, final String motorId, final PdfPTable parent, int leading) {
|
private void addFlightData(final FlightData flight, final Rocket theRocket, final String motorId, final PdfPTable parent, int leading) {
|
||||||
|
|
||||||
// Output the flight data
|
// Output the flight data
|
||||||
if (flight != null) {
|
if (flight != null) {
|
||||||
try {
|
try {
|
||||||
final Unit distanceUnit = UnitGroup.UNITS_DISTANCE.getDefaultUnit();
|
final Unit distanceUnit = UnitGroup.UNITS_DISTANCE.getDefaultUnit();
|
||||||
@ -444,7 +444,7 @@ public class DesignReport {
|
|||||||
PdfPTable labelTable = new PdfPTable(2);
|
PdfPTable labelTable = new PdfPTable(2);
|
||||||
labelTable.setWidths(new int[] { 3, 2 });
|
labelTable.setWidths(new int[] { 3, 2 });
|
||||||
final Paragraph chunk = ITextHelper.createParagraph(stripBrackets(
|
final Paragraph chunk = ITextHelper.createParagraph(stripBrackets(
|
||||||
theRocket.getMotorConfigurationNameOrDescription(motorId)), PrintUtilities.BOLD);
|
theRocket.getMotorConfigurationNameOrDescription(motorId)), PrintUtilities.BOLD);
|
||||||
chunk.setLeading(leading);
|
chunk.setLeading(leading);
|
||||||
chunk.setSpacingAfter(3f);
|
chunk.setSpacingAfter(3f);
|
||||||
|
|
||||||
@ -468,8 +468,8 @@ public class DesignReport {
|
|||||||
labelTable.addCell(ITextHelper.createCell(MAX_VELOCITY, 2, 2));
|
labelTable.addCell(ITextHelper.createCell(MAX_VELOCITY, 2, 2));
|
||||||
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getMaxVelocity()), 2, 2));
|
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getMaxVelocity()), 2, 2));
|
||||||
|
|
||||||
labelTable.addCell(ITextHelper.createCell(DEPLOYMENT_VELOCITY, 2,2));
|
labelTable.addCell(ITextHelper.createCell(DEPLOYMENT_VELOCITY, 2, 2));
|
||||||
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getDeploymentVelocity()),2,2));
|
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getDeploymentVelocity()), 2, 2));
|
||||||
|
|
||||||
labelTable.addCell(ITextHelper.createCell(LANDING_VELOCITY, 2, 2));
|
labelTable.addCell(ITextHelper.createCell(LANDING_VELOCITY, 2, 2));
|
||||||
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getGroundHitVelocity()), 2, 2));
|
labelTable.addCell(ITextHelper.createCell(velocityUnit.toStringUnit(flight.getGroundHitVelocity()), 2, 2));
|
||||||
@ -486,35 +486,35 @@ public class DesignReport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locate the simulation based on the motor id. Copy the simulation and execute it, then return the resulting
|
* Locate the simulation based on the motor id. Copy the simulation and execute it, then return the resulting
|
||||||
* flight data.
|
* flight data.
|
||||||
*
|
*
|
||||||
* @param motorId the motor id corresponding to the simulation to find
|
* @param motorId the motor id corresponding to the simulation to find
|
||||||
* @param simulations the list of simulations currently associated with the rocket
|
* @param simulations the list of simulations currently associated with the rocket
|
||||||
*
|
*
|
||||||
* @return the flight data from the simulation for the specified motor id, or null if not found
|
* @return the flight data from the simulation for the specified motor id, or null if not found
|
||||||
*/
|
*/
|
||||||
private FlightData findSimulation(final String motorId, List<Simulation> simulations) {
|
private FlightData findSimulation(final String motorId, List<Simulation> simulations) {
|
||||||
// Perform flight simulation
|
// Perform flight simulation
|
||||||
FlightData flight = null;
|
FlightData flight = null;
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < simulations.size(); i++) {
|
for (int i = 0; i < simulations.size(); i++) {
|
||||||
Simulation simulation = simulations.get(i);
|
Simulation simulation = simulations.get(i);
|
||||||
if (simulation.getOptions().getMotorConfigurationID().equals(motorId)) {
|
if (Utils.equals(simulation.getOptions().getMotorConfigurationID(), motorId)) {
|
||||||
simulation = simulation.copy();
|
simulation = simulation.copy();
|
||||||
simulation.simulate();
|
simulation.simulate();
|
||||||
flight = simulation.getSimulatedData();
|
flight = simulation.getSimulatedData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SimulationException e1) {
|
} catch (SimulationException e1) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
return flight;
|
return flight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strip [] brackets from a string.
|
* Strip [] brackets from a string.
|
||||||
*
|
*
|
||||||
* @param target the original string
|
* @param target the original string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user