2013-09-25 19:17:06 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2024-05-14 13:04:02 +00:00
|
|
|
* Copyright (C) 2016-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-25 19:17:06 +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
|
|
|
|
*/
|
2013-09-21 07:30:23 +00:00
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <unordered_set>
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <pcb_io/pcb_io.h>
|
|
|
|
#include <pcb_io/pcb_io_mgr.h>
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <ki_exception.h>
|
2022-11-06 16:51:52 +00:00
|
|
|
#include <string_utf8_map.h>
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/filename.h>
|
2020-10-01 08:52:03 +00:00
|
|
|
#include <wx/translation.h>
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <wx/dir.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2013-09-21 07:30:23 +00:00
|
|
|
|
2023-04-11 08:53:35 +00:00
|
|
|
#define FMT_UNIMPLEMENTED wxT( "Plugin \"%s\" does not implement the \"%s\" function." )
|
|
|
|
#define NOT_IMPLEMENTED( aCaller ) \
|
|
|
|
THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, \
|
2023-12-24 04:31:22 +00:00
|
|
|
GetName(), \
|
2020-10-01 08:52:03 +00:00
|
|
|
wxString::FromUTF8( aCaller ) ) );
|
2023-04-11 08:53:35 +00:00
|
|
|
|
2013-09-21 07:30:23 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
bool PCB_IO::CanReadBoard( const wxString& aFileName ) const
|
2023-08-13 02:26:06 +00:00
|
|
|
{
|
|
|
|
const std::vector<std::string>& exts = GetBoardFileDesc().m_FileExtensions;
|
|
|
|
|
|
|
|
wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
|
|
|
|
|
2023-08-17 15:32:11 +00:00
|
|
|
for( const std::string& ext : exts )
|
2023-08-13 02:26:06 +00:00
|
|
|
{
|
2023-08-17 15:32:11 +00:00
|
|
|
if( fileExt == wxString( ext ).Lower() )
|
2023-08-13 02:26:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
bool PCB_IO::CanReadFootprint( const wxString& aFileName ) const
|
2023-08-13 02:26:06 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
const std::vector<std::string>& exts = GetLibraryFileDesc().m_FileExtensions;
|
2023-08-13 02:26:06 +00:00
|
|
|
|
|
|
|
wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
|
|
|
|
|
2023-08-17 15:32:11 +00:00
|
|
|
for( const std::string& ext : exts )
|
2023-08-13 02:26:06 +00:00
|
|
|
{
|
2023-08-17 15:32:11 +00:00
|
|
|
if( fileExt == wxString( ext ).Lower() )
|
2023-08-13 02:26:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
BOARD* PCB_IO::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
2023-12-27 17:06:23 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties, PROJECT* aProject )
|
2013-09-21 07:30:23 +00:00
|
|
|
{
|
2023-04-11 08:53:35 +00:00
|
|
|
NOT_IMPLEMENTED( __FUNCTION__ );
|
2013-09-21 07:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
std::vector<FOOTPRINT*> PCB_IO::GetImportedCachedLibraryFootprints()
|
2021-01-31 21:55:51 +00:00
|
|
|
{
|
2023-04-11 08:53:35 +00:00
|
|
|
NOT_IMPLEMENTED( __FUNCTION__ );
|
2021-01-31 21:55:51 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 02:11:58 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
void PCB_IO::SaveBoard( const wxString& aFileName, BOARD* aBoard,
|
2023-12-27 17:06:23 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2013-09-21 07:30:23 +00:00
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
|
2023-04-11 08:53:35 +00:00
|
|
|
NOT_IMPLEMENTED( __FUNCTION__ );
|
2013-09-21 07:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
bool aBestEfforts, const STRING_UTF8_MAP* aProperties )
|
2013-09-21 07:30:23 +00:00
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
|
2023-04-11 08:53:35 +00:00
|
|
|
NOT_IMPLEMENTED( __FUNCTION__ );
|
2013-09-21 07:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
void PCB_IO::PrefetchLib( const wxString&, const STRING_UTF8_MAP* )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
FOOTPRINT* PCB_IO::ImportFootprint( const wxString& aFootprintPath, wxString& aFootprintNameOut,
|
2023-08-13 02:26:06 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
|
|
|
{
|
|
|
|
wxArrayString footprintNames;
|
|
|
|
|
|
|
|
FootprintEnumerate( footprintNames, aFootprintPath, true, aProperties );
|
|
|
|
|
|
|
|
if( footprintNames.empty() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if( footprintNames.size() > 1 )
|
|
|
|
{
|
|
|
|
wxLogWarning( _( "Selected file contains multiple footprints. Only the first one will be "
|
2024-05-14 13:04:02 +00:00
|
|
|
"imported.\nTo load all footprints, add it as a library using Preferences "
|
|
|
|
"-> Manage Footprint "
|
|
|
|
"Libraries..." ) );
|
2023-08-13 02:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aFootprintNameOut = footprintNames.front();
|
|
|
|
|
|
|
|
return FootprintLoad( aFootprintPath, aFootprintNameOut, false, aProperties );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
const FOOTPRINT* PCB_IO::GetEnumeratedFootprint( const wxString& aLibraryPath,
|
2020-11-13 15:15:52 +00:00
|
|
|
const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2018-02-23 12:21:06 +00:00
|
|
|
{
|
|
|
|
// default implementation
|
2021-03-30 09:38:03 +00:00
|
|
|
return FootprintLoad( aLibraryPath, aFootprintName, false, aProperties );
|
2018-02-23 12:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
bool PCB_IO::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2019-07-11 21:59:14 +00:00
|
|
|
{
|
|
|
|
// default implementation
|
2021-03-30 09:38:03 +00:00
|
|
|
return FootprintLoad( aLibraryPath, aFootprintName, true, aProperties ) != nullptr;
|
2019-07-11 21:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
FOOTPRINT* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
bool aKeepUUID, const STRING_UTF8_MAP* aProperties )
|
2013-09-21 07:30:23 +00:00
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
|
2023-04-11 08:53:35 +00:00
|
|
|
NOT_IMPLEMENTED( __FUNCTION__ );
|
2013-09-21 07:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
void PCB_IO::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFootprint,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2013-09-21 07:30:23 +00:00
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
|
2023-04-11 08:53:35 +00:00
|
|
|
NOT_IMPLEMENTED( __FUNCTION__ );
|
2013-09-21 07:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
void PCB_IO::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2013-09-21 07:30:23 +00:00
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
|
2023-04-11 08:53:35 +00:00
|
|
|
NOT_IMPLEMENTED( __FUNCTION__ );
|
2013-09-21 07:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
void PCB_IO::GetLibraryOptions( STRING_UTF8_MAP* aListToAppendTo ) const
|
2013-09-21 07:30:23 +00:00
|
|
|
{
|
2023-12-27 00:25:41 +00:00
|
|
|
// Get base options first
|
|
|
|
IO_BASE::GetLibraryOptions( aListToAppendTo );
|
2013-09-21 07:30:23 +00:00
|
|
|
|
2013-11-19 20:38:29 +00:00
|
|
|
// disable all these in another couple of months, after everyone has seen them:
|
2013-11-12 20:49:17 +00:00
|
|
|
#if 1
|
2022-02-04 22:44:59 +00:00
|
|
|
(*aListToAppendTo)["debug_level"] = UTF8( _( "Enable <b>debug</b> logging for Footprint*() "
|
2023-12-19 17:39:26 +00:00
|
|
|
"functions in this PCB_IO." ) );
|
2022-02-04 22:44:59 +00:00
|
|
|
|
|
|
|
(*aListToAppendTo)["read_filter_regex"] = UTF8( _( "Regular expression <b>footprint name</b> "
|
|
|
|
"filter." ) );
|
|
|
|
|
|
|
|
(*aListToAppendTo)["enable_transaction_logging"] = UTF8( _( "Enable transaction logging. The "
|
|
|
|
"mere presence of this option "
|
|
|
|
"turns on the logging, no need to "
|
|
|
|
"set a Value." ) );
|
|
|
|
|
|
|
|
(*aListToAppendTo)["username"] = UTF8( _( "User name for <b>login</b> to some special library "
|
|
|
|
"server." ) );
|
|
|
|
|
|
|
|
(*aListToAppendTo)["password"] = UTF8( _( "Password for <b>login</b> to some special library "
|
|
|
|
"server." ) );
|
2013-11-12 20:49:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1
|
2023-12-19 17:39:26 +00:00
|
|
|
// Suitable for a C++ to python PCB_IO::Footprint*() adapter, move it to the adapter
|
2013-11-12 20:49:17 +00:00
|
|
|
// if and when implemented.
|
2022-02-04 22:44:59 +00:00
|
|
|
(*aListToAppendTo)["python_footprint_plugin"] = UTF8( _( "Enter the python module which "
|
2023-12-19 17:39:26 +00:00
|
|
|
"implements the PCB_IO::Footprint*() "
|
2022-02-04 22:44:59 +00:00
|
|
|
"functions." ) );
|
2013-11-12 20:49:17 +00:00
|
|
|
#endif
|
2013-11-12 00:17:27 +00:00
|
|
|
}
|