2010-11-26 11:55:34 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-11-26 11:55:34 +00:00
|
|
|
*
|
2019-02-09 13:56:02 +00:00
|
|
|
* Copyright (C) 1992-2019 Jean_Pierre Charras <jp.charras at wanadoo.fr>
|
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2010-11-26 11:55:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2017-05-01 18:42:18 +00:00
|
|
|
#include <confirm.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbplot.h>
|
2012-10-05 12:25:12 +00:00
|
|
|
#include <gendrill_Excellon_writer.h>
|
2017-04-28 10:53:30 +00:00
|
|
|
#include <gendrill_gerber_writer.h>
|
2018-02-09 18:00:13 +00:00
|
|
|
#include <bitmaps.h>
|
2019-06-04 20:59:59 +00:00
|
|
|
#include <tools/pcb_editor_control.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <dialog_gendrill.h>
|
2012-10-05 12:25:12 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2015-04-29 15:37:37 +00:00
|
|
|
#include <reporter.h>
|
2015-09-25 19:38:09 +00:00
|
|
|
#include <wx/stdpaths.h>
|
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
// list of allowed precision for EXCELLON files, for integer format:
|
2010-11-24 15:10:33 +00:00
|
|
|
// Due to difference between inches and mm,
|
2012-10-05 19:04:17 +00:00
|
|
|
// there are 2 precision values, one for inches and one for metric
|
2019-02-09 13:56:02 +00:00
|
|
|
// Note: for decimla format, the precision is not used
|
2012-10-05 19:04:17 +00:00
|
|
|
static DRILL_PRECISION precisionListForInches( 2, 4 );
|
|
|
|
static DRILL_PRECISION precisionListForMetric( 3, 3 );
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* This function displays the dialog frame for drill tools
|
|
|
|
*/
|
2019-06-04 20:59:59 +00:00
|
|
|
int PCB_EDITOR_CONTROL::GenerateDrillFiles( const TOOL_EVENT& aEvent )
|
2012-10-05 12:25:12 +00:00
|
|
|
{
|
2019-06-09 23:21:50 +00:00
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
DIALOG_GENDRILL dlg( editFrame, editFrame );
|
2020-10-03 14:40:36 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
dlg.ShowModal();
|
2019-06-04 20:59:59 +00:00
|
|
|
return 0;
|
2012-10-05 12:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-13 10:41:52 +00:00
|
|
|
DIALOG_GENDRILL::DIALOG_GENDRILL( PCB_EDIT_FRAME* aPcbEditFrame, wxWindow* aParent ) :
|
|
|
|
DIALOG_GENDRILL_BASE( aParent )
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2019-02-13 10:41:52 +00:00
|
|
|
m_pcbEditFrame = aPcbEditFrame;
|
|
|
|
m_board = m_pcbEditFrame->GetBoard();
|
|
|
|
m_plotOpts = m_pcbEditFrame->GetPlotSettings();
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
// We use a sdbSizer to get platform-dependent ordering of the action buttons, but
|
|
|
|
// that requires us to correct the button labels here.
|
2019-02-13 10:41:52 +00:00
|
|
|
m_sdbSizerOK->SetLabel( _( "Generate Drill File" ) );
|
|
|
|
m_sdbSizerApply->SetLabel( _( "Generate Map File" ) );
|
|
|
|
m_sdbSizerCancel->SetLabel( _( "Close" ) );
|
2018-02-28 09:44:22 +00:00
|
|
|
m_buttonsSizer->Layout();
|
|
|
|
|
2019-02-13 10:41:52 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2010-11-24 15:10:33 +00:00
|
|
|
SetReturnCode( 1 );
|
|
|
|
initDialog();
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Static members of DIALOG_GENDRILL
|
2017-04-28 10:53:30 +00:00
|
|
|
int DIALOG_GENDRILL::m_UnitDrillIsInch = true; // Only for Excellon format
|
|
|
|
int DIALOG_GENDRILL::m_ZerosFormat = EXCELLON_WRITER::DECIMAL_FORMAT;
|
|
|
|
bool DIALOG_GENDRILL::m_MinimalHeader = false; // Only for Excellon format
|
2020-08-31 16:29:13 +00:00
|
|
|
bool DIALOG_GENDRILL::m_Mirror = false; // Only for Excellon format
|
2017-04-28 10:53:30 +00:00
|
|
|
bool DIALOG_GENDRILL::m_Merge_PTH_NPTH = false; // Only for Excellon format
|
|
|
|
int DIALOG_GENDRILL::m_mapFileType = 1;
|
|
|
|
int DIALOG_GENDRILL::m_drillFileType = 0;
|
2019-02-09 13:56:02 +00:00
|
|
|
bool DIALOG_GENDRILL::m_UseRouteModeForOvalHoles = true; // Use G00 route mode to "drill" oval holes
|
2010-11-24 15:10:33 +00:00
|
|
|
|
|
|
|
DIALOG_GENDRILL::~DIALOG_GENDRILL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GENDRILL::initDialog()
|
|
|
|
{
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_pcbEditFrame->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_Merge_PTH_NPTH = cfg->m_GenDrill.merge_pth_npth;
|
|
|
|
m_MinimalHeader = cfg->m_GenDrill.minimal_header;
|
|
|
|
m_Mirror = cfg->m_GenDrill.mirror;
|
|
|
|
m_UnitDrillIsInch = cfg->m_GenDrill.unit_drill_is_inch;
|
|
|
|
m_UseRouteModeForOvalHoles = cfg->m_GenDrill.use_route_for_oval_holes;
|
|
|
|
m_drillFileType = cfg->m_GenDrill.drill_file_type;
|
|
|
|
m_mapFileType = cfg->m_GenDrill.map_file_type;
|
|
|
|
m_ZerosFormat = cfg->m_GenDrill.zeros_format;
|
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
m_drillOriginIsAuxAxis = m_plotOpts.GetUseAuxOrigin();
|
2011-10-01 19:24:27 +00:00
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
InitDisplayParams();
|
|
|
|
}
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
void DIALOG_GENDRILL::InitDisplayParams()
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_rbExcellon->SetValue( m_drillFileType == 0 );
|
|
|
|
m_rbGerberX2->SetValue( m_drillFileType == 1 );
|
2010-11-24 15:10:33 +00:00
|
|
|
m_Choice_Unit->SetSelection( m_UnitDrillIsInch ? 1 : 0 );
|
|
|
|
m_Choice_Zeros_Format->SetSelection( m_ZerosFormat );
|
2011-08-19 13:08:24 +00:00
|
|
|
UpdatePrecisionOptions();
|
2010-11-24 15:10:33 +00:00
|
|
|
m_Check_Minimal->SetValue( m_MinimalHeader );
|
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
if( m_drillOriginIsAuxAxis )
|
2010-11-24 15:10:33 +00:00
|
|
|
m_Choice_Drill_Offset->SetSelection( 1 );
|
|
|
|
|
|
|
|
m_Check_Mirror->SetValue( m_Mirror );
|
2015-11-16 18:42:58 +00:00
|
|
|
m_Check_Merge_PTH_NPTH->SetValue( m_Merge_PTH_NPTH );
|
2012-10-05 12:25:12 +00:00
|
|
|
m_Choice_Drill_Map->SetSelection( m_mapFileType );
|
2019-02-09 13:56:02 +00:00
|
|
|
m_radioBoxOvalHoleMode->SetSelection( m_UseRouteModeForOvalHoles ? 0 : 1 );
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_platedPadsHoleCount = 0;
|
|
|
|
m_notplatedPadsHoleCount = 0;
|
2011-08-19 13:08:24 +00:00
|
|
|
m_throughViasCount = 0;
|
|
|
|
m_microViasCount = 0;
|
|
|
|
m_blindOrBuriedViasCount = 0;
|
2011-10-01 19:24:27 +00:00
|
|
|
|
2020-08-31 16:29:13 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2020-08-31 16:29:13 +00:00
|
|
|
for( D_PAD* pad : module->Pads() )
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
if( pad->GetDrillSize().x != 0 )
|
2011-08-19 13:08:24 +00:00
|
|
|
{
|
2020-09-30 15:38:35 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB_NPTH )
|
2011-08-19 13:08:24 +00:00
|
|
|
m_notplatedPadsHoleCount++;
|
|
|
|
else
|
|
|
|
m_platedPadsHoleCount++;
|
|
|
|
}
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
else
|
2011-10-01 19:24:27 +00:00
|
|
|
{
|
2012-12-06 21:53:00 +00:00
|
|
|
if( pad->GetDrillSize().x != 0 && pad->GetDrillSize().y != 0 )
|
2011-08-19 13:08:24 +00:00
|
|
|
{
|
2020-09-30 15:38:35 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB_NPTH )
|
2011-08-19 13:08:24 +00:00
|
|
|
m_notplatedPadsHoleCount++;
|
|
|
|
else
|
|
|
|
m_platedPadsHoleCount++;
|
|
|
|
}
|
2011-10-01 19:24:27 +00:00
|
|
|
}
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 16:29:13 +00:00
|
|
|
for( TRACK* track : m_board->Tracks() )
|
2018-02-28 09:44:22 +00:00
|
|
|
{
|
|
|
|
const VIA *via = dynamic_cast<const VIA*>( track );
|
|
|
|
if( via )
|
|
|
|
{
|
|
|
|
switch( via->GetViaType() )
|
|
|
|
{
|
2020-08-31 16:29:13 +00:00
|
|
|
case VIATYPE::THROUGH: m_throughViasCount++; break;
|
|
|
|
case VIATYPE::MICROVIA: m_microViasCount++; break;
|
|
|
|
case VIATYPE::BLIND_BURIED: m_blindOrBuriedViasCount++; break;
|
|
|
|
default: break;
|
2018-02-28 09:44:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
// Display hole counts:
|
2018-02-09 18:00:13 +00:00
|
|
|
m_PlatedPadsCountInfoMsg-> SetLabel( wxString() << m_platedPadsHoleCount );
|
|
|
|
m_NotPlatedPadsCountInfoMsg->SetLabel( wxString() << m_notplatedPadsHoleCount );
|
|
|
|
m_ThroughViasInfoMsg-> SetLabel( wxString() << m_throughViasCount );
|
|
|
|
m_MicroViasInfoMsg-> SetLabel( wxString() << m_microViasCount );
|
|
|
|
m_BuriedViasInfoMsg-> SetLabel( wxString() << m_blindOrBuriedViasCount );
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
// Output directory
|
|
|
|
m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
|
2017-04-28 10:53:30 +00:00
|
|
|
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
onFileFormatSelection( dummy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GENDRILL::onFileFormatSelection( wxCommandEvent& event )
|
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
bool enbl_Excellon = m_rbExcellon->GetValue();
|
|
|
|
|
|
|
|
m_drillFileType = enbl_Excellon ? 0 : 1;
|
2017-04-28 10:53:30 +00:00
|
|
|
|
|
|
|
m_Choice_Unit->Enable( enbl_Excellon );
|
|
|
|
m_Choice_Zeros_Format->Enable( enbl_Excellon );
|
|
|
|
m_Check_Mirror->Enable( enbl_Excellon );
|
|
|
|
m_Check_Minimal->Enable( enbl_Excellon );
|
|
|
|
m_Check_Merge_PTH_NPTH->Enable( enbl_Excellon );
|
2019-02-09 13:56:02 +00:00
|
|
|
m_radioBoxOvalHoleMode->Enable( enbl_Excellon );
|
2017-04-28 10:53:30 +00:00
|
|
|
|
|
|
|
if( enbl_Excellon )
|
|
|
|
UpdatePrecisionOptions();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_staticTextPrecision->Enable( true );
|
|
|
|
m_staticTextPrecision->SetLabel( m_plotOpts.GetGerberPrecision() == 6 ? "4.6" : "4.5" );
|
|
|
|
}
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
void DIALOG_GENDRILL::UpdateConfig()
|
|
|
|
{
|
2019-02-13 10:41:52 +00:00
|
|
|
UpdateDrillParams();
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_pcbEditFrame->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
cfg->m_GenDrill.merge_pth_npth = m_Merge_PTH_NPTH;
|
|
|
|
cfg->m_GenDrill.minimal_header = m_MinimalHeader;
|
|
|
|
cfg->m_GenDrill.mirror = m_Mirror;
|
|
|
|
cfg->m_GenDrill.unit_drill_is_inch = m_UnitDrillIsInch;
|
|
|
|
cfg->m_GenDrill.use_route_for_oval_holes = m_UseRouteModeForOvalHoles;
|
|
|
|
cfg->m_GenDrill.drill_file_type = m_drillFileType;
|
|
|
|
cfg->m_GenDrill.map_file_type = m_mapFileType;
|
|
|
|
cfg->m_GenDrill.zeros_format = m_ZerosFormat;
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
void DIALOG_GENDRILL::OnSelDrillUnitsSelected( wxCommandEvent& event )
|
|
|
|
{
|
2011-08-19 13:08:24 +00:00
|
|
|
UpdatePrecisionOptions();
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 14:57:45 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
void DIALOG_GENDRILL::OnGenMapFile( wxCommandEvent& event )
|
|
|
|
{
|
2020-05-06 01:43:37 +00:00
|
|
|
GenDrillAndMapFiles( false, true );
|
2012-10-05 12:25:12 +00:00
|
|
|
}
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2014-03-03 14:28:05 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
void DIALOG_GENDRILL::OnGenDrillFile( wxCommandEvent& event )
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2020-05-06 01:43:37 +00:00
|
|
|
GenDrillAndMapFiles( true, false );
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GENDRILL::OnSelZerosFmtSelected( wxCommandEvent& event )
|
|
|
|
{
|
2011-08-19 13:08:24 +00:00
|
|
|
UpdatePrecisionOptions();
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
void DIALOG_GENDRILL::UpdatePrecisionOptions()
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
|
|
|
if( m_Choice_Unit->GetSelection()== 1 ) // Units = inches
|
2012-10-05 19:04:17 +00:00
|
|
|
m_staticTextPrecision->SetLabel( precisionListForInches.GetPrecisionString() );
|
2010-11-24 15:10:33 +00:00
|
|
|
else
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// metric options
|
2012-10-05 19:04:17 +00:00
|
|
|
m_staticTextPrecision->SetLabel( precisionListForMetric.GetPrecisionString() );
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
2011-10-01 19:24:27 +00:00
|
|
|
|
2010-11-24 19:54:59 +00:00
|
|
|
if( m_Choice_Zeros_Format->GetSelection() == EXCELLON_WRITER::DECIMAL_FORMAT )
|
2012-10-05 19:04:17 +00:00
|
|
|
m_staticTextPrecision->Enable( false );
|
2010-11-24 15:10:33 +00:00
|
|
|
else
|
2012-10-05 19:04:17 +00:00
|
|
|
m_staticTextPrecision->Enable( true );
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 14:28:05 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
void DIALOG_GENDRILL::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
|
|
|
|
{
|
2020-04-05 21:10:42 +00:00
|
|
|
// Build the absolute path of current output directory to preselect it in the file browser.
|
|
|
|
wxString path = ExpandEnvVarSubstitutions( m_outputDirectoryName->GetValue(), &Prj() );
|
|
|
|
path = Prj().AbsolutePath( path );
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
|
|
|
|
|
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2020-04-05 21:10:42 +00:00
|
|
|
wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
|
|
|
|
wxFileName fn( Prj().AbsolutePath( m_board->GetFileName() ) );
|
|
|
|
wxString defaultPath = fn.GetPathWithSep();
|
|
|
|
wxString msg;
|
2020-10-16 00:39:55 +00:00
|
|
|
msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ), defaultPath );
|
2016-07-27 12:53:45 +00:00
|
|
|
|
|
|
|
wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
|
2012-10-05 12:25:12 +00:00
|
|
|
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
|
|
|
|
|
|
|
|
if( dialog.ShowModal() == wxID_YES )
|
|
|
|
{
|
2016-07-27 12:53:45 +00:00
|
|
|
if( !dirName.MakeRelativeTo( defaultPath ) )
|
|
|
|
wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
|
2012-10-05 12:25:12 +00:00
|
|
|
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputDirectoryName->SetValue( dirName.GetFullPath() );
|
|
|
|
}
|
2010-11-24 15:10:33 +00:00
|
|
|
|
2014-03-03 14:28:05 +00:00
|
|
|
|
2019-02-13 10:41:52 +00:00
|
|
|
void DIALOG_GENDRILL::UpdateDrillParams()
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
// Set output directory and replace backslashes with forward ones
|
|
|
|
wxString dirStr;
|
|
|
|
dirStr = m_outputDirectoryName->GetValue();
|
|
|
|
dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
|
|
|
|
m_plotOpts.SetOutputDirectory( dirStr );
|
2017-04-28 10:53:30 +00:00
|
|
|
m_drillOriginIsAuxAxis = m_Choice_Drill_Offset->GetSelection();
|
|
|
|
m_plotOpts.SetUseAuxOrigin( m_drillOriginIsAuxAxis );
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
m_mapFileType = m_Choice_Drill_Map->GetSelection();
|
2011-08-19 13:08:24 +00:00
|
|
|
|
2012-01-22 17:20:22 +00:00
|
|
|
m_UnitDrillIsInch = (m_Choice_Unit->GetSelection() == 0) ? false : true;
|
2020-07-01 12:28:10 +00:00
|
|
|
m_MinimalHeader = m_Check_Minimal->IsChecked();
|
2010-11-24 15:10:33 +00:00
|
|
|
m_Mirror = m_Check_Mirror->IsChecked();
|
2015-11-16 18:42:58 +00:00
|
|
|
m_Merge_PTH_NPTH = m_Check_Merge_PTH_NPTH->IsChecked();
|
2010-11-24 15:10:33 +00:00
|
|
|
m_ZerosFormat = m_Choice_Zeros_Format->GetSelection();
|
2019-02-09 13:56:02 +00:00
|
|
|
m_UseRouteModeForOvalHoles = m_radioBoxOvalHoleMode->GetSelection() == 0;
|
2010-11-24 15:10:33 +00:00
|
|
|
|
|
|
|
if( m_Choice_Drill_Offset->GetSelection() == 0 )
|
|
|
|
m_FileDrillOffset = wxPoint( 0, 0 );
|
|
|
|
else
|
2020-07-01 12:28:10 +00:00
|
|
|
m_FileDrillOffset = m_board->GetDesignSettings().m_AuxOrigin;
|
2010-11-24 15:10:33 +00:00
|
|
|
|
|
|
|
if( m_UnitDrillIsInch )
|
2012-10-05 19:04:17 +00:00
|
|
|
m_Precision = precisionListForInches;
|
2010-11-24 15:10:33 +00:00
|
|
|
else
|
2012-10-05 19:04:17 +00:00
|
|
|
m_Precision = precisionListForMetric;
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
m_board->SetPlotOptions( m_plotOpts );
|
|
|
|
}
|
|
|
|
|
2014-03-03 14:28:05 +00:00
|
|
|
|
2016-10-07 14:57:45 +00:00
|
|
|
void DIALOG_GENDRILL::GenDrillAndMapFiles( bool aGenDrill, bool aGenMap )
|
2012-10-05 12:25:12 +00:00
|
|
|
{
|
2014-07-20 14:46:59 +00:00
|
|
|
UpdateConfig(); // set params and Save drill options
|
2012-10-05 12:25:12 +00:00
|
|
|
|
2019-02-13 10:41:52 +00:00
|
|
|
m_pcbEditFrame->ClearMsgPanel();
|
2015-04-29 15:37:37 +00:00
|
|
|
WX_TEXT_CTRL_REPORTER reporter( m_messagesBox );
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
const PLOT_FORMAT filefmt[6] = {
|
|
|
|
// Keep these format ids in the same order than m_Choice_Drill_Map choices
|
|
|
|
PLOT_FORMAT::HPGL, PLOT_FORMAT::POST, PLOT_FORMAT::GERBER, PLOT_FORMAT::DXF,
|
|
|
|
PLOT_FORMAT::SVG, PLOT_FORMAT::PDF
|
2015-04-29 15:37:37 +00:00
|
|
|
};
|
2016-10-07 14:57:45 +00:00
|
|
|
|
2015-04-29 15:37:37 +00:00
|
|
|
unsigned choice = (unsigned) m_Choice_Drill_Map->GetSelection();
|
2012-10-05 12:25:12 +00:00
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
if( choice >= arrayDim( filefmt ) )
|
2015-04-29 15:37:37 +00:00
|
|
|
choice = 1;
|
2012-10-05 12:25:12 +00:00
|
|
|
|
2017-05-01 18:42:18 +00:00
|
|
|
// Create output directory if it does not exist (also transform it in
|
|
|
|
// absolute form). Bail if it fails
|
2020-04-05 21:10:42 +00:00
|
|
|
wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() );
|
|
|
|
wxFileName outputDir = wxFileName::DirName( path );
|
2019-02-13 10:41:52 +00:00
|
|
|
wxString boardFilename = m_board->GetFileName();
|
2017-05-01 18:42:18 +00:00
|
|
|
|
|
|
|
if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Could not write drill and/or map files to folder \"%s\"." ),
|
2020-10-16 00:39:55 +00:00
|
|
|
outputDir.GetPath() );
|
2017-05-01 18:42:18 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
if( m_drillFileType == 0 )
|
|
|
|
{
|
2019-02-13 10:41:52 +00:00
|
|
|
EXCELLON_WRITER excellonWriter( m_board );
|
2017-04-28 10:53:30 +00:00
|
|
|
excellonWriter.SetFormat( !m_UnitDrillIsInch, (EXCELLON_WRITER::ZEROS_FMT) m_ZerosFormat,
|
|
|
|
m_Precision.m_lhs, m_Precision.m_rhs );
|
|
|
|
excellonWriter.SetOptions( m_Mirror, m_MinimalHeader, m_FileDrillOffset, m_Merge_PTH_NPTH );
|
2019-02-09 13:56:02 +00:00
|
|
|
excellonWriter.SetRouteModeForOvalHoles( m_UseRouteModeForOvalHoles );
|
2017-04-28 10:53:30 +00:00
|
|
|
excellonWriter.SetMapFileFormat( filefmt[choice] );
|
2012-10-05 12:25:12 +00:00
|
|
|
|
2020-04-05 21:10:42 +00:00
|
|
|
excellonWriter.CreateDrillandMapFilesSet( outputDir.GetFullPath(), aGenDrill, aGenMap,
|
|
|
|
&reporter );
|
2017-04-28 10:53:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-13 10:41:52 +00:00
|
|
|
GERBER_WRITER gerberWriter( m_board );
|
2017-04-28 10:53:30 +00:00
|
|
|
// Set gerber precision: only 5 or 6 digits for mantissa are allowed
|
|
|
|
// (SetFormat() accept 5 or 6, and any other value set the precision to 5)
|
|
|
|
// the integer part precision is always 4, and units always mm
|
|
|
|
gerberWriter.SetFormat( m_plotOpts.GetGerberPrecision() );
|
|
|
|
gerberWriter.SetOptions( m_FileDrillOffset );
|
|
|
|
gerberWriter.SetMapFileFormat( filefmt[choice] );
|
|
|
|
|
2017-05-01 18:42:18 +00:00
|
|
|
gerberWriter.CreateDrillandMapFilesSet( outputDir.GetFullPath(),
|
|
|
|
aGenDrill, aGenMap, &reporter );
|
2017-04-28 10:53:30 +00:00
|
|
|
}
|
2012-10-05 12:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GENDRILL::OnGenReportFile( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
UpdateConfig(); // set params and Save drill options
|
|
|
|
|
2019-02-13 10:41:52 +00:00
|
|
|
wxFileName fn = m_board->GetFileName();
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-drl" ) );
|
|
|
|
fn.SetExt( ReportFileExtension );
|
|
|
|
|
2020-04-05 21:10:42 +00:00
|
|
|
wxString defaultPath = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() );
|
|
|
|
defaultPath = Prj().AbsolutePath( defaultPath );
|
2014-03-03 14:28:05 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
if( defaultPath.IsEmpty() )
|
2015-09-25 19:38:09 +00:00
|
|
|
defaultPath = wxStandardPaths::Get().GetDocumentsDir();
|
2012-10-05 12:25:12 +00:00
|
|
|
|
2016-10-07 14:57:45 +00:00
|
|
|
wxFileDialog dlg( this, _( "Save Drill Report File" ), defaultPath, fn.GetFullName(),
|
2017-11-12 00:31:38 +00:00
|
|
|
ReportFileWildcard(), wxFD_SAVE );
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
bool success;
|
2012-10-05 12:25:12 +00:00
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
// Info is slightly different between Excellon and Gerber
|
|
|
|
// (file ext, Merge PTH/NPTH option)
|
|
|
|
if( m_drillFileType == 0 )
|
|
|
|
{
|
2019-02-13 10:41:52 +00:00
|
|
|
EXCELLON_WRITER excellonWriter( m_board );
|
2017-04-28 10:53:30 +00:00
|
|
|
excellonWriter.SetMergeOption( m_Merge_PTH_NPTH );
|
|
|
|
success = excellonWriter.GenDrillReportFile( dlg.GetPath() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-13 10:41:52 +00:00
|
|
|
GERBER_WRITER gerberWriter( m_board );
|
2017-04-28 10:53:30 +00:00
|
|
|
success = gerberWriter.GenDrillReportFile( dlg.GetPath() );
|
|
|
|
}
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( ! success )
|
|
|
|
{
|
2020-10-16 00:39:55 +00:00
|
|
|
msg.Printf( _( "** Unable to create %s **\n" ), dlg.GetPath() );
|
2012-10-05 12:25:12 +00:00
|
|
|
m_messagesBox->AppendText( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-16 00:39:55 +00:00
|
|
|
msg.Printf( _( "Report file %s created\n" ), dlg.GetPath() );
|
2012-10-05 12:25:12 +00:00
|
|
|
m_messagesBox->AppendText( msg );
|
|
|
|
}
|
|
|
|
}
|