KiCad PCB EDA Suite
dialog_print_pcbnew.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-2016 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * Copyright (C) 2018 CERN
7  *
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <kiface_base.h>
29 #include <confirm.h>
30 #include <core/arraydim.h>
31 #include <base_units.h>
32 #include <pcbnew_settings.h>
33 #include <pcbplot.h>
34 #include <board.h>
35 #include <tool/tool_manager.h>
36 #include <tools/pcb_actions.h>
37 #include <tools/pcb_control.h>
39 #include <pcbnew_printout.h>
40 #include <wx/checklst.h>
41 #include <wx/textdlg.h>
42 
43 
45 {
46 public:
49 
50 private:
52  {
53  wxASSERT( dynamic_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings ) );
54  return static_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings );
55  }
56 
57  bool TransferDataToWindow() override;
58 
59  void createExtraOptions();
60  void createLeftPanel();
61 
62  void onSelectAllClick( wxCommandEvent& event );
63  void onDeselectAllClick( wxCommandEvent& event );
64 
65  void onUseThemeClicked( wxCommandEvent& event );
66  void onPagePerLayerClicked( wxCommandEvent& event );
67  void onColorModeClicked( wxCommandEvent& event );
68 
70  void setListBoxValue( wxCheckListBox* aList, bool aValue );
71 
73  bool isLayerEnabled( unsigned int aLayer ) const;
74 
76  void enableLayer( unsigned int aLayer, bool aValue );
77 
79  int setLayerSetFromList();
80 
81  void saveSettings() override;
82 
83  wxPrintout* createPrintout( const wxString& aTitle ) override
84  {
85  return new PCBNEW_PRINTOUT( m_parent->GetBoard(), *settings(),
86  m_parent->GetCanvas()->GetView(), aTitle );
87  }
88 
90 
91  // List of existing board layers in wxCheckListBox, with the board layers id:
92  std::pair<wxCheckListBox*, int> m_layers[PCB_LAYER_ID_COUNT];
93 
94  // Extra widgets
95  wxCheckListBox* m_listTechLayers;
96  wxCheckListBox* m_listCopperLayers;
97  wxButton* m_buttonSelectAll;
99  wxCheckBox* m_checkboxMirror;
103  wxCheckBox* m_checkAsItems;
104  wxCheckBox* m_checkBackground;
105  wxCheckBox* m_checkUseTheme;
106  wxChoice* m_colorTheme;
107 };
108 
109 
111  PCBNEW_PRINTOUT_SETTINGS* aSettings ) :
112  DIALOG_PRINT_GENERIC( aParent, aSettings ),
113  m_parent( aParent )
114 {
116 
118  createLeftPanel();
119 
120  m_outputMode->Bind( wxEVT_COMMAND_CHOICE_SELECTED, &DIALOG_PRINT_PCBNEW::onColorModeClicked,
121  this );
122 }
123 
124 
126 {
128  return false;
129 
130  BOARD* board = m_parent->GetBoard();
131 
132  // Create layer list
133  for( LSEQ seq = board->GetEnabledLayers().UIOrder(); seq; ++seq )
134  {
135  PCB_LAYER_ID layer = *seq;
136  int checkIndex;
137 
138  if( IsCopperLayer( layer ) )
139  {
140  checkIndex = m_listCopperLayers->Append( board->GetLayerName( layer ) );
141  m_layers[layer] = std::make_pair( m_listCopperLayers, checkIndex );
142  }
143  else
144  {
145  checkIndex = m_listTechLayers->Append( board->GetLayerName( layer ) );
146  m_layers[layer] = std::make_pair( m_listTechLayers, checkIndex );
147  }
148 
149  m_layers[layer].first->Check( checkIndex, settings()->m_LayerSet.test( layer ) );
150  }
151 
152  m_checkboxMirror->SetValue( settings()->m_Mirror );
153  m_titleBlock->SetValue( settings()->m_titleBlock );
154 
156 
157  m_checkBackground->SetValue( cfg->m_Printing.background );
158  m_checkUseTheme->SetValue( cfg->m_Printing.use_theme );
159 
160  m_colorTheme->Clear();
161 
162  int width = 0;
163  int height = 0;
164  int minwidth = width;
165 
166  wxString target = cfg->m_Printing.use_theme ? cfg->m_Printing.color_theme : cfg->m_ColorTheme;
167 
169  {
170  int pos = m_colorTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
171 
172  if( settings->GetFilename() == target )
173  m_colorTheme->SetSelection( pos );
174 
175  m_colorTheme->GetTextExtent( settings->GetName(), &width, &height );
176  minwidth = std::max( minwidth, width );
177  }
178 
179  m_colorTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
180 
181  wxCommandEvent dummy;
183 
184  // Options to plot pads and vias holes
185  m_drillMarksChoice->SetSelection( settings()->m_DrillMarks );
186 
187  // Print all layers one one page or separately
188  m_checkboxPagePerLayer->SetValue( settings()->m_Pagination
191 
192  // Update the dialog layout when layers are added
193  GetSizer()->Fit( this );
194 
195  return true;
196 }
197 
198 
200 {
201  wxGridBagSizer* optionsSizer = getOptionsSizer();
202  wxStaticBox* box = getOptionsBox();
203  int rows = optionsSizer->GetEffectiveRowsCount();
204  int cols = optionsSizer->GetEffectiveColsCount();
205 
206  m_checkAsItems = new wxCheckBox( box, wxID_ANY,
207  _( "Print according to objects tab of appearance manager" ) );
208  optionsSizer->Add( m_checkAsItems, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ),
209  wxLEFT|wxRIGHT|wxBOTTOM, 5 );
210 
211  m_checkBackground = new wxCheckBox( box, wxID_ANY, _( "Print background color" ) );
212  optionsSizer->Add( m_checkBackground, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ),
213  wxLEFT|wxRIGHT|wxBOTTOM, 5 );
214 
215  m_checkUseTheme = new wxCheckBox( box, wxID_ANY,
216  _( "Use a different color theme for printing:" ) );
217  optionsSizer->Add( m_checkUseTheme, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ),
218  wxLEFT|wxRIGHT, 5 );
219 
220  m_checkUseTheme->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
222 
223  wxArrayString m_colorThemeChoices;
224  m_colorTheme = new wxChoice( box, wxID_ANY, wxDefaultPosition, wxDefaultSize,
225  m_colorThemeChoices, 0 );
226  m_colorTheme->SetSelection( 0 );
227 
228  optionsSizer->Add( m_colorTheme, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
229  wxLEFT, 28 );
230 
231  rows++;
232 
233  // Drill marks option
234  auto drillMarksLabel = new wxStaticText( box, wxID_ANY, _( "Drill marks:" ) );
235  std::vector<wxString> drillMarkChoices = { _( "No drill mark" ),
236  _( "Small mark" ),
237  _( "Real drill" ) };
238  m_drillMarksChoice = new wxChoice( box, wxID_ANY, wxDefaultPosition, wxDefaultSize,
239  drillMarkChoices.size(), drillMarkChoices.data(), 0 );
240  m_drillMarksChoice->SetSelection( 0 );
241 
242  optionsSizer->Add( drillMarksLabel, wxGBPosition( rows, 0 ), wxGBSpan( 1, 1 ),
243  wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
244  optionsSizer->Add( m_drillMarksChoice, wxGBPosition( rows++, 1 ), wxGBSpan( 1, cols - 1 ),
245  wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
246 
247  // Print mirrored
248  m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
249 
250  optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows++, 0 ), wxGBSpan( 1, cols ),
251  wxLEFT|wxRIGHT|wxBOTTOM, 5 );
252 
253  // Pagination
254  m_checkboxPagePerLayer = new wxCheckBox( box, wxID_ANY, _( "Print one page per layer" ) );
255 
256  m_checkboxPagePerLayer->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
258 
259  m_checkboxEdgesOnAllPages = new wxCheckBox( box, wxID_ANY,
260  _( "Print board edges on all pages" ) );
261 
262  optionsSizer->Add( m_checkboxPagePerLayer, wxGBPosition( rows++, 0 ), wxGBSpan( 1, cols ),
263  wxLEFT|wxRIGHT, 5 );
264  optionsSizer->Add( m_checkboxEdgesOnAllPages, wxGBPosition( rows++, 0 ), wxGBSpan( 1, cols ),
265  wxLEFT, 28 );
266 }
267 
268 
270 {
271  wxStaticBox* box = new wxStaticBox( this, wxID_ANY, _( "Included Layers" ) );
272  wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( box, wxVERTICAL );
273 
274  // Copper layer list
275  auto copperLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY,
276  _( "Copper layers:" ) );
277  m_listCopperLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
278 
279  wxBoxSizer* sizerLeft = new wxBoxSizer( wxVERTICAL );
280  sizerLeft->Add( copperLabel, 0, wxRIGHT, 5 );
281  sizerLeft->Add( m_listCopperLayers, 1, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
282 
283  // Technical layer list
284  auto technicalLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY,
285  _( "Technical layers:" ) );
286  m_listTechLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
287 
288  wxBoxSizer* sizerRight = new wxBoxSizer( wxVERTICAL );
289  sizerRight->Add( technicalLabel, 0, wxLEFT, 5 );
290  sizerRight->Add( m_listTechLayers, 1, wxEXPAND | wxBOTTOM | wxLEFT, 5 );
291 
292  // Layer list layout
293  wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
294  bLayerListsSizer->Add( sizerLeft, 1, wxEXPAND, 5 );
295  bLayerListsSizer->Add( sizerRight, 1, wxEXPAND, 5 );
296 
297  // Select/Unselect all buttons
298  m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
299  m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY,
300  _( "Deselect all" ) );
301 
302  m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
303  wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onSelectAllClick ),
304  nullptr, this );
305  m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
306  wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onDeselectAllClick ),
307  nullptr, this );
308 
309  wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
310  buttonSizer->Add( m_buttonSelectAll, 1, wxRIGHT | wxTOP | wxBOTTOM, 5 );
311  buttonSizer->Add( m_buttonDeselectAll, 1, wxLEFT | wxTOP | wxBOTTOM, 5 );
312 
313  // Static box sizer layout
314  sbLayersSizer->Add( bLayerListsSizer, 1, wxRIGHT | wxEXPAND, 5 );
315  sbLayersSizer->Add( buttonSizer, 0, wxRIGHT | wxEXPAND, 5 );
316 
317  getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND | wxALL, 5 );
318 }
319 
320 
321 void DIALOG_PRINT_PCBNEW::onSelectAllClick( wxCommandEvent& event )
322 {
325 }
326 
327 
328 void DIALOG_PRINT_PCBNEW::onDeselectAllClick( wxCommandEvent& event )
329 {
332 }
333 
334 
335 void DIALOG_PRINT_PCBNEW::onUseThemeClicked( wxCommandEvent& event )
336 {
337  m_colorTheme->Enable( m_checkUseTheme->GetValue() );
338 }
339 
340 
341 void DIALOG_PRINT_PCBNEW::onPagePerLayerClicked( wxCommandEvent& event )
342 {
343  if( m_checkboxPagePerLayer->GetValue() )
344  {
345  m_checkboxEdgesOnAllPages->Enable( true );
346  m_checkboxEdgesOnAllPages->SetValue( settings()->m_PrintEdgeCutsOnAllPages );
347  }
348  else
349  {
350  m_checkboxEdgesOnAllPages->Enable( false );
351  m_checkboxEdgesOnAllPages->SetValue( false );
352  }
353 }
354 
355 
356 void DIALOG_PRINT_PCBNEW::onColorModeClicked( wxCommandEvent& event )
357 {
359 
360  m_settings->m_blackWhite = m_outputMode->GetSelection();
361 
365 }
366 
367 
368 void DIALOG_PRINT_PCBNEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
369 {
370  for( unsigned int i = 0; i < aList->GetCount(); ++i )
371  aList->Check( i, aValue );
372 }
373 
374 
375 bool DIALOG_PRINT_PCBNEW::isLayerEnabled( unsigned int aLayer ) const
376 {
377  wxCHECK( aLayer < arrayDim( m_layers ), false );
378  const auto& layerInfo = m_layers[aLayer];
379 
380  if( layerInfo.first )
381  return layerInfo.first->IsChecked( layerInfo.second );
382 
383  return false;
384 }
385 
386 
387 void DIALOG_PRINT_PCBNEW::enableLayer( unsigned int aLayer, bool aValue )
388 {
389  wxCHECK( aLayer < arrayDim( m_layers ), /* void */ );
390  const auto& layerInfo = m_layers[aLayer];
391  layerInfo.first->Check( layerInfo.second, aValue );
392 }
393 
394 
396 {
397  settings()->m_LayerSet = LSET();
398  int& pageCount = settings()->m_pageCount;
399  pageCount = 0;
400 
401  for( unsigned int layer = 0; layer < arrayDim( m_layers ); ++layer )
402  {
403  if( isLayerEnabled( layer ) )
404  {
405  ++pageCount;
406  settings()->m_LayerSet.set( layer );
407  }
408  }
409 
410  // In Pcbnew force the EDGE layer to be printed or not with the other layers
412 
413  // All layers on one page (only if there is at least one layer selected)
414  if( !m_checkboxPagePerLayer->GetValue() && pageCount > 0 )
415  pageCount = 1;
416 
417  return pageCount;
418 }
419 
420 
422 {
424 
425  settings()->m_AsItemCheckboxes = m_checkAsItems->GetValue();
426 
429 
430  if( m_checkboxPagePerLayer->GetValue() )
431  {
434  }
435  else
436  {
438  }
439 
440  settings()->m_Mirror = m_checkboxMirror->GetValue();
441 
443 
444  cfg->m_Printing.background = m_checkBackground->GetValue();
446  cfg->m_Printing.use_theme = m_checkUseTheme->GetValue();
447 
448  int sel = m_colorTheme->GetSelection();
449  COLOR_SETTINGS* theme = static_cast<COLOR_SETTINGS*>( m_colorTheme->GetClientData( sel ) );
450 
451  if( theme && m_checkUseTheme->IsChecked() )
452  {
453  cfg->m_Printing.color_theme = theme->GetFilename();
454  settings()->m_colorSettings = theme;
455  }
456  else
457  {
459  }
460 
462 }
463 
464 
465 int PCB_CONTROL::Print( const TOOL_EVENT& aEvent )
466 {
467  // Selection affects the origin item visibility
469 
471  DIALOG_PRINT_PCBNEW dlg( (PCB_BASE_EDIT_FRAME*) m_frame, &settings );
472 
473  if( m_isFootprintEditor )
474  dlg.ForcePrintBorder( false );
475 
476  dlg.ShowModal();
477 
478  return 0;
479 }
480 
481 
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
bool m_background
Print background color.
Definition: printout.h:62
void onDeselectAllClick(wxCommandEvent &event)
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:361
SETTINGS_MANAGER * GetSettingsManager() const
Implementation of conversion functions that require both schematic and board internal units.
This file is part of the common library.
PCB_BASE_FRAME * m_frame
Grid origin marker.
Definition: pcb_control.h:127
std::vector< COLOR_SETTINGS * > GetColorSettingsList()
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
enum PCBNEW_PRINTOUT_SETTINGS::DRILL_MARK_SHAPE_T m_DrillMarks
std::pair< wxCheckListBox *, int > m_layers[PCB_LAYER_ID_COUNT]
void onUseThemeClicked(wxCommandEvent &event)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void saveSettings() override
wxString GetFilename() const
Definition: json_settings.h:72
void enableLayer(unsigned int aLayer, bool aValue)
Update layerset basing on the selected layers.
wxPrintout * createPrintout(const wxString &aTitle) override
Create a printout with a requested title.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:137
void onColorModeClicked(wxCommandEvent &event)
(Un)check all items in a checklist box.
LSET m_LayerSet
Layers to print.
bool isLayerEnabled(unsigned int aLayer) const
Enable/disable layer in a listbox.
wxCheckListBox * m_listCopperLayers
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:466
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:136
wxStaticBox * getOptionsBox()
void onSelectAllClick(wxCommandEvent &event)
Board plot function definition file.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition: printout.h:66
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:502
bool m_AsItemCheckboxes
Honor checkboxes in the Items tab of the Layers Manager.
wxCheckBox * m_checkboxPagePerLayer
PCB_BASE_EDIT_FRAME * m_parent
DIALOG_PRINT_PCBNEW(PCB_BASE_EDIT_FRAME *aParent, PCBNEW_PRINTOUT_SETTINGS *aSettings)
PRINTOUT_SETTINGS * m_settings
Generic, UI-independent tool event.
Definition: tool_event.h:152
wxCheckListBox * m_listTechLayers
#define _(s)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
void setListBoxValue(wxCheckListBox *aList, bool aValue)
Check whether a layer is enabled in a listbox.
void onPagePerLayerClicked(wxCommandEvent &event)
bool m_isFootprintEditor
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
bool background
Whether or not to print background color.
Definition: app_settings.h:133
bool m_PrintEdgeCutsOnAllPages
Print board outline on each page.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:463
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:787
bool m_blackWhite
Print in B&W or Color.
Definition: printout.h:60
bool TransferDataToWindow() override
bool TransferDataToWindow() override
int Print(const TOOL_EVENT &aEvent)
Common, abstract interface for edit frames.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
int m_pageCount
Number of pages to print.
Definition: printout.h:61
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:64
PCBNEW_PRINTOUT_SETTINGS * settings() const
PCBNEW_SETTINGS * GetPcbNewSettings() const
const PAGE_INFO & GetPageSettings() const override
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:92
Color settings are a bit different than most of the settings objects in that there can be more than o...
wxGridBagSizer * getOptionsSizer()
BOARD * GetBoard() const
LSEQ UIOrder() const
Definition: lset.cpp:895
bool m_Mirror
Print mirrored.
APP_SETTINGS_BASE * m_config
wxCheckBox * m_checkboxEdgesOnAllPages
COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
enum PCBNEW_PRINTOUT_SETTINGS::PAGINATION_T m_Pagination
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:184