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_i.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 
41 
43 {
44 public:
47 
48 private:
50  {
51  wxASSERT( dynamic_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings ) );
52  return static_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings );
53  }
54 
55  bool TransferDataToWindow() override;
56 
57  void createExtraOptions();
58  void createLeftPanel();
59 
60  void onSelectAllClick( wxCommandEvent& event );
61  void onDeselectAllClick( wxCommandEvent& event );
62 
63  void onUseThemeChecked( wxCommandEvent& event );
64  void onColorModeChanged( wxCommandEvent& event );
65 
67  void setListBoxValue( wxCheckListBox* aList, bool aValue );
68 
70  bool isLayerEnabled( unsigned int aLayer ) const;
71 
73  void enableLayer( unsigned int aLayer, bool aValue );
74 
76  int setLayerSetFromList();
77 
78  void saveSettings() override;
79 
80  wxPrintout* createPrintout( const wxString& aTitle ) override
81  {
82  return new PCBNEW_PRINTOUT( m_parent->GetBoard(), *settings(),
83  m_parent->GetCanvas()->GetView(), aTitle );
84  }
85 
87 
88  // List of existing board layers in wxCheckListBox, with the board layers id:
89  std::pair<wxCheckListBox*, int> m_layers[PCB_LAYER_ID_COUNT];
90 
91  // Extra widgets
92  wxCheckListBox* m_listTechLayers;
93  wxCheckListBox* m_listCopperLayers;
94  wxButton* m_buttonSelectAll;
96  wxCheckBox* m_checkboxNoEdge;
97  wxCheckBox* m_checkboxMirror;
98  wxChoice* m_drillMarksChoice;
99  wxRadioBox* m_boxPagination;
100  wxCheckBox* m_checkAsItems;
101  wxCheckBox* m_checkBackground;
102  wxCheckBox* m_checkUseTheme;
103  wxChoice* m_colorTheme;
104 };
105 
106 
108  PCBNEW_PRINTOUT_SETTINGS* aSettings ) :
109  DIALOG_PRINT_GENERIC( aParent, aSettings ),
110  m_parent( aParent )
111 {
113 
115  createLeftPanel();
116 
117  m_outputMode->Bind( wxEVT_COMMAND_CHOICE_SELECTED, &DIALOG_PRINT_PCBNEW::onColorModeChanged,
118  this );
119 }
120 
121 
123 {
125  return false;
126 
127  BOARD* board = m_parent->GetBoard();
128 
129  // Create layer list
130  for( LSEQ seq = board->GetEnabledLayers().UIOrder(); seq; ++seq )
131  {
132  PCB_LAYER_ID layer = *seq;
133  int checkIndex;
134 
135  if( IsCopperLayer( layer ) )
136  {
137  checkIndex = m_listCopperLayers->Append( board->GetLayerName( layer ) );
138  m_layers[layer] = std::make_pair( m_listCopperLayers, checkIndex );
139  }
140  else
141  {
142  checkIndex = m_listTechLayers->Append( board->GetLayerName( layer ) );
143  m_layers[layer] = std::make_pair( m_listTechLayers, checkIndex );
144  }
145 
146  m_layers[layer].first->Check( checkIndex, settings()->m_LayerSet.test( layer ) );
147  }
148 
149  m_checkboxMirror->SetValue( settings()->m_Mirror );
150  m_checkboxNoEdge->SetValue( settings()->m_noEdgeLayer );
151  m_titleBlock->SetValue( settings()->m_titleBlock );
152 
154 
155  m_checkBackground->SetValue( cfg->m_Printing.background );
156  m_checkUseTheme->SetValue( cfg->m_Printing.use_theme );
157 
158  m_colorTheme->Clear();
159 
160  int width = 0;
161  int height = 0;
162  int minwidth = width;
163 
164  wxString target = cfg->m_Printing.use_theme ? cfg->m_Printing.color_theme : cfg->m_ColorTheme;
165 
166  for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
167  {
168  int pos = m_colorTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
169 
170  if( settings->GetFilename() == target )
171  m_colorTheme->SetSelection( pos );
172 
173  m_colorTheme->GetTextExtent( settings->GetName(), &width, &height );
174  minwidth = std::max( minwidth, width );
175  }
176 
177  m_colorTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
178 
179  wxCommandEvent dummy;
181 
182  // Options to plot pads and vias holes
183  m_drillMarksChoice->SetSelection( settings()->m_drillMarks );
184 
185  // Print all layers one one page or separately
186  m_boxPagination->SetSelection( settings()->m_pagination );
187 
188  // Update the dialog layout when layers are added
189  GetSizer()->Fit( this );
190 
191  return true;
192 }
193 
194 
196 {
197  wxGridBagSizer* optionsSizer = getOptionsSizer();
198  wxStaticBox* box = getOptionsBox();
199  int rows = optionsSizer->GetEffectiveRowsCount();
200  int cols = optionsSizer->GetEffectiveColsCount();
201 
202  m_checkAsItems = new wxCheckBox( sbOptionsSizer->GetStaticBox(), wxID_ANY,
203  _( "Print according to objects tab of appearance manager" ),
204  wxDefaultPosition, wxDefaultSize, 0 );
205  optionsSizer->Add( m_checkAsItems, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ), wxALL, 5 );
206 
207  m_checkBackground = new wxCheckBox( sbOptionsSizer->GetStaticBox(), wxID_ANY,
208  _( "Print background color" ), wxDefaultPosition,
209  wxDefaultSize, 0 );
210  optionsSizer->Add( m_checkBackground, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ), wxALL, 5 );
211 
212  m_checkUseTheme = new wxCheckBox( sbOptionsSizer->GetStaticBox(), wxID_ANY,
213  _( "Use a different color theme for printing:" ),
214  wxDefaultPosition, wxDefaultSize, 0 );
215  optionsSizer->Add( m_checkUseTheme, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ), wxALL, 5 );
216 
217  m_checkUseTheme->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
219 
220  wxArrayString m_colorThemeChoices;
221  m_colorTheme = new wxChoice( sbOptionsSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition,
222  wxDefaultSize, m_colorThemeChoices, 0 );
223  m_colorTheme->SetSelection( 0 );
224 
225  optionsSizer->Add( m_colorTheme, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
226  wxALIGN_CENTER_VERTICAL | wxLEFT, 25 );
227 
228  // Drill marks option
229  auto drillMarksLabel = new wxStaticText( box, wxID_ANY, _( "Drill marks:" ) );
230  std::vector<wxString> drillMarkChoices = { _( "No drill mark" ),
231  _( "Small mark" ),
232  _( "Real drill" ) };
233  m_drillMarksChoice = new wxChoice( box, wxID_ANY, wxDefaultPosition, wxDefaultSize,
234  drillMarkChoices.size(), drillMarkChoices.data(), 0 );
235  m_drillMarksChoice->SetSelection( 0 );
236 
237  // Print mirrored
238  m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
239 
240  // Pagination
241  std::vector<wxString> pagesOption = { _( "One page per layer" ),
242  _( "All layers on single page" ) };
243  m_boxPagination = new wxRadioBox( box, wxID_ANY, _( "Pagination" ), wxDefaultPosition,
244  wxDefaultSize, pagesOption.size(), pagesOption.data(), 1,
245  wxRA_SPECIFY_COLS );
246  m_boxPagination->SetSelection( 0 );
247 
248  // Sizer layout
249  rows++;
250 
251  optionsSizer->Add( drillMarksLabel, wxGBPosition( rows, 0 ), wxGBSpan( 1, 1 ),
252  wxBOTTOM | wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
253  optionsSizer->Add( m_drillMarksChoice, wxGBPosition( rows, 1 ), wxGBSpan( 1, cols - 1 ),
254  wxBOTTOM | wxRIGHT | wxLEFT, 5 );
255  optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows + 1, 0 ), wxGBSpan( 1, cols ),
256  wxBOTTOM | wxRIGHT | wxLEFT, 5 );
257  optionsSizer->Add( m_boxPagination, wxGBPosition( rows + 2, 0 ), wxGBSpan( 1, cols ),
258  wxALL | wxEXPAND, 5 );
259 }
260 
261 
263 {
264  wxStaticBox* box = new wxStaticBox( this, wxID_ANY, _( "Included Layers" ) );
265  wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( box, wxVERTICAL );
266 
267  // Copper layer list
268  auto copperLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY,
269  _( "Copper layers:" ) );
270  m_listCopperLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
271 
272  wxBoxSizer* sizerLeft = new wxBoxSizer( wxVERTICAL );
273  sizerLeft->Add( copperLabel, 0, wxRIGHT, 5 );
274  sizerLeft->Add( m_listCopperLayers, 1, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
275 
276 
277  // Technical layer list
278  auto technicalLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY,
279  _( "Technical layers:" ) );
280  m_listTechLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
281 
282  wxBoxSizer* sizerRight = new wxBoxSizer( wxVERTICAL );
283  sizerRight->Add( technicalLabel, 0, wxLEFT, 5 );
284  sizerRight->Add( m_listTechLayers, 1, wxEXPAND | wxBOTTOM | wxLEFT, 5 );
285 
286 
287  // Layer list layout
288  wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
289  bLayerListsSizer->Add( sizerLeft, 1, wxEXPAND, 5 );
290  bLayerListsSizer->Add( sizerRight, 1, wxEXPAND, 5 );
291 
292 
293  // Select/Unselect all buttons
294  m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
295  m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY,
296  _( "Deselect all" ) );
297 
298  m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
299  wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onSelectAllClick ), NULL, this );
300  m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
301  wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onDeselectAllClick ), NULL, this );
302 
303  wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
304  buttonSizer->Add( m_buttonSelectAll, 1, wxRIGHT | wxTOP | wxBOTTOM, 5 );
305  buttonSizer->Add( m_buttonDeselectAll, 1, wxLEFT | wxTOP | wxBOTTOM, 5 );
306 
307 
308  // Exclude Edge.Pcb layer checkbox
309  m_checkboxNoEdge = new wxCheckBox( sbLayersSizer->GetStaticBox(), wxID_ANY,
310  _( "Exclude PCB edge layer" ) );
311  m_checkboxNoEdge->SetToolTip( _("Exclude contents of Edges_Pcb layer from all other layers") );
312 
313  // Static box sizer layout
314  sbLayersSizer->Add( bLayerListsSizer, 1, wxRIGHT | wxEXPAND, 5 );
315  sbLayersSizer->Add( buttonSizer, 0, wxRIGHT | wxEXPAND, 5 );
316  sbLayersSizer->Add( m_checkboxNoEdge, 0, wxTOP | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
317 
318  getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND | wxALL, 5 );
319 }
320 
321 
322 void DIALOG_PRINT_PCBNEW::onSelectAllClick( wxCommandEvent& event )
323 {
326 }
327 
328 
329 void DIALOG_PRINT_PCBNEW::onDeselectAllClick( wxCommandEvent& event )
330 {
333 }
334 
335 
336 void DIALOG_PRINT_PCBNEW::onUseThemeChecked( wxCommandEvent& event )
337 {
338  m_colorTheme->Enable( m_checkUseTheme->GetValue() );
339 }
340 
341 
342 void DIALOG_PRINT_PCBNEW::onColorModeChanged( wxCommandEvent& event )
343 {
345 
346  m_settings->m_blackWhite = m_outputMode->GetSelection();
347 
351 }
352 
353 
354 void DIALOG_PRINT_PCBNEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
355 {
356  for( unsigned int i = 0; i < aList->GetCount(); ++i )
357  aList->Check( i, aValue );
358 }
359 
360 
361 bool DIALOG_PRINT_PCBNEW::isLayerEnabled( unsigned int aLayer ) const
362 {
363  wxCHECK( aLayer < arrayDim( m_layers ), false );
364  const auto& layerInfo = m_layers[aLayer];
365 
366  if( layerInfo.first )
367  return layerInfo.first->IsChecked( layerInfo.second );
368 
369  return false;
370 }
371 
372 
373 void DIALOG_PRINT_PCBNEW::enableLayer( unsigned int aLayer, bool aValue )
374 {
375  wxCHECK( aLayer < arrayDim( m_layers ), /* void */ );
376  const auto& layerInfo = m_layers[aLayer];
377  layerInfo.first->Check( layerInfo.second, aValue );
378 }
379 
380 
382 {
383  settings()->m_LayerSet = LSET();
384  int& pageCount = settings()->m_pageCount;
385  pageCount = 0;
386 
387  for( unsigned int layer = 0; layer < arrayDim( m_layers ); ++layer )
388  {
389  if( isLayerEnabled( layer ) )
390  {
391  ++pageCount;
392  settings()->m_LayerSet.set( layer );
393  }
394  }
395 
396  // In Pcbnew force the EDGE layer to be printed or not with the other layers
397  settings()->m_noEdgeLayer = m_checkboxNoEdge->IsChecked();
398 
399  // All layers on one page (only if there is at least one layer selected)
400  if( m_boxPagination->GetSelection() != 0 && pageCount > 0 )
401  pageCount = 1;
402 
403  return pageCount;
404 }
405 
406 
408 {
410 
411  settings()->m_asItemCheckboxes = m_checkAsItems->GetValue();
412 
415 
416  settings()->m_pagination = m_boxPagination->GetSelection() == 0
418 
419  settings()->m_Mirror = m_checkboxMirror->GetValue();
420 
422 
423  cfg->m_Printing.background = m_checkBackground->GetValue();
425  cfg->m_Printing.use_theme = m_checkUseTheme->GetValue();
426 
427  int sel = m_colorTheme->GetSelection();
428  COLOR_SETTINGS* theme = static_cast<COLOR_SETTINGS*>( m_colorTheme->GetClientData( sel ) );
429 
430  if( theme && m_checkUseTheme->IsChecked() )
431  {
432  cfg->m_Printing.color_theme = theme->GetFilename();
433  settings()->m_colorSettings = theme;
434  }
435  else
436  {
438  }
439 
441 }
442 
443 
444 int PCB_CONTROL::Print( const TOOL_EVENT& aEvent )
445 {
446  // Selection affects the origin item visibility
448 
450  DIALOG_PRINT_PCBNEW dlg( (PCB_BASE_EDIT_FRAME*) m_frame, &settings );
451 
452  if( m_isFootprintEditor )
453  dlg.ForcePrintBorder( false );
454 
455  dlg.ShowModal();
456 
457  return 0;
458 }
459 
460 
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
bool m_background
Print background color.
Definition: printout.h:62
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.
Definition: board.cpp:342
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:116
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)
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:215
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:92
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:137
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 Returns a bit-mask of all t...
Definition: board.cpp:447
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:136
wxStaticBox * getOptionsBox()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void onSelectAllClick(wxCommandEvent &event)
Board plot function definition file.
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition: printout.h:66
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
#define NULL
void onColorModeChanged(wxCommandEvent &event)
(Un)check all items in a checklist box.
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.
Generic, UI-independent tool event.
Definition: tool_event.h:173
wxCheckListBox * m_listTechLayers
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.
bool m_asItemCheckboxes
Honor checkboxes in the Items tab of the Layers Manager.
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
SETTINGS_MANAGER * GetSettingsManager()
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
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
#define _(s)
Definition: 3d_actions.cpp:33
int m_pageCount
Number of pages to print.
Definition: printout.h:61
PCBNEW_PRINTOUT_SETTINGS * settings() const
PCBNEW_SETTINGS * GetPcbNewSettings() 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:895
void onUseThemeChecked(wxCommandEvent &event)
bool m_Mirror
Print mirrored.
APP_SETTINGS_BASE * m_config
COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:184