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 <fctsys.h>
28 #include <kiface_i.h>
29 #include <confirm.h>
30 #include <base_units.h>
31 #include <pcbnew.h>
32 #include <pcbnew_settings.h>
33 #include <pcbplot.h>
34 #include <class_board.h>
35 #include <tool/tool_manager.h>
36 #include <tools/pcb_actions.h>
37 #include <tools/pcbnew_control.h>
38 #include <dialog_print_generic.h>
39 #include <pcbnew_printout.h>
40 
42 {
43 public:
46 
47 private:
49  {
50  wxASSERT( dynamic_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings ) );
51  return static_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings );
52  }
53 
54  bool TransferDataToWindow() override;
55 
56  void createExtraOptions();
57  void createLeftPanel();
58 
59  void onSelectAllClick( wxCommandEvent& event );
60  void onDeselectAllClick( wxCommandEvent& event );
61 
62  void onUseThemeChecked( wxCommandEvent& event );
63  void onColorModeChanged( wxCommandEvent& event );
64 
66  void setListBoxValue( wxCheckListBox* aList, bool aValue );
67 
69  bool isLayerEnabled( unsigned int aLayer ) const;
70 
72  void enableLayer( unsigned int aLayer, bool aValue );
73 
75  int setLayerSetFromList();
76 
77  void saveSettings() override;
78 
79  wxPrintout* createPrintout( const wxString& aTitle ) override
80  {
81  return new PCBNEW_PRINTOUT( m_parent->GetBoard(), *settings(),
82  m_parent->GetCanvas()->GetView(), aTitle );
83  }
84 
86 
87  // List of existing board layers in wxCheckListBox, with the board layers id:
88  std::pair<wxCheckListBox*, int> m_layers[PCB_LAYER_ID_COUNT];
89 
90  // Extra widgets
91  wxCheckListBox* m_listTechLayers;
92  wxCheckListBox* m_listCopperLayers;
93  wxButton* m_buttonSelectAll;
95  wxCheckBox* m_checkboxNoEdge;
96  wxCheckBox* m_checkboxMirror;
97  wxChoice* m_drillMarksChoice;
98  wxRadioBox* m_boxPagination;
99  wxCheckBox* m_checkBackground;
100  wxCheckBox* m_checkUseTheme;
101  wxStaticText* m_lblTheme;
102  wxChoice* m_colorTheme;
103 };
104 
105 
107  DIALOG_PRINT_GENERIC( aParent, aSettings ), m_parent( aParent )
108 {
110 
112  createLeftPanel();
113 
114  m_outputMode->Bind(
115  wxEVT_COMMAND_CHOICE_SELECTED, &DIALOG_PRINT_PCBNEW::onColorModeChanged, this );
116 }
117 
118 
120 {
122  return false;
123 
124  BOARD* board = m_parent->GetBoard();
125 
126  // Create layer list
127  for( LSEQ seq = board->GetEnabledLayers().UIOrder(); seq; ++seq )
128  {
129  PCB_LAYER_ID layer = *seq;
130  int checkIndex;
131 
132  if( IsCopperLayer( layer ) )
133  {
134  checkIndex = m_listCopperLayers->Append( board->GetLayerName( layer ) );
135  m_layers[layer] = std::make_pair( m_listCopperLayers, checkIndex );
136  }
137  else
138  {
139  checkIndex = m_listTechLayers->Append( board->GetLayerName( layer ) );
140  m_layers[layer] = std::make_pair( m_listTechLayers, checkIndex );
141  }
142 
143  m_layers[layer].first->Check( checkIndex, settings()->m_layerSet.test( layer ) );
144  }
145 
146  m_checkboxMirror->SetValue( settings()->m_mirror );
147  m_checkboxNoEdge->SetValue( settings()->m_noEdgeLayer );
148  m_titleBlock->SetValue( settings()->m_titleBlock );
149 
151 
152  m_checkBackground->SetValue( cfg->m_Printing.background );
153  m_checkUseTheme->SetValue( cfg->m_Printing.use_theme );
154 
155  m_colorTheme->Clear();
156 
157  int width = 0;
158  int height = 0;
159  int minwidth = width;
160 
161  wxString target = cfg->m_Printing.use_theme ? cfg->m_Printing.color_theme : cfg->m_ColorTheme;
162 
163  for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
164  {
165  int pos = m_colorTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
166 
167  if( settings->GetFilename() == target )
168  m_colorTheme->SetSelection( pos );
169 
170  m_colorTheme->GetTextExtent( settings->GetName(), &width, &height );
171  minwidth = std::max( minwidth, width );
172  }
173 
174  m_colorTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
175 
176  wxCommandEvent dummy;
178 
179  // Options to plot pads and vias holes
180  m_drillMarksChoice->SetSelection( settings()->m_drillMarks );
181 
182  // Print all layers one one page or separately
183  m_boxPagination->SetSelection( settings()->m_pagination );
184 
185  // Update the dialog layout when layers are added
186  GetSizer()->Fit( this );
187 
188  return true;
189 }
190 
191 
193 {
194  wxGridBagSizer* optionsSizer = getOptionsSizer();
195  wxStaticBox* box = getOptionsBox();
196  int rows = optionsSizer->GetEffectiveRowsCount();
197  int cols = optionsSizer->GetEffectiveColsCount();
198 
199  m_checkBackground = new wxCheckBox( sbOptionsSizer->GetStaticBox(), wxID_ANY,
200  _( "Print background color" ), wxDefaultPosition, wxDefaultSize, 0 );
201  optionsSizer->Add( m_checkBackground, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ), wxALL, 5 );
202 
203  m_checkUseTheme = new wxCheckBox( sbOptionsSizer->GetStaticBox(), wxID_ANY,
204  _( "Use a different color theme for printing" ), wxDefaultPosition, wxDefaultSize, 0 );
205  optionsSizer->Add( m_checkUseTheme, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 3 ), wxALL, 5 );
206 
207  m_checkUseTheme->Bind(
208  wxEVT_COMMAND_CHECKBOX_CLICKED, &DIALOG_PRINT_PCBNEW::onUseThemeChecked, this );
209 
210  m_lblTheme = new wxStaticText( sbOptionsSizer->GetStaticBox(), wxID_ANY, _( "Color theme:" ),
211  wxDefaultPosition, wxDefaultSize, 0 );
212  m_lblTheme->Wrap( -1 );
213  optionsSizer->Add( m_lblTheme, wxGBPosition( rows, 0 ), wxGBSpan( 1, 1 ),
214  wxALIGN_CENTER_VERTICAL | wxALL, 5 );
215 
216  wxArrayString m_colorThemeChoices;
217  m_colorTheme = new wxChoice( sbOptionsSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition,
218  wxDefaultSize, m_colorThemeChoices, 0 );
219  m_colorTheme->SetSelection( 0 );
220  optionsSizer->Add( m_colorTheme, wxGBPosition( rows++, 1 ), wxGBSpan( 1, 2 ), wxALL, 5 );
221 
222  // Drill marks option
223  auto drillMarksLabel = new wxStaticText( box, wxID_ANY, _( "Drill marks:" ) );
224  std::vector<wxString> drillMarkChoices =
225  { _( "No drill mark" ), _( "Small mark" ), _( "Real drill" ) };
226  m_drillMarksChoice = new wxChoice( box, wxID_ANY, wxDefaultPosition,
227  wxDefaultSize, drillMarkChoices.size(), drillMarkChoices.data(), 0 );
228  m_drillMarksChoice->SetSelection( 0 );
229 
230  // Print mirrored
231  m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
232 
233  // Pagination
234  std::vector<wxString> pagesOption = { _( "One page per layer" ), _( "All layers on single page" ) };
235  m_boxPagination = new wxRadioBox( box, wxID_ANY, _( "Pagination" ), wxDefaultPosition,
236  wxDefaultSize, pagesOption.size(), pagesOption.data(), 1, wxRA_SPECIFY_COLS );
237  m_boxPagination->SetSelection( 0 );
238 
239  // Sizer layout
240  optionsSizer->Add( drillMarksLabel, wxGBPosition( rows, 0 ), wxGBSpan( 1, 1 ),
241  wxBOTTOM | wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
242  optionsSizer->Add( m_drillMarksChoice, wxGBPosition( rows, 1 ), wxGBSpan( 1, cols - 1 ),
243  wxBOTTOM | wxRIGHT | wxLEFT, 5 );
244  optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows + 1, 0 ), wxGBSpan( 1, cols ),
245  wxBOTTOM | wxRIGHT | wxLEFT, 5 );
246  optionsSizer->Add( m_boxPagination, wxGBPosition( rows + 2, 0 ), wxGBSpan( 1, cols ),
247  wxALL | wxEXPAND, 5 );
248 }
249 
250 
252 {
253  wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( new wxStaticBox( this,
254  wxID_ANY, _( "Included Layers" ) ), wxVERTICAL );
255 
256  // Copper layer list
257  auto copperLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Copper layers:" ) );
258  m_listCopperLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
259 
260  wxBoxSizer* sizerLeft = new wxBoxSizer( wxVERTICAL );
261  sizerLeft->Add( copperLabel, 0, wxRIGHT | wxLEFT, 5 );
262  sizerLeft->Add( m_listCopperLayers, 1, wxEXPAND | wxBOTTOM | wxRIGHT | wxLEFT, 5 );
263 
264 
265  // Technical layer list
266  auto technicalLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Technical layers:" ) );
267  m_listTechLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
268 
269  wxBoxSizer* sizerRight = new wxBoxSizer( wxVERTICAL );
270  sizerRight->Add( technicalLabel, 0, wxRIGHT | wxLEFT, 5 );
271  sizerRight->Add( m_listTechLayers, 1, wxEXPAND | wxBOTTOM | wxRIGHT | wxLEFT, 5 );
272 
273 
274  // Layer list layout
275  wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
276  bLayerListsSizer->Add( sizerLeft, 1, wxEXPAND, 5 );
277  bLayerListsSizer->Add( sizerRight, 1, wxEXPAND, 5 );
278 
279 
280  // Select/Unselect all buttons
281  m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
282  m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Deselect all" ) );
283 
284  m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
285  wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onSelectAllClick ), NULL, this );
286  m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
287  wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onDeselectAllClick ), NULL, this );
288 
289  wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
290  buttonSizer->Add( m_buttonSelectAll, 1, wxALL, 5 );
291  buttonSizer->Add( m_buttonDeselectAll, 1, wxALL, 5 );
292 
293 
294  // Exclude Edge.Pcb layer checkbox
295  m_checkboxNoEdge = new wxCheckBox( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Exclude PCB edge layer" ) );
296  m_checkboxNoEdge->SetToolTip( _("Exclude contents of Edges_Pcb layer from all other layers") );
297 
298  // Static box sizer layout
299  sbLayersSizer->Add( bLayerListsSizer, 1, wxALL | wxEXPAND, 5 );
300  sbLayersSizer->Add( buttonSizer, 0, wxALL | wxEXPAND, 5 );
301  sbLayersSizer->Add( m_checkboxNoEdge, 0, wxALL | wxEXPAND, 5 );
302 
303  getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND );
304 }
305 
306 
307 void DIALOG_PRINT_PCBNEW::onSelectAllClick( wxCommandEvent& event )
308 {
311 }
312 
313 
314 void DIALOG_PRINT_PCBNEW::onDeselectAllClick( wxCommandEvent& event )
315 {
318 }
319 
320 
321 void DIALOG_PRINT_PCBNEW::onUseThemeChecked( wxCommandEvent& event )
322 {
323  m_lblTheme->Enable( m_checkUseTheme->GetValue() );
324  m_colorTheme->Enable( m_checkUseTheme->GetValue() );
325 }
326 
327 
328 void DIALOG_PRINT_PCBNEW::onColorModeChanged( wxCommandEvent& event )
329 {
331 
332  m_settings->m_blackWhite = m_outputMode->GetSelection();
333 
338 }
339 
340 
341 void DIALOG_PRINT_PCBNEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
342 {
343  for( unsigned int i = 0; i < aList->GetCount(); ++i )
344  aList->Check( i, aValue );
345 }
346 
347 
348 bool DIALOG_PRINT_PCBNEW::isLayerEnabled( unsigned int aLayer ) const
349 {
350  wxCHECK( aLayer < arrayDim( m_layers ), false );
351  const auto& layerInfo = m_layers[aLayer];
352 
353  if( layerInfo.first )
354  return layerInfo.first->IsChecked( layerInfo.second );
355 
356  return false;
357 }
358 
359 
360 void DIALOG_PRINT_PCBNEW::enableLayer( unsigned int aLayer, bool aValue )
361 {
362  wxCHECK( aLayer < arrayDim( m_layers ), /* void */ );
363  const auto& layerInfo = m_layers[aLayer];
364  layerInfo.first->Check( layerInfo.second, aValue );
365 }
366 
367 
369 {
370  settings()->m_layerSet = LSET();
371  int& pageCount = settings()->m_pageCount;
372  pageCount = 0;
373 
374  for( unsigned int layer = 0; layer < arrayDim( m_layers ); ++layer )
375  {
376  if( isLayerEnabled( layer ) )
377  {
378  ++pageCount;
379  settings()->m_layerSet.set( layer );
380  }
381  }
382 
383  // In Pcbnew force the EDGE layer to be printed or not with the other layers
384  settings()->m_noEdgeLayer = m_checkboxNoEdge->IsChecked();
385 
386  // All layers on one page (only if there is at least one layer selected)
387  if( m_boxPagination->GetSelection() != 0 && pageCount > 0 )
388  pageCount = 1;
389 
390  return pageCount;
391 }
392 
393 
395 {
397 
400 
401  settings()->m_pagination = m_boxPagination->GetSelection() == 0
403 
404  settings()->m_mirror = m_checkboxMirror->GetValue();
405 
407 
408  cfg->m_Printing.background = m_checkBackground->GetValue();
410  cfg->m_Printing.use_theme = m_checkUseTheme->GetValue();
411 
412  COLOR_SETTINGS* theme = static_cast<COLOR_SETTINGS*>(
413  m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) );
414 
415  if( theme && m_checkUseTheme->IsChecked() )
416  {
417  cfg->m_Printing.color_theme = theme->GetFilename();
418  settings()->m_colorSettings = theme;
419  }
420  else
421  {
422  // This should always work, but in case it doesn't we fall back on default colors
423  if( auto pcbframe = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_parent ) )
424  settings()->m_colorSettings = pcbframe->GetColorSettings();
425  else
427  }
428 
430 }
431 
432 
433 int PCBNEW_CONTROL::Print( const TOOL_EVENT& aEvent )
434 {
435  // Selection affects the origin item visibility
437 
439  DIALOG_PRINT_PCBNEW dlg( (PCB_BASE_EDIT_FRAME*) m_frame, &settings );
440 
441  if( m_editModules )
442  dlg.ForcePrintBorder( false );
443 
444  dlg.ShowModal();
445 
446  return 0;
447 }
448 
449 
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)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer.
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
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:140
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:103
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:121
bool isLayerEnabled(unsigned int aLayer) const
Check whether a layer is enabled in a listbox
wxCheckListBox * m_listCopperLayers
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:120
PCBNEW_SETTINGS * GetPcbNewSettings()
wxStaticBox * getOptionsBox()
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
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:117
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:160
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.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#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
Pagination.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer 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...
std::string GetFilename() const
Definition: json_settings.h:56
enum PCBNEW_PRINTOUT_SETTINGS::DRILL_MARK_SHAPE_T m_drillMarks
Drill marks shape.
wxGridBagSizer * getOptionsSizer()
BOARD * GetBoard() const
LSEQ UIOrder() const
Definition: lset.cpp:839
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:156