Commit 84c7b07e authored by Wayne Stambaugh's avatar Wayne Stambaugh

Pcbnew print fixes and improvements.

* Fix offset errors when scale factor greater is than one.
* Changed behavior of fit in page when not drawing border and
  title block to fit board outline in page.
* Fix offset errors when mirroring (still not 100% correct on MSW with
  wxWidgets 2.9.4).
* Lots of the usual code cleaning and simplifying.
parent 70ca712c
...@@ -341,8 +341,8 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event ) ...@@ -341,8 +341,8 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
// Pass two printout objects: for preview, and possible printing. // Pass two printout objects: for preview, and possible printing.
wxString title = _( "Print Preview" ); wxString title = _( "Print Preview" );
wxPrintPreview* preview = wxPrintPreview* preview =
new wxPrintPreview( new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ), new wxPrintPreview( new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_Parent, title ),
new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ), new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_Parent, title ),
g_PrintData ); g_PrintData );
if( preview == NULL ) if( preview == NULL )
...@@ -396,7 +396,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) ...@@ -396,7 +396,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
wxPrinter printer( &printDialogData ); wxPrinter printer( &printDialogData );
wxString title = _( "Print" ); wxString title = _( "Print" );
BOARD_PRINTOUT_CONTROLER printout( s_Parameters, m_Parent, title ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_Parent, title );
#if !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0) #if !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0)
wxDC* dc = printout.GetDC(); wxDC* dc = printout.GetDC();
......
...@@ -162,8 +162,8 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintPreview( wxCommandEvent& event ) ...@@ -162,8 +162,8 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintPreview( wxCommandEvent& event )
// Pass two printout objects: for preview, and possible printing. // Pass two printout objects: for preview, and possible printing.
wxString title = _( "Print Preview" ); wxString title = _( "Print Preview" );
wxPrintPreview* preview = wxPrintPreview* preview =
new wxPrintPreview( new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_parent, title ), new wxPrintPreview( new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_parent, title ), new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
s_PrintData ); s_PrintData );
if( preview == NULL ) if( preview == NULL )
...@@ -200,7 +200,7 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event ) ...@@ -200,7 +200,7 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event )
wxPrintDialogData printDialogData( *s_PrintData ); wxPrintDialogData printDialogData( *s_PrintData );
wxPrinter printer( &printDialogData ); wxPrinter printer( &printDialogData );
BOARD_PRINTOUT_CONTROLER printout( s_Parameters, m_parent, _( "Print Footprint" ) ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, _( "Print Footprint" ) );
#if !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0) #if !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0)
wxDC* dc = printout.GetDC(); wxDC* dc = printout.GetDC();
......
...@@ -432,8 +432,8 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event ) ...@@ -432,8 +432,8 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
// Pass two printout objects: for preview, and possible printing. // Pass two printout objects: for preview, and possible printing.
wxString title = _( "Print Preview" ); wxString title = _( "Print Preview" );
wxPrintPreview* preview = wxPrintPreview* preview =
new wxPrintPreview( new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_parent, title ), new wxPrintPreview( new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_parent, title ), new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
s_PrintData ); s_PrintData );
if( preview == NULL ) if( preview == NULL )
...@@ -481,7 +481,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) ...@@ -481,7 +481,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
wxPrinter printer( &printDialogData ); wxPrinter printer( &printDialogData );
wxString title = _( "Print" ); wxString title = _( "Print" );
BOARD_PRINTOUT_CONTROLER printout( s_Parameters, m_parent, title ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, title );
// Alexander's patch had this removed altogether, waiting for testing. // Alexander's patch had this removed altogether, waiting for testing.
#if 0 && !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0) #if 0 && !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0)
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
*/ */
/** /**
* printout_controler.cpp * @file printout_controler.cpp
* @brief Board print handler implementation file.
*/ */
// Set this to 1 if you want to test PostScript printing under MSW. // Set this to 1 if you want to test PostScript printing under MSW.
#define wxTEST_POSTSCRIPT_IN_MSW 1 #define wxTEST_POSTSCRIPT_IN_MSW 1
...@@ -47,13 +49,21 @@ ...@@ -47,13 +49,21 @@
#endif #endif
#include <printout_controler.h> #include <printout_controler.h>
// This class is an helper to pass print parameters to print functions
/**
* Definition for enabling and disabling print controller trace output. See the
* wxWidgets documentation on using the WXTRACE environment variable.
*/
static const wxString tracePrinting( wxT( "KicadPrinting" ) );
PRINT_PARAMETERS::PRINT_PARAMETERS() PRINT_PARAMETERS::PRINT_PARAMETERS()
{ {
m_PenDefaultSize = 50; // A reasonnable minimal value to draw items m_PenDefaultSize = 50; // A reasonable minimal value to draw items
// mainly that do not have a specifed line width // mainly that do not have a specified line width
m_PrintScale = 1.0; m_PrintScale = 1.0;
m_XScaleAdjust = m_YScaleAdjust = 1.0; m_XScaleAdjust = 1.0;
m_YScaleAdjust = 1.0;
m_Print_Sheet_Ref = false; m_Print_Sheet_Ref = false;
m_PrintMaskLayer = 0xFFFFFFFF; m_PrintMaskLayer = 0xFFFFFFFF;
m_PrintMirror = false; m_PrintMirror = false;
...@@ -67,18 +77,17 @@ PRINT_PARAMETERS::PRINT_PARAMETERS() ...@@ -67,18 +77,17 @@ PRINT_PARAMETERS::PRINT_PARAMETERS()
} }
BOARD_PRINTOUT_CONTROLER::BOARD_PRINTOUT_CONTROLER( const PRINT_PARAMETERS& print_params, BOARD_PRINTOUT_CONTROLLER::BOARD_PRINTOUT_CONTROLLER( const PRINT_PARAMETERS& aParams,
EDA_DRAW_FRAME* parent, EDA_DRAW_FRAME* aParent,
const wxString& title ) : const wxString& aTitle ) :
wxPrintout( title ) wxPrintout( aTitle )
{ {
m_PrintParams = print_params; // Make a local copy of parameters. m_PrintParams = aParams; // Make a local copy of the print parameters.
// So they can change in printout controler m_Parent = aParent;
m_Parent = parent;
} }
bool BOARD_PRINTOUT_CONTROLER::OnPrintPage( int page ) bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
{ {
#ifdef PCBNEW #ifdef PCBNEW
int layers_count = NB_LAYERS; int layers_count = NB_LAYERS;
...@@ -98,7 +107,7 @@ bool BOARD_PRINTOUT_CONTROLER::OnPrintPage( int page ) ...@@ -98,7 +107,7 @@ bool BOARD_PRINTOUT_CONTROLER::OnPrintPage( int page )
if( mask_layer & mask ) if( mask_layer & mask )
jj++; jj++;
if( jj == page ) if( jj == aPage )
{ {
m_PrintParams.m_PrintMaskLayer = mask; m_PrintParams.m_PrintMaskLayer = mask;
break; break;
...@@ -125,15 +134,14 @@ bool BOARD_PRINTOUT_CONTROLER::OnPrintPage( int page ) ...@@ -125,15 +134,14 @@ bool BOARD_PRINTOUT_CONTROLER::OnPrintPage( int page )
} }
/*********************************************************/ void BOARD_PRINTOUT_CONTROLLER::GetPageInfo( int* minPage, int* maxPage,
void BOARD_PRINTOUT_CONTROLER::GetPageInfo( int* minPage, int* maxPage,
int* selPageFrom, int* selPageTo ) int* selPageFrom, int* selPageTo )
/*********************************************************/
{ {
*minPage = 1; *minPage = 1;
*selPageFrom = 1; *selPageFrom = 1;
int icnt = 1; int icnt = 1;
if( m_PrintParams.m_OptionPrintPage == 0 ) if( m_PrintParams.m_OptionPrintPage == 0 )
icnt = m_PrintParams.m_PageCount; icnt = m_PrintParams.m_PageCount;
...@@ -142,88 +150,77 @@ void BOARD_PRINTOUT_CONTROLER::GetPageInfo( int* minPage, int* maxPage, ...@@ -142,88 +150,77 @@ void BOARD_PRINTOUT_CONTROLER::GetPageInfo( int* minPage, int* maxPage,
} }
/* void BOARD_PRINTOUT_CONTROLLER::DrawPage()
* This is the real print function: print the active screen
*/
void BOARD_PRINTOUT_CONTROLER::DrawPage()
{ {
int tmpzoom; wxPoint offset;
wxPoint tmp_startvisu;
wxPoint old_org;
wxPoint DrawOffset; // Offset de trace
double userscale; double userscale;
double DrawZoom = 1; EDA_RECT boardBoundingBox;
EDA_RECT drawRect;
wxDC* dc = GetDC(); wxDC* dc = GetDC();
BASE_SCREEN* screen = m_Parent->GetScreen(); BASE_SCREEN* screen = m_Parent->GetScreen();
bool printMirror = m_PrintParams.m_PrintMirror; bool printMirror = m_PrintParams.m_PrintMirror;
wxBusyCursor dummy; wxBusyCursor dummy;
// Save old draw scale and draw offset
tmp_startvisu = screen->m_StartVisu;
tmpzoom = screen->GetZoom();
old_org = screen->m_DrawOrg;
// Change draw scale and offset to draw the whole page
screen->SetScalingFactor( DrawZoom );
screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
#ifdef PCBNEW #ifdef PCBNEW
EDA_RECT bbbox= ((PCB_BASE_FRAME*) m_Parent)->GetBoard()->ComputeBoundingBox(); if( m_PrintParams.PrintBorderAndTitleBlock() )
boardBoundingBox =((PCB_BASE_FRAME*) m_Parent)->GetBoard()->ComputeBoundingBox();
else
boardBoundingBox =((PCB_BASE_FRAME*) m_Parent)->GetBoard()->ComputeBoundingBox( true );
#else #else
EDA_RECT bbbox = ((GERBVIEW_FRAME*) m_Parent)->GetLayoutBoundingBox(); boardBoundingBox = ((GERBVIEW_FRAME*) m_Parent)->GetLayoutBoundingBox();
#endif #endif
wxSize pageSizeIU = m_Parent->GetPageSizeIU(); // internal units // Use the page size as the drawing area when the board is shown or the user scale
// is less than 1.
if( m_PrintParams.PrintBorderAndTitleBlock() )
boardBoundingBox = EDA_RECT( wxPoint( 0, 0 ), m_Parent->GetPageSizeIU() );
// In module editor, the module is located at 0,0 but for printing // In module editor, the module is located at 0,0 but for printing
// it is moved to pageSizeIU.x/2, pageSizeIU.y/2. // it is moved to pageSizeIU.x/2, pageSizeIU.y/2.
// So the equivalent board must be moved: // So the equivalent board must be moved:
if( m_Parent->IsType( MODULE_EDITOR_FRAME_TYPE ) ) if( m_Parent->IsType( MODULE_EDITOR_FRAME_TYPE ) )
{ {
bbbox.Move( wxPoint( pageSizeIU.x/2, pageSizeIU.y/2 ) ); boardBoundingBox.Move( wxPoint( boardBoundingBox.GetWidth()/2,
boardBoundingBox.GetHeight()/2 ) );
} }
wxLogTrace( tracePrinting, wxT( "Drawing bounding box: x=%d, y=%d, w=%d, h=%d" ),
boardBoundingBox.GetX(), boardBoundingBox.GetY(),
boardBoundingBox.GetWidth(), boardBoundingBox.GetHeight() );
// Compute the PCB size in internal units // Compute the PCB size in internal units
userscale = m_PrintParams.m_PrintScale; userscale = m_PrintParams.m_PrintScale;
if( userscale == 0 ) // fit in page if( m_PrintParams.m_PrintScale == 0 ) // fit in page
{ {
// Margin = 10mm userscale = 1.0;
int extra_margin = int( 10 * IU_PER_MM );
pageSizeIU.x = bbbox.GetWidth() + extra_margin * 2;
pageSizeIU.y = bbbox.GetHeight() + extra_margin * 2;
userscale = 0.99;
} }
if( (m_PrintParams.m_PrintScale > 1.0) // scale > 1 -> Recadrage wxSize scaledPageSize = m_Parent->GetPageSizeIU();
|| (m_PrintParams.m_PrintScale == 0) ) // fit in page drawRect.SetSize( scaledPageSize );
{ scaledPageSize.x = wxRound( (double) scaledPageSize.x / userscale );
DrawOffset += bbbox.Centre(); scaledPageSize.y = wxRound( (double) scaledPageSize.y / userscale );
}
if( m_PrintParams.m_PageSetupData ) if( m_PrintParams.m_PageSetupData )
{ {
wxSize pagesize; wxLogTrace( tracePrinting, wxT( "Fit size to page margins: x=%d, y=%d" ),
scaledPageSize.x, scaledPageSize.y );
pagesize.x = int( pageSizeIU.x / userscale );
pagesize.y = int( pageSizeIU.y / userscale );
FitThisSizeToPageMargins( pagesize, *m_PrintParams.m_PageSetupData ); // Always scale to the size of the paper.
FitThisSizeToPageMargins( scaledPageSize, *m_PrintParams.m_PageSetupData );
} }
// Compute Accurate scale 1 // Compute Accurate scale 1
if( userscale == 1.0 ) if( m_PrintParams.m_PrintScale == 1.0 )
{ {
// We want a 1:1 scale and margins for printing // We want a 1:1 scale and margins for printing
MapScreenSizeToPaper(); MapScreenSizeToPaper();
int w, h; int w, h;
GetPPIPrinter( &w, &h ); GetPPIPrinter( &w, &h );
double accurate_Xscale = ( (double) ( DrawZoom * w ) ) / (IU_PER_MILS*1000); double accurate_Xscale = ( (double) ( w ) ) / (IU_PER_MILS*1000);
double accurate_Yscale = ( (double) ( DrawZoom * h ) ) / (IU_PER_MILS*1000); double accurate_Yscale = ( (double) ( h ) ) / (IU_PER_MILS*1000);
if( IsPreview() ) // Scale must take in account the DC size in Preview if( IsPreview() ) // Scale must take in account the DC size in Preview
{ {
...@@ -236,8 +233,10 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() ...@@ -236,8 +233,10 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage()
accurate_Yscale *= PlotAreaSize.y; accurate_Yscale *= PlotAreaSize.y;
accurate_Yscale /= (double) h; accurate_Yscale /= (double) h;
} }
accurate_Xscale *= m_PrintParams.m_XScaleAdjust; accurate_Xscale *= m_PrintParams.m_XScaleAdjust;
accurate_Yscale *= m_PrintParams.m_YScaleAdjust; accurate_Yscale *= m_PrintParams.m_YScaleAdjust;
// Fine scale adjust // Fine scale adjust
dc->SetUserScale( accurate_Xscale, accurate_Yscale ); dc->SetUserScale( accurate_Xscale, accurate_Yscale );
} }
...@@ -245,27 +244,38 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() ...@@ -245,27 +244,38 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage()
// Get the final size of the DC in pixels // Get the final size of the DC in pixels
wxSize PlotAreaSizeInPixels; wxSize PlotAreaSizeInPixels;
dc->GetSize( &PlotAreaSizeInPixels.x, &PlotAreaSizeInPixels.y ); dc->GetSize( &PlotAreaSizeInPixels.x, &PlotAreaSizeInPixels.y );
wxLogTrace( tracePrinting, wxT( "Plot area in pixels: x=%d, y=%d" ),
PlotAreaSizeInPixels.x, PlotAreaSizeInPixels.y );
double scalex, scaley; double scalex, scaley;
dc->GetUserScale(&scalex, &scaley); dc->GetUserScale( &scalex, &scaley );
wxLogTrace( tracePrinting, wxT( "DC user scale: x=%g, y=%g" ),
scalex, scaley );
wxSize PlotAreaSizeInUserUnits; wxSize PlotAreaSizeInUserUnits;
PlotAreaSizeInUserUnits.x = (int) (PlotAreaSizeInPixels.x/scalex); PlotAreaSizeInUserUnits.x = (int) (PlotAreaSizeInPixels.x/scalex);
PlotAreaSizeInUserUnits.y = (int) (PlotAreaSizeInPixels.y/scaley); PlotAreaSizeInUserUnits.y = (int) (PlotAreaSizeInPixels.y/scaley);
wxLogTrace( tracePrinting, wxT( "Scaled plot area in user units: x=%d, y=%d" ),
PlotAreaSizeInUserUnits.x, PlotAreaSizeInUserUnits.y );
/* In some cases the plot origin is the centre of the page // In some cases the plot origin is the centre of the board outline rather than the center
* when: // of the selected paper size.
* - Asked if( m_PrintParams.CenterOnBoardOutline() )
* - scale > 1 {
* - fit in page // Here we are only drawing the board and it's contents.
*/ drawRect = boardBoundingBox;
if( m_PrintParams.m_ForceCentered offset.x += wxRound( (double) -scaledPageSize.x / 2.0 );
|| (m_PrintParams.m_PrintScale > 1.0) // scale > 1 offset.y += wxRound( (double) -scaledPageSize.y / 2.0 );
|| (m_PrintParams.m_PrintScale == 0) ) // fit in page
wxPoint center = boardBoundingBox.Centre();
if( printMirror )
{ {
DrawOffset.x -= PlotAreaSizeInUserUnits.x / 2; // Calculate the mirrored center of the board.
DrawOffset.y -= PlotAreaSizeInUserUnits.y / 2; center.y = m_Parent->GetPageSizeIU().y - boardBoundingBox.Centre().y;
} }
screen->m_DrawOrg = DrawOffset; offset += center;
}
GRResetPenAndBrush( dc ); GRResetPenAndBrush( dc );
...@@ -280,21 +290,14 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() ...@@ -280,21 +290,14 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage()
// and that allows calculations without overflow // and that allows calculations without overflow
panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) ); panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) );
m_Parent->GetScreen()->m_IsPrinting = true; screen->m_IsPrinting = true;
EDA_COLOR_T bg_color = g_DrawBgColor; EDA_COLOR_T bg_color = g_DrawBgColor;
if( m_PrintParams.m_Print_Sheet_Ref )
m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
IU_PER_MILS, m_Parent->GetScreenDesc() );
if( printMirror ) if( printMirror )
{ {
// To plot mirror, we reverse the y axis, and modify the plot y origin // To plot mirror, we reverse the y axis, and modify the plot y origin
dc->SetAxisOrientation( true, true ); dc->SetAxisOrientation( true, true );
if( userscale < 1.0 )
scaley /= userscale;
/* Plot offset y is moved by the y plot area size in order to have /* Plot offset y is moved by the y plot area size in order to have
* the old draw area in the new draw area, because the draw origin has not moved * the old draw area in the new draw area, because the draw origin has not moved
* (this is the upper left corner) but the Y axis is reversed, therefore the plotting area * (this is the upper left corner) but the Y axis is reversed, therefore the plotting area
...@@ -302,50 +305,58 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() ...@@ -302,50 +305,58 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage()
int y_dc_offset = PlotAreaSizeInPixels.y; int y_dc_offset = PlotAreaSizeInPixels.y;
y_dc_offset = (int) ( ( double ) y_dc_offset * userscale ); y_dc_offset = (int) ( ( double ) y_dc_offset * userscale );
dc->SetDeviceOrigin( 0, y_dc_offset ); dc->SetDeviceOrigin( 0, y_dc_offset );
int ysize = (int) ( PlotAreaSizeInPixels.y / scaley );
DrawOffset.y += ysize;
/* in order to keep the board position in the sheet
* (when user scale <= 1) the y offset in moved by the distance between
* the middle of the page and the middle of the board
* This is equivalent to put the mirror axis to the board centre
* for scales > 1, the DrawOffset was already computed to have the board centre
* to the middle of the page.
*/
wxPoint pcb_centre = bbbox.Centre();
if( userscale <= 1.0 ) wxLogTrace( tracePrinting, wxT( "Device origin: x=%d, y=%d" ),
DrawOffset.y += pcb_centre.y - (ysize / 2); 0, y_dc_offset );
dc->SetLogicalOrigin( screen->m_DrawOrg.x, screen->m_DrawOrg.y );
panel->SetClipBox( EDA_RECT( wxPoint( -MAX_VALUE/2, -MAX_VALUE/2 ), panel->SetClipBox( EDA_RECT( wxPoint( -MAX_VALUE/2, -MAX_VALUE/2 ),
panel->GetClipBox()->GetSize() ) ); panel->GetClipBox()->GetSize() ) );
} }
// screen->m_DrawOrg = offset;
dc->SetLogicalOrigin( offset.x, offset.y );
wxLogTrace( tracePrinting, wxT( "Logical origin: x=%d, y=%d" ),
offset.x, offset.y );
wxRect paperRect = GetPaperRectPixels();
wxLogTrace( tracePrinting, wxT( "Paper rectangle: left=%d, top=%d, "
"right=%d, bottom=%d" ),
paperRect.GetLeft(), paperRect.GetTop(), paperRect.GetRight(),
paperRect.GetBottom() );
int devLeft = dc->LogicalToDeviceX( drawRect.GetX() );
int devTop = dc->LogicalToDeviceY( drawRect.GetY() );
int devRight = dc->LogicalToDeviceX( drawRect.GetRight() );
int devBottom = dc->LogicalToDeviceY( drawRect.GetBottom() );
wxLogTrace( tracePrinting, wxT( "Final device rectangle: left=%d, top=%d, "
"right=%d, bottom=%d\n" ),
devLeft, devTop, devRight, devBottom );
g_DrawBgColor = WHITE; g_DrawBgColor = WHITE;
/* when printing in color mode, we use the graphic OR mode that gives the same look as the screen /* when printing in color mode, we use the graphic OR mode that gives the same look as
* But because the background is white when printing, we must use a trick: * the screen but because the background is white when printing, we must use a trick:
* In order to plot on a white background in OR mode we must: * In order to plot on a white background in OR mode we must:
* 1 - Plot all items in black, this creates a local black background * 1 - Plot all items in black, this creates a local black background
* 2 - Plot in OR mode on black "local" background * 2 - Plot in OR mode on black "local" background
*/ */
if( !m_PrintParams.m_Print_Black_and_White ) if( !m_PrintParams.m_Print_Black_and_White )
{ // Creates a "local" black background {
// Creates a "local" black background
GRForceBlackPen( true ); GRForceBlackPen( true );
m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams ); m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams );
GRForceBlackPen( false ); GRForceBlackPen( false );
} }
if( m_PrintParams.PrintBorderAndTitleBlock() )
m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
IU_PER_MILS, m_Parent->GetScreenDesc() );
m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams ); m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams );
g_DrawBgColor = bg_color; g_DrawBgColor = bg_color;
m_Parent->GetScreen()->m_IsPrinting = false; screen->m_IsPrinting = false;
panel->SetClipBox( tmp ); panel->SetClipBox( tmp );
GRForceBlackPen( false ); GRForceBlackPen( false );
screen->m_StartVisu = tmp_startvisu;
screen->m_DrawOrg = old_org;
screen->SetZoom( tmpzoom );
} }
/**************************/ /*
/* printout_controler.h */ * This program source code file is part of KiCad, a free EDA CAD application.
/**************************/ *
* Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef PRINTOUT_CONTROLER_H /**
#define PRINTOUT_CONTROLER_H * @file printout_controler.h
* @brief Board print handler definition file.
*/
#ifndef PRINTOUT_CONTROLLER_H
#define PRINTOUT_CONTROLLER_H
#include <wx/dcps.h> #include <wx/dcps.h>
...@@ -12,59 +38,83 @@ ...@@ -12,59 +38,83 @@
/** /**
* This class handle parameters used to draw (print) a board * Class PRINT_PARAMETERS
* layers, scale and others options * handles the parameters used to print a board drawing.
*/ */
class PRINT_PARAMETERS class PRINT_PARAMETERS
{ {
public: public:
int m_PenDefaultSize; // The defAUlt value pen size to plot/print items int m_PenDefaultSize; // The default value pen size to plot/print items
// that have no defined pen size // that have no defined pen size
double m_PrintScale; // general scale when printing double m_PrintScale; // general scale when printing
double m_XScaleAdjust, m_YScaleAdjust; // fine scale adjust for X and Y axis double m_XScaleAdjust; // fine scale adjust for X axis
bool m_Print_Sheet_Ref; // Option: pring page references double m_YScaleAdjust; // fine scale adjust for Y axis
bool m_Print_Sheet_Ref; // Option: print page references
long m_PrintMaskLayer; // Layers to print long m_PrintMaskLayer; // Layers to print
bool m_PrintMirror; // Option: Print mirroed bool m_PrintMirror; // Option: Print mirrored
bool m_Print_Black_and_White; // Option: Print in B&W ou Color bool m_Print_Black_and_White; // Option: Print in B&W or Color
int m_OptionPrintPage; // Option: 0 = a layer per page, 1 = all layers at once int m_OptionPrintPage; // Option: 0 = a layer per page, 1 = all layers at once
int m_PageCount; // Number of page to print int m_PageCount; // Number of pages to print
bool m_ForceCentered; // Forge plot origin to page centre (used in modedit) bool m_ForceCentered; // Force plot origin to page centre (used in modedit)
int m_Flags; // auxiliary variable: can be used to pass some other info int m_Flags; // Can be used to pass some other info
wxPageSetupDialogData* m_PageSetupData; // A wxPageSetupDialogData to know page options (margins) wxPageSetupDialogData* m_PageSetupData; // A wxPageSetupDialogData for page options (margins)
enum DrillShapeOptT { enum DrillShapeOptT {
NO_DRILL_SHAPE = 0, NO_DRILL_SHAPE = 0,
SMALL_DRILL_SHAPE = 1, SMALL_DRILL_SHAPE = 1,
FULL_DRILL_SHAPE = 2 FULL_DRILL_SHAPE = 2
}; };
DrillShapeOptT m_DrillShapeOpt; // Options to print pads and vias holes
DrillShapeOptT m_DrillShapeOpt; // Options to print pads and via holes
public: public:
PRINT_PARAMETERS(); PRINT_PARAMETERS();
/**
* Function PrintBorderAndTitleBlock
* returns true if the drawing border and title block should be printed.
*
* For scale factors greater than one, the border is not printed because it will end up
* scaling off of the page.
*/
bool PrintBorderAndTitleBlock() const { return m_PrintScale <= 1.0 && m_Print_Sheet_Ref; }
/**
* Function CenterOnBoardOutline
* returns true if the print should be centered by the board outline instead of the
* paper size.
*/
bool CenterOnBoardOutline() const
{
return !PrintBorderAndTitleBlock() && ( m_ForceCentered || (m_PrintScale > 1.0) ||
(m_PrintScale == 0) );
}
}; };
/** /**
* This class derived from wxPrintout handle the necessary info * Class BOARD_PRINTOUT_CONTROLLER
* to control a printer when printing a board * is a class derived from wxPrintout to handle the necessary information to control a printer
* when printing a board
*/ */
class BOARD_PRINTOUT_CONTROLER : public wxPrintout class BOARD_PRINTOUT_CONTROLLER : public wxPrintout
{ {
private: private:
EDA_DRAW_FRAME* m_Parent; EDA_DRAW_FRAME* m_Parent;
PRINT_PARAMETERS m_PrintParams; PRINT_PARAMETERS m_PrintParams;
public: public:
BOARD_PRINTOUT_CONTROLER( const PRINT_PARAMETERS& print_params, BOARD_PRINTOUT_CONTROLLER( const PRINT_PARAMETERS& aParams,
EDA_DRAW_FRAME* parent, EDA_DRAW_FRAME* aParent,
const wxString& title ); const wxString& aTitle );
bool OnPrintPage( int page ); bool OnPrintPage( int aPage );
bool HasPage( int page ) // do not test page num bool HasPage( int aPage ) // do not test page num
{ {
if (page <= m_PrintParams.m_PageCount) if( aPage <= m_PrintParams.m_PageCount )
return true; return true;
else else
return false; return false;
...@@ -75,4 +125,4 @@ public: ...@@ -75,4 +125,4 @@ public:
void DrawPage(); void DrawPage();
}; };
#endif // ifndef PRINTOUT_CONTROLER_H #endif // PRINTOUT_CONTROLLER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment