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