KiCad PCB EDA Suite
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 (C) 1992-2016 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 <common.h>
30 #include <confirm.h>
32 #include <gerbview_printout.h>
33 #include <gerbview.h>
34 #include <gerbview_frame.h>
35 #include <gerber_file_image.h>
36 #include <gerber_file_image_list.h>
37 #include <tool/tool_manager.h>
38 #include <tools/gerbview_actions.h>
39 #include <tools/gerbview_control.h>
40 
41 // TODO(JE)
42 #define OPTKEY_LAYERBASE wxT( "PlotLayer_%d" )
43 
44 
46 {
47 public:
50 
51 private:
53  {
54  wxASSERT( dynamic_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings ) );
55  return static_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings );
56  }
57 
58  bool TransferDataToWindow() override;
59 
60  void createExtraOptions();
61  void createLeftPanel();
62 
63  void onSelectAllClick( wxCommandEvent& event );
64  void onDeselectAllClick( wxCommandEvent& event );
65 
67  void setListBoxValue( wxCheckListBox* aList, bool aValue );
68 
70  bool isLayerEnabled( unsigned int aLayer ) const;
71 
73  void enableLayer( unsigned int aLayer, bool aValue );
74 
76  int setLayerSetFromList();
77 
78  void saveSettings() override;
79 
80  wxPrintout* createPrintout( const wxString& aTitle ) override
81  {
83  m_parent->GetCanvas()->GetView(), aTitle );
84  }
85 
87 
88  // Number of layers in each list
89  static constexpr unsigned int LAYER_PER_LIST = 16;
90 
91  // Number of layer list widgets
92  static constexpr unsigned int LAYER_LIST_COUNT = 2;
93 
94  // Extra widgets
95  wxCheckListBox* m_layerLists[LAYER_LIST_COUNT];
96  wxButton* m_buttonSelectAll;
98  wxCheckBox* m_checkboxMirror;
99 
100  // Map layer numbers to items on the list
101  std::unordered_map<int, int> m_layerToItemMap;
102 };
103 
104 
106  BOARD_PRINTOUT_SETTINGS* aSettings ) :
107  DIALOG_PRINT_GENERIC( aParent, aSettings ),
108  m_parent( aParent )
109 {
111 
113  createLeftPanel();
114 }
115 
116 
118 {
120  return false;
121 
123  int itemIdx = 0;
124 
125  // Create layer list
126  for( unsigned ii = 0; ii < images->ImagesMaxCount(); ++ii )
127  {
128  wxString layerName;
129  unsigned int listIdx = itemIdx / LAYER_PER_LIST;
130 
131  if( listIdx >= LAYER_LIST_COUNT )
132  {
133  wxFAIL;
134  break;
135  }
136 
137  GERBER_FILE_IMAGE* gbrImage = images->GetGbrImage( ii );
138 
139  if( !gbrImage )
140  continue;
141 
142  wxFileName filename( gbrImage->m_FileName );
143  wxCheckListBox* listBox = m_layerLists[listIdx];
144  listBox->Append( filename.GetFullName() );
145 
146  if( settings()->m_layerSet.test(ii) )
147  listBox->Check( ii, true );
148 
149  wxASSERT( m_layerToItemMap.count( ii ) == 0 );
150  m_layerToItemMap[ii] = itemIdx;
151 
152  ++itemIdx;
153  }
154 
155  m_checkboxMirror->SetValue( settings()->m_mirror );
156 
157  // Update the dialog layout when layers are added
158  GetSizer()->Fit( this );
159 
160  return true;
161 }
162 
163 
165 {
166  wxGridBagSizer* optionsSizer = getOptionsSizer();
167  wxStaticBox* box = getOptionsBox();
168  int rows = optionsSizer->GetEffectiveRowsCount();
169  int cols = optionsSizer->GetEffectiveColsCount();
170 
171  // Print mirrored
172  m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
173  optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows, 0 ), wxGBSpan( 1, cols ),
174  wxBOTTOM | wxRIGHT | wxLEFT, 5 );
175 }
176 
177 
179 {
180  wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( new wxStaticBox( this,
181  wxID_ANY, _( "Included Layers" ) ), wxVERTICAL );
182 
183  // Layer lists
184  wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
185 
186  for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
187  {
188  m_layerLists[i] = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
189  bLayerListsSizer->Add( m_layerLists[i], 1, wxEXPAND, 5 );
190  }
191 
192 
193  // Select/Unselect all buttons
194  m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
195  m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Deselect all" ) );
196 
197  m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
198  wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onSelectAllClick ), NULL, this );
199  m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
200  wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onDeselectAllClick ), NULL, this );
201 
202  wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
203  buttonSizer->Add( m_buttonSelectAll, 1, wxALL, 5 );
204  buttonSizer->Add( m_buttonDeselectAll, 1, wxALL, 5 );
205 
206  // Static box sizer layout
207  sbLayersSizer->Add( bLayerListsSizer, 1, wxALL | wxEXPAND, 5 );
208  sbLayersSizer->Add( buttonSizer, 0, wxALL | wxEXPAND, 5 );
209 
210  getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND );
211 }
212 
213 
214 void DIALOG_PRINT_GERBVIEW::onSelectAllClick( wxCommandEvent& event )
215 {
216  for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
217  setListBoxValue( m_layerLists[i], true );
218 }
219 
220 
221 void DIALOG_PRINT_GERBVIEW::onDeselectAllClick( wxCommandEvent& event )
222 {
223  for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
224  setListBoxValue( m_layerLists[i], false );
225 }
226 
227 
228 void DIALOG_PRINT_GERBVIEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
229 {
230  for( unsigned int i = 0; i < aList->GetCount(); ++i )
231  aList->Check( i, aValue );
232 }
233 
234 
235 bool DIALOG_PRINT_GERBVIEW::isLayerEnabled( unsigned int aLayer ) const
236 {
237  auto layerMapIt = m_layerToItemMap.find( aLayer );
238 
239  if( layerMapIt == m_layerToItemMap.end() )
240  return false;
241 
242  unsigned int itemNr = layerMapIt->second;
243  unsigned int listIdx = itemNr / LAYER_PER_LIST;
244  unsigned int itemIdx = itemNr % LAYER_PER_LIST;
245  wxCHECK( listIdx < LAYER_LIST_COUNT, false );
246  wxCheckListBox* listBox = m_layerLists[listIdx];
247 
248  return itemIdx < listBox->GetCount() && listBox->IsChecked( itemIdx );
249 }
250 
251 
252 void DIALOG_PRINT_GERBVIEW::enableLayer( unsigned int aLayer, bool aValue )
253 {
254  auto layerMapIt = m_layerToItemMap.find( aLayer );
255 
256  if( layerMapIt == m_layerToItemMap.end() )
257  return;
258 
259  unsigned int itemNr = layerMapIt->second;
260  unsigned int listIdx = itemNr / LAYER_PER_LIST;
261  unsigned int itemIdx = itemNr % LAYER_PER_LIST;
262  wxCHECK( listIdx < LAYER_LIST_COUNT, /* void */ );
263  wxCheckListBox* listBox = m_layerLists[listIdx];
264 
265  if( itemIdx < listBox->GetCount() )
266  listBox->Check( itemIdx, aValue );
267 }
268 
269 
271 {
272  settings()->m_layerSet = LSET();
273  int& pageCount = settings()->m_pageCount;
274  pageCount = 0;
275 
276  unsigned int layer = 0;
277 
278  for( unsigned int j = 0; j < LAYER_LIST_COUNT; ++j )
279  {
280  for( unsigned int i = 0; i < LAYER_PER_LIST; ++i )
281  {
282  if( isLayerEnabled( layer ) )
283  {
284  settings()->m_layerSet.set( layer );
285  ++pageCount;
286  }
287 
288  ++layer;
289  }
290  }
291 
292  return pageCount;
293 }
294 
295 
297 {
299 
300  settings()->m_mirror = m_checkboxMirror->GetValue();
301 
303 }
304 
305 
307 {
308  // Selection affects the original item visibility
310 
313  DIALOG_PRINT_GERBVIEW dlg( m_frame, &settings );
314  dlg.ForcePrintBorder( false );
315  dlg.ShowModal();
316 
317  return 0;
318 }
void onDeselectAllClick(wxCommandEvent &event)
static TOOL_ACTION selectionClear
Clears the current selection.
static constexpr unsigned int LAYER_PER_LIST
GERBVIEW_FRAME * m_frame
This file is part of the common library.
BOARD_PRINTOUT_SETTINGS * settings() const
int Print(const TOOL_EVENT &aEvent)
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
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
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
wxStaticBox * getOptionsBox()
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition: printout.h:59
LSET is a set of PCB_LAYER_IDs.
#define NULL
wxPrintout * createPrintout(const wxString &aTitle) override
Create a printout with a requested title.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
bool m_mirror
Print mirrored.
bool TransferDataToWindow() override
PRINTOUT_SETTINGS * m_settings
int setLayerSetFromList()
Update layerset basing on the selected layers
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
TOOL_EVENT.
Definition: tool_event.h:171
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
static constexpr unsigned int LAYER_LIST_COUNT
std::unordered_map< int, int > m_layerToItemMap
wxCheckListBox * m_layerLists[LAYER_LIST_COUNT]
GBR_LAYOUT * GetGerberLayout() const
void setListBoxValue(wxCheckListBox *aList, bool aValue)
(Un)check all items in a checklist box
DIALOG_PRINT_GERBVIEW(GERBVIEW_FRAME *aParent, BOARD_PRINTOUT_SETTINGS *aSettings)
void onSelectAllClick(wxCommandEvent &event)
const PAGE_INFO & GetPageSettings() const override
bool TransferDataToWindow() override
#define _(s)
Definition: 3d_actions.cpp:33
int m_pageCount
Number of pages to print.
Definition: printout.h:54
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:44
The common library.
virtual COLOR_SETTINGS * GetColorSettings()
Returns a pointer to the active color theme settings.
bool isLayerEnabled(unsigned int aLayer) const
Check whether a layer is enabled in a listbox
wxGridBagSizer * getOptionsSizer()
void ForcePrintBorder(bool aValue)
Set 'print border and title block' to a requested value and hides the corresponding checkbox.
APP_SETTINGS_BASE * m_config
void enableLayer(unsigned int aLayer, bool aValue)
Enable/disable layer in a listbox
LSET m_layerSet
Layers to print.