KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.txt for contributors.
6 * Copyright (C) 2018-2023 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 <pcbnew_settings.h>
30#include <pcbplot.h>
31#include <board.h>
32#include <tool/tool_manager.h>
33#include <tools/pcb_actions.h>
34#include <tools/pcb_control.h>
36#include <pcbnew_printout.h>
37#include <wx/checklst.h>
38
39
41{
42public:
45
46private:
47 enum
48 {
56 };
57
59 {
60 wxASSERT( dynamic_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings ) );
61 return static_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings );
62 }
63
64 bool TransferDataToWindow() override;
65
66 void createExtraOptions();
67 void createLeftPanel();
68
69 void onUseThemeClicked( wxCommandEvent& event );
70 void onPagePerLayerClicked( wxCommandEvent& event );
71 void onColorModeClicked( wxCommandEvent& event );
72 void onPopUpLayers( wxCommandEvent& event );
73
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 LSEQ m_layerList; // List to hold CheckListBox layer numbers
87 wxMenu* m_popMenu;
88
89 wxCheckListBox* m_layerCheckListBox;
90 wxCheckBox* m_checkboxMirror;
94 wxCheckBox* m_checkAsItems;
95 wxCheckBox* m_checkBackground;
96 wxCheckBox* m_checkUseTheme;
97 wxChoice* m_colorTheme;
98};
99
100
102 PCBNEW_PRINTOUT_SETTINGS* aSettings ) :
103 DIALOG_PRINT_GENERIC( aParent, aSettings ),
104 m_parent( aParent )
105{
107
110
111 BOARD* board = m_parent->GetBoard();
112
113 // Create layer list
114 // Could devote a PlotOrder() function in place of UIOrder().
116
117 // Populate the check list box by all enabled layers names. They will be enabled later
118 // when the dlg settings are loaded (i.e. after DIALOG_PRINT_GENERIC::TransferDataToWindow()
119 // is called
120 for( PCB_LAYER_ID layer : m_layerList )
121 m_layerCheckListBox->Append( board->GetLayerName( layer ) );
122
123 m_infoText->SetFont( KIUI::GetInfoFont( this ) );
124 m_infoText->SetLabel( _( "Right-click for layer selection commands." ) );
125 m_infoText->Show( true );
126
128
129 m_popMenu->Bind( wxEVT_COMMAND_MENU_SELECTED,
130 wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onPopUpLayers ), this,
132
133 m_outputMode->Bind( wxEVT_COMMAND_CHOICE_SELECTED, &DIALOG_PRINT_PCBNEW::onColorModeClicked,
134 this );
135}
136
137
139{
140 m_popMenu->Unbind( wxEVT_COMMAND_MENU_SELECTED,
141 wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onPopUpLayers ), this,
143
144 m_outputMode->Unbind( wxEVT_COMMAND_CHOICE_SELECTED, &DIALOG_PRINT_PCBNEW::onColorModeClicked,
145 this );
146}
147
148
150{
152 return false;
153
154 BOARD* board = m_parent->GetBoard();
155
156 // Enable layers from previous dlg settings
158 int choice_ly_id = 0;
159
160 for( PCB_LAYER_ID layer : m_layerList )
161 {
162 if( settings()->m_LayerSet.test( layer ) )
163 m_layerCheckListBox->Check( choice_ly_id );
164
165 choice_ly_id++;
166 }
167
168 m_checkAsItems->SetValue( settings()->m_AsItemCheckboxes );
169 m_checkboxMirror->SetValue( settings()->m_Mirror );
170 m_titleBlock->SetValue( settings()->m_titleBlock );
171
173
174 m_checkBackground->SetValue( cfg->m_Printing.background );
175 m_checkUseTheme->SetValue( cfg->m_Printing.use_theme );
176
177 m_colorTheme->Clear();
178
179 int width = 0;
180 int height = 0;
181 int minwidth = width;
182
183 wxString target = cfg->m_Printing.use_theme ? cfg->m_Printing.color_theme : cfg->m_ColorTheme;
184
186 {
187 int pos = m_colorTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
188
189 if( settings->GetFilename() == target )
190 m_colorTheme->SetSelection( pos );
191
192 m_colorTheme->GetTextExtent( settings->GetName(), &width, &height );
193 minwidth = std::max( minwidth, width );
194 }
195
196 m_colorTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
197
198 wxCommandEvent dummy;
200
201 // Options to plot pads and vias holes
202 m_drillMarksChoice->SetSelection( (int)settings()->m_DrillMarks );
203
204 // Print all layers one one page or separately
205 m_checkboxPagePerLayer->SetValue( settings()->m_Pagination
208
209 // Update the dialog layout when layers are added
210 GetSizer()->Fit( this );
211
212 return true;
213}
214
215
217{
218 wxGridBagSizer* optionsSizer = getOptionsSizer();
219 wxStaticBox* box = getOptionsBox();
220 int rows = optionsSizer->GetEffectiveRowsCount();
221
222 m_checkAsItems = new wxCheckBox( box, wxID_ANY, _( "Print according to objects tab of "
223 "appearance manager" ) );
224 optionsSizer->Add( m_checkAsItems, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
225 wxLEFT|wxRIGHT|wxBOTTOM, 5 );
226
227 m_checkBackground = new wxCheckBox( box, wxID_ANY, _( "Print background color" ) );
228 optionsSizer->Add( m_checkBackground, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
229 wxLEFT|wxRIGHT|wxBOTTOM, 5 );
230
231 m_checkUseTheme = new wxCheckBox( box, wxID_ANY, _( "Use a different color theme for "
232 "printing:" ) );
233 optionsSizer->Add( m_checkUseTheme, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
234 wxLEFT|wxRIGHT, 5 );
235
236 m_checkUseTheme->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
238
239 wxArrayString choices;
240 m_colorTheme = new wxChoice( box, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices, 0 );
241 m_colorTheme->SetSelection( 0 );
242 m_colorTheme->SetMinSize( { 200, -1 } );
243 optionsSizer->Add( m_colorTheme, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ), wxLEFT, 28 );
244
245 rows++;
246
247 // Drill marks option
248 auto drillMarksLabel = new wxStaticText( box, wxID_ANY, _( "Drill marks:" ) );
249 std::vector<wxString> drillMarkChoices = { _( "No drill mark" ),
250 _( "Small mark" ),
251 _( "Real drill" ) };
252 m_drillMarksChoice = new wxChoice( box, wxID_ANY, wxDefaultPosition, wxDefaultSize,
253 drillMarkChoices.size(), drillMarkChoices.data(), 0 );
254 m_drillMarksChoice->SetSelection( 0 );
255
256 optionsSizer->Add( drillMarksLabel, wxGBPosition( rows, 0 ), wxGBSpan( 1, 1 ),
257 wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
258 optionsSizer->Add( m_drillMarksChoice, wxGBPosition( rows++, 1 ), wxGBSpan( 1, 1 ),
259 wxALIGN_CENTER_VERTICAL|wxRIGHT|wxBOTTOM, 5 );
260
261 // Print mirrored
262 m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
263
264 optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
265 wxLEFT|wxRIGHT|wxBOTTOM, 5 );
266
267 // Pagination
268 m_checkboxPagePerLayer = new wxCheckBox( box, wxID_ANY, _( "Print one page per layer" ) );
269
270 m_checkboxPagePerLayer->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
272
273 m_checkboxEdgesOnAllPages = new wxCheckBox( box, wxID_ANY,
274 _( "Print board edges on all pages" ) );
275
276 optionsSizer->Add( m_checkboxPagePerLayer, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
277 wxLEFT|wxRIGHT, 5 );
278 optionsSizer->Add( m_checkboxEdgesOnAllPages, wxGBPosition( rows++, 0 ), wxGBSpan( 1, 2 ),
279 wxLEFT, 28 );
280}
281
282
284{
285 wxStaticBox* box = new wxStaticBox( this, wxID_ANY, _( "Include Layers" ) );
286 wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( box, wxVERTICAL );
287
288 m_layerCheckListBox = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
289 m_layerCheckListBox->SetMinSize( wxSize( 180, -1 ) );
290
291 sbLayersSizer->Add( m_layerCheckListBox, 1, wxEXPAND|wxBOTTOM|wxRIGHT, 5 );
292
293 getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND | wxALL, 5 );
294
295 m_popMenu = new wxMenu();
296 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_SELECT_FAB_LAYERS,
297 _( "Select Fab Layers" ), wxEmptyString ) );
298
299 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_SELECT_COPPER_LAYERS,
300 _( "Select all Copper Layers" ), wxEmptyString ) );
301
302 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_DESELECT_COPPER_LAYERS,
303 _( "Deselect all Copper Layers" ), wxEmptyString ) );
304
305 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_SELECT_ALL_LAYERS,
306 _( "Select all Layers" ), wxEmptyString ) );
307
308 m_popMenu->Append( new wxMenuItem( m_popMenu, ID_DESELECT_ALL_LAYERS,
309 _( "Deselect all Layers" ), wxEmptyString ) );
310
311 this->Bind( wxEVT_RIGHT_DOWN,
312 [&]( wxMouseEvent& aEvent )
313 {
314 this->PopupMenu( m_popMenu, aEvent.GetPosition() );
315 } );
316
317 m_layerCheckListBox->Bind( wxEVT_RIGHT_DOWN,
318 [&]( wxMouseEvent& aEvent )
319 {
320 this->PopupMenu( m_popMenu, aEvent.GetPosition() );
321 } );
322}
323
324
325void DIALOG_PRINT_PCBNEW::onUseThemeClicked( wxCommandEvent& event )
326{
327 m_colorTheme->Enable( m_checkUseTheme->GetValue() );
328}
329
330
332{
333 if( m_checkboxPagePerLayer->GetValue() )
334 {
335 m_checkboxEdgesOnAllPages->Enable( true );
336 m_checkboxEdgesOnAllPages->SetValue( settings()->m_PrintEdgeCutsOnAllPages );
337 }
338 else
339 {
340 m_checkboxEdgesOnAllPages->Enable( false );
341 m_checkboxEdgesOnAllPages->SetValue( false );
342 }
343}
344
345
346void DIALOG_PRINT_PCBNEW::onColorModeClicked( wxCommandEvent& event )
347{
349
350 m_settings->m_blackWhite = m_outputMode->GetSelection();
351
355}
356
357
358// Select or deselect groups of layers in the layers list:
359void DIALOG_PRINT_PCBNEW::onPopUpLayers( wxCommandEvent& event )
360{
361 // Build a list of layers for usual fabrication: copper layers + tech layers without courtyard
362 LSET fab_layer_set = ( LSET::AllCuMask() | LSET::AllTechMask() ) & ~LSET( { B_CrtYd, F_CrtYd } );
363
364 switch( event.GetId() )
365 {
366 case ID_SELECT_FAB_LAYERS: // Select layers usually needed to build a board
367 for( unsigned i = 0; i < m_layerList.size(); i++ )
368 {
369 LSET layermask( { m_layerList[ i ] } );
370
371 if( ( layermask & fab_layer_set ).any() )
372 m_layerCheckListBox->Check( i, true );
373 else
374 m_layerCheckListBox->Check( i, false );
375 }
376 break;
377
379 for( unsigned i = 0; i < m_layerList.size(); i++ )
380 {
381 if( IsCopperLayer( m_layerList[i] ) )
382 m_layerCheckListBox->Check( i, true );
383 }
384 break;
385
387 for( unsigned i = 0; i < m_layerList.size(); i++ )
388 {
389 if( IsCopperLayer( m_layerList[i] ) )
390 m_layerCheckListBox->Check( i, false );
391 }
392 break;
393
395 for( unsigned i = 0; i < m_layerList.size(); i++ )
396 m_layerCheckListBox->Check( i, true );
397 break;
398
400 for( unsigned i = 0; i < m_layerList.size(); i++ )
401 m_layerCheckListBox->Check( i, false );
402 break;
403
404 default:
405 break;
406 }
407}
408
409
411{
412 settings()->m_LayerSet = LSET();
413 int& pageCount = settings()->m_pageCount;
414 pageCount = 0;
415
416 for( unsigned i = 0; i < m_layerList.size(); i++ )
417 {
418 if( m_layerCheckListBox->IsChecked( i ) )
419 {
420 ++pageCount;
422 }
423 }
424
425 // In Pcbnew force the EDGE layer to be printed or not with the other layers
427
428 // All layers on one page (only if there is at least one layer selected)
429 if( !m_checkboxPagePerLayer->GetValue() && pageCount > 0 )
430 pageCount = 1;
431
432 return pageCount;
433}
434
435
437{
439
441
442 settings()->m_DrillMarks = static_cast<DRILL_MARKS>( m_drillMarksChoice->GetSelection() );
443
444 if( m_checkboxPagePerLayer->GetValue() )
445 {
448 }
449 else
450 {
452 }
453
454 settings()->m_Mirror = m_checkboxMirror->GetValue();
455
457
458 cfg->m_Printing.background = m_checkBackground->GetValue();
460 cfg->m_Printing.use_theme = m_checkUseTheme->GetValue();
461
462 int sel = m_colorTheme->GetSelection();
463 COLOR_SETTINGS* theme = static_cast<COLOR_SETTINGS*>( m_colorTheme->GetClientData( sel ) );
464
465 if( theme && m_checkUseTheme->IsChecked() )
466 {
467 cfg->m_Printing.color_theme = theme->GetFilename();
468 settings()->m_colorSettings = theme;
469 }
470 else
471 {
473 }
474
476}
477
478
479int PCB_CONTROL::Print( const TOOL_EVENT& aEvent )
480{
481 // Selection affects the origin item visibility
483
486
488 dlg.ForcePrintBorder( false );
489
490 dlg.ShowModal();
491
492 return 0;
493}
494
495
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:199
BASE_SET & set(size_t pos)
Definition: base_set.h:116
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:295
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:831
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:616
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...
int ShowModal() override
SETTINGS_MANAGER * GetSettingsManager() const
wxString GetFilename() const
Definition: json_settings.h:80
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition: lset.cpp:703
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:628
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:564
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
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:149
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:220
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
#define _(s)
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition: layer_ids.h:618
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:116
@ B_CrtYd
Definition: layer_ids.h:115
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:155
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:140
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:144
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:143
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