2010-11-26 12:55:34 +01:00
|
|
|
/*
|
2011-09-30 14:15:37 -04:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-11-26 12:55:34 +01:00
|
|
|
*
|
2019-02-09 14:56:02 +01:00
|
|
|
* Copyright (C) 1992-2019 Jean_Pierre Charras <jp.charras at wanadoo.fr>
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2010-11-26 12:55:34 +01: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 16:10:33 +01:00
|
|
|
|
2017-05-01 20:42:18 +02:00
|
|
|
#include <confirm.h>
|
2020-11-17 20:21:04 -05:00
|
|
|
#include <core/arraydim.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2018-01-29 21:58:58 +01:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <pcbnew_settings.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <pcbplot.h>
|
2012-10-05 14:25:12 +02:00
|
|
|
#include <gendrill_Excellon_writer.h>
|
2017-04-28 12:53:30 +02: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 <footprint.h>
|
2021-06-06 15:03:10 -04:00
|
|
|
#include <pad.h>
|
2021-06-11 22:07:02 +01:00
|
|
|
#include <pcb_track.h>
|
2021-01-22 23:17:32 -05:00
|
|
|
#include <paths.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <dialog_gendrill.h>
|
2012-10-05 14:25:12 +02:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2015-04-29 17:37:37 +02:00
|
|
|
#include <reporter.h>
|
2021-05-01 09:50:29 +02:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/dirdlg.h>
|
|
|
|
#include <wx/filedlg.h>
|
2024-07-15 18:20:13 -04:00
|
|
|
#include <jobs/job_export_pcb_drill.h>
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2011-08-19 15:08:24 +02:00
|
|
|
// list of allowed precision for EXCELLON files, for integer format:
|
2010-11-24 16:10:33 +01:00
|
|
|
// Due to difference between inches and mm,
|
2012-10-05 21:04:17 +02:00
|
|
|
// there are 2 precision values, one for inches and one for metric
|
2019-02-09 14:56:02 +01:00
|
|
|
// Note: for decimla format, the precision is not used
|
2012-10-05 21:04:17 +02:00
|
|
|
static DRILL_PRECISION precisionListForInches( 2, 4 );
|
|
|
|
static DRILL_PRECISION precisionListForMetric( 3, 3 );
|
2012-10-05 14:25:12 +02:00
|
|
|
|
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
// Static members of DIALOG_GENDRILL
|
|
|
|
int DIALOG_GENDRILL::g_unitDrillIsInch = false; // Only for Excellon format
|
|
|
|
int DIALOG_GENDRILL::g_zerosFormat = EXCELLON_WRITER::DECIMAL_FORMAT;
|
|
|
|
bool DIALOG_GENDRILL::g_minimalHeader = false; // Only for Excellon format
|
|
|
|
bool DIALOG_GENDRILL::g_mirror = false; // Only for Excellon format
|
|
|
|
bool DIALOG_GENDRILL::g_merge_PTH_NPTH = false; // Only for Excellon format
|
|
|
|
bool DIALOG_GENDRILL::g_generateMap = false;
|
2025-03-01 18:02:54 +00:00
|
|
|
bool DIALOG_GENDRILL::g_generateTenting = false;
|
2025-01-07 17:07:10 +00:00
|
|
|
int DIALOG_GENDRILL::g_mapFileType = 4; // The last choice in m_Choice_Drill_Map
|
|
|
|
int DIALOG_GENDRILL::g_drillFileType = 0;
|
|
|
|
|
|
|
|
bool DIALOG_GENDRILL::g_useRouteModeForOvalHoles = true; // Use G00 route mode to "drill" oval
|
|
|
|
// holes
|
|
|
|
DRILL_PRECISION DIALOG_GENDRILL::g_precision;
|
|
|
|
VECTOR2I DIALOG_GENDRILL::g_drillFileOffset;
|
|
|
|
|
|
|
|
|
2012-10-05 14:25:12 +02: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 14:25:12 +02:00
|
|
|
{
|
2019-06-10 00:21:50 +01:00
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
DIALOG_GENDRILL dlg( editFrame, editFrame );
|
2020-10-03 16:40:36 +02:00
|
|
|
|
2012-10-05 14:25:12 +02:00
|
|
|
dlg.ShowModal();
|
2019-06-04 21:59:59 +01:00
|
|
|
return 0;
|
2012-10-05 14:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-15 18:20:13 -04:00
|
|
|
DIALOG_GENDRILL::DIALOG_GENDRILL( PCB_EDIT_FRAME* aPcbEditFrame, wxWindow* aParent ) :
|
2025-01-07 17:07:10 +00:00
|
|
|
DIALOG_GENDRILL_BASE( aParent )
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2019-02-13 11:41:52 +01:00
|
|
|
m_pcbEditFrame = aPcbEditFrame;
|
|
|
|
m_board = m_pcbEditFrame->GetBoard();
|
2024-10-18 15:49:27 -07:00
|
|
|
m_job = nullptr;
|
2019-02-13 11:41:52 +01:00
|
|
|
m_plotOpts = m_pcbEditFrame->GetPlotSettings();
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
|
|
|
|
2024-12-28 18:17:57 -05:00
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Generate" ) },
|
|
|
|
{ wxID_CANCEL, _( "Close" ) } } );
|
2021-11-16 19:39:58 +00:00
|
|
|
|
2010-11-24 16:10:33 +01:00
|
|
|
initDialog();
|
2025-01-01 20:09:55 +00:00
|
|
|
finishDialogSettings();
|
2010-11-24 16:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-15 18:20:13 -04:00
|
|
|
DIALOG_GENDRILL::DIALOG_GENDRILL( PCB_EDIT_FRAME* aPcbEditFrame, JOB_EXPORT_PCB_DRILL* aJob,
|
|
|
|
wxWindow* aParent ) :
|
2025-01-07 17:07:10 +00:00
|
|
|
DIALOG_GENDRILL_BASE( aParent )
|
2024-07-15 18:20:13 -04:00
|
|
|
{
|
|
|
|
m_pcbEditFrame = aPcbEditFrame;
|
|
|
|
m_board = m_pcbEditFrame->GetBoard();
|
|
|
|
m_job = aJob;
|
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
|
|
|
|
2024-07-15 18:20:13 -04:00
|
|
|
// hide ui elements that dont belong for job config
|
|
|
|
m_buttonReport->Hide();
|
|
|
|
bMainSizer->Remove( bMsgSizer );
|
|
|
|
m_messagesBox->Hide();
|
|
|
|
|
2025-01-01 19:15:33 +00:00
|
|
|
SetupStandardButtons();
|
2024-07-15 18:20:13 -04:00
|
|
|
|
2024-12-30 21:20:14 +00:00
|
|
|
initDialog();
|
2025-01-01 20:09:55 +00:00
|
|
|
finishDialogSettings();
|
2024-07-15 18:20:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-24 16:10:33 +01:00
|
|
|
DIALOG_GENDRILL::~DIALOG_GENDRILL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-15 18:20:13 -04:00
|
|
|
bool DIALOG_GENDRILL::TransferDataFromWindow()
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2025-01-01 20:09:55 +00:00
|
|
|
if( !m_job )
|
|
|
|
{
|
2025-03-01 18:02:54 +00:00
|
|
|
genDrillAndMapFiles( true, m_cbGenerateMap->GetValue(),
|
|
|
|
m_generateTentingLayers->GetValue() );
|
2025-01-01 20:09:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-01-14 20:02:53 -05:00
|
|
|
m_job->SetConfiguredOutputPath( m_outputDirectoryName->GetValue() );
|
2025-01-01 20:09:55 +00:00
|
|
|
m_job->m_format = m_rbExcellon->GetValue() ? JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::EXCELLON
|
|
|
|
: JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::GERBER;
|
2025-03-01 20:24:37 +00:00
|
|
|
m_job->m_drillUnits = m_units->GetSelection() == 0 ? JOB_EXPORT_PCB_DRILL::DRILL_UNITS::MM
|
|
|
|
: JOB_EXPORT_PCB_DRILL::DRILL_UNITS::IN;
|
2025-01-07 11:11:14 +00:00
|
|
|
m_job->m_drillOrigin = static_cast<JOB_EXPORT_PCB_DRILL::DRILL_ORIGIN>( m_origin->GetSelection() );
|
2025-01-01 20:09:55 +00:00
|
|
|
m_job->m_excellonCombinePTHNPTH = m_Check_Merge_PTH_NPTH->IsChecked();
|
|
|
|
m_job->m_excellonMinimalHeader = m_Check_Minimal->IsChecked();
|
|
|
|
m_job->m_excellonMirrorY = m_Check_Mirror->IsChecked();
|
2025-01-07 11:11:14 +00:00
|
|
|
m_job->m_excellonOvalDrillRoute = !m_altDrillMode->GetValue();
|
|
|
|
m_job->m_mapFormat = static_cast<JOB_EXPORT_PCB_DRILL::MAP_FORMAT>( m_choiceDrillMap->GetSelection() );
|
|
|
|
m_job->m_zeroFormat = static_cast<JOB_EXPORT_PCB_DRILL::ZEROS_FORMAT>( m_zeros->GetSelection() );
|
2025-01-01 20:09:55 +00:00
|
|
|
m_job->m_generateMap = m_cbGenerateMap->IsChecked();
|
2025-03-01 18:02:54 +00:00
|
|
|
m_job->m_generateTenting = m_generateTentingLayers->IsChecked();
|
2025-01-01 20:09:55 +00:00
|
|
|
}
|
|
|
|
|
2024-07-15 18:20:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
2020-01-12 20:44:19 -05:00
|
|
|
|
|
|
|
|
2024-07-15 18:20:13 -04:00
|
|
|
bool DIALOG_GENDRILL::TransferDataToWindow()
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2024-07-15 18:20:13 -04:00
|
|
|
if( !m_job )
|
|
|
|
{
|
2025-01-07 17:07:10 +00:00
|
|
|
m_rbExcellon->SetValue( g_drillFileType == 0 );
|
|
|
|
m_rbGerberX2->SetValue( g_drillFileType == 1 );
|
|
|
|
m_units->SetSelection( g_unitDrillIsInch ? 1 : 0 );
|
|
|
|
m_zeros->SetSelection( g_zerosFormat );
|
|
|
|
updatePrecisionOptions();
|
|
|
|
m_Check_Minimal->SetValue( g_minimalHeader );
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2025-01-07 11:11:14 +00:00
|
|
|
m_origin->SetSelection( m_drillOriginIsAuxAxis ? 1 : 0 );
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
m_Check_Mirror->SetValue( g_mirror );
|
|
|
|
m_Check_Merge_PTH_NPTH->SetValue( g_merge_PTH_NPTH );
|
|
|
|
m_choiceDrillMap->SetSelection( g_mapFileType );
|
|
|
|
m_altDrillMode->SetValue( !g_useRouteModeForOvalHoles );
|
|
|
|
m_cbGenerateMap->SetValue( g_generateMap );
|
2025-03-01 18:02:54 +00:00
|
|
|
m_generateTentingLayers->SetValue( g_generateTenting );
|
2024-07-15 18:20:13 -04:00
|
|
|
|
|
|
|
// Output directory
|
|
|
|
m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_browseButton->Hide();
|
2025-01-14 20:02:53 -05:00
|
|
|
m_outputDirectoryName->SetValue( m_job->GetConfiguredOutputPath() );
|
2024-07-15 18:20:13 -04:00
|
|
|
|
|
|
|
m_rbExcellon->SetValue( m_job->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::EXCELLON );
|
|
|
|
m_rbGerberX2->SetValue( m_job->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::GERBER );
|
2025-03-01 20:24:37 +00:00
|
|
|
m_units->SetSelection( m_job->m_drillUnits == JOB_EXPORT_PCB_DRILL::DRILL_UNITS::IN );
|
2025-01-07 11:11:14 +00:00
|
|
|
m_zeros->SetSelection( static_cast<int>( m_job->m_zeroFormat ) );
|
2025-01-07 17:07:10 +00:00
|
|
|
updatePrecisionOptions();
|
2024-07-15 18:20:13 -04:00
|
|
|
m_Check_Minimal->SetValue( m_job->m_excellonMinimalHeader );
|
|
|
|
|
2025-01-07 11:11:14 +00:00
|
|
|
m_origin->SetSelection( m_job->m_drillOrigin == JOB_EXPORT_PCB_DRILL::DRILL_ORIGIN::PLOT );
|
2024-07-15 18:20:13 -04:00
|
|
|
|
|
|
|
m_Check_Mirror->SetValue( m_job->m_excellonMirrorY );
|
|
|
|
m_Check_Merge_PTH_NPTH->SetValue( m_job->m_excellonCombinePTHNPTH );
|
2025-01-07 11:11:14 +00:00
|
|
|
m_choiceDrillMap->SetSelection( static_cast<int>( m_job->m_mapFormat ) );
|
|
|
|
m_altDrillMode->SetValue( !m_job->m_excellonOvalDrillRoute );
|
2024-12-28 18:25:17 -05:00
|
|
|
m_cbGenerateMap->SetValue( m_job->m_generateMap );
|
2025-03-01 18:02:54 +00:00
|
|
|
m_generateTentingLayers->SetValue( m_job->m_generateTenting );
|
2024-07-15 18:20:13 -04:00
|
|
|
}
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2017-04-28 12:53:30 +02:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
onFileFormatSelection( dummy );
|
2025-01-07 17:07:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GENDRILL::initDialog()
|
|
|
|
{
|
|
|
|
if( m_job )
|
|
|
|
{
|
|
|
|
SetTitle( m_job->GetSettingsDialogTitle() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto cfg = m_pcbEditFrame->GetPcbNewSettings();
|
|
|
|
|
|
|
|
g_merge_PTH_NPTH = cfg->m_GenDrill.merge_pth_npth;
|
|
|
|
g_minimalHeader = cfg->m_GenDrill.minimal_header;
|
|
|
|
g_mirror = cfg->m_GenDrill.mirror;
|
|
|
|
g_unitDrillIsInch = cfg->m_GenDrill.unit_drill_is_inch;
|
|
|
|
g_useRouteModeForOvalHoles = cfg->m_GenDrill.use_route_for_oval_holes;
|
|
|
|
g_drillFileType = cfg->m_GenDrill.drill_file_type;
|
|
|
|
g_mapFileType = cfg->m_GenDrill.map_file_type;
|
|
|
|
g_zerosFormat = cfg->m_GenDrill.zeros_format;
|
|
|
|
g_generateMap = cfg->m_GenDrill.generate_map;
|
2025-03-01 18:02:54 +00:00
|
|
|
g_generateTenting = cfg->m_GenDrill.generate_tenting;
|
2025-01-07 17:07:10 +00:00
|
|
|
|
|
|
|
// Ensure validity of g_mapFileType
|
|
|
|
if( g_mapFileType < 0 || g_mapFileType >= (int) m_choiceDrillMap->GetCount() )
|
|
|
|
g_mapFileType = m_choiceDrillMap->GetCount() - 1; // last item in list = default = PDF
|
|
|
|
}
|
|
|
|
|
|
|
|
// DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
|
|
|
|
// non-job versions (which have different sizes).
|
|
|
|
m_hash_key = TO_UTF8( GetTitle() );
|
|
|
|
|
|
|
|
m_drillOriginIsAuxAxis = m_plotOpts.GetUseAuxOrigin();
|
2017-04-28 12:53:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GENDRILL::onFileFormatSelection( wxCommandEvent& event )
|
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
bool enbl_Excellon = m_rbExcellon->GetValue();
|
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
g_drillFileType = enbl_Excellon ? 0 : 1;
|
2017-04-28 12:53:30 +02:00
|
|
|
|
2025-01-07 11:11:14 +00:00
|
|
|
m_unitsLabel->Enable( enbl_Excellon );
|
|
|
|
m_units->Enable( enbl_Excellon );
|
|
|
|
m_zerosLabel->Enable( enbl_Excellon );
|
|
|
|
m_zeros->Enable( enbl_Excellon );
|
2017-04-28 12:53:30 +02:00
|
|
|
m_Check_Mirror->Enable( enbl_Excellon );
|
|
|
|
m_Check_Minimal->Enable( enbl_Excellon );
|
|
|
|
m_Check_Merge_PTH_NPTH->Enable( enbl_Excellon );
|
2025-01-07 11:11:14 +00:00
|
|
|
m_altDrillMode->Enable( enbl_Excellon );
|
2025-03-01 18:02:54 +00:00
|
|
|
m_generateTentingLayers->Enable( !enbl_Excellon );
|
2017-04-28 12:53:30 +02:00
|
|
|
|
|
|
|
if( enbl_Excellon )
|
2021-09-18 10:34:02 +01:00
|
|
|
{
|
2025-01-07 17:07:10 +00:00
|
|
|
updatePrecisionOptions();
|
2021-09-18 10:34:02 +01:00
|
|
|
}
|
2017-04-28 12:53:30 +02:00
|
|
|
else
|
|
|
|
{
|
2025-01-07 11:11:14 +00:00
|
|
|
m_precisionLabel->Enable( true );
|
2017-04-28 12:53:30 +02:00
|
|
|
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 12:53:30 +02:00
|
|
|
}
|
2010-11-24 16:10:33 +01:00
|
|
|
}
|
|
|
|
|
2011-08-19 15:08:24 +02:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
void DIALOG_GENDRILL::updateConfig()
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2019-02-13 11:41:52 +01:00
|
|
|
UpdateDrillParams();
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = m_pcbEditFrame->GetPcbNewSettings();
|
|
|
|
|
|
|
|
cfg->m_GenDrill.merge_pth_npth = g_merge_PTH_NPTH;
|
|
|
|
cfg->m_GenDrill.minimal_header = g_minimalHeader;
|
|
|
|
cfg->m_GenDrill.mirror = g_mirror;
|
|
|
|
cfg->m_GenDrill.unit_drill_is_inch = g_unitDrillIsInch;
|
|
|
|
cfg->m_GenDrill.use_route_for_oval_holes = g_useRouteModeForOvalHoles;
|
|
|
|
cfg->m_GenDrill.drill_file_type = g_drillFileType;
|
|
|
|
cfg->m_GenDrill.map_file_type = g_mapFileType;
|
|
|
|
cfg->m_GenDrill.zeros_format = g_zerosFormat;
|
|
|
|
cfg->m_GenDrill.generate_map = g_generateMap;
|
2025-03-01 18:02:54 +00:00
|
|
|
cfg->m_GenDrill.generate_tenting = g_generateTenting;
|
2010-11-24 16:10:33 +01:00
|
|
|
}
|
|
|
|
|
2011-08-19 15:08:24 +02:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
void DIALOG_GENDRILL::onSelDrillUnitsSelected( wxCommandEvent& event )
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2025-01-07 17:07:10 +00:00
|
|
|
updatePrecisionOptions();
|
2010-11-24 16:10:33 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 10:57:45 -04:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
void DIALOG_GENDRILL::onSelZerosFmtSelected( wxCommandEvent& event )
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2025-01-07 17:07:10 +00:00
|
|
|
updatePrecisionOptions();
|
2010-11-24 16:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
void DIALOG_GENDRILL::updatePrecisionOptions()
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2025-01-07 11:11:14 +00:00
|
|
|
if( m_units->GetSelection() == 1 )
|
2020-11-12 23:50:33 +00:00
|
|
|
{
|
|
|
|
// Units = inches
|
2012-10-05 21:04:17 +02:00
|
|
|
m_staticTextPrecision->SetLabel( precisionListForInches.GetPrecisionString() );
|
2020-11-12 23:50:33 +00:00
|
|
|
}
|
2010-11-24 16:10:33 +01:00
|
|
|
else
|
|
|
|
{
|
2012-02-18 22:02:19 -06:00
|
|
|
// metric options
|
2012-10-05 21:04:17 +02:00
|
|
|
m_staticTextPrecision->SetLabel( precisionListForMetric.GetPrecisionString() );
|
2010-11-24 16:10:33 +01:00
|
|
|
}
|
2011-10-01 15:24:27 -04:00
|
|
|
|
2025-01-07 11:11:14 +00:00
|
|
|
if( m_zeros->GetSelection() == EXCELLON_WRITER::DECIMAL_FORMAT )
|
|
|
|
{
|
|
|
|
m_precisionLabel->Enable( false );
|
2012-10-05 21:04:17 +02:00
|
|
|
m_staticTextPrecision->Enable( false );
|
2025-01-07 11:11:14 +00:00
|
|
|
}
|
2010-11-24 16:10:33 +01:00
|
|
|
else
|
2025-01-07 11:11:14 +00:00
|
|
|
{
|
|
|
|
m_precisionLabel->Enable( true );
|
2012-10-05 21:04:17 +02:00
|
|
|
m_staticTextPrecision->Enable( true );
|
2025-01-07 11:11:14 +00:00
|
|
|
}
|
2010-11-24 16:10:33 +01:00
|
|
|
}
|
|
|
|
|
2014-03-03 09:28:05 -05:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
void DIALOG_GENDRILL::onOutputDirectoryBrowseClicked( wxCommandEvent& event )
|
2012-10-05 14:25:12 +02:00
|
|
|
{
|
2020-04-05 22:10:42 +01: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 14:25:12 +02:00
|
|
|
|
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
|
|
|
|
|
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2020-04-05 22:10:42 +01:00
|
|
|
wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
|
|
|
|
wxFileName fn( Prj().AbsolutePath( m_board->GetFileName() ) );
|
|
|
|
wxString defaultPath = fn.GetPathWithSep();
|
|
|
|
wxString msg;
|
2021-06-16 23:35:00 +01:00
|
|
|
msg.Printf( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath );
|
2016-07-27 14:53:45 +02:00
|
|
|
|
|
|
|
wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
|
2012-10-05 14:25:12 +02:00
|
|
|
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
|
|
|
|
|
|
|
|
if( dialog.ShowModal() == wxID_YES )
|
|
|
|
{
|
2016-07-27 14:53:45 +02:00
|
|
|
if( !dirName.MakeRelativeTo( defaultPath ) )
|
2021-09-18 10:34:02 +01:00
|
|
|
{
|
2022-12-13 20:47:28 +00:00
|
|
|
wxMessageBox( _( "Cannot make path relative (target volume different from board "
|
|
|
|
"file volume)!" ),
|
2012-10-05 14:25:12 +02:00
|
|
|
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
|
2021-09-18 10:34:02 +01:00
|
|
|
}
|
2012-10-05 14:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m_outputDirectoryName->SetValue( dirName.GetFullPath() );
|
|
|
|
}
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2014-03-03 09:28:05 -05:00
|
|
|
|
2019-02-13 11:41:52 +01:00
|
|
|
void DIALOG_GENDRILL::UpdateDrillParams()
|
2010-11-24 16:10:33 +01:00
|
|
|
{
|
2012-10-05 14:25:12 +02:00
|
|
|
// Set output directory and replace backslashes with forward ones
|
|
|
|
wxString dirStr;
|
|
|
|
dirStr = m_outputDirectoryName->GetValue();
|
|
|
|
dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
|
|
|
|
m_plotOpts.SetOutputDirectory( dirStr );
|
2025-01-07 11:11:14 +00:00
|
|
|
m_drillOriginIsAuxAxis = m_origin->GetSelection() == 1;
|
2017-04-28 12:53:30 +02:00
|
|
|
m_plotOpts.SetUseAuxOrigin( m_drillOriginIsAuxAxis );
|
2012-04-05 13:27:56 -05:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
g_mapFileType = m_choiceDrillMap->GetSelection();
|
2011-08-19 15:08:24 +02:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
g_unitDrillIsInch = ( m_units->GetSelection() == 0 ) ? false : true;
|
|
|
|
g_minimalHeader = m_Check_Minimal->IsChecked();
|
|
|
|
g_mirror = m_Check_Mirror->IsChecked();
|
|
|
|
g_merge_PTH_NPTH = m_Check_Merge_PTH_NPTH->IsChecked();
|
|
|
|
g_zerosFormat = m_zeros->GetSelection();
|
|
|
|
g_useRouteModeForOvalHoles = !m_altDrillMode->GetValue();
|
|
|
|
g_generateMap = m_cbGenerateMap->IsChecked();
|
2025-03-01 18:02:54 +00:00
|
|
|
g_generateTenting = m_generateTentingLayers->IsChecked();
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2025-01-07 11:11:14 +00:00
|
|
|
if( m_origin->GetSelection() == 0 )
|
2025-01-07 17:07:10 +00:00
|
|
|
g_drillFileOffset = VECTOR2I( 0, 0 );
|
2010-11-24 16:10:33 +01:00
|
|
|
else
|
2025-01-07 17:07:10 +00:00
|
|
|
g_drillFileOffset = m_board->GetDesignSettings().GetAuxOrigin();
|
2010-11-24 16:10:33 +01:00
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
if( g_unitDrillIsInch )
|
|
|
|
g_precision = precisionListForInches;
|
2010-11-24 16:10:33 +01:00
|
|
|
else
|
2025-01-07 17:07:10 +00:00
|
|
|
g_precision = precisionListForMetric;
|
2012-04-05 13:27:56 -05:00
|
|
|
|
2021-03-05 20:41:21 +01:00
|
|
|
if( !m_plotOpts.IsSameAs( m_board->GetPlotOptions() ) )
|
|
|
|
{
|
|
|
|
m_board->SetPlotOptions( m_plotOpts );
|
|
|
|
m_pcbEditFrame->OnModify();
|
|
|
|
}
|
2012-10-05 14:25:12 +02:00
|
|
|
}
|
|
|
|
|
2014-03-03 09:28:05 -05:00
|
|
|
|
2025-03-01 18:02:54 +00:00
|
|
|
void DIALOG_GENDRILL::genDrillAndMapFiles( bool aGenDrill, bool aGenMap, bool aGenTenting )
|
2012-10-05 14:25:12 +02:00
|
|
|
{
|
2025-01-07 17:07:10 +00:00
|
|
|
updateConfig(); // set params and Save drill options
|
2012-10-05 14:25:12 +02:00
|
|
|
|
2019-02-13 11:41:52 +01:00
|
|
|
m_pcbEditFrame->ClearMsgPanel();
|
2015-04-29 17:37:37 +02:00
|
|
|
WX_TEXT_CTRL_REPORTER reporter( m_messagesBox );
|
|
|
|
|
2022-06-22 11:13:06 +02: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 17:39:09 +01:00
|
|
|
PLOT_FORMAT::POST,
|
2022-06-23 11:56:27 +02:00
|
|
|
PLOT_FORMAT::GERBER, // Only X2 format because we need the .FileFunction attribute
|
2021-06-27 17:39:09 +01:00
|
|
|
PLOT_FORMAT::DXF,
|
|
|
|
PLOT_FORMAT::SVG,
|
|
|
|
PLOT_FORMAT::PDF
|
2015-04-29 17:37:37 +02:00
|
|
|
};
|
2016-10-07 10:57:45 -04:00
|
|
|
|
2025-01-07 11:11:14 +00:00
|
|
|
unsigned choice = (unsigned) m_choiceDrillMap->GetSelection();
|
2012-10-05 14:25:12 +02:00
|
|
|
|
2019-01-06 08:43:12 -08:00
|
|
|
if( choice >= arrayDim( filefmt ) )
|
2022-06-22 11:13:06 +02:00
|
|
|
choice = arrayDim( filefmt )-1; // Last choice = PDF
|
2012-10-05 14:25:12 +02: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 22:10:42 +01:00
|
|
|
wxFileName outputDir = wxFileName::DirName( path );
|
2019-02-13 11:41:52 +01:00
|
|
|
wxString boardFilename = m_board->GetFileName();
|
2017-05-01 20:42:18 +02:00
|
|
|
|
|
|
|
if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2021-06-16 23:35:00 +01:00
|
|
|
msg.Printf( _( "Could not write drill and/or map files to folder '%s'." ),
|
2021-06-27 17:39:09 +01:00
|
|
|
outputDir.GetPath() );
|
2017-05-01 20:42:18 +02:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
if( g_drillFileType == 0 )
|
2017-04-28 12:53:30 +02:00
|
|
|
{
|
2019-02-13 11:41:52 +01:00
|
|
|
EXCELLON_WRITER excellonWriter( m_board );
|
2025-01-07 17:07:10 +00:00
|
|
|
excellonWriter.SetFormat( !g_unitDrillIsInch, (EXCELLON_WRITER::ZEROS_FMT) g_zerosFormat,
|
|
|
|
g_precision.m_Lhs, g_precision.m_Rhs );
|
|
|
|
excellonWriter.SetOptions( g_mirror, g_minimalHeader, g_drillFileOffset, g_merge_PTH_NPTH );
|
|
|
|
excellonWriter.SetRouteModeForOvalHoles( g_useRouteModeForOvalHoles );
|
2017-04-28 12:53:30 +02:00
|
|
|
excellonWriter.SetMapFileFormat( filefmt[choice] );
|
2012-10-05 14:25:12 +02:00
|
|
|
|
2020-04-05 22:10:42 +01:00
|
|
|
excellonWriter.CreateDrillandMapFilesSet( outputDir.GetFullPath(), aGenDrill, aGenMap,
|
|
|
|
&reporter );
|
2017-04-28 12:53:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-13 11:41:52 +01:00
|
|
|
GERBER_WRITER gerberWriter( m_board );
|
2017-04-28 12:53:30 +02: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() );
|
2025-01-07 17:07:10 +00:00
|
|
|
gerberWriter.SetOptions( g_drillFileOffset );
|
2017-04-28 12:53:30 +02:00
|
|
|
gerberWriter.SetMapFileFormat( filefmt[choice] );
|
|
|
|
|
2021-06-27 17:39:09 +01:00
|
|
|
gerberWriter.CreateDrillandMapFilesSet( outputDir.GetFullPath(), aGenDrill, aGenMap,
|
2025-03-01 18:02:54 +00:00
|
|
|
aGenTenting, &reporter );
|
2017-04-28 12:53:30 +02:00
|
|
|
}
|
2012-10-05 14:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-07 17:07:10 +00:00
|
|
|
void DIALOG_GENDRILL::onGenReportFile( wxCommandEvent& event )
|
2012-10-05 14:25:12 +02:00
|
|
|
{
|
2025-01-07 17:07:10 +00:00
|
|
|
updateConfig(); // set params and Save drill options
|
2012-10-05 14:25:12 +02:00
|
|
|
|
2019-02-13 11:41:52 +01:00
|
|
|
wxFileName fn = m_board->GetFileName();
|
2012-10-05 14:25:12 +02:00
|
|
|
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-drl" ) );
|
2023-12-27 21:10:01 -05:00
|
|
|
fn.SetExt( FILEEXT::ReportFileExtension );
|
2012-10-05 14:25:12 +02:00
|
|
|
|
2020-04-05 22:10:42 +01:00
|
|
|
wxString defaultPath = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() );
|
|
|
|
defaultPath = Prj().AbsolutePath( defaultPath );
|
2014-03-03 09:28:05 -05:00
|
|
|
|
2012-10-05 14:25:12 +02:00
|
|
|
if( defaultPath.IsEmpty() )
|
2021-01-22 23:17:32 -05:00
|
|
|
defaultPath = PATHS::GetDefaultUserProjectsPath();
|
2012-10-05 14:25:12 +02:00
|
|
|
|
2016-10-07 10:57:45 -04:00
|
|
|
wxFileDialog dlg( this, _( "Save Drill Report File" ), defaultPath, fn.GetFullName(),
|
2023-12-27 21:10:01 -05:00
|
|
|
FILEEXT::ReportFileWildcard(), wxFD_SAVE );
|
2012-10-05 14:25:12 +02:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2017-04-28 12:53:30 +02:00
|
|
|
bool success;
|
2012-10-05 14:25:12 +02:00
|
|
|
|
2017-04-28 12:53:30 +02:00
|
|
|
// Info is slightly different between Excellon and Gerber
|
|
|
|
// (file ext, Merge PTH/NPTH option)
|
2025-01-07 17:07:10 +00:00
|
|
|
if( g_drillFileType == 0 )
|
2017-04-28 12:53:30 +02:00
|
|
|
{
|
2019-02-13 11:41:52 +01:00
|
|
|
EXCELLON_WRITER excellonWriter( m_board );
|
2025-01-07 17:07:10 +00:00
|
|
|
excellonWriter.SetMergeOption( g_merge_PTH_NPTH );
|
2017-04-28 12:53:30 +02:00
|
|
|
success = excellonWriter.GenDrillReportFile( dlg.GetPath() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-13 11:41:52 +01:00
|
|
|
GERBER_WRITER gerberWriter( m_board );
|
2017-04-28 12:53:30 +02:00
|
|
|
success = gerberWriter.GenDrillReportFile( dlg.GetPath() );
|
|
|
|
}
|
2012-10-05 14:25:12 +02:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( ! success )
|
|
|
|
{
|
2021-07-05 13:40:38 +01:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), dlg.GetPath() );
|
2012-10-05 14:25:12 +02:00
|
|
|
m_messagesBox->AppendText( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-05 13:40:38 +01:00
|
|
|
msg.Printf( _( "Report file '%s' created." ), dlg.GetPath() );
|
2012-10-05 14:25:12 +02:00
|
|
|
m_messagesBox->AppendText( msg );
|
|
|
|
}
|
|
|
|
}
|