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 
43 
44 #define OPTKEY_LAYERBASE wxT( "PlotLayer_%d" )
45 #define OPTKEY_PRINT_X_FINESCALE_ADJ wxT( "PrintXFineScaleAdj" )
46 #define OPTKEY_PRINT_Y_FINESCALE_ADJ wxT( "PrintYFineScaleAdj" )
47 #define OPTKEY_PRINT_SCALE wxT( "PrintScale" )
48 #define OPTKEY_PRINT_PAGE_FRAME wxT( "PrintPageFrame" )
49 #define OPTKEY_PRINT_MONOCHROME_MODE wxT( "PrintMonochrome" )
50 
52 
53 
55 {
56 public:
59 
60 private:
62  {
63  wxASSERT( dynamic_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings ) );
64  return static_cast<BOARD_PRINTOUT_SETTINGS*>( m_settings );
65  }
66 
67  bool TransferDataToWindow() override;
68 
69  void createExtraOptions();
70  void createLeftPanel();
71 
72  void onSelectAllClick( wxCommandEvent& event );
73  void onDeselectAllClick( wxCommandEvent& event );
74 
76  void setListBoxValue( wxCheckListBox* aList, bool aValue );
77 
79  bool isLayerEnabled( unsigned int aLayer ) const;
80 
82  void enableLayer( unsigned int aLayer, bool aValue );
83 
85  int setLayerSetFromList();
86 
87  void saveSettings() override;
88 
89  wxPrintout* createPrintout( const wxString& aTitle ) override
90  {
92  m_parent->GetCanvas()->GetView(), aTitle );
93  }
94 
96 
97  // Number of layers in each list
98  static constexpr unsigned int LAYER_PER_LIST = 16;
99 
100  // Number of layer list widgets
101  static constexpr unsigned int LAYER_LIST_COUNT = 2;
102 
103  // Extra widgets
104  wxCheckListBox* m_layerLists[LAYER_LIST_COUNT];
105  wxButton* m_buttonSelectAll;
107  wxCheckBox* m_checkboxMirror;
108 
109  // Map layer numbers to items on the list
110  std::unordered_map<int, int> m_layerToItemMap;
111 };
112 
113 
115  DIALOG_PRINT_GENERIC( aParent, aSettings ), m_parent( aParent )
116 {
118 
120  createLeftPanel();
121 }
122 
123 
125 {
127  return false;
128 
130  int itemIdx = 0;
131 
132  // Create layer list
133  for( unsigned ii = 0; ii < images->ImagesMaxCount(); ++ii )
134  {
135  wxString layerName;
136  unsigned int listIdx = itemIdx / LAYER_PER_LIST;
137 
138  if( listIdx >= LAYER_LIST_COUNT )
139  {
140  wxFAIL;
141  break;
142  }
143 
144  GERBER_FILE_IMAGE* gbrImage = images->GetGbrImage( ii );
145 
146  if( !gbrImage )
147  continue;
148 
149  wxFileName filename( gbrImage->m_FileName );
150  wxCheckListBox* listBox = m_layerLists[listIdx];
151  listBox->Append( filename.GetFullName() );
152 
153  if( settings()->m_layerSet.test(ii) )
154  listBox->Check( ii, true );
155 
156  wxASSERT( m_layerToItemMap.count( ii ) == 0 );
157  m_layerToItemMap[ii] = itemIdx;
158 
159  ++itemIdx;
160  }
161 
162  m_checkboxMirror->SetValue( settings()->m_mirror );
163 
164  // Update the dialog layout when layers are added
165  GetSizer()->Fit( this );
166 
167  return true;
168 }
169 
170 
172 {
173  wxGridBagSizer* optionsSizer = getOptionsSizer();
174  wxStaticBox* box = getOptionsBox();
175  int rows = optionsSizer->GetEffectiveRowsCount();
176  int cols = optionsSizer->GetEffectiveColsCount();
177 
178  // Print mirrored
179  m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
180  optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows, 0 ), wxGBSpan( 1, cols ),
181  wxBOTTOM | wxRIGHT | wxLEFT, 5 );
182 }
183 
184 
186 {
187  wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( new wxStaticBox( this,
188  wxID_ANY, _( "Included Layers" ) ), wxVERTICAL );
189 
190  // Layer lists
191  wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
192 
193  for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
194  {
195  m_layerLists[i] = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
196  bLayerListsSizer->Add( m_layerLists[i], 1, wxEXPAND, 5 );
197  }
198 
199 
200  // Select/Unselect all buttons
201  m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
202  m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Deselect all" ) );
203 
204  m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
205  wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onSelectAllClick ), NULL, this );
206  m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
207  wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onDeselectAllClick ), NULL, this );
208 
209  wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
210  buttonSizer->Add( m_buttonSelectAll, 1, wxALL, 5 );
211  buttonSizer->Add( m_buttonDeselectAll, 1, wxALL, 5 );
212 
213  // Static box sizer layout
214  sbLayersSizer->Add( bLayerListsSizer, 1, wxALL | wxEXPAND, 5 );
215  sbLayersSizer->Add( buttonSizer, 0, wxALL | wxEXPAND, 5 );
216 
217  getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND );
218 }
219 
220 
221 void DIALOG_PRINT_GERBVIEW::onSelectAllClick( wxCommandEvent& event )
222 {
223  for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
224  setListBoxValue( m_layerLists[i], true );
225 }
226 
227 
228 void DIALOG_PRINT_GERBVIEW::onDeselectAllClick( wxCommandEvent& event )
229 {
230  for( unsigned int i = 0; i < LAYER_LIST_COUNT; ++i )
231  setListBoxValue( m_layerLists[i], false );
232 }
233 
234 
235 void DIALOG_PRINT_GERBVIEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
236 {
237  for( unsigned int i = 0; i < aList->GetCount(); ++i )
238  aList->Check( i, aValue );
239 }
240 
241 
242 bool DIALOG_PRINT_GERBVIEW::isLayerEnabled( unsigned int aLayer ) const
243 {
244  auto layerMapIt = m_layerToItemMap.find( aLayer );
245 
246  if( layerMapIt == m_layerToItemMap.end() )
247  return false;
248 
249  unsigned int itemNr = layerMapIt->second;
250  unsigned int listIdx = itemNr / LAYER_PER_LIST;
251  unsigned int itemIdx = itemNr % LAYER_PER_LIST;
252  wxCHECK( listIdx < LAYER_LIST_COUNT, false );
253  wxCheckListBox* listBox = m_layerLists[listIdx];
254 
255  return itemIdx < listBox->GetCount() && listBox->IsChecked( itemIdx );
256 }
257 
258 
259 void DIALOG_PRINT_GERBVIEW::enableLayer( unsigned int aLayer, bool aValue )
260 {
261  auto layerMapIt = m_layerToItemMap.find( aLayer );
262 
263  if( layerMapIt == m_layerToItemMap.end() )
264  return;
265 
266  unsigned int itemNr = layerMapIt->second;
267  unsigned int listIdx = itemNr / LAYER_PER_LIST;
268  unsigned int itemIdx = itemNr % LAYER_PER_LIST;
269  wxCHECK( listIdx < LAYER_LIST_COUNT, /* void */ );
270  wxCheckListBox* listBox = m_layerLists[listIdx];
271 
272  if( itemIdx < listBox->GetCount() )
273  listBox->Check( itemIdx, aValue );
274 }
275 
276 
278 {
279  settings()->m_layerSet = LSET();
280  int& pageCount = settings()->m_pageCount;
281  pageCount = 0;
282 
283  unsigned int layer = 0;
284 
285  for( unsigned int j = 0; j < LAYER_LIST_COUNT; ++j )
286  {
287  for( unsigned int i = 0; i < LAYER_PER_LIST; ++i )
288  {
289  if( isLayerEnabled( layer ) )
290  {
291  settings()->m_layerSet.set( layer );
292  ++pageCount;
293  }
294 
295  ++layer;
296  }
297  }
298 
299  return pageCount;
300 }
301 
302 
304 {
306 
307  settings()->m_mirror = m_checkboxMirror->GetValue();
308 
310 }
311 
312 
314 {
315  // Selection affects the original item visibility
317 
319  DIALOG_PRINT_GERBVIEW dlg( m_frame, &settings );
320  dlg.ForcePrintBorder( false );
321  dlg.ShowModal();
322 
323  return 0;
324 }
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.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
wxStaticBox * getOptionsBox()
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
Class LSET is a set of PCB_LAYER_IDs.
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
Class 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
#define _(s)
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
int m_pageCount
Number of pages to print.
Definition: printout.h:47
size_t i
Definition: json11.cpp:649
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:44
The common library.
bool isLayerEnabled(unsigned int aLayer) const
Check whether a layer is enabled in a listbox
wxGridBagSizer * getOptionsSizer()
void enableLayer(unsigned int aLayer, bool aValue)
Enable/disable layer in a listbox
LSET m_layerSet
Layers to print.