kicad/pcbnew/plotps.cpp

138 lines
4.0 KiB
C++
Raw Normal View History

/**
* @file plotps.cpp
* @brief Plot Postscript.
*/
#include "fctsys.h"
#include "common.h"
#include "plot_common.h"
#include "confirm.h"
#include "trigo.h"
#include "wxBasePcbFrame.h"
#include "macros.h"
#include "class_board.h"
#include "pcbnew.h"
#include "protos.h"
#include "pcbplot.h"
/* Generate a PostScript file (*. ps) of the circuit layer.
* If layer < 0: all layers are plotted.
*/
bool PCB_BASE_FRAME::ExportToPostScriptFile( const wxString& aFullFileName, int aLayer,
bool aUseA4, GRTraceMode aTraceMode )
{
2009-06-29 05:30:08 +00:00
wxSize SheetSize;
2007-08-23 04:28:46 +00:00
wxSize PaperSize;
wxSize BoardSize;
wxPoint BoardCenter;
bool Center = false;
Ki_PageDescr* currentsheet = GetScreen()->m_CurrentSheetDesc;
2009-06-29 05:30:08 +00:00
double scale, paperscale;
Ki_PageDescr* SheetPS;
2009-06-29 05:30:08 +00:00
wxPoint offset;
2007-08-23 04:28:46 +00:00
FILE* output_file = wxFopen( aFullFileName, wxT( "wt" ) );
if( output_file == NULL )
2007-08-23 04:28:46 +00:00
{
return false;
2007-08-23 04:28:46 +00:00
}
SetLocaleTo_C_standard();
2007-08-23 04:28:46 +00:00
if( g_PcbPlotOptions.m_PlotScale != 1.0 || g_PcbPlotOptions.m_AutoScale )
Center = true; // when scale != 1.0 we must calculate the position in page
// because actual position has no meaning
2008-03-22 05:55:06 +00:00
2007-08-23 04:28:46 +00:00
// Set default line width
if( g_PcbPlotOptions.m_PlotLineWidth < 1 )
g_PcbPlotOptions.m_PlotLineWidth = 1;
2007-08-23 04:28:46 +00:00
SheetSize.x = currentsheet->m_Size.x * U_PCB;
SheetSize.y = currentsheet->m_Size.y * U_PCB;
2008-03-22 05:55:06 +00:00
if( aUseA4 )
2007-08-23 04:28:46 +00:00
{
2009-06-29 05:30:08 +00:00
SheetPS = &g_Sheet_A4;
PaperSize.x = g_Sheet_A4.m_Size.x * U_PCB;
PaperSize.y = g_Sheet_A4.m_Size.y * U_PCB;
paperscale = (float) PaperSize.x / SheetSize.x;
2007-08-23 04:28:46 +00:00
}
else
{
2009-06-29 05:30:08 +00:00
SheetPS = currentsheet;
PaperSize = SheetSize;
paperscale = 1;
2007-08-23 04:28:46 +00:00
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
EDA_RECT bbbox = GetBoardBoundingBox();
BoardSize = bbbox.GetSize();
BoardCenter = bbbox.Centre();
2007-08-23 04:28:46 +00:00
if( g_PcbPlotOptions.m_AutoScale ) // Optimum scale
2007-08-23 04:28:46 +00:00
{
2009-06-29 05:30:08 +00:00
double Xscale, Yscale;
// Fit to 80% of the page
Xscale = (PaperSize.x * 0.8) / BoardSize.x;
Yscale = (PaperSize.y * 0.8) / BoardSize.y;
scale = MIN( Xscale, Yscale );
2007-08-23 04:28:46 +00:00
}
else
{
scale = g_PcbPlotOptions.m_PlotScale * paperscale;
}
2007-08-23 04:28:46 +00:00
if( Center )
{
offset.x = wxRound( (double) BoardCenter.x - ( (double) PaperSize.x / 2.0 ) / scale );
offset.y = wxRound( (double) BoardCenter.y - ( (double) PaperSize.y / 2.0 ) / scale );
2007-08-23 04:28:46 +00:00
}
2009-06-29 05:30:08 +00:00
else
{
2009-06-29 05:30:08 +00:00
offset.x = 0;
offset.y = 0;
2007-08-23 04:28:46 +00:00
}
PS_PLOTTER* plotter = new PS_PLOTTER();
2009-06-29 05:30:08 +00:00
plotter->set_paper_size( SheetPS );
plotter->set_scale_adjust( g_PcbPlotOptions.m_FineScaleAdjustX,
2011-12-16 18:15:24 +00:00
g_PcbPlotOptions.m_FineScaleAdjustY );
plotter->set_viewport( offset, scale, g_PcbPlotOptions.m_PlotMirror );
plotter->set_default_line_width( g_PcbPlotOptions.m_PlotLineWidth );
2009-06-29 05:30:08 +00:00
plotter->set_creator( wxT( "PCBNEW-PS" ) );
plotter->set_filename( aFullFileName );
2009-06-29 05:30:08 +00:00
plotter->start_plot( output_file );
/* The worksheet is not significant with scale!=1... It is with paperscale!=1, anyway */
if( g_PcbPlotOptions.m_PlotFrameRef && !Center )
2009-06-29 05:30:08 +00:00
PlotWorkSheet( plotter, GetScreen() );
2007-08-23 04:28:46 +00:00
// If plot a negative board:
// Draw a black rectangle (background for plot board in white)
// and switch the current color to WHITE
if( g_PcbPlotOptions.m_PlotPSNegative )
{
int margin = 500; // Add a 0.5 inch margin around the board
2009-06-29 05:30:08 +00:00
plotter->set_negative( true );
plotter->set_color( WHITE ); // Which will be plotted as black
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
plotter->rect( wxPoint( bbbox.GetX() - margin,
bbbox.GetY() - margin ),
wxPoint( bbbox.GetRight() + margin,
bbbox.GetBottom() + margin ),
2009-06-29 05:30:08 +00:00
FILLED_SHAPE );
plotter->set_color( BLACK );
}
Plot_Layer( plotter, aLayer, aTraceMode );
plotter->end_plot();
delete plotter;
SetLocaleTo_Default();
return true;
}