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, 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 <kiface_base.h>
28#include <confirm.h>
30#include <gerbview_printout.h>
31#include <gerbview.h>
32#include <gerbview_frame.h>
33#include <gerber_file_image.h>
35#include <tool/tool_manager.h>
38#include <wx/checklst.h>
39
40// TODO(JE)
41#define OPTKEY_LAYERBASE wxT( "PlotLayer_%d" )
42
43
45{
46public:
49
50private:
52 {
53 wxASSERT( dynamic_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings ) );
54 return static_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings );
55 }
56
57 bool TransferDataToWindow() override;
58
59 void createExtraOptions();
60 void createLeftPanel();
61
62 void onSelectAllClick( wxCommandEvent& event );
63 void onDeselectAllClick( 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
76
77 void saveSettings() override;
78
79 wxPrintout* createPrintout( const wxString& aTitle ) override
80 {
82 m_parent->GetCanvas()->GetView(), aTitle );
83 }
84
86
87 // Number of layers in each list
88 static constexpr unsigned int LAYER_PER_LIST = 16;
89
90 // Number of layer list widgets
91 static constexpr unsigned int LAYER_LIST_COUNT = 2;
92
93 // Extra widgets
97 wxCheckBox* m_checkboxMirror;
98
99 // Map layer numbers to items on the list
100 std::unordered_map<int, int> m_layerToItemMap;
101};
102
103
105 BOARD_PRINTOUT_SETTINGS* aSettings ) :
106 DIALOG_PRINT_GENERIC( aParent, aSettings ),
107 m_parent( aParent )
108{
110
113}
114
115
117{
119 return false;
120
122 int itemIdx = 0;
123
124 // Create layer list
125 for( unsigned ii = 0; ii < images->ImagesMaxCount(); ++ii )
126 {
127 unsigned int listIdx = itemIdx / LAYER_PER_LIST;
128
129 if( listIdx >= LAYER_LIST_COUNT )
130 {
131 wxFAIL;
132 break;
133 }
134
135 GERBER_FILE_IMAGE* gbrImage = images->GetGbrImage( ii );
136
137 if( !gbrImage )
138 continue;
139
140 wxFileName filename( gbrImage->m_FileName );
141 wxCheckListBox* listBox = m_layerLists[listIdx];
142 listBox->Append( filename.GetFullName() );
143
144 if( settings()->m_LayerSet.test( ii) )
145 listBox->Check( ii, true );
146
147 wxASSERT( m_layerToItemMap.count( ii ) == 0 );
148 m_layerToItemMap[ii] = itemIdx;
149
150 ++itemIdx;
151 }
152
153 m_checkboxMirror->SetValue( settings()->m_Mirror );
154
155 // Update the dialog layout when layers are added
156 GetSizer()->Fit( this );
157
158 return true;
159}
160
161
163{
164 wxGridBagSizer* optionsSizer = getOptionsSizer();
165 wxStaticBox* box = getOptionsBox();
166 int rows = optionsSizer->GetEffectiveRowsCount();
167 int cols = optionsSizer->GetEffectiveColsCount();
168
169 // Print mirrored
170 m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
171 optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows, 0 ), wxGBSpan( 1, cols ),
172 wxBOTTOM | wxRIGHT | wxLEFT, 5 );
173}
174
175
177{
178 wxStaticBox* box = new wxStaticBox( this, wxID_ANY, _( "Include Layers" ) );
179 wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( box, wxVERTICAL );
180
181 // Layer lists
182 wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
183
184 for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
185 {
186 m_layerLists[i] = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
187 bLayerListsSizer->Add( m_layerLists[i], 1, wxEXPAND, 5 );
188 }
189
190 // Select/Unselect all buttons
191 m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY,
192 _( "Select all" ) );
193 m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY,
194 _( "Deselect all" ) );
195
196 m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
197 wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onSelectAllClick ),
198 nullptr, this );
199 m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
200 wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onDeselectAllClick ),
201 nullptr, this );
202
203 wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
204 buttonSizer->Add( m_buttonSelectAll, 1, wxALL, 5 );
205 buttonSizer->Add( m_buttonDeselectAll, 1, wxALL, 5 );
206
207 // Static box sizer layout
208 sbLayersSizer->Add( bLayerListsSizer, 1, wxEXPAND, 5 );
209 sbLayersSizer->Add( buttonSizer, 0, wxEXPAND, 5 );
210
211 getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND | wxALL, 5 );
212}
213
214
215void DIALOG_PRINT_GERBVIEW::onSelectAllClick( wxCommandEvent& event )
216{
217 for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
218 setListBoxValue( m_layerLists[i], true );
219}
220
221
222void DIALOG_PRINT_GERBVIEW::onDeselectAllClick( wxCommandEvent& event )
223{
224 for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
225 setListBoxValue( m_layerLists[i], false );
226}
227
228
229void DIALOG_PRINT_GERBVIEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
230{
231 for( unsigned int i = 0; i < aList->GetCount(); ++i )
232 aList->Check( i, aValue );
233}
234
235
236bool DIALOG_PRINT_GERBVIEW::isLayerEnabled( unsigned int aLayer ) const
237{
238 auto layerMapIt = m_layerToItemMap.find( aLayer );
239
240 if( layerMapIt == m_layerToItemMap.end() )
241 return false;
242
243 unsigned int itemNr = layerMapIt->second;
244 unsigned int listIdx = itemNr / LAYER_PER_LIST;
245 unsigned int itemIdx = itemNr % LAYER_PER_LIST;
246 wxCHECK( listIdx < LAYER_LIST_COUNT, false );
247 wxCheckListBox* listBox = m_layerLists[listIdx];
248
249 return itemIdx < listBox->GetCount() && listBox->IsChecked( itemIdx );
250}
251
252
253void DIALOG_PRINT_GERBVIEW::enableLayer( unsigned int aLayer, bool aValue )
254{
255 auto layerMapIt = m_layerToItemMap.find( aLayer );
256
257 if( layerMapIt == m_layerToItemMap.end() )
258 return;
259
260 unsigned int itemNr = layerMapIt->second;
261 unsigned int listIdx = itemNr / LAYER_PER_LIST;
262 unsigned int itemIdx = itemNr % LAYER_PER_LIST;
263 wxCHECK( listIdx < LAYER_LIST_COUNT, /* void */ );
264 wxCheckListBox* listBox = m_layerLists[listIdx];
265
266 if( itemIdx < listBox->GetCount() )
267 listBox->Check( itemIdx, aValue );
268}
269
270
272{
273 settings()->m_LayerSet = LSET();
274 int& pageCount = settings()->m_pageCount;
275 pageCount = 0;
276
277 unsigned int layer = 0;
278
279 for( unsigned int j = 0; j < LAYER_LIST_COUNT; ++j )
280 {
281 for( unsigned int i = 0; i < LAYER_PER_LIST; ++i )
282 {
283 if( isLayerEnabled( layer ) )
284 {
285 settings()->m_LayerSet.set( layer );
286 ++pageCount;
287 }
288
289 ++layer;
290 }
291 }
292
293 return pageCount;
294}
295
296
298{
300
301 settings()->m_Mirror = m_checkboxMirror->GetValue();
302
304}
305
306
308{
309 // Selection affects the original item visibility
311
314 DIALOG_PRINT_GERBVIEW dlg( m_frame, &settings );
315 dlg.ForcePrintBorder( false );
316 dlg.ShowModal();
317
318 return 0;
319}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
BASE_SET & set(size_t pos)
Definition: base_set.h:116
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
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]
bool isLayerEnabled(unsigned int aLayer) const
Enable/disable layer in a listbox.
void enableLayer(unsigned int aLayer, bool aValue)
Update layerset basing on the selected layers.
BOARD_PRINTOUT_SETTINGS * settings() const
DIALOG_PRINT_GERBVIEW(GERBVIEW_FRAME *aParent, BOARD_PRINTOUT_SETTINGS *aSettings)
bool TransferDataToWindow() override
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
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:41
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.
static TOOL_ACTION selectionClear
Clear the current selection.
GERBVIEW_FRAME * m_frame
int Print(const TOOL_EVENT &aEvent)
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
const PAGE_INFO & GetPageSettings() const override
GBR_LAYOUT * GetGerberLayout() const
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
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: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
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