2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file plotps.cpp
|
|
|
|
* @brief Plot Postscript.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#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>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 13:28:34 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Generate a PostScript file (*. ps) of the circuit layer.
|
|
|
|
* If layer < 0: all layers are plotted.
|
2007-08-20 13:28:34 +00:00
|
|
|
*/
|
2011-09-29 16:49:40 +00:00
|
|
|
bool PCB_BASE_FRAME::ExportToPostScriptFile( const wxString& aFullFileName, int aLayer,
|
2012-01-03 17:14:17 +00:00
|
|
|
bool aUseA4, EDA_DRAW_MODE_T aTraceMode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
const PAGE_INFO& pageInfo = GetPageSettings();
|
2012-04-05 18:27:56 +00:00
|
|
|
PCB_PLOT_PARAMS plotOpts = GetPlotSettings();
|
2011-12-22 21:57:50 +00:00
|
|
|
|
|
|
|
wxSize paperSizeIU;
|
|
|
|
wxSize boardSize;
|
|
|
|
wxPoint boardCenter;
|
|
|
|
bool center = false;
|
|
|
|
double scale;
|
|
|
|
double paperscale;
|
|
|
|
wxPoint offset;
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
PAGE_INFO pageA4( wxT( "A4" ) );
|
|
|
|
|
|
|
|
const PAGE_INFO* sheetPS;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
FILE* output_file = wxFopen( aFullFileName, wxT( "wt" ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( output_file == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2010-01-01 13:30:39 +00:00
|
|
|
return false;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plotOpts.m_PlotScale != 1.0 || plotOpts.m_AutoScale )
|
2011-12-22 21:57:50 +00:00
|
|
|
{
|
|
|
|
// when scale != 1.0 we must calculate the position in page
|
|
|
|
// because actual position has no meaning
|
|
|
|
center = true;
|
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
// Set default line width
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plotOpts.m_PlotLineWidth < 1 )
|
|
|
|
plotOpts.m_PlotLineWidth = 1;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
wxSize pageSizeIU = GetPageSizeIU();
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
if( aUseA4 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
sheetPS = &pageA4;
|
|
|
|
paperSizeIU = pageA4.GetSizeIU();
|
|
|
|
paperscale = (double) paperSizeIU.x / pageSizeIU.x;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
sheetPS = &pageInfo;
|
|
|
|
paperSizeIU = pageSizeIU;
|
2009-06-29 05:30:08 +00:00
|
|
|
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();
|
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
boardSize = bbbox.GetSize();
|
|
|
|
boardCenter = bbbox.Centre();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plotOpts.m_AutoScale ) // Optimum scale
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-06-29 05:30:08 +00:00
|
|
|
// Fit to 80% of the page
|
2011-12-22 21:57:50 +00:00
|
|
|
double Xscale = (paperSizeIU.x * 0.8) / boardSize.x;
|
|
|
|
double Yscale = (paperSizeIU.y * 0.8) / boardSize.y;
|
|
|
|
|
2009-06-29 05:30:08 +00:00
|
|
|
scale = MIN( Xscale, Yscale );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2011-09-29 16:49:40 +00:00
|
|
|
{
|
2012-04-05 18:27:56 +00:00
|
|
|
scale = plotOpts.m_PlotScale * paperscale;
|
2011-09-29 16:49:40 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
if( center )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
offset.x = KiROUND( (double) boardCenter.x - ( (double) paperSizeIU.x / 2.0 ) / scale );
|
|
|
|
offset.y = KiROUND( (double) boardCenter.y - ( (double) paperSizeIU.y / 2.0 ) / scale );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-06-29 05:30:08 +00:00
|
|
|
else
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-06-29 05:30:08 +00:00
|
|
|
offset.x = 0;
|
|
|
|
offset.y = 0;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
PS_PLOTTER* plotter = new PS_PLOTTER();
|
2011-12-22 21:57:50 +00:00
|
|
|
|
|
|
|
plotter->SetPageSettings( *sheetPS );
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
// why did we have to change these settings?
|
|
|
|
SetPlotSettings( plotOpts );
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
plotter->SetScaleAdjust( plotOpts.m_FineScaleAdjustX,
|
2012-04-05 18:27:56 +00:00
|
|
|
plotOpts.m_FineScaleAdjustY );
|
2012-05-03 18:37:56 +00:00
|
|
|
plotter->SetPlotWidthAdj( plotOpts.m_FineWidthAdjust );
|
2012-06-09 09:38:58 +00:00
|
|
|
plotter->SetViewport( offset, IU_PER_DECIMILS, scale,
|
2012-05-03 18:37:56 +00:00
|
|
|
plotOpts.m_PlotMirror );
|
|
|
|
plotter->SetDefaultLineWidth( plotOpts.m_PlotLineWidth );
|
|
|
|
plotter->SetCreator( wxT( "PCBNEW-PS" ) );
|
|
|
|
plotter->SetFilename( aFullFileName );
|
|
|
|
plotter->SetPsTextMode( PSTEXTMODE_PHANTOM );
|
|
|
|
plotter->StartPlot( output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
/* The worksheet is not significant with scale!=1... It is with paperscale!=1, anyway */
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plotOpts.m_PlotFrameRef && !center )
|
2012-06-09 09:38:58 +00:00
|
|
|
PlotWorkSheet( plotter, GetScreen(), plotOpts.GetPlotLineWidth() );
|
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
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plotOpts.m_PlotPSNegative )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
int margin = 500; // Add a 0.5 inch margin around the board
|
2012-05-03 18:37:56 +00:00
|
|
|
plotter->SetNegative( true );
|
|
|
|
plotter->SetColor( WHITE ); // Which will be plotted as black
|
|
|
|
plotter->Rect( wxPoint( bbbox.GetX() - margin,
|
++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
|
|
|
bbbox.GetY() - margin ),
|
|
|
|
wxPoint( bbbox.GetRight() + margin,
|
|
|
|
bbbox.GetBottom() + margin ),
|
2009-06-29 05:30:08 +00:00
|
|
|
FILLED_SHAPE );
|
2012-05-03 18:37:56 +00:00
|
|
|
plotter->SetColor( BLACK );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
Plot_Layer( plotter, aLayer, aTraceMode );
|
2012-05-03 18:37:56 +00:00
|
|
|
plotter->EndPlot();
|
2009-06-28 16:50:42 +00:00
|
|
|
delete plotter;
|
2010-01-01 13:30:39 +00:00
|
|
|
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|