KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_print_gerbview.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 jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * Copyright (C) 2018 CERN
7 * Author: Maciej Suminski <[email protected]>
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, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <kiface_base.h>
24#include <confirm.h>
26#include <gerbview_printout.h>
27#include <gerbview.h>
28#include <gerbview_frame.h>
29#include <gerber_file_image.h>
31#include <tool/tool_manager.h>
34#include <wx/checklst.h>
35
36// TODO(JE)
37#define OPTKEY_LAYERBASE wxT( "PlotLayer_%d" )
38
39
41{
42public:
45
46private:
48 {
49 wxASSERT( dynamic_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings ) );
50 return static_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings );
51 }
52
53 bool TransferDataToWindow() override;
54
55 void createExtraOptions();
56 void createLeftPanel();
57
58 void onSelectAllClick( wxCommandEvent& event );
59 void onDeselectAllClick( wxCommandEvent& event );
60
62 void setListBoxValue( wxCheckListBox* aList, bool aValue );
63
65 bool isLayerEnabled( unsigned int aLayer ) const;
66
69
70 void saveSettings() override;
71
72 wxPrintout* createPrintout( const wxString& aTitle ) override
73 {
74 return new GERBVIEW_PRINTOUT( m_parent->GetGerberLayout(), *settings(), m_parent->GetCanvas()->GetView(),
75 aTitle );
76 }
77
79
80 // Number of layers in each list
81 static constexpr unsigned int LAYER_PER_LIST = 16;
82
83 // Number of layer list widgets
84 static constexpr unsigned int LAYER_LIST_COUNT = 2;
85
86 // Extra widgets
90 wxCheckBox* m_checkboxMirror;
91
92 // Map layer numbers to items on the list
93 std::unordered_map<int, int> m_layerToItemMap;
94};
95
96
98 DIALOG_PRINT_GENERIC( aParent, aSettings ),
99 m_parent( aParent )
100{
103}
104
105
107{
109 return false;
110
111 GERBER_FILE_IMAGE_LIST* images = m_parent->GetGerberLayout()->GetImagesList();
112 int itemIdx = 0;
113
114 // Create layer list
115 for( unsigned ii = 0; ii < images->ImagesMaxCount(); ++ii )
116 {
117 unsigned int listIdx = itemIdx / LAYER_PER_LIST;
118
119 if( listIdx >= LAYER_LIST_COUNT )
120 {
121 wxFAIL;
122 break;
123 }
124
125 GERBER_FILE_IMAGE* gbrImage = images->GetGbrImage( ii );
126
127 if( !gbrImage )
128 continue;
129
130 wxFileName filename( gbrImage->m_FileName );
131 wxCheckListBox* listBox = m_layerLists[listIdx];
132 listBox->Append( filename.GetFullName() );
133
134 if( settings()->m_LayerSet.test( ii) )
135 listBox->Check( ii, true );
136
137 wxASSERT( m_layerToItemMap.count( ii ) == 0 );
138 m_layerToItemMap[ii] = itemIdx;
139
140 ++itemIdx;
141 }
142
143 m_checkboxMirror->SetValue( settings()->m_Mirror );
144
145 // Update the dialog layout when layers are added
146 GetSizer()->Fit( this );
147
148 return true;
149}
150
151
153{
154 wxGridBagSizer* optionsSizer = getOptionsSizer();
155 wxStaticBox* box = getOptionsBox();
156 int rows = optionsSizer->GetEffectiveRowsCount();
157 int cols = optionsSizer->GetEffectiveColsCount();
158
159 // Print mirrored
160 m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
161 optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows, 0 ), wxGBSpan( 1, cols ), wxBOTTOM|wxRIGHT|wxLEFT, 5 );
162}
163
164
166{
167 wxStaticBox* box = new wxStaticBox( this, wxID_ANY, _( "Include Layers" ) );
168 wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( box, wxVERTICAL );
169
170 // Layer lists
171 wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
172
173 for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
174 {
175 m_layerLists[i] = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
176 bLayerListsSizer->Add( m_layerLists[i], 1, wxEXPAND, 5 );
177 }
178
179 // Select/Unselect all buttons
180 m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
181 m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Deselect all" ) );
182
183 m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
184 wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onSelectAllClick ), nullptr, this );
185 m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
186 wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onDeselectAllClick ), nullptr, this );
187
188 wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
189 buttonSizer->Add( m_buttonSelectAll, 1, wxALL, 5 );
190 buttonSizer->Add( m_buttonDeselectAll, 1, wxALL, 5 );
191
192 // Static box sizer layout
193 sbLayersSizer->Add( bLayerListsSizer, 1, wxEXPAND, 5 );
194 sbLayersSizer->Add( buttonSizer, 0, wxEXPAND, 5 );
195
196 getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND | wxALL, 5 );
197}
198
199
200void DIALOG_PRINT_GERBVIEW::onSelectAllClick( wxCommandEvent& event )
201{
202 for( wxCheckListBox* checkbox : m_layerLists )
203 setListBoxValue( checkbox, true );
204}
205
206
207void DIALOG_PRINT_GERBVIEW::onDeselectAllClick( wxCommandEvent& event )
208{
209 for( wxCheckListBox* checkbox : m_layerLists )
210 setListBoxValue( checkbox, false );
211}
212
213
214void DIALOG_PRINT_GERBVIEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
215{
216 for( unsigned int i = 0; i < aList->GetCount(); ++i )
217 aList->Check( i, aValue );
218}
219
220
221bool DIALOG_PRINT_GERBVIEW::isLayerEnabled( unsigned int aLayer ) const
222{
223 auto layerMapIt = m_layerToItemMap.find( aLayer );
224
225 if( layerMapIt == m_layerToItemMap.end() )
226 return false;
227
228 unsigned int itemNr = layerMapIt->second;
229 unsigned int listIdx = itemNr / LAYER_PER_LIST;
230 unsigned int itemIdx = itemNr % LAYER_PER_LIST;
231 wxCHECK( listIdx < LAYER_LIST_COUNT, false );
232 wxCheckListBox* listBox = m_layerLists[listIdx];
233
234 return itemIdx < listBox->GetCount() && listBox->IsChecked( itemIdx );
235}
236
237
239{
240 settings()->m_LayerSet = LSET();
241 int& pageCount = settings()->m_pageCount;
242 pageCount = 0;
243
244 unsigned int layer = 0;
245
246 for( unsigned int j = 0; j < LAYER_LIST_COUNT; ++j )
247 {
248 for( unsigned int i = 0; i < LAYER_PER_LIST; ++i )
249 {
250 if( isLayerEnabled( layer ) )
251 {
252 settings()->m_LayerSet.set( layer );
253 ++pageCount;
254 }
255
256 ++layer;
257 }
258 }
259
260 return pageCount;
261}
262
263
272
273
275{
276 // Selection affects the original item visibility
278
279 BOARD_PRINTOUT_SETTINGS settings( m_frame->GetPageSettings() );
280 settings.m_colorSettings = m_frame->GetColorSettings();
281 DIALOG_PRINT_GERBVIEW dlg( m_frame, &settings );
282 dlg.ForcePrintBorder( false );
283 dlg.ShowModal();
284
285 return 0;
286}
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
BASE_SET & set(size_t pos)
Definition base_set.h:116
DIALOG_PRINT_GENERIC(EDA_DRAW_FRAME *aParent, PRINTOUT_SETTINGS *aSettings)
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
static constexpr unsigned int LAYER_PER_LIST
static constexpr unsigned int LAYER_LIST_COUNT
void setListBoxValue(wxCheckListBox *aList, bool aValue)
Check whether a layer is enabled in a listbox.
std::unordered_map< int, int > m_layerToItemMap
wxCheckListBox * m_layerLists[LAYER_LIST_COUNT]
~DIALOG_PRINT_GERBVIEW()=default
bool isLayerEnabled(unsigned int aLayer) const
Update layerset basing on the selected layers.
BOARD_PRINTOUT_SETTINGS * settings() const
DIALOG_PRINT_GERBVIEW(GERBVIEW_FRAME *aParent, BOARD_PRINTOUT_SETTINGS *aSettings)
void onDeselectAllClick(wxCommandEvent &event)
(Un)check all items in a checklist box
wxPrintout * createPrintout(const wxString &aTitle) override
Create a printout with a requested title.
void onSelectAllClick(wxCommandEvent &event)
int ShowModal() override
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Hold the image data and parameters for one gerber file and layer parameters.
wxString m_FileName
Full File Name for this layer.
GERBVIEW_FRAME * m_frame
int Print(const TOOL_EVENT &aEvent)
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
Generic, UI-independent tool event.
Definition tool_event.h:167
This file is part of the common library.
#define _(s)
LSET m_LayerSet
Layers to print.
bool m_Mirror
Print mirrored.
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition printout.h:66
int m_pageCount
Number of pages to print.
Definition printout.h:61