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 <[email protected]>
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{
46public:
49
50private:
51 enum
52 {
60 };
61
63 {
64 wxASSERT( dynamic_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings ) );
65 return static_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings );
66 }
67
68 bool TransferDataToWindow() override;
69
70 void createExtraOptions();
71 void createLeftPanel();
72
73 void onUseThemeClicked( wxCommandEvent& event );
74 void onPagePerLayerClicked( wxCommandEvent& event );
75 void onColorModeClicked( wxCommandEvent& event );
76 void onPopUpLayers( wxCommandEvent& event );
77
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 LSEQ m_layerList; // List to hold CheckListBox layer numbers
91 wxMenu* m_popMenu;
92
93 wxCheckListBox* m_layerCheckListBox;
94 wxCheckBox* m_checkboxMirror;
98 wxCheckBox* m_checkAsItems;
99 wxCheckBox* m_checkBackground;
100 wxCheckBox* m_checkUseTheme;
101 wxChoice* m_colorTheme;
102};
103
104
106 PCBNEW_PRINTOUT_SETTINGS* aSettings ) :
107 DIALOG_PRINT_GENERIC( aParent, aSettings ),
108 m_parent( aParent )
109{
111
114
115 m_infoText->SetFont( KIUI::GetInfoFont( this ) );
116 m_infoText->SetLabel( _( "Right-click for layer selection commands." ) );
117 m_infoText->Show( true );
118
120
121 m_popMenu->Bind( wxEVT_COMMAND_MENU_SELECTED,
122 wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onPopUpLayers ), this,
124
125 m_outputMode->Bind( wxEVT_COMMAND_CHOICE_SELECTED, &DIALOG_PRINT_PCBNEW::onColorModeClicked,
126 this );
127}
128
129
131{
133 return false;
134
135 BOARD* board = m_parent->GetBoard();
136
137 // Create layer list
138 // Could devote a PlotOrder() function in place of UIOrder().
140
141 // Populate the check list box by all enabled layers names
142 for( LSEQ seq = m_layerList; seq; ++seq )
143 {
144 PCB_LAYER_ID layer = *seq;
145
146 int checkIndex = m_layerCheckListBox->Append( board->GetLayerName( layer ) );
147
148 if( settings()->m_LayerSet.test( layer ) )
149 m_layerCheckListBox->Check( checkIndex );
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( (int)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, _( "Include Layers" ) );
272 wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( box, wxVERTICAL );
273
274 m_layerCheckListBox = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
275 m_layerCheckListBox->SetMinSize( wxSize( 180, -1 ) );
276
277 sbLayersSizer->Add( m_layerCheckListBox, 1, wxEXPAND|wxBOTTOM|wxRIGHT, 5 );
278
279 getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND | wxALL, 5 );
280
281 m_popMenu = new wxMenu();
282 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_SELECT_FAB_LAYERS,
283 _( "Select Fab Layers" ), wxEmptyString ) );
284
285 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_SELECT_COPPER_LAYERS,
286 _( "Select all Copper Layers" ), wxEmptyString ) );
287
288 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_DESELECT_COPPER_LAYERS,
289 _( "Deselect all Copper Layers" ), wxEmptyString ) );
290
291 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_SELECT_ALL_LAYERS,
292 _( "Select all Layers" ), wxEmptyString ) );
293
294 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_DESELECT_ALL_LAYERS,
295 _( "Deselect all Layers" ), wxEmptyString ) );
296
297 this->Bind( wxEVT_RIGHT_DOWN,
298 [&]( wxMouseEvent& aEvent )
299 {
300 this->PopupMenu( m_popMenu, aEvent.GetPosition() );
301 } );
302
303 m_layerCheckListBox->Bind( wxEVT_RIGHT_DOWN,
304 [&]( wxMouseEvent& aEvent )
305 {
306 this->PopupMenu( m_popMenu, aEvent.GetPosition() );
307 } );
308}
309
310
311void DIALOG_PRINT_PCBNEW::onUseThemeClicked( wxCommandEvent& event )
312{
313 m_colorTheme->Enable( m_checkUseTheme->GetValue() );
314}
315
316
318{
319 if( m_checkboxPagePerLayer->GetValue() )
320 {
321 m_checkboxEdgesOnAllPages->Enable( true );
322 m_checkboxEdgesOnAllPages->SetValue( settings()->m_PrintEdgeCutsOnAllPages );
323 }
324 else
325 {
326 m_checkboxEdgesOnAllPages->Enable( false );
327 m_checkboxEdgesOnAllPages->SetValue( false );
328 }
329}
330
331
332void DIALOG_PRINT_PCBNEW::onColorModeClicked( wxCommandEvent& event )
333{
335
336 m_settings->m_blackWhite = m_outputMode->GetSelection();
337
341}
342
343
344// Select or deselect groups of layers in the layers list:
345void DIALOG_PRINT_PCBNEW::onPopUpLayers( wxCommandEvent& event )
346{
347 // Build a list of layers for usual fabrication: copper layers + tech layers without courtyard
348 LSET fab_layer_set = ( LSET::AllCuMask() | LSET::AllTechMask() ) & ~LSET( 2, B_CrtYd, F_CrtYd );
349
350 switch( event.GetId() )
351 {
352 case ID_SELECT_FAB_LAYERS: // Select layers usually needed to build a board
353 for( unsigned i = 0; i < m_layerList.size(); i++ )
354 {
355 LSET layermask( m_layerList[ i ] );
356
357 if( ( layermask & fab_layer_set ).any() )
358 m_layerCheckListBox->Check( i, true );
359 else
360 m_layerCheckListBox->Check( i, false );
361 }
362 break;
363
365 for( unsigned i = 0; i < m_layerList.size(); i++ )
366 {
367 if( IsCopperLayer( m_layerList[i] ) )
368 m_layerCheckListBox->Check( i, true );
369 }
370 break;
371
373 for( unsigned i = 0; i < m_layerList.size(); i++ )
374 {
375 if( IsCopperLayer( m_layerList[i] ) )
376 m_layerCheckListBox->Check( i, false );
377 }
378 break;
379
381 for( unsigned i = 0; i < m_layerList.size(); i++ )
382 m_layerCheckListBox->Check( i, true );
383 break;
384
386 for( unsigned i = 0; i < m_layerList.size(); i++ )
387 m_layerCheckListBox->Check( i, false );
388 break;
389
390 default:
391 break;
392 }
393}
394
395
397{
398 settings()->m_LayerSet = LSET();
399 int& pageCount = settings()->m_pageCount;
400 pageCount = 0;
401
402 for( unsigned i = 0; i < m_layerList.size(); i++ )
403 {
404 if( m_layerCheckListBox->IsChecked( i ) )
405 {
406 ++pageCount;
407 settings()->m_LayerSet.set( m_layerList[i] );
408 }
409 }
410
411 // In Pcbnew force the EDGE layer to be printed or not with the other layers
413
414 // All layers on one page (only if there is at least one layer selected)
415 if( !m_checkboxPagePerLayer->GetValue() && pageCount > 0 )
416 pageCount = 1;
417
418 return pageCount;
419}
420
421
423{
425
427
428 settings()->m_DrillMarks = static_cast<DRILL_MARKS>( m_drillMarksChoice->GetSelection() );
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
465int PCB_CONTROL::Print( const TOOL_EVENT& aEvent )
466{
467 // Selection affects the origin item visibility
469
472
474 dlg.ForcePrintBorder( false );
475
476 dlg.ShowModal();
477
478 return 0;
479}
480
481
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:190
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:565
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:452
Color settings are a bit different than most of the settings objects in that there can be more than o...
APP_SETTINGS_BASE * m_config
wxStaticBox * getOptionsBox()
bool TransferDataToWindow() override
void ForcePrintBorder(bool aValue)
Set 'print border and title block' to a requested value and hides the corresponding checkbox.
wxGridBagSizer * getOptionsSizer()
PRINTOUT_SETTINGS * m_settings
wxCheckBox * m_checkboxPagePerLayer
void onPopUpLayers(wxCommandEvent &event)
Update layerset basing on the selected layers.
wxPrintout * createPrintout(const wxString &aTitle) override
Create a printout with a requested title.
PCB_BASE_EDIT_FRAME * m_parent
DIALOG_PRINT_PCBNEW(PCB_BASE_EDIT_FRAME *aParent, PCBNEW_PRINTOUT_SETTINGS *aSettings)
wxCheckBox * m_checkboxEdgesOnAllPages
bool TransferDataToWindow() override
void saveSettings() override
void onColorModeClicked(wxCommandEvent &event)
void onPagePerLayerClicked(wxCommandEvent &event)
wxCheckListBox * m_layerCheckListBox
void onUseThemeClicked(wxCommandEvent &event)
PCBNEW_PRINTOUT_SETTINGS * settings() const
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
SETTINGS_MANAGER * GetSettingsManager() const
wxString GetFilename() const
Definition: json_settings.h:73
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:93
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:491
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
LSEQ UIOrder() const
Definition: lset.cpp:922
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:841
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
Common, abstract interface for edit frames.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
PCBNEW_SETTINGS * GetPcbNewSettings() const
const PAGE_INFO & GetPageSettings() const override
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
PCB_BASE_FRAME * m_frame
Grid origin marker.
Definition: pcb_control.h:140
int Print(const TOOL_EVENT &aEvent)
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
bool m_isFootprintEditor
std::vector< COLOR_SETTINGS * > GetColorSettingsList()
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
Generic, UI-independent tool event.
Definition: tool_event.h:156
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
This file is part of the common library.
#define _(s)
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:825
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ F_CrtYd
Definition: layer_ids.h:117
@ B_CrtYd
Definition: layer_ids.h:116
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
DRILL_MARKS
Plots and prints can show holes in pads and vias 3 options are available:
std::vector< FAB_LAYER_COLOR > dummy
bool background
Whether or not to print background color.
Definition: app_settings.h:145
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:149
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:148
LSET m_LayerSet
Layers to print.
bool m_Mirror
Print mirrored.
enum PCBNEW_PRINTOUT_SETTINGS::PAGINATION_T m_Pagination
bool m_PrintEdgeCutsOnAllPages
Print board outline on each page.
enum DRILL_MARKS m_DrillMarks
bool m_AsItemCheckboxes
Honor checkboxes in the Items tab of the Layers Manager.
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition: printout.h:66
bool m_blackWhite
Print in B&W or Color.
Definition: printout.h:60
int m_pageCount
Number of pages to print.
Definition: printout.h:61
bool m_background
Print background color.
Definition: printout.h:62