DGP - design report figure honors rotation angle of main figure; added rocksim constants for future use

This commit is contained in:
Doug Pedrick 2012-03-25 15:56:12 +00:00
parent 09067de7cf
commit 3fa0f9ce67
6 changed files with 44 additions and 26 deletions

View File

@ -1,3 +1,8 @@
2012-03-25 Doug Pedrick
* Printed rocket figure in design report now honors rotation angle of main figure; fixed bug in layout where the
figure was clipped in the page margin.
2012-03-18 Jason Blood
* Updated importing images to freeform fin sets to work with color images with improved description

View File

@ -79,6 +79,10 @@ public class RocksimCommonConstants {
public static final String ROCK_SIM_DOCUMENT = "RockSimDocument";
public static final String FILE_VERSION = "FileVersion";
public static final String DESIGN_INFORMATION = "DesignInformation";
public static final String TUBE_FIN_SET = "TubeFinSet";
public static final String RING_TAIL = "RingTail";
public static final String EXTERNAL_POD = "ExternalPod";
/**
* Length conversion. Rocksim is in millimeters, OpenRocket in meters.
*/
@ -103,7 +107,4 @@ public class RocksimCommonConstants {
* Radius conversion. Rocksim is always in diameters, OpenRocket mostly in radius.
*/
public static final int ROCKSIM_TO_OPENROCKET_RADIUS = 2 * ROCKSIM_TO_OPENROCKET_LENGTH;
public static final String TUBE_FIN_SET = "TubeFinSet";
public static final String RING_TAIL = "RingTail";
public static final String EXTERNAL_POD = "ExternalPod";
}

View File

@ -61,22 +61,25 @@ public class PrintDialog extends JDialog implements TreeSelectionListener {
private JButton previewButton;
private JButton saveAsPDF;
private JButton cancel;
private double rotation = 0d;
private final static SwingPreferences prefs = (SwingPreferences) Application.getPreferences();
/**
* Constructor.
*
* @param parent the parent awt component
* @param orDocument the OR rocket container
* @param theRotation the angle of rocket figure rotation
*/
public PrintDialog(Window parent, OpenRocketDocument orDocument) {
public PrintDialog(Window parent, OpenRocketDocument orDocument, double theRotation) {
super(parent, trans.get("title"), ModalityType.APPLICATION_MODAL);
JPanel panel = new JPanel(new MigLayout("fill, gap rel unrel"));
this.add(panel);
rotation = theRotation;
// before any Desktop APIs are used, first check whether the API is
// supported by this particular VM on this particular host
@ -257,7 +260,7 @@ public class PrintDialog extends JDialog implements TreeSelectionListener {
/**
* Generate a report using a temporary file. The file will be deleted upon JVM exit.
*
* @param paper the name of the paper size
* @param settings the container of different print settings
*
* @return a file, populated with the "printed" output (the rocket info)
*
@ -273,7 +276,7 @@ public class PrintDialog extends JDialog implements TreeSelectionListener {
* Generate a report to a specified file.
*
* @param f the file to which rocket data will be written
* @param paper the name of the paper size
* @param settings the container of different print settings
*
* @return a file, populated with the "printed" output (the rocket info)
*
@ -281,7 +284,7 @@ public class PrintDialog extends JDialog implements TreeSelectionListener {
*/
private File generateReport(File f, PrintSettings settings) throws IOException {
Iterator<PrintableContext> toBePrinted = currentTree.getToBePrinted();
new PrintController().print(document, toBePrinted, new FileOutputStream(f), settings);
new PrintController().print(document, toBePrinted, new FileOutputStream(f), settings, rotation);
return f;
}

View File

@ -1442,7 +1442,11 @@ public class BasicFrame extends JFrame {
*
*/
public void printAction() {
new PrintDialog(this, document).setVisible(true);
Double rotation = rocketpanel.getFigure().getRotation();
if (rotation == null) {
rotation = 0d;
}
new PrintDialog(this, document, rotation).setVisible(true);
}
/**

View File

@ -96,7 +96,12 @@ public class DesignReport {
* The iText document.
*/
protected Document document;
/**
* The figure rotation.
*/
private double rotation = 0d;
/** The displayed strings. */
private static final String STAGES = "Stages: ";
private static final String MASS_WITH_MOTORS = "Mass (with motors): ";
@ -128,11 +133,13 @@ public class DesignReport {
*
* @param theRocDoc the OR document
* @param theIDoc the iText document
* @param figureRotation the angle the figure is rotated on the screen; printed report will mimic
*/
public DesignReport(OpenRocketDocument theRocDoc, Document theIDoc) {
public DesignReport(OpenRocketDocument theRocDoc, Document theIDoc, Double figureRotation) {
document = theIDoc;
rocketDocument = theRocDoc;
panel = new RocketPanel(rocketDocument);
rotation = figureRotation;
}
/**
@ -156,6 +163,7 @@ public class DesignReport {
PdfContentByte canvas = writer.getDirectContent();
final PrintFigure figure = new PrintFigure(configuration);
figure.setRotation(rotation);
FigureElement cp = panel.getExtraCP();
FigureElement cg = panel.getExtraCG();

View File

@ -35,9 +35,10 @@ public class PrintController {
* @param toBePrinted the user chosen items to print
* @param outputFile the file being written to
* @param settings the print settings
* @param rotation the angle the rocket figure is rotated
*/
public void print(OpenRocketDocument doc, Iterator<PrintableContext> toBePrinted, OutputStream outputFile,
PrintSettings settings) {
PrintSettings settings, double rotation) {
Document idoc = new Document(getSize(settings));
PdfWriter writer = null;
@ -59,23 +60,19 @@ public class PrintController {
switch (printableContext.getPrintable()) {
case DESIGN_REPORT:
DesignReport dp = new DesignReport(doc, idoc);
DesignReport dp = new DesignReport(doc, idoc, rotation);
dp.writeToDocument(writer);
idoc.newPage();
break;
case FIN_TEMPLATE:
final FinSetPrintStrategy finWriter = new FinSetPrintStrategy(idoc,
writer,
stages);
finWriter.writeToDocument(doc.getRocket());
break;
case PARTS_DETAIL:
final PartsDetailVisitorStrategy detailVisitor = new PartsDetailVisitorStrategy(idoc,
writer,
stages);
detailVisitor.writeToDocument(doc.getRocket());
detailVisitor.close();
idoc.newPage();
final FinSetPrintStrategy finWriter = new FinSetPrintStrategy(idoc, writer, stages);
finWriter.writeToDocument(doc.getRocket());
break;
case PARTS_DETAIL:
final PartsDetailVisitorStrategy detailVisitor = new PartsDetailVisitorStrategy(idoc, writer, stages);
detailVisitor.writeToDocument(doc.getRocket());
detailVisitor.close();
idoc.newPage();
break;
case TRANSITION_TEMPLATE:
final TransitionStrategy tranWriter = new TransitionStrategy(idoc, writer, stages);