From f43f7af5fe1fe55b2f83ee0f8c24044288f95fa2 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 17 Jan 2011 19:37:58 +0100 Subject: [PATCH] Modedit: fix issues when printing a footprint. But needs refinement. Work in progress (mainly "Fit in page" is not working). Minor code cleaning --- common/drawframe.cpp | 2 +- eeschema/libedit_plot_component.cpp | 3 +- eeschema/libeditframe.h | 3 +- gerbview/draw_gerber_screen.cpp | 6 +-- gerbview/wxGerberFrame.h | 3 +- include/wxPcbStruct.h | 3 +- include/wxstruct.h | 3 +- pcbnew/dialogs/dialog_SVG_print.cpp | 15 ++++++-- pcbnew/dialogs/dialog_print_for_modedit.cpp | 34 +++++++++++------ pcbnew/dialogs/dialog_print_using_printer.cpp | 38 +++++++++---------- pcbnew/module_editor_frame.h | 3 +- pcbnew/print_board_functions.cpp | 10 ----- pcbnew/printout_controler.cpp | 13 +++---- 13 files changed, 66 insertions(+), 70 deletions(-) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index de87c3c977..a4a06d18ed 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -191,7 +191,7 @@ void WinEDA_DrawFrame::ToolOnRightClick( wxCommandEvent& event ) * because WinEDA_DrawFrame does not know how to print a page * This is the reason it is a virtual function */ -void WinEDA_DrawFrame::PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref,int aPrintMask, +void WinEDA_DrawFrame::PrintPage( wxDC* aDC,int aPrintMask, bool aPrintMirrorMode, void* aData ) { wxMessageBox( wxT("WinEDA_DrawFrame::PrintPage() error")); diff --git a/eeschema/libedit_plot_component.cpp b/eeschema/libedit_plot_component.cpp index 81fe9f6267..2a1354c6a6 100644 --- a/eeschema/libedit_plot_component.cpp +++ b/eeschema/libedit_plot_component.cpp @@ -126,12 +126,11 @@ void LIB_EDIT_FRAME::CreatePNGorJPEGFile( const wxString& aFileName, bool aFmt_j * Function PrintPage (virtual) * used to print a page. * @param aDC = wxDC given by the calling print function - * @param aPrint_Sheet_Ref = true to print page references * @param aPrintMask = not used here * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) * @param aData = a pointer on an auxiliary data (not used here) */ -void LIB_EDIT_FRAME::PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, int aPrintMask, +void LIB_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData) { if( ! m_component ) diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index dacfabaa60..fa0cf66e3c 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -331,12 +331,11 @@ protected: * used to print a page * Print the page pointed by ActiveScreen, set by the calling print function * @param aDC = wxDC given by the calling print function - * @param aPrint_Sheet_Ref = true to print page references * @param aPrintMask = not used here * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) * @param aData = a pointer on an auxiliary data (not always used, NULL if not used) */ - virtual void PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, int aPrintMask, + virtual void PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData = NULL ); /** diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp index 1521ed8971..8252ec0656 100644 --- a/gerbview/draw_gerber_screen.cpp +++ b/gerbview/draw_gerber_screen.cpp @@ -32,12 +32,11 @@ * Used to print the board (on printer, or when creating SVF files). * Print the board, but only layers allowed by aPrintMaskLayer * @param aDC = the print device context - * @param aPrint_Sheet_Ref = true to print frame references * @param aPrintMasklayer = a 32 bits mask: bit n = 1 -> layer n is printed * @param aPrintMirrorMode = true to plot mirrored * @param aData = a pointer to an optional data (not used here: can be NULL) */ -void WinEDA_GerberFrame::PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, int aPrintMasklayer, +void WinEDA_GerberFrame::PrintPage( wxDC* aDC, int aPrintMasklayer, bool aPrintMirrorMode, void* aData ) { // Save current draw options, because print mode has specfic options: @@ -56,9 +55,6 @@ void WinEDA_GerberFrame::PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, int aPrint GetBoard()->Draw( DrawPanel, aDC, GR_COPY, wxPoint( 0, 0 ) ); - if( aPrint_Sheet_Ref ) - TraceWorkSheet( aDC, GetScreen(), 0 ); - DrawPanel->m_PrintIsMirrored = false; // Restore draw options: diff --git a/gerbview/wxGerberFrame.h b/gerbview/wxGerberFrame.h index c6332aad44..c981b3b960 100644 --- a/gerbview/wxGerberFrame.h +++ b/gerbview/wxGerberFrame.h @@ -438,12 +438,11 @@ public: WinEDA_GerberFrame( wxWindow* father, const wxString& title, /** Virtual function PrintPage * used to print a page * @param aDC = wxDC given by the calling print function - * @param aPrint_Sheet_Ref = true to print page references * @param aPrintMasklayer = a 32 bits mask: bit n = 1 -> layer n is printed * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) * @param aData = a pointer on an auxiliary data (not always used, NULL if not used) */ - virtual void PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, + virtual void PrintPage( wxDC* aDC, int aPrintMasklayer, bool aPrintMirrorMode, void* aData = NULL ); diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 7fa350e4f1..d994b86da2 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -162,12 +162,11 @@ public: * used to print a page * Print the page pointed by ActiveScreen, set by the calling print function * @param aDC = wxDC given by the calling print function - * @param aPrint_Sheet_Ref = true to print page references * @param aPrintMaskLayer = a 32 bits mask: bit n = 1 -> layer n is printed * @param aPrintMirrorMode = true to plot mirrored * @param aData = a pointer on an auxiliary data (NULL if not used) */ - virtual void PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, + virtual void PrintPage( wxDC* aDC, int aPrintMaskLayer, bool aPrintMirrorMode, void * aData = NULL ); diff --git a/include/wxstruct.h b/include/wxstruct.h index 3678626fb3..5f731f6730 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -507,12 +507,11 @@ public: * used to print a page * Print the page pointed by ActiveScreen, set by the calling print function * @param aDC = wxDC given by the calling print function - * @param aPrint_Sheet_Ref = true to print page references * @param aPrintMask = not used here * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) * @param aData = a pointer on an auxiliary data (not always used, NULL if not used) */ - virtual void PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, + virtual void PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void * aData = NULL); diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index 892898a084..7da44ff5c9 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -249,16 +249,23 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName, panel->m_ClipBox.SetX( 0 ); panel->m_ClipBox.SetY( 0 ); - panel->m_ClipBox.SetWidth( 0x7FFFFF0 ); - panel->m_ClipBox.SetHeight( 0x7FFFFF0 ); + // Set clip box to the max size + #define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer + // and that allows calculations without overflow + panel->m_ClipBox.SetWidth( MAX_VALUE ); + panel->m_ClipBox.SetHeight( MAX_VALUE ); screen->m_IsPrinting = true; int bg_color = g_DrawBgColor; g_DrawBgColor = WHITE; - m_Parent->PrintPage( &dc, aPrint_Frame_Ref, m_PrintMaskLayer, false, &s_Parameters); + + if( aPrint_Frame_Ref ) + m_Parent->TraceWorkSheet( &dc, ActiveScreen, s_Parameters.m_PenDefaultSize ); + + m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters); g_DrawBgColor = bg_color; - SetLocaleTo_Default(); // revert to the current locale + SetLocaleTo_Default(); // revert to the current locale screen->m_IsPrinting = false; panel->m_ClipBox = tmp; diff --git a/pcbnew/dialogs/dialog_print_for_modedit.cpp b/pcbnew/dialogs/dialog_print_for_modedit.cpp index b65b172d24..af6d306e1a 100644 --- a/pcbnew/dialogs/dialog_print_for_modedit.cpp +++ b/pcbnew/dialogs/dialog_print_for_modedit.cpp @@ -27,7 +27,8 @@ static double s_ScaleList[] = // static print data and page setup data, to remember settings during the session static PRINT_PARAMETERS s_Parameters; -static wxPrintData* g_PrintData; +static wxPrintData* s_PrintData; +static wxPageSetupDialogData* s_pageSetupData = (wxPageSetupDialogData*) NULL; /* Dialog to print schematic. Class derived from DIALOG_PRINT_FOR_MODEDIT_BASE @@ -61,16 +62,16 @@ void WinEDA_ModuleEditFrame::ToPrinter( wxCommandEvent& event ) * Display the print dialog */ { - if( g_PrintData == NULL ) // First print + if( s_PrintData == NULL ) // First print { - g_PrintData = new wxPrintData(); + s_PrintData = new wxPrintData(); - if( !g_PrintData->Ok() ) + if( !s_PrintData->Ok() ) { DisplayError( this, _( "Error Init Printer info" ) ); } - g_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGHT; - g_PrintData->SetOrientation( DEFAULT_ORIENTATION_PAPER ); + s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGHT; + s_PrintData->SetOrientation( DEFAULT_ORIENTATION_PAPER ); } DIALOG_PRINT_FOR_MODEDIT* frame = new DIALOG_PRINT_FOR_MODEDIT( this ); @@ -99,6 +100,17 @@ void DIALOG_PRINT_FOR_MODEDIT::InitValues( ) { SetFocus(); + if( s_pageSetupData == NULL ) + { + s_pageSetupData = new wxPageSetupDialogData; + // Set initial page margins. + // Margins are already set in Pcbnew, so we cans use 0 + s_pageSetupData->SetMarginTopLeft(wxPoint(0, 0)); + s_pageSetupData->SetMarginBottomRight(wxPoint(0, 0)); + } + + s_Parameters.m_PageSetupData = s_pageSetupData; + // Read the scale adjust option int scale_Select = 3; // default selected scale = ScaleList[3] = 1 if( m_Config ) @@ -136,13 +148,13 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintSetup( wxCommandEvent& event ) /* Open a dialog box for printer setup (printer options, page size ...) */ { - wxPrintDialogData printDialogData( *g_PrintData ); + wxPrintDialogData printDialogData( *s_PrintData ); if( printDialogData.Ok() ) { wxPrintDialog printerDialog( this, &printDialogData ); printerDialog.ShowModal(); - *g_PrintData = printerDialog.GetPrintDialogData().GetPrintData(); + *s_PrintData = printerDialog.GetPrintDialogData().GetPrintData(); } else DisplayError( this, _( "Printer Problem!" ) ); @@ -164,7 +176,7 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintPreview( wxCommandEvent& event ) wxPrintPreview* preview = new wxPrintPreview( new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ), new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ), - g_PrintData ); + s_PrintData ); if( preview == NULL ) { @@ -198,7 +210,7 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event ) g_PcbPlotOptions.m_FineScaleAdjustY = s_Parameters.m_YScaleAdjust; g_PcbPlotOptions.m_PlotScale = s_Parameters.m_PrintScale; - wxPrintDialogData printDialogData( *g_PrintData ); + wxPrintDialogData printDialogData( *s_PrintData ); wxPrinter printer( &printDialogData ); BOARD_PRINTOUT_CONTROLER printout( s_Parameters, m_Parent, _( "Print Footprint" ) ); @@ -216,6 +228,6 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event ) } else { - *g_PrintData = printer.GetPrintDialogData().GetPrintData(); + *s_PrintData = printer.GetPrintDialogData().GetPrintData(); } } diff --git a/pcbnew/dialogs/dialog_print_using_printer.cpp b/pcbnew/dialogs/dialog_print_using_printer.cpp index 24dce243bd..e89d2b55fd 100644 --- a/pcbnew/dialogs/dialog_print_using_printer.cpp +++ b/pcbnew/dialogs/dialog_print_using_printer.cpp @@ -35,8 +35,8 @@ static double s_ScaleList[] = #define MAX_SCALE 100.0 // static print data and page setup data, to remember settings during the session -static wxPrintData* g_PrintData; -static wxPageSetupDialogData* g_pageSetupData = (wxPageSetupDialogData*) NULL; +static wxPrintData* s_PrintData; +static wxPageSetupDialogData* s_pageSetupData = (wxPageSetupDialogData*) NULL; static PRINT_PARAMETERS s_Parameters; @@ -95,16 +95,16 @@ void WinEDA_PcbFrame::ToPrinter( wxCommandEvent& event ) * Display the print dialog */ { - if( g_PrintData == NULL ) // First print + if( s_PrintData == NULL ) // First print { - g_PrintData = new wxPrintData(); + s_PrintData = new wxPrintData(); - if( !g_PrintData->Ok() ) + if( !s_PrintData->Ok() ) { DisplayError( this, _( "Error Init Printer info" ) ); } - g_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGHT; - g_PrintData->SetOrientation( DEFAULT_ORIENTATION_PAPER ); + s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGHT; + s_PrintData->SetOrientation( DEFAULT_ORIENTATION_PAPER ); } DIALOG_PRINT_USING_PRINTER* frame = new DIALOG_PRINT_USING_PRINTER( this ); @@ -140,16 +140,16 @@ void DIALOG_PRINT_USING_PRINTER::InitValues( ) int layer_max = NB_LAYERS; wxString msg; BOARD* board = m_Parent->GetBoard(); - if( g_pageSetupData == NULL ) + if( s_pageSetupData == NULL ) { - g_pageSetupData = new wxPageSetupDialogData; + s_pageSetupData = new wxPageSetupDialogData; // Set initial page margins. // Margins are already set in Pcbnew, so we cans use 0 - g_pageSetupData->SetMarginTopLeft(wxPoint(0, 0)); - g_pageSetupData->SetMarginBottomRight(wxPoint(0, 0)); + s_pageSetupData->SetMarginTopLeft(wxPoint(0, 0)); + s_pageSetupData->SetMarginBottomRight(wxPoint(0, 0)); } - s_Parameters.m_PageSetupData = g_pageSetupData; + s_Parameters.m_PageSetupData = s_pageSetupData; // Create layer list. int layer; @@ -450,13 +450,13 @@ void DIALOG_PRINT_USING_PRINTER::OnPageSetup( wxCommandEvent& event ) /* Open a dialog box for printer setup (printer options, page size ...) */ { - *g_pageSetupData = *g_PrintData; + *s_pageSetupData = *s_PrintData; - wxPageSetupDialog pageSetupDialog(this, g_pageSetupData); + wxPageSetupDialog pageSetupDialog(this, s_pageSetupData); pageSetupDialog.ShowModal(); - (*g_PrintData) = pageSetupDialog.GetPageSetupDialogData().GetPrintData(); - (*g_pageSetupData) = pageSetupDialog.GetPageSetupDialogData(); + (*s_PrintData) = pageSetupDialog.GetPageSetupDialogData().GetPrintData(); + (*s_pageSetupData) = pageSetupDialog.GetPageSetupDialogData(); } @@ -474,7 +474,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event ) wxPrintPreview* preview = new wxPrintPreview( new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ), new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ), - g_PrintData ); + s_PrintData ); if( preview == NULL ) { @@ -522,7 +522,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) return; } - wxPrintDialogData printDialogData( *g_PrintData ); + wxPrintDialogData printDialogData( *s_PrintData ); wxPrinter printer( &printDialogData ); @@ -542,7 +542,7 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) } else { - *g_PrintData = printer.GetPrintDialogData().GetPrintData(); + *s_PrintData = printer.GetPrintDialogData().GetPrintData(); } } diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index 349e86d2d4..3a50443da0 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -73,12 +73,11 @@ public: * used to print a page * Print the page pointed by ActiveScreen, set by the calling print function * @param aDC = wxDC given by the calling print function - * @param aPrint_Sheet_Ref = true to print page references * @param aPrintMaskLayer = not used here * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) * @param aData = a pointer on an auxiliary data (NULL if not used) */ - virtual void PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref, + virtual void PrintPage( wxDC* aDC, int aPrintMaskLayer, bool aPrintMirrorMode, void * aData = NULL); diff --git a/pcbnew/print_board_functions.cpp b/pcbnew/print_board_functions.cpp index 9dd655be88..2f0d09aad7 100644 --- a/pcbnew/print_board_functions.cpp +++ b/pcbnew/print_board_functions.cpp @@ -25,13 +25,11 @@ static void Print_Module( WinEDA_DrawPanel* aPanel, wxDC* aDC, MODULE* aModule, * Used to print the board (on printer, or when creating SVF files). * Print the board, but only layers allowed by aPrintMaskLayer * @param aDC = the print device context - * @param aPrint_Sheet_Ref = true to print frame references * @param aPrintMaskLayer = a 32 bits mask: bit n = 1 -> layer n is printed * @param aPrintMirrorMode = true to plot mirrored * @param aData = a pointer to an optional data (NULL if not used) */ void WinEDA_ModuleEditFrame::PrintPage( wxDC* aDC, - bool aPrint_Sheet_Ref, int aPrintMaskLayer, bool aPrintMirrorMode, void * aData) @@ -96,9 +94,6 @@ void WinEDA_ModuleEditFrame::PrintPage( wxDC* aDC, } D_PAD::m_PadSketchModePenSize = tmp; - if( aPrint_Sheet_Ref ) - TraceWorkSheet( aDC, GetScreen(), defaultPenSize ); - DrawPanel->m_PrintIsMirrored = false; DisplayOpt = save_opt; @@ -115,13 +110,11 @@ void WinEDA_ModuleEditFrame::PrintPage( wxDC* aDC, * is used to print the board (on printer, or when creating SVF files). * Print the board, but only layers allowed by aPrintMaskLayer * @param aDC = the print device context - * @param aPrint_Sheet_Ref = true to print frame references * @param aPrintMaskLayer = a 32 bits mask: bit n = 1 -> layer n is printed * @param aPrintMirrorMode = true to plot mirrored * @param aData = a pointer to an optional data (NULL if not used) */ void WinEDA_PcbFrame::PrintPage( wxDC* aDC, - bool aPrint_Sheet_Ref, int aPrintMaskLayer, bool aPrintMirrorMode, void * aData) @@ -310,9 +303,6 @@ void WinEDA_PcbFrame::PrintPage( wxDC* aDC, GRForceBlackPen( blackpenstate ); } - if( aPrint_Sheet_Ref ) - TraceWorkSheet( aDC, GetScreen(), defaultPenSize ); - DrawPanel->m_PrintIsMirrored = false; DisplayOpt = save_opt; diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp index d32ff775e6..d980ec8da1 100644 --- a/pcbnew/printout_controler.cpp +++ b/pcbnew/printout_controler.cpp @@ -228,7 +228,7 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() WinEDA_DrawPanel* panel = m_Parent->DrawPanel; EDA_Rect tmp = panel->m_ClipBox; - // SEt clip box to the max size + // Set clip box to the max size #define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer // and that allows calculations without overflow panel->m_ClipBox.SetOrigin( wxPoint( 0, 0 ) ); @@ -243,12 +243,9 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( printMirror ) { // To plot mirror, we reverse the y axis, and modify the plot y origin - double sx, sy; - - dc->GetUserScale( &sx, &sy ); dc->SetAxisOrientation( true, true ); if( userscale < 1.0 ) - sy /= userscale; + scaley /= userscale; /* 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 @@ -259,7 +256,7 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() y_dc_offset = (int) y_dc_offset * userscale; dc->SetDeviceOrigin( 0, y_dc_offset ); #endif - int ysize = (int) ( PlotAreaSizeInPixels.y / sy ); + int ysize = (int) ( PlotAreaSizeInPixels.y / scaley ); DrawOffset.y += ysize; /* in order to keep the board position in the sheet @@ -291,11 +288,11 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( !m_PrintParams.m_Print_Black_and_White ) { // Creates a "local" black background GRForceBlackPen( true ); - m_Parent->PrintPage( dc, 0, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams ); + m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams ); GRForceBlackPen( false ); } - m_Parent->PrintPage( dc, 0, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams ); + m_Parent->PrintPage( dc, m_PrintParams.m_PrintMaskLayer, printMirror, &m_PrintParams ); g_DrawBgColor = bg_color; m_Parent->GetBaseScreen()->m_IsPrinting = false;