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 <wxPcbStruct.h>
33 #include <module_editor_frame.h>
34 #include <pcbplot.h>
35 
37 #include <printout_controler.h>
38 
39 static double s_scaleList[] =
40 { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 3.0, 4.0, 8.0, 16.0 };
41 
42 
43 // static print data and page setup data, to remember settings during the session
45 static wxPrintData* s_PrintData;
46 static wxPageSetupDialogData* s_pageSetupData = (wxPageSetupDialogData*) NULL;
47 
48 
54 {
55 public:
57 
58 private:
60  wxConfigBase* m_config;
61 
62  void OnCloseWindow( wxCloseEvent& event ) override;
63 
65  void OnPageSetup( wxCommandEvent& event ) override;
66 
67  void OnPrintPreview( wxCommandEvent& event ) override;
68 
70  void OnPrintButtonClick( wxCommandEvent& event ) override;
71 
72  void OnButtonCancelClick( wxCommandEvent& event ) override { Close(); }
73 
74  void OnInitDlg( wxInitDialogEvent& event )
75  {
76  // Call the default wxDialog handler of a wxInitDialogEvent
77  TransferDataToWindow();
78 
79  // Now all widgets have the size fixed, call FinishDialogSettings
81  }
82 
83  void InitValues( );
84 };
85 
86 
87 void FOOTPRINT_EDIT_FRAME::ToPrinter( wxCommandEvent& event )
88 {
89  const PAGE_INFO& pageInfo = GetPageSettings();
90 
91  if( s_PrintData == NULL ) // First print
92  {
93  s_PrintData = new wxPrintData();
94 
95  if( !s_PrintData->Ok() )
96  {
97  DisplayError( this, _( "An error occurred initializing the printer information." ) );
98  }
99 
100  s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
101  }
102 
103  if( s_pageSetupData == NULL )
104  s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
105 
106  s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
107  s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
108  s_PrintData->SetOrientation( pageInfo.GetWxOrientation() );
109 
110  *s_PrintData = s_pageSetupData->GetPrintData();
111  s_Parameters.m_PageSetupData = s_pageSetupData;
112 
113  DIALOG_PRINT_FOR_MODEDIT dlg( this );
114 
115  dlg.ShowModal();
116 }
117 
118 
121 {
122  m_parent = parent;
123  s_Parameters.m_ForceCentered = true;
125  InitValues();
126 
127  m_buttonPrint->SetDefault();
128  GetSizer()->SetSizeHints( this );
129  GetSizer()->Fit( this ); // Needed on Ubuntu/Unity to display the dialog
130 }
131 
132 
134 {
135  // Read the scale adjust option
136  int scale_Select = 3; // default selected scale = ScaleList[3] = 1
137 
138  if( m_config )
139  {
140  m_config->Read( OPTKEY_PRINT_MODULE_SCALE, &scale_Select );
142  }
143 
145  m_ScaleOption->SetSelection( scale_Select );
146 
147  if( s_Parameters.m_Print_Black_and_White )
148  m_ModeColorOption->SetSelection( 1 );
149 }
150 
151 
152 
153 void DIALOG_PRINT_FOR_MODEDIT::OnCloseWindow( wxCloseEvent& event )
154 {
155  if( m_config )
156  {
157  m_config->Write( OPTKEY_PRINT_MODULE_SCALE, m_ScaleOption->GetSelection() );
159  }
160 
161  EndModal( 0 );
162 }
163 
164 
165 void DIALOG_PRINT_FOR_MODEDIT::OnPageSetup( wxCommandEvent& event )
166 {
167  wxPageSetupDialog pageSetupDialog( this, s_pageSetupData );
168  pageSetupDialog.ShowModal();
169 
170  (*s_PrintData) = pageSetupDialog.GetPageSetupDialogData().GetPrintData();
171  (*s_pageSetupData) = pageSetupDialog.GetPageSetupDialogData();
172 }
173 
174 
175 void DIALOG_PRINT_FOR_MODEDIT::OnPrintPreview( wxCommandEvent& event )
176 {
177  s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
178  s_Parameters.m_PrintScale = s_scaleList[m_ScaleOption->GetSelection()];
179 
180  // Pass two printout objects: for preview, and possible printing.
181  wxString title = _( "Print Preview" );
182  wxPrintPreview* preview =
183  new wxPrintPreview( new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
184  new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
185  s_PrintData );
186 
187  if( preview == NULL )
188  {
189  DisplayError( this, wxT( "OnPrintPreview() problem" ) );
190  return;
191  }
192 
193  // Uses the parent position and size.
194  // @todo uses last position and size ans store them when exit in m_config
195  wxPoint WPos = m_parent->GetPosition();
196  wxSize WSize = m_parent->GetSize();
197 
198  wxPreviewFrame* frame = new wxPreviewFrame( preview, this, title, WPos, WSize );
199  frame->SetMinSize( wxSize( 550, 350 ) );
200 
201  // On wxGTK, set the flag wxTOPLEVEL_EX_DIALOG is mandatory, if we want
202  // close the frame using the X box in caption, when the preview frame is run
203  // from a dialog
204  frame->SetExtraStyle( frame->GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
205 
206  // We use here wxPreviewFrame_WindowModal option to make the wxPrintPreview frame
207  // modal for its caller only.
208  // An other reason is the fact when closing the frame without this option,
209  // all top level frames are reenabled.
210  // With this option, only the parent is reenabled.
211  // Reenabling all top level frames should be made by the parent dialog.
212  frame->InitializeWithModality( wxPreviewFrame_WindowModal );
213 
214  frame->Raise(); // Needed on Ubuntu/Unity to display the frame
215  frame->Show( true );
216 }
217 
218 
219 void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event )
220 {
222 
223  s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
224  s_Parameters.m_PrintScale = s_scaleList[m_ScaleOption->GetSelection()];
225 
226  plot_opts.SetFineScaleAdjustX( s_Parameters.m_XScaleAdjust );
227  plot_opts.SetFineScaleAdjustY( s_Parameters.m_YScaleAdjust );
228  plot_opts.SetScale( s_Parameters.m_PrintScale );
229 
230  m_parent->SetPlotSettings( plot_opts );
231 
232  wxPrintDialogData printDialogData( *s_PrintData );
233  wxPrinter printer( &printDialogData );
234 
235  BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, _( "Print Footprint" ) );
236 
237  if( !printer.Print( this, &printout, true ) )
238  {
239  if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
240  DisplayError( this, _( "There was a problem printing." ) );
241 
242  return;
243  }
244  else
245  {
246  *s_PrintData = printer.GetPrintDialogData().GetPrintData();
247  }
248 }
static wxPrintData * s_PrintData
Definition of class FOOTPRINT_EDIT_FRAME.
#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 ...)
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...
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
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.
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
const PAGE_INFO & GetPageSettings() const override
void SetFineScaleAdjustY(double aVal)
wxPrintOrientation GetWxOrientation() const
Function GetWxOrientation.
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:69
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...