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>
|
2023-01-17 16:54:08 +00:00
|
|
|
* Copyright (C) 1992-2023 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>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.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>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/board_editor_control.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2021-01-23 04:17:32 +00:00
|
|
|
#include <paths.h>
|
2021-06-09 01:56:00 +00:00
|
|
|
#include <project.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#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>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/dirdlg.h>
|
|
|
|
#include <wx/filedlg.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
|
|
|
|
*/
|
2020-12-16 13:31:32 +00:00
|
|
|
int BOARD_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
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Generate Drill File" ) },
|
|
|
|
{ wxID_APPLY, _( "Generate Map File" ) },
|
|
|
|
{ wxID_CANCEL, _( "Close" ) } } );
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_buttonsSizer->Layout();
|
|
|
|
|
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
|
2022-06-23 09:56:27 +00:00
|
|
|
int DIALOG_GENDRILL::m_mapFileType = 4; // The last choice in m_Choice_Drill_Map
|
2017-04-28 10:53:30 +00:00
|
|
|
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
|
|
|
|
2022-06-22 09:13:06 +00:00
|
|
|
// Ensure validity of m_mapFileType
|
2022-06-23 09:56:27 +00:00
|
|
|
if( m_mapFileType < 0 || m_mapFileType >= (int)m_Choice_Drill_Map->GetCount() )
|
|
|
|
m_mapFileType = m_Choice_Drill_Map->GetCount() - 1; // last item in list = default = PDF
|
2022-06-22 09:13:06 +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
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
|
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 );
|
|
|
|
|
2021-03-05 19:41:21 +00:00
|
|
|
m_Choice_Drill_Offset->SetSelection( m_drillOriginIsAuxAxis ? 1 : 0 );
|
2010-11-24 15:10:33 +00:00
|
|
|
|
|
|
|
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-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->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
|
|
|
{
|
2021-05-01 14:46:50 +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
|
|
|
{
|
2021-05-01 14:46:50 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
2018-02-28 09:44:22 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA *via = dynamic_cast<const PCB_VIA*>( track );
|
2020-11-12 23:50:33 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
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:
|
2021-03-05 19:41:21 +00:00
|
|
|
m_PlatedPadsCountInfoMsg->SetLabel( wxString() << m_platedPadsHoleCount );
|
2018-02-09 18:00:13 +00:00
|
|
|
m_NotPlatedPadsCountInfoMsg->SetLabel( wxString() << m_notplatedPadsHoleCount );
|
2021-03-05 19:41:21 +00:00
|
|
|
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 )
|
2021-09-18 09:34:02 +00:00
|
|
|
{
|
2017-04-28 10:53:30 +00:00
|
|
|
UpdatePrecisionOptions();
|
2021-09-18 09:34:02 +00:00
|
|
|
}
|
2017-04-28 10:53:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_staticTextPrecision->Enable( true );
|
2022-02-04 22:44:59 +00:00
|
|
|
m_staticTextPrecision->SetLabel( m_plotOpts.GetGerberPrecision() == 6 ? wxT( "4.6" )
|
|
|
|
: wxT( "4.5" ) );
|
2017-04-28 10:53:30 +00:00
|
|
|
}
|
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
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if( m_Choice_Unit->GetSelection()== 1 )
|
|
|
|
{
|
|
|
|
// Units = inches
|
2012-10-05 19:04:17 +00:00
|
|
|
m_staticTextPrecision->SetLabel( precisionListForInches.GetPrecisionString() );
|
2020-11-12 23:50:33 +00:00
|
|
|
}
|
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;
|
2021-06-16 22:35:00 +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 ) )
|
2021-09-18 09:34:02 +00:00
|
|
|
{
|
2022-12-13 20:47:28 +00:00
|
|
|
wxMessageBox( _( "Cannot make path relative (target volume different from board "
|
|
|
|
"file volume)!" ),
|
2012-10-05 12:25:12 +00:00
|
|
|
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
|
2021-09-18 09:34:02 +00:00
|
|
|
}
|
2012-10-05 12:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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 );
|
2021-03-05 19:41:21 +00:00
|
|
|
m_drillOriginIsAuxAxis = m_Choice_Drill_Offset->GetSelection() == 1;
|
2017-04-28 10:53:30 +00:00
|
|
|
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 )
|
2021-12-29 21:30:11 +00:00
|
|
|
m_DrillFileOffset = VECTOR2I( 0, 0 );
|
2010-11-24 15:10:33 +00:00
|
|
|
else
|
2021-11-09 03:36:40 +00:00
|
|
|
m_DrillFileOffset = m_board->GetDesignSettings().GetAuxOrigin();
|
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
|
|
|
|
2021-03-05 19:41:21 +00:00
|
|
|
if( !m_plotOpts.IsSameAs( m_board->GetPlotOptions() ) )
|
|
|
|
{
|
|
|
|
m_board->SetPlotOptions( m_plotOpts );
|
|
|
|
m_pcbEditFrame->OnModify();
|
|
|
|
}
|
2012-10-05 12:25:12 +00:00
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
2022-06-22 09:13:06 +00:00
|
|
|
const PLOT_FORMAT filefmt[] = {
|
2019-12-28 00:55:11 +00:00
|
|
|
// Keep these format ids in the same order than m_Choice_Drill_Map choices
|
2021-06-27 16:39:09 +00:00
|
|
|
PLOT_FORMAT::POST,
|
2022-06-23 09:56:27 +00:00
|
|
|
PLOT_FORMAT::GERBER, // Only X2 format because we need the .FileFunction attribute
|
2021-06-27 16:39:09 +00:00
|
|
|
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 ) )
|
2022-06-22 09:13:06 +00:00
|
|
|
choice = arrayDim( filefmt )-1; // Last choice = PDF
|
2012-10-05 12:25:12 +00:00
|
|
|
|
2022-01-23 17:23:17 +00:00
|
|
|
// Create output directory if it does not exist (also transform it in absolute form).
|
|
|
|
// Bail if it fails.
|
|
|
|
|
|
|
|
std::function<bool( wxString* )> textResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
// Handles m_board->GetTitleBlock() *and* m_board->GetProject()
|
|
|
|
return m_board->ResolveTextVar( token, 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
wxString path = m_plotOpts.GetOutputDirectory();
|
2023-01-17 16:54:08 +00:00
|
|
|
path = ExpandTextVars( path, &textResolver );
|
2022-01-23 17:23:17 +00:00
|
|
|
path = ExpandEnvVarSubstitutions( path, nullptr );
|
|
|
|
|
2020-04-05 21:10:42 +00:00
|
|
|
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;
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Could not write drill and/or map files to folder '%s'." ),
|
2021-06-27 16:39:09 +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,
|
2020-11-16 00:04:55 +00:00
|
|
|
m_Precision.m_Lhs, m_Precision.m_Rhs );
|
2021-06-27 16:39:09 +00:00
|
|
|
excellonWriter.SetOptions( m_Mirror, m_MinimalHeader, m_DrillFileOffset, 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() );
|
2021-06-27 16:39:09 +00:00
|
|
|
gerberWriter.SetOptions( m_DrillFileOffset );
|
2017-04-28 10:53:30 +00:00
|
|
|
gerberWriter.SetMapFileFormat( filefmt[choice] );
|
|
|
|
|
2021-06-27 16:39:09 +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() )
|
2021-01-23 04:17:32 +00:00
|
|
|
defaultPath = PATHS::GetDefaultUserProjectsPath();
|
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 )
|
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), dlg.GetPath() );
|
2012-10-05 12:25:12 +00:00
|
|
|
m_messagesBox->AppendText( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Report file '%s' created." ), dlg.GetPath() );
|
2012-10-05 12:25:12 +00:00
|
|
|
m_messagesBox->AppendText( msg );
|
|
|
|
}
|
|
|
|
}
|