2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file plotps.cpp
|
|
|
|
* @brief Plot Postscript.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "plot_common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "trigo.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "wxBasePcbFrame.h"
|
|
|
|
#include "macros.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "class_board.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2009-06-28 16:50:42 +00:00
|
|
|
#include "protos.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#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,
|
|
|
|
bool aUseA4, GRTraceMode aTraceMode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-06-29 05:30:08 +00:00
|
|
|
wxSize SheetSize;
|
2007-08-23 04:28:46 +00:00
|
|
|
wxSize PaperSize;
|
|
|
|
wxSize BoardSize;
|
|
|
|
wxPoint BoardCenter;
|
2011-09-07 19:41:04 +00:00
|
|
|
bool Center = false;
|
2008-04-17 16:25:29 +00:00
|
|
|
Ki_PageDescr* currentsheet = GetScreen()->m_CurrentSheetDesc;
|
2009-06-29 05:30:08 +00:00
|
|
|
double scale, paperscale;
|
2009-06-28 16:50:42 +00:00
|
|
|
Ki_PageDescr* SheetPS;
|
2009-06-29 05:30:08 +00:00
|
|
|
wxPoint offset;
|
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
|
|
|
}
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
SetLocaleTo_C_standard();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2010-12-11 18:40:39 +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
|
2010-12-11 18:40:39 +00:00
|
|
|
if( g_PcbPlotOptions.m_PlotLineWidth < 1 )
|
|
|
|
g_PcbPlotOptions.m_PlotLineWidth = 1;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-06-28 16:50:42 +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
|
|
|
|
2011-09-29 16:49:40 +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
|
|
|
}
|
|
|
|
|
2011-02-25 16:23:24 +00:00
|
|
|
m_Pcb->ComputeBoundingBox();
|
2007-08-23 04:28:46 +00:00
|
|
|
BoardSize = m_Pcb->m_BoundaryBox.GetSize();
|
|
|
|
BoardCenter = m_Pcb->m_BoundaryBox.Centre();
|
|
|
|
|
2010-12-11 18:40:39 +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
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2011-09-29 16:49:40 +00:00
|
|
|
{
|
2010-12-11 18:40:39 +00:00
|
|
|
scale = g_PcbPlotOptions.m_PlotScale * paperscale;
|
2011-09-29 16:49:40 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( Center )
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
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-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();
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->set_paper_size( SheetPS );
|
2010-12-11 18:40:39 +00:00
|
|
|
plotter->set_scale_adjust( g_PcbPlotOptions.m_FineScaleAdjustX,
|
|
|
|
g_PcbPlotOptions.m_FineScaleAdjustX );
|
|
|
|
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" ) );
|
2011-09-29 16:49:40 +00:00
|
|
|
plotter->set_filename( aFullFileName );
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->start_plot( 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 */
|
2010-12-11 18:40:39 +00:00
|
|
|
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
|
2010-12-11 18:40:39 +00:00
|
|
|
if( g_PcbPlotOptions.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
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->set_negative( true );
|
2009-11-20 14:55:20 +00:00
|
|
|
plotter->set_color( WHITE ); // Which will be plotted as black
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->rect( wxPoint( m_Pcb->m_BoundaryBox.GetX() - margin,
|
|
|
|
m_Pcb->m_BoundaryBox.GetY() - margin ),
|
|
|
|
wxPoint( m_Pcb->m_BoundaryBox.GetRight() + margin,
|
|
|
|
m_Pcb->m_BoundaryBox.GetBottom() + margin ),
|
|
|
|
FILLED_SHAPE );
|
|
|
|
plotter->set_color( BLACK );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
Plot_Layer( plotter, aLayer, aTraceMode );
|
2009-06-28 16:50:42 +00:00
|
|
|
plotter->end_plot();
|
|
|
|
delete plotter;
|
|
|
|
SetLocaleTo_Default();
|
2010-01-01 13:30:39 +00:00
|
|
|
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|