2012-02-15 10:41:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-08-02 09:22:12 +00:00
|
|
|
* Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-02-15 10:41:16 +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
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2021-07-19 23:56:05 +00:00
|
|
|
* 1 - create ASCII files for automatic placement of smd components
|
2020-11-13 11:17:15 +00:00
|
|
|
* 2 - create a footprint report (pos and footprint descr) (ascii file)
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gestfich.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>
|
2018-02-17 16:27:59 +00:00
|
|
|
#include <bitmaps.h>
|
2014-09-08 11:07:54 +00:00
|
|
|
#include <reporter.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>
|
|
|
|
#include <footprint.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2022-09-03 18:29:02 +00:00
|
|
|
#include "widgets/wx_html_report_panel.h"
|
2018-02-16 16:52:19 +00:00
|
|
|
#include <dialog_gen_footprint_position_file_base.h>
|
2019-06-30 11:54:35 +00:00
|
|
|
#include <export_footprints_placefile.h>
|
2019-09-15 15:08:57 +00:00
|
|
|
#include "gerber_placefile_writer.h"
|
2019-06-04 20:59:59 +00:00
|
|
|
|
2021-06-07 07:26:13 +00:00
|
|
|
#include <wx/dirdlg.h>
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
/**
|
2018-07-07 16:46:23 +00:00
|
|
|
* The dialog to create footprint position files and choose options (one or 2 files, units
|
|
|
|
* and force all SMD footprints in list)
|
2012-02-15 10:41:16 +00:00
|
|
|
*/
|
2018-02-16 19:26:55 +00:00
|
|
|
class DIALOG_GEN_FOOTPRINT_POSITION : public DIALOG_GEN_FOOTPRINT_POSITION_BASE
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-02-16 19:26:55 +00:00
|
|
|
DIALOG_GEN_FOOTPRINT_POSITION( PCB_EDIT_FRAME * aParent ):
|
|
|
|
DIALOG_GEN_FOOTPRINT_POSITION_BASE( aParent ),
|
2012-04-05 18:27:56 +00:00
|
|
|
m_parent( aParent ),
|
|
|
|
m_plotOpts( aParent->GetPlotSettings() )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2021-02-25 15:05:26 +00:00
|
|
|
m_messagesPanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
|
2015-06-19 08:55:37 +00:00
|
|
|
m_reporter = &m_messagesPanel->Reporter();
|
2015-05-01 15:01:09 +00:00
|
|
|
initDialog();
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Generate Position File" ) },
|
|
|
|
{ wxID_CANCEL, _( "Close" ) } } );
|
2018-02-28 09:44:22 +00:00
|
|
|
|
2015-05-01 15:01:09 +00:00
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
Centre();
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-07-25 19:14:31 +00:00
|
|
|
void initDialog();
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnOutputDirectoryBrowseClicked( wxCommandEvent& event ) override;
|
2018-02-17 16:27:59 +00:00
|
|
|
void OnGenerate( wxCommandEvent& event ) override;
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2021-08-20 22:02:18 +00:00
|
|
|
void onUpdateUIUnits( wxUpdateUIEvent& event ) override
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
|
|
|
m_radioBoxUnits->Enable( m_rbFormat->GetSelection() != 2 );
|
|
|
|
}
|
|
|
|
|
2021-08-20 22:02:18 +00:00
|
|
|
void onUpdateUIFileOpt( wxUpdateUIEvent& event ) override
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
|
|
|
m_radioBoxFilesCount->Enable( m_rbFormat->GetSelection() != 2 );
|
|
|
|
}
|
|
|
|
|
2021-08-20 22:02:18 +00:00
|
|
|
void onUpdateUIOnlySMD( wxUpdateUIEvent& event ) override
|
2021-07-20 08:23:21 +00:00
|
|
|
{
|
|
|
|
if( m_rbFormat->GetSelection() == 2 )
|
|
|
|
{
|
|
|
|
m_onlySMD->SetValue( false );
|
|
|
|
m_onlySMD->Enable( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_onlySMD->Enable( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 09:22:12 +00:00
|
|
|
void onUpdateUInegXcoord( wxUpdateUIEvent& event ) override
|
|
|
|
{
|
|
|
|
if( m_rbFormat->GetSelection() == 2 )
|
|
|
|
{
|
|
|
|
m_negateXcb->SetValue( false );
|
|
|
|
m_negateXcb->Enable( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_negateXcb->Enable( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-20 22:02:18 +00:00
|
|
|
void onUpdateUIExcludeTH( wxUpdateUIEvent& event ) override
|
2019-11-01 12:35:42 +00:00
|
|
|
{
|
2020-08-26 21:43:38 +00:00
|
|
|
if( m_rbFormat->GetSelection() == 2 )
|
|
|
|
{
|
|
|
|
m_excludeTH->SetValue( false );
|
|
|
|
m_excludeTH->Enable( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_excludeTH->Enable( true );
|
|
|
|
}
|
2019-11-01 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 22:02:18 +00:00
|
|
|
void onUpdateUIincludeBoardEdge( wxUpdateUIEvent& event ) override
|
2019-11-01 12:35:42 +00:00
|
|
|
{
|
|
|
|
m_cbIncludeBoardEdge->Enable( m_rbFormat->GetSelection() == 2 );
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
/**
|
|
|
|
* Creates files in text or csv format
|
2019-09-15 15:08:57 +00:00
|
|
|
*/
|
|
|
|
bool CreateAsciiFiles();
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
/**
|
|
|
|
* Creates placement files in gerber format
|
2019-09-15 15:08:57 +00:00
|
|
|
*/
|
|
|
|
bool CreateGerberFiles();
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
// accessors to options:
|
|
|
|
bool UnitsMM()
|
|
|
|
{
|
|
|
|
return m_radioBoxUnits->GetSelection() == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OneFileOnly()
|
|
|
|
{
|
|
|
|
return m_radioBoxFilesCount->GetSelection() == 1;
|
|
|
|
}
|
|
|
|
|
2021-07-20 08:23:21 +00:00
|
|
|
bool OnlySMD()
|
|
|
|
{
|
|
|
|
return m_onlySMD->GetValue();
|
|
|
|
}
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
bool ExcludeAllTH()
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2020-08-26 21:43:38 +00:00
|
|
|
return m_excludeTH->GetValue();
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
PCB_EDIT_FRAME* m_parent;
|
|
|
|
PCB_PLOT_PARAMS m_plotOpts;
|
|
|
|
REPORTER* m_reporter;
|
|
|
|
|
|
|
|
static int m_unitsOpt;
|
|
|
|
static int m_fileOpt;
|
|
|
|
static int m_fileFormat;
|
|
|
|
static bool m_includeBoardEdge;
|
2021-08-21 08:52:51 +00:00
|
|
|
static bool m_excludeTHOpt;
|
|
|
|
static bool m_onlySMDOpt;
|
2022-08-02 09:22:12 +00:00
|
|
|
static bool m_negateBottomX;
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
// Static members to remember choices
|
2018-02-16 19:26:55 +00:00
|
|
|
int DIALOG_GEN_FOOTPRINT_POSITION::m_fileOpt = 0;
|
|
|
|
int DIALOG_GEN_FOOTPRINT_POSITION::m_fileFormat = 0;
|
2019-11-01 12:35:42 +00:00
|
|
|
bool DIALOG_GEN_FOOTPRINT_POSITION::m_includeBoardEdge = false;
|
2021-08-21 08:52:51 +00:00
|
|
|
bool DIALOG_GEN_FOOTPRINT_POSITION::m_excludeTHOpt = false;
|
|
|
|
bool DIALOG_GEN_FOOTPRINT_POSITION::m_onlySMDOpt = false;
|
2022-08-02 09:22:12 +00:00
|
|
|
bool DIALOG_GEN_FOOTPRINT_POSITION::m_negateBottomX = false;
|
2019-11-01 12:35:42 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_GEN_FOOTPRINT_POSITION::initDialog()
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
|
2018-02-17 16:27:59 +00:00
|
|
|
|
2021-06-27 16:39:09 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-10-05 08:50:40 +00:00
|
|
|
m_units = cfg->m_PlaceFile.units == 0 ? EDA_UNITS::INCHES : EDA_UNITS::MILLIMETRES;
|
2020-01-13 01:44:19 +00:00
|
|
|
m_fileOpt = cfg->m_PlaceFile.file_options;
|
|
|
|
m_fileFormat = cfg->m_PlaceFile.file_format;
|
|
|
|
m_includeBoardEdge = cfg->m_PlaceFile.include_board_edge;
|
2022-08-02 09:22:12 +00:00
|
|
|
m_negateBottomX = cfg->m_PlaceFile.negate_xcoord;
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
// Output directory
|
2012-04-05 18:27:56 +00:00
|
|
|
m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
// Update Options
|
2020-10-05 08:50:40 +00:00
|
|
|
m_radioBoxUnits->SetSelection( cfg->m_PlaceFile.units );
|
2012-02-15 10:41:16 +00:00
|
|
|
m_radioBoxFilesCount->SetSelection( m_fileOpt );
|
2016-04-26 12:16:16 +00:00
|
|
|
m_rbFormat->SetSelection( m_fileFormat );
|
2019-11-01 12:35:42 +00:00
|
|
|
m_cbIncludeBoardEdge->SetValue( m_includeBoardEdge );
|
2021-06-27 16:39:09 +00:00
|
|
|
m_useDrillPlaceOrigin->SetValue( cfg->m_PlaceFile.use_aux_origin );
|
2021-08-21 08:52:51 +00:00
|
|
|
m_onlySMD->SetValue( m_onlySMDOpt );
|
2022-08-02 09:22:12 +00:00
|
|
|
m_negateXcb->SetValue( m_negateBottomX );
|
2021-08-21 08:52:51 +00:00
|
|
|
m_excludeTH->SetValue( m_excludeTHOpt );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2018-02-17 16:27:59 +00:00
|
|
|
// Update sizes and sizers:
|
|
|
|
m_messagesPanel->MsgPanelSetMinSize( wxSize( -1, 160 ) );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_GEN_FOOTPRINT_POSITION::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2020-04-05 21:17:26 +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-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
|
|
|
|
|
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
|
|
|
|
|
2017-11-02 17:18:57 +00:00
|
|
|
wxMessageDialog dialog( this, _( "Use a relative path?"),
|
2012-02-15 10:41:16 +00:00
|
|
|
_( "Plot Output Directory" ),
|
|
|
|
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
|
|
|
|
|
|
|
|
if( dialog.ShowModal() == wxID_YES )
|
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
wxString boardFilePath = ( (wxFileName) m_parent->GetBoard()->GetFileName() ).GetPath();
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
if( !dirName.MakeRelativeTo( boardFilePath ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
wxMessageBox( _( "Cannot make path relative (target volume different from board "
|
|
|
|
"file volume)!" ),
|
2012-02-15 10:41:16 +00:00
|
|
|
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputDirectoryName->SetValue( dirName.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2018-02-17 16:27:59 +00:00
|
|
|
void DIALOG_GEN_FOOTPRINT_POSITION::OnGenerate( wxCommandEvent& event )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
|
|
|
m_fileOpt = m_radioBoxFilesCount->GetSelection();
|
2016-04-26 12:16:16 +00:00
|
|
|
m_fileFormat = m_rbFormat->GetSelection();
|
2019-11-01 12:35:42 +00:00
|
|
|
m_includeBoardEdge = m_cbIncludeBoardEdge->GetValue();
|
2021-08-21 08:52:51 +00:00
|
|
|
m_onlySMDOpt = m_onlySMD->GetValue();
|
2022-08-02 09:22:12 +00:00
|
|
|
m_negateBottomX = m_negateXcb->GetValue();
|
2021-08-21 08:52:51 +00:00
|
|
|
m_excludeTHOpt = m_excludeTH->GetValue();
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parent->GetPcbNewSettings();
|
2020-10-05 08:50:40 +00:00
|
|
|
m_units = m_radioBoxUnits->GetSelection() == 0 ? EDA_UNITS::INCHES : EDA_UNITS::MILLIMETRES;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-10-05 08:50:40 +00:00
|
|
|
cfg->m_PlaceFile.units = m_units == EDA_UNITS::INCHES ? 0 : 1;
|
2020-01-13 01:44:19 +00:00
|
|
|
cfg->m_PlaceFile.file_options = m_fileOpt;
|
|
|
|
cfg->m_PlaceFile.file_format = m_fileFormat;
|
|
|
|
cfg->m_PlaceFile.include_board_edge = m_includeBoardEdge;
|
2021-06-27 16:39:09 +00:00
|
|
|
cfg->m_PlaceFile.use_aux_origin = m_useDrillPlaceOrigin->GetValue();
|
2022-08-02 09:22:12 +00:00
|
|
|
cfg->m_PlaceFile.negate_xcoord = m_negateBottomX;
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
// Set output directory and replace backslashes with forward ones
|
|
|
|
// (Keep unix convention in cfg files)
|
|
|
|
wxString dirStr;
|
|
|
|
dirStr = m_outputDirectoryName->GetValue();
|
|
|
|
dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
|
2012-04-05 18:27:56 +00:00
|
|
|
|
|
|
|
m_plotOpts.SetOutputDirectory( dirStr );
|
|
|
|
m_parent->SetPlotSettings( m_plotOpts );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
if( m_fileFormat == 2 )
|
|
|
|
CreateGerberFiles();
|
|
|
|
else
|
|
|
|
CreateAsciiFiles();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
bool DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles()
|
|
|
|
{
|
2021-06-27 16:39:09 +00:00
|
|
|
BOARD* brd = m_parent->GetBoard();
|
|
|
|
wxFileName fn;
|
|
|
|
wxString msg;
|
|
|
|
int fullcount = 0;
|
2019-09-15 15:08:57 +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 board->GetTitleBlock() *and* board->GetProject()
|
|
|
|
return m_parent->GetBoard()->ResolveTextVar( token, 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
wxString path = m_plotOpts.GetOutputDirectory();
|
|
|
|
path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
|
|
|
|
path = ExpandEnvVarSubstitutions( path, nullptr );
|
|
|
|
|
2020-04-05 21:17:26 +00:00
|
|
|
wxFileName outputDir = wxFileName::DirName( path );
|
2019-09-15 15:08:57 +00:00
|
|
|
wxString boardFilename = m_parent->GetBoard()->GetFileName();
|
|
|
|
|
|
|
|
m_reporter = &m_messagesPanel->Reporter();
|
|
|
|
|
|
|
|
if( !EnsureFileDirectoryExists( &outputDir, boardFilename, m_reporter ) )
|
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Could not write plot files to folder '%s'." ),
|
2019-09-15 15:08:57 +00:00
|
|
|
outputDir.GetPath() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn = m_parent->GetBoard()->GetFileName();
|
|
|
|
fn.SetPath( outputDir.GetPath() );
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Create the Front and Top side placement files. Gerber P&P files are always separated.
|
2019-11-01 12:35:42 +00:00
|
|
|
// Not also they include all footprints
|
2019-09-15 15:08:57 +00:00
|
|
|
PLACEFILE_GERBER_WRITER exporter( brd );
|
|
|
|
wxString filename = exporter.GetPlaceFileName( fn.GetFullPath(), F_Cu );
|
|
|
|
|
2019-11-01 12:35:42 +00:00
|
|
|
int fpcount = exporter.CreatePlaceFile( filename, F_Cu, m_includeBoardEdge );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
if( fpcount < 0 )
|
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), fn.GetFullPath() );
|
2019-09-15 15:08:57 +00:00
|
|
|
wxMessageBox( msg );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2019-09-15 15:08:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Front (top side) placement file: '%s'." ), filename );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Component count: %d." ), fpcount );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
// Create the Back or Bottom side placement file
|
|
|
|
fullcount = fpcount;
|
|
|
|
|
|
|
|
filename = exporter.GetPlaceFileName( fn.GetFullPath(), B_Cu );
|
|
|
|
|
2019-11-01 12:35:42 +00:00
|
|
|
fpcount = exporter.CreatePlaceFile( filename, B_Cu, m_includeBoardEdge );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
if( fpcount < 0 )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), filename );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2019-09-15 15:08:57 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display results
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Back (bottom side) placement file: '%s'." ), filename );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Component count: %d." ), fpcount );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
fullcount += fpcount;
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Full component count: %d." ), fullcount );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2021-07-05 12:40:38 +00:00
|
|
|
m_reporter->Report( _( "File generation successful." ), RPT_SEVERITY_INFO );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
return true;
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles()
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2021-06-27 16:39:09 +00:00
|
|
|
BOARD * brd = m_parent->GetBoard();
|
|
|
|
wxFileName fn;
|
|
|
|
wxString msg;
|
|
|
|
bool singleFile = OneFileOnly();
|
|
|
|
bool useCSVfmt = m_fileFormat == 1;
|
|
|
|
bool useAuxOrigin = m_useDrillPlaceOrigin->GetValue();
|
|
|
|
int fullcount = 0;
|
|
|
|
int topSide = true;
|
|
|
|
int bottomSide = true;
|
2022-08-02 09:22:12 +00:00
|
|
|
bool negateBottomX = m_negateXcb->GetValue();
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
// Test for any footprint candidate in list.
|
2013-11-27 19:38:59 +00:00
|
|
|
{
|
2021-07-20 08:23:21 +00:00
|
|
|
PLACE_FILE_EXPORTER exporter( brd, UnitsMM(), OnlySMD(), ExcludeAllTH(), topSide,
|
2022-08-02 09:22:12 +00:00
|
|
|
bottomSide, useCSVfmt, useAuxOrigin, negateBottomX );
|
2019-06-30 11:54:35 +00:00
|
|
|
exporter.GenPositionData();
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
if( exporter.GetFootprintCount() == 0 )
|
2019-06-30 11:54:35 +00:00
|
|
|
{
|
|
|
|
wxMessageBox( _( "No footprint for automated placement." ) );
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-27 19:38:59 +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 board->GetTitleBlock() *and* board->GetProject()
|
|
|
|
return m_parent->GetBoard()->ResolveTextVar( token, 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
wxString path = m_plotOpts.GetOutputDirectory();
|
|
|
|
path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
|
|
|
|
path = ExpandEnvVarSubstitutions( path, nullptr );
|
|
|
|
|
2021-04-12 09:17:01 +00:00
|
|
|
wxFileName outputDir = wxFileName::DirName( path );
|
2014-09-08 11:07:54 +00:00
|
|
|
wxString boardFilename = m_parent->GetBoard()->GetFileName();
|
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
m_reporter = &m_messagesPanel->Reporter();
|
|
|
|
|
|
|
|
if( !EnsureFileDirectoryExists( &outputDir, boardFilename, m_reporter ) )
|
2014-09-08 11:07:54 +00:00
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Could not write plot files to folder '%s'." ), outputDir.GetPath() );
|
2014-09-08 11:07:54 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = m_parent->GetBoard()->GetFileName();
|
2014-09-08 11:07:54 +00:00
|
|
|
fn.SetPath( outputDir.GetPath() );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Create the Front or Top side placement file, or a single file
|
2021-06-27 16:39:09 +00:00
|
|
|
topSide = true;
|
|
|
|
bottomSide = false;
|
2013-11-27 19:38:59 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
if( singleFile )
|
|
|
|
{
|
2021-06-27 16:39:09 +00:00
|
|
|
bottomSide = true;
|
2021-07-19 23:56:05 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + wxT( "all" ) );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2013-11-27 19:38:59 +00:00
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2019-06-30 11:54:35 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + PLACE_FILE_EXPORTER::GetFrontSideName().c_str() );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2016-04-26 12:16:16 +00:00
|
|
|
|
|
|
|
if( useCSVfmt )
|
|
|
|
{
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + FootprintPlaceFileExtension );
|
|
|
|
fn.SetExt( wxT( "csv" ) );
|
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2016-04-26 12:16:16 +00:00
|
|
|
fn.SetExt( FootprintPlaceFileExtension );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2021-07-20 08:23:21 +00:00
|
|
|
int fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(), OnlySMD(),
|
2021-06-27 16:39:09 +00:00
|
|
|
ExcludeAllTH(), topSide, bottomSide,
|
2022-08-02 09:22:12 +00:00
|
|
|
useCSVfmt, useAuxOrigin, negateBottomX );
|
2012-02-15 10:41:16 +00:00
|
|
|
if( fpcount < 0 )
|
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), fn.GetFullPath() );
|
2012-02-15 10:41:16 +00:00
|
|
|
wxMessageBox( msg );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2012-02-15 10:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( singleFile )
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Placement file: '%s'." ), fn.GetFullPath() );
|
2012-02-15 10:41:16 +00:00
|
|
|
else
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Front (top side) placement file: '%s'." ), fn.GetFullPath() );
|
|
|
|
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
msg.Printf( _( "Component count: %d." ), fpcount );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
if( singleFile )
|
2015-06-16 12:20:42 +00:00
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
m_reporter->Report( _( "File generation successful." ), RPT_SEVERITY_INFO );
|
2012-02-15 10:41:16 +00:00
|
|
|
return true;
|
2015-06-16 12:20:42 +00:00
|
|
|
}
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
// Create the Back or Bottom side placement file
|
|
|
|
fullcount = fpcount;
|
2021-06-27 16:39:09 +00:00
|
|
|
topSide = false;
|
|
|
|
bottomSide = true;
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = brd->GetFileName();
|
2014-09-08 11:07:54 +00:00
|
|
|
fn.SetPath( outputDir.GetPath() );
|
2019-06-30 11:54:35 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + PLACE_FILE_EXPORTER::GetBackSideName().c_str() );
|
2016-04-26 12:16:16 +00:00
|
|
|
|
|
|
|
if( useCSVfmt )
|
|
|
|
{
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + FootprintPlaceFileExtension );
|
|
|
|
fn.SetExt( wxT( "csv" ) );
|
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2016-04-26 12:16:16 +00:00
|
|
|
fn.SetExt( FootprintPlaceFileExtension );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-02-15 10:41:16 +00:00
|
|
|
|
2021-07-20 08:23:21 +00:00
|
|
|
fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(), OnlySMD(),
|
|
|
|
ExcludeAllTH(), topSide, bottomSide, useCSVfmt,
|
2022-08-02 09:22:12 +00:00
|
|
|
useAuxOrigin, negateBottomX );
|
2012-02-15 10:41:16 +00:00
|
|
|
|
|
|
|
if( fpcount < 0 )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), fn.GetFullPath() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2012-02-15 10:41:16 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display results
|
|
|
|
if( !singleFile )
|
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Back (bottom side) placement file: '%s'." ), fn.GetFullPath() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2015-06-16 12:20:42 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Component count: %d." ), fpcount );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !singleFile )
|
|
|
|
{
|
|
|
|
fullcount += fpcount;
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Full component count: %d." ), fullcount );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 12:40:38 +00:00
|
|
|
m_reporter->Report( _( "File generation successful." ), RPT_SEVERITY_INFO );
|
2015-06-16 12:20:42 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-04-23 18:11:36 +00:00
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
int BOARD_EDITOR_CONTROL::GeneratePosFile( const TOOL_EVENT& aEvent )
|
2012-02-15 10:41:16 +00:00
|
|
|
{
|
2019-06-09 23:21:50 +00:00
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
DIALOG_GEN_FOOTPRINT_POSITION dlg( editFrame );
|
2019-06-30 11:54:35 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
dlg.ShowModal();
|
2019-06-04 20:59:59 +00:00
|
|
|
return 0;
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2008-04-23 18:11:36 +00:00
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
|
2019-06-04 20:59:59 +00:00
|
|
|
int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName, bool aUnitsMM,
|
2021-07-20 08:23:21 +00:00
|
|
|
bool aOnlySMD, bool aNoTHItems, bool aTopSide,
|
2021-06-27 16:39:09 +00:00
|
|
|
bool aBottomSide, bool aFormatCSV,
|
2022-08-02 09:22:12 +00:00
|
|
|
bool aUseAuxOrigin, bool aNegateBottomX )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
FILE * file = nullptr;
|
2008-04-23 18:11:36 +00:00
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
if( !aFullFileName.IsEmpty() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2019-06-30 11:54:35 +00:00
|
|
|
file = wxFopen( aFullFileName, wxT( "wt" ) );
|
2016-02-12 11:50:42 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( file == nullptr )
|
2019-06-30 11:54:35 +00:00
|
|
|
return -1;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
std::string data;
|
2021-07-20 08:23:21 +00:00
|
|
|
PLACE_FILE_EXPORTER exporter( GetBoard(), aUnitsMM, aOnlySMD, aNoTHItems, aTopSide, aBottomSide,
|
2022-08-02 09:22:12 +00:00
|
|
|
aFormatCSV, aUseAuxOrigin, aNegateBottomX );
|
2019-06-30 11:54:35 +00:00
|
|
|
data = exporter.GenPositionData();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
// if aFullFileName is empty, the file is not created, only the
|
|
|
|
// count of footprints to place is returned
|
|
|
|
if( file )
|
2016-04-26 12:16:16 +00:00
|
|
|
{
|
2019-06-30 11:54:35 +00:00
|
|
|
// Creates a footprint position file
|
|
|
|
// aSide = 0 -> Back (bottom) side)
|
|
|
|
// aSide = 1 -> Front (top) side)
|
|
|
|
// aSide = 2 -> both sides
|
|
|
|
fputs( data.c_str(), file );
|
|
|
|
fclose( file );
|
2016-04-26 12:16:16 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
return exporter.GetFootprintCount();
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
void PCB_EDIT_FRAME::GenFootprintsReport( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2020-04-05 21:17:26 +00:00
|
|
|
wxString boardFilePath = ( (wxFileName) GetBoard()->GetFileName() ).GetPath();
|
2012-02-15 10:41:16 +00:00
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), boardFilePath );
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = GetBoard()->GetFileName();
|
2012-02-15 10:41:16 +00:00
|
|
|
fn.SetPath( dirDialog.GetPath() );
|
|
|
|
fn.SetExt( wxT( "rpt" ) );
|
2008-10-01 16:05:20 +00:00
|
|
|
|
2020-10-03 23:56:42 +00:00
|
|
|
bool unitMM = GetUserUnits() == EDA_UNITS::MILLIMETRES;
|
2016-02-12 11:50:42 +00:00
|
|
|
bool success = DoGenFootprintsReport( fn.GetFullPath(), unitMM );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
wxString msg;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
if( success )
|
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Footprint report file created:\n'%s'." ), fn.GetFullPath() );
|
2014-11-02 12:44:57 +00:00
|
|
|
wxMessageBox( msg, _( "Footprint Report" ), wxICON_INFORMATION );
|
2012-02-15 10:41:16 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
else
|
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), fn.GetFullPath() );
|
2012-02-15 10:41:16 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool aUnitsMM )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-04-05 21:17:26 +00:00
|
|
|
FILE* rptfile = wxFopen( aFullFilename, wxT( "wt" ) );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( rptfile == nullptr )
|
2012-02-15 10:41:16 +00:00
|
|
|
return false;
|
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
std::string data;
|
2022-08-02 09:22:12 +00:00
|
|
|
PLACE_FILE_EXPORTER exporter( GetBoard(), aUnitsMM,
|
|
|
|
false, false, // SMD aOnlySMD, aNoTHItems
|
|
|
|
true, true, // aTopSide, aBottomSide
|
|
|
|
false, true, false // aFormatCSV, aUseAuxOrigin, aNegateBottomX
|
|
|
|
);
|
2019-06-30 11:54:35 +00:00
|
|
|
data = exporter.GenReportData();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
fputs( data.c_str(), rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
fclose( rptfile );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2012-02-15 10:41:16 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|