KiCad PCB EDA Suite
dialog_print_for_modedit.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2010-2014 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
5  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 /* File: dialog_print_for_modedit.cpp */
26 
27 #include <fctsys.h>
28 #include <kiface_i.h>
29 #include <class_drawpanel.h>
30 #include <confirm.h>
31 #include <pcbnew.h>
32 #include <pcb_edit_frame.h>
33 #include <footprint_edit_frame.h>
34 #include <pcbplot.h>
35 
37 #include <printout_controler.h>
38 #include <enabler.h>
39 
40 static double s_scaleList[] =
41 { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 3.0, 4.0, 8.0, 16.0 };
42 
43 
44 // static print data and page setup data, to remember settings during the session
46 static wxPrintData* s_PrintData;
47 static wxPageSetupDialogData* s_pageSetupData = (wxPageSetupDialogData*) NULL;
48 
49 
55 {
56 public:
58 
59 private:
61  wxConfigBase* m_config;
62 
63  void OnCloseWindow( wxCloseEvent& event ) override;
64 
66  void OnPageSetup( wxCommandEvent& event ) override;
67 
68  void OnPrintPreview( wxCommandEvent& event ) override;
69 
71  void OnPrintButtonClick( wxCommandEvent& event ) override;
72 
73  void OnButtonCancelClick( wxCommandEvent& event ) override { Close(); }
74 
75  void OnInitDlg( wxInitDialogEvent& event )
76  {
77  // Call the default wxDialog handler of a wxInitDialogEvent
78  TransferDataToWindow();
79 
80  // Now all widgets have the size fixed, call FinishDialogSettings
82  }
83 
84  void InitValues( );
85 };
86 
87 
88 void FOOTPRINT_EDIT_FRAME::ToPrinter( wxCommandEvent& event )
89 {
90  const PAGE_INFO& pageInfo = GetPageSettings();
91 
92  if( s_PrintData == NULL ) // First print
93  {
94  s_PrintData = new wxPrintData();
95 
96  if( !s_PrintData->Ok() )
97  {
98  DisplayError( this, _( "An error occurred initializing the printer information." ) );
99  }
100 
101  s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
102  }
103 
104  if( s_pageSetupData == NULL )
105  s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
106 
107  s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
108  s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
109  s_PrintData->SetOrientation( pageInfo.GetWxOrientation() );
110 
111  *s_PrintData = s_pageSetupData->GetPrintData();
112  s_Parameters.m_PageSetupData = s_pageSetupData;
113 
114  DIALOG_PRINT_FOR_MODEDIT dlg( this );
115 
116  dlg.ShowModal();
117 }
118 
119 
122 {
123  m_parent = parent;
124  s_Parameters.m_ForceCentered = true;
126  InitValues();
127 
128  m_buttonPrint->SetDefault();
129  GetSizer()->SetSizeHints( this );
130  GetSizer()->Fit( this ); // Needed on Ubuntu/Unity to display the dialog
131 }
132 
133 
135 {
136  // Read the scale adjust option
137  int scale_Select = 3; // default selected scale = ScaleList[3] = 1
138 
139  if( m_config )
140  {
141  m_config->Read( OPTKEY_PRINT_MODULE_SCALE, &scale_Select );
143  }
144 
146  m_ScaleOption->SetSelection( scale_Select );
147 
148  if( s_Parameters.m_Print_Black_and_White )
149  m_ModeColorOption->SetSelection( 1 );
150 }
151 
152 
153 
154 void DIALOG_PRINT_FOR_MODEDIT::OnCloseWindow( wxCloseEvent& event )
155 {
156  if( m_config )
157  {
158  m_config->Write( OPTKEY_PRINT_MODULE_SCALE, m_ScaleOption->GetSelection() );
160  }
161 
162  EndModal( 0 );
163 }
164 
165 
166 void DIALOG_PRINT_FOR_MODEDIT::OnPageSetup( wxCommandEvent& event )
167 {
168  wxPageSetupDialog pageSetupDialog( this, s_pageSetupData );
169  pageSetupDialog.ShowModal();
170 
171  (*s_PrintData) = pageSetupDialog.GetPageSetupDialogData().GetPrintData();
172  (*s_pageSetupData) = pageSetupDialog.GetPageSetupDialogData();
173 }
174 
175 
176 void DIALOG_PRINT_FOR_MODEDIT::OnPrintPreview( wxCommandEvent& event )
177 {
178  s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
179  s_Parameters.m_PrintScale = s_scaleList[m_ScaleOption->GetSelection()];
180 
181  // Pass two printout objects: for preview, and possible printing.
182  wxString title = _( "Print Preview" );
183  wxPrintPreview* preview =
184  new wxPrintPreview( new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
185  new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
186  s_PrintData );
187 
188  if( preview == NULL )
189  {
190  DisplayError( this, wxT( "OnPrintPreview() problem" ) );
191  return;
192  }
193 
194  // Uses the parent position and size.
195  // @todo uses last position and size ans store them when exit in m_config
196  wxPoint WPos = m_parent->GetPosition();
197  wxSize WSize = m_parent->GetSize();
198 
199  wxPreviewFrame* frame = new wxPreviewFrame( preview, this, title, WPos, WSize );
200  frame->SetMinSize( wxSize( 550, 350 ) );
201 
202  // On wxGTK, set the flag wxTOPLEVEL_EX_DIALOG is mandatory, if we want
203  // close the frame using the X box in caption, when the preview frame is run
204  // from a dialog
205  frame->SetExtraStyle( frame->GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
206 
207  // We use here wxPreviewFrame_WindowModal option to make the wxPrintPreview frame
208  // modal for its caller only.
209  // An other reason is the fact when closing the frame without this option,
210  // all top level frames are reenabled.
211  // With this option, only the parent is reenabled.
212  // Reenabling all top level frames should be made by the parent dialog.
213  frame->InitializeWithModality( wxPreviewFrame_WindowModal );
214 
215  frame->Raise(); // Needed on Ubuntu/Unity to display the frame
216  frame->Show( true );
217 }
218 
219 
220 void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event )
221 {
223 
224  s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
225  s_Parameters.m_PrintScale = s_scaleList[m_ScaleOption->GetSelection()];
226 
227  plot_opts.SetFineScaleAdjustX( s_Parameters.m_XScaleAdjust );
228  plot_opts.SetFineScaleAdjustY( s_Parameters.m_YScaleAdjust );
229  plot_opts.SetScale( s_Parameters.m_PrintScale );
230 
231  m_parent->SetPlotSettings( plot_opts );
232 
233  wxPrintDialogData printDialogData( *s_PrintData );
234  wxPrinter printer( &printDialogData );
235 
236  BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, _( "Print Footprint" ) );
237 
238  // Disable 'Print' button to prevent issuing another print
239  // command before the previous one is finished (causes problems on Windows)
240  ENABLER printBtnDisable( *m_buttonPrint, false );
241 
242  if( !printer.Print( this, &printout, true ) )
243  {
244  if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
245  DisplayError( this, _( "There was a problem printing." ) );
246  }
247  else
248  {
249  *s_PrintData = printer.GetPrintDialogData().GetPrintData();
250  }
251 }
static wxPrintData * s_PrintData
#define OPTKEY_PRINT_MONOCHROME_MODE
Definition: pcbplot.h:58
Board print handler definition file.
This file is part of the common library.
Class PRINT_PARAMETERS handles the parameters used to print a board drawing.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_PRINT_FOR_MODEDIT_BASE.
void OnButtonCancelClick(wxCommandEvent &event) override
Class DIALOG_PRINT_FOR_MODEDIT is derived from DIALOG_PRINT_FOR_MODEDIT_BASE which is created by wxFo...
void OnPageSetup(wxCommandEvent &event) override
Open a dialog box for printer setup (printer options, page size ...)
Definition of class FOOTPRINT_EDIT_FRAME.
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
Board plot function definition file.
#define OPTKEY_PRINT_MODULE_SCALE
Definition: pcbplot.h:56
void OnInitDlg(wxInitDialogEvent &event)
static wxPageSetupDialogData * s_pageSetupData
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:49
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
int g_DrawDefaultLineThickness
Default line thickness in internal units used to draw or plot items using a default thickness line va...
Class PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board...
void SetScale(double aVal)
wxPageSetupDialogData * m_PageSetupData
void SetFineScaleAdjustX(double aVal)
void OnPrintPreview(wxCommandEvent &event) override
wxPaperSize GetPaperId() const
Function GetPaperId.
Definition: page_info.h:129
Class BOARD_PRINTOUT_CONTROLLER is a class derived from wxPrintout to handle the necessary informatio...
DIALOG_PRINT_FOR_MODEDIT(PCB_BASE_FRAME *parent)
void ToPrinter(wxCommandEvent &event)
Function ToPrinter Install the print dialog.
static PRINT_PARAMETERS s_Parameters
void SetFineScaleAdjustY(double aVal)
wxPrintOrientation GetWxOrientation() const
Function GetWxOrientation.
Definition: page_info.h:122
static double s_scaleList[]
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:185
void OnCloseWindow(wxCloseEvent &event) override
void OnPrintButtonClick(wxCommandEvent &event) override
Called on activate Print button.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
Simple class to automatically enable/disable widgets.
Definition: enabler.h:29