KiCad PCB EDA Suite
dialog_gendrill.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2012 Jean_Pierre Charras <jp.charras at wanadoo.fr>
9  * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <fctsys.h>
30 #include <kiface_i.h>
31 #include <pcbnew.h>
32 #include <wxPcbStruct.h>
33 #include <pcbplot.h>
35 #include <macros.h>
36 
37 #include <class_board.h>
38 #include <class_track.h>
39 #include <class_module.h>
40 
41 #include <dialog_gendrill.h>
43 #include <reporter.h>
44 
45 #include <wx/stdpaths.h>
46 
47 
48 // Keywords for read and write config
49 #define ZerosFormatKey wxT( "DrillZerosFormat" )
50 #define PrecisionKey wxT( "DrilltPrecisionOpt" )
51 #define MirrorKey wxT( "DrillMirrorYOpt" )
52 #define MinimalHeaderKey wxT( "DrillMinHeader" )
53 #define MergePTHNPTHKey wxT( "DrillMergePTHNPTH" )
54 #define UnitDrillInchKey wxT( "DrillUnit" )
55 #define DrillOriginIsAuxAxisKey wxT( "DrillAuxAxis" )
56 #define DrillMapFileTypeKey wxT( "DrillMapFileType" )
57 
58 // list of allowed precision for EXCELLON files, for integer format:
59 // Due to difference between inches and mm,
60 // there are 2 precision values, one for inches and one for metric
63 
64 
65 /* This function displays the dialog frame for drill tools
66  */
67 void PCB_EDIT_FRAME::InstallDrillFrame( wxCommandEvent& event )
68 {
69  DIALOG_GENDRILL dlg( this );
70 
71  dlg.ShowModal();
72 }
73 
74 
76  DIALOG_GENDRILL_BASE( parent )
77 {
78  m_parent = parent;
79  m_board = parent->GetBoard();
82 
83  SetReturnCode( 1 );
84  initDialog();
85  GetSizer()->SetSizeHints( this );
86 }
87 
88 
89 // Static members of DIALOG_GENDRILL
93 bool DIALOG_GENDRILL::m_Mirror = false;
97 
98 
100 {
101  UpdateConfig();
102 }
103 
104 
106 {
108  m_config->Read( MirrorKey, &m_Mirror );
114 
116 }
117 
118 
120 {
121  wxString msg;
122 
123  m_Choice_Unit->SetSelection( m_UnitDrillIsInch ? 1 : 0 );
124  m_Choice_Zeros_Format->SetSelection( m_ZerosFormat );
126  m_Check_Minimal->SetValue( m_MinimalHeader );
127 
129  m_Choice_Drill_Offset->SetSelection( 1 );
130 
131  m_Check_Mirror->SetValue( m_Mirror );
133  m_Choice_Drill_Map->SetSelection( m_mapFileType );
134  m_ViaDrillValue->SetLabel( _( "Use Netclass values" ) );
135  m_MicroViaDrillValue->SetLabel( _( "Use Netclass values" ) );
136 
137  // See if we have some buried vias or/and microvias, and display
138  // microvias drill value if so
139  m_throughViasCount = 0;
140  m_microViasCount = 0;
142 
143  for( TRACK* track = m_parent->GetBoard()->m_Track; track != NULL; track = track->Next() )
144  {
145  const VIA *via = dynamic_cast<const VIA*>( track );
146  if( via )
147  {
148  switch( via->GetViaType() )
149  {
150  case VIA_THROUGH:
152  break;
153 
154  case VIA_MICROVIA:
156  break;
157 
158  case VIA_BLIND_BURIED:
160  break;
161 
162  default:
163  break;
164  }
165  }
166  }
167 
169 
170  // Count plated pad holes and not plated pad holes:
173 
174  for( MODULE* module = m_parent->GetBoard()->m_Modules; module; module = module->Next() )
175  {
176  for( D_PAD* pad = module->Pads(); pad != NULL; pad = pad->Next() )
177  {
178  if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
179  {
180  if( pad->GetDrillSize().x != 0 )
181  {
182  if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
184  else
186  }
187  }
188  else
189  {
190  if( pad->GetDrillSize().x != 0 && pad->GetDrillSize().y != 0 )
191  {
192  if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
194  else
196  }
197  }
198  }
199  }
200 
201  // Display hole counts:
202  msg = m_PlatedPadsCountInfoMsg->GetLabel();
203  msg << wxT( " " ) << m_platedPadsHoleCount;
204  m_PlatedPadsCountInfoMsg->SetLabel( msg );
205 
206  msg = m_NotPlatedPadsCountInfoMsg->GetLabel();
207  msg << wxT( " " ) << m_notplatedPadsHoleCount;
208  m_NotPlatedPadsCountInfoMsg->SetLabel( msg );
209 
210  msg = m_ThroughViasInfoMsg->GetLabel();
211  msg << wxT( " " ) << m_throughViasCount;
212  m_ThroughViasInfoMsg->SetLabel( msg );
213 
214  msg = m_MicroViasInfoMsg->GetLabel();
215  msg << wxT( " " ) << m_microViasCount;
216  m_MicroViasInfoMsg->SetLabel( msg );
217 
218  msg = m_BuriedViasInfoMsg->GetLabel();
219  msg << wxT( " " ) << m_blindOrBuriedViasCount;
220  m_BuriedViasInfoMsg->SetLabel( msg );
221 
222  // Output directory
224 }
225 
226 
228 {
229  SetParams();
230 
232  m_config->Write( MirrorKey, m_Mirror );
238 }
239 
240 
241 void DIALOG_GENDRILL::OnSelDrillUnitsSelected( wxCommandEvent& event )
242 {
244 }
245 
246 
247 void DIALOG_GENDRILL::OnGenMapFile( wxCommandEvent& event )
248 {
249  GenDrillAndMapFiles( false, true);
250 }
251 
252 
253 void DIALOG_GENDRILL::OnGenDrillFile( wxCommandEvent& event )
254 {
255  GenDrillAndMapFiles(true, false);
256 }
257 
258 
259 void DIALOG_GENDRILL::OnCancelClick( wxCommandEvent& event )
260 {
261  UpdateConfig(); // Save drill options:
262  EndModal( wxID_CANCEL ); // Process the default cancel event (close dialog)
263 }
264 
265 
266 void DIALOG_GENDRILL::OnSelZerosFmtSelected( wxCommandEvent& event )
267 {
269 }
270 
271 
273 {
274  if( m_Choice_Unit->GetSelection()== 1 ) // Units = inches
276  else
277  {
278  // metric options
280  }
281 
283  m_staticTextPrecision->Enable( false );
284  else
285  m_staticTextPrecision->Enable( true );
286 }
287 
288 
290 {
291  // Build the absolute path of current output plot directory
292  // to preselect it when opening the dialog.
293  wxFileName fn( m_outputDirectoryName->GetValue() );
294  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
295 
296  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
297 
298  if( dirDialog.ShowModal() == wxID_CANCEL )
299  return;
300 
301  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
302 
303  fn = Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() );
304  wxString defaultPath = fn.GetPathWithSep();
305  wxString msg;
306  msg.Printf( _( "Do you want to use a path relative to\n'%s'" ), GetChars( defaultPath ) );
307 
308  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
309  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
310 
311  if( dialog.ShowModal() == wxID_YES )
312  {
313  if( !dirName.MakeRelativeTo( defaultPath ) )
314  wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
315  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
316  }
317 
318  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
319 }
320 
321 
323 {
324  wxString msg;
325 
326  // Set output directory and replace backslashes with forward ones
327  wxString dirStr;
328  dirStr = m_outputDirectoryName->GetValue();
329  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
330  m_plotOpts.SetOutputDirectory( dirStr );
331 
332  m_mapFileType = m_Choice_Drill_Map->GetSelection();
333 
334  m_UnitDrillIsInch = (m_Choice_Unit->GetSelection() == 0) ? false : true;
335  m_MinimalHeader = m_Check_Minimal->IsChecked();
336  m_Mirror = m_Check_Mirror->IsChecked();
338  m_ZerosFormat = m_Choice_Zeros_Format->GetSelection();
340 
341  if( m_Choice_Drill_Offset->GetSelection() == 0 )
342  m_FileDrillOffset = wxPoint( 0, 0 );
343  else
345 
346  if( m_UnitDrillIsInch )
348  else
350 
352 }
353 
354 
355 void DIALOG_GENDRILL::GenDrillAndMapFiles( bool aGenDrill, bool aGenMap )
356 {
357  UpdateConfig(); // set params and Save drill options
358 
360  wxString defaultPath = Prj().AbsolutePath( m_plotOpts.GetOutputDirectory() );
362 
363  const PlotFormat filefmt[6] =
364  { // Keep these format ids in the same order than m_Choice_Drill_Map choices
367  };
368 
369  unsigned choice = (unsigned) m_Choice_Drill_Map->GetSelection();
370 
371  if( choice >= DIM( filefmt ) )
372  choice = 1;
373 
374  EXCELLON_WRITER excellonWriter( m_parent->GetBoard() );
377  excellonWriter.SetOptions( m_Mirror, m_MinimalHeader, m_FileDrillOffset, m_Merge_PTH_NPTH );
378  excellonWriter.SetMapFileFormat( filefmt[choice] );
379 
380  excellonWriter.CreateDrillandMapFilesSet( defaultPath, aGenDrill, aGenMap, &reporter );
381 }
382 
383 
384 void DIALOG_GENDRILL::OnGenReportFile( wxCommandEvent& event )
385 {
386  UpdateConfig(); // set params and Save drill options
387 
388  wxFileName fn = m_parent->GetBoard()->GetFileName();
389 
390  fn.SetName( fn.GetName() + wxT( "-drl" ) );
391  fn.SetExt( ReportFileExtension );
392 
393  wxString defaultPath = Prj().AbsolutePath( m_plotOpts.GetOutputDirectory() );
394 
395  if( defaultPath.IsEmpty() )
396  defaultPath = wxStandardPaths::Get().GetDocumentsDir();
397 
398  wxFileDialog dlg( this, _( "Save Drill Report File" ), defaultPath, fn.GetFullName(),
399  wxGetTranslation( ReportFileWildcard ), wxFD_SAVE );
400 
401  if( dlg.ShowModal() == wxID_CANCEL )
402  return;
403 
404  EXCELLON_WRITER excellonWriter( m_parent->GetBoard() );
407  excellonWriter.SetOptions( m_Mirror, m_MinimalHeader, m_FileDrillOffset, m_Merge_PTH_NPTH );
408 
409  bool success = excellonWriter.GenDrillReportFile( dlg.GetPath() );
410 
411  wxString msg;
412 
413  if( ! success )
414  {
415  msg.Printf( _( "** Unable to create %s **\n" ), GetChars( dlg.GetPath() ) );
416  m_messagesBox->AppendText( msg );
417  }
418  else
419  {
420  msg.Printf( _( "Report file %s created\n" ), GetChars( dlg.GetPath() ) );
421  m_messagesBox->AppendText( msg );
422  }
423 }
#define DrillMapFileTypeKey
#define UnitDrillInchKey
static int m_UnitDrillIsInch
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxStaticText * m_PlatedPadsCountInfoMsg
void OnGenDrillFile(wxCommandEvent &event) override
wxConfigBase * m_config
static bool m_DrillOriginIsAuxAxis
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
#define MinimalHeaderKey
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plot_common.h:49
wxRadioBox * m_Choice_Drill_Offset
#define MergePTHNPTHKey
void OnSelZerosFmtSelected(wxCommandEvent &event) override
Class BOARD to handle a board.
MODULE * Next() const
Definition: class_module.h:99
EXCELLON_WRITER is a class mainly used to create Excellon drill files However, this class is also use...
wxCheckBox * m_Check_Merge_PTH_NPTH
void OnSelDrillUnitsSelected(wxCommandEvent &event) override
Class DIALOG_GENDRILL_BASE.
static bool m_Merge_PTH_NPTH
static int m_ZerosFormat
BOARD * GetBoard() const
wxPoint m_FileDrillOffset
#define ZerosFormatKey
static int m_mapFileType
wxStaticText * m_NotPlatedPadsCountInfoMsg
wxStaticText * m_ViaDrillValue
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
const wxPoint & GetAuxOrigin() const override
Function GetAuxOrigin returns the origin of the axis used for plotting and various exports...
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
#define MirrorKey
Functions relatives to tracks, vias and segments used to fill zones.
Class WX_TEXT_CTRL_REPORTER is wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:95
This file contains miscellaneous commonly used macros and functions.
void SetFormat(bool aMetric, ZEROS_FMT aZerosFmt=DECIMAL_FORMAT, int aLeftDigits=0, int aRightDigits=0)
Function SetFormat Initialize internal parameters to match the given format.
Board plot function definition file.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
static bool m_MinimalHeader
wxStaticText * m_MicroViasInfoMsg
wxString GetOutputDirectory() const
#define DrillOriginIsAuxAxisKey
VIATYPE_T GetViaType() const
Definition: class_track.h:442
wxStaticText * m_BuriedViasInfoMsg
const wxString & GetFileName() const
Definition: class_board.h:237
wxStaticText * m_ThroughViasInfoMsg
void OnCancelClick(wxCommandEvent &event) override
wxTextCtrl * m_outputDirectoryName
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
Definition: project.cpp:371
D_PAD * Next() const
Definition: class_pad.h:106
wxRadioBox * m_Choice_Zeros_Format
The common library.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
PCB_PLOT_PARAMS m_plotOpts
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
Definition: class_board.h:549
void SetOutputDirectory(wxString aDir)
static DRILL_PRECISION precisionListForMetric(3, 3)
static bool m_Mirror
DRILL_PRECISION m_Precision
TRACK * Next() const
Definition: class_track.h:97
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
wxStaticText * m_MicroViaDrillValue
DLIST< MODULE > m_Modules
Definition: class_board.h:243
void InitDisplayParams(void)
const wxString ReportFileExtension
Classes used in drill files, map files and report files generation.
wxStaticText * m_staticTextPrecision
const wxString ReportFileWildcard
void OnGenReportFile(wxCommandEvent &event) override
DLIST< TRACK > m_Track
Definition: class_board.h:244
Module description (excepted pads)
DIALOG_GENDRILL(PCB_EDIT_FRAME *parent)
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
void OnGenMapFile(wxCommandEvent &event) override
void GenDrillAndMapFiles(bool aGenDrill, bool aGenMap)
Function GenDrillAndMapFiles Calls the functions to create EXCELLON drill files and/or drill map file...
void InstallDrillFrame(wxCommandEvent &event)
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:742
PCB_EDIT_FRAME * m_parent
static DRILL_PRECISION precisionListForInches(2, 4)