2013-05-06 17:57:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Jean-Pierre Charras, <jp.charras@wanadoo.fr>
|
2016-01-10 21:44:37 +00:00
|
|
|
* Copyright (C) 2013-2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2021-07-15 19:26:35 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-06 17:57:18 +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
|
|
|
/*
|
2011-02-22 17:59:46 +00:00
|
|
|
* Functions to read footprint libraries and fill m_footprints by available footprints names
|
2009-11-23 21:03:26 +00:00
|
|
|
* and their documentation (comments and keywords)
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <footprint_info.h>
|
2013-05-28 16:54:59 +00:00
|
|
|
#include <fp_lib_table.h>
|
2021-09-14 18:26:03 +00:00
|
|
|
#include <dialogs/html_message_box.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <kiface_ids.h>
|
|
|
|
#include <kiway.h>
|
2016-11-20 23:35:08 +00:00
|
|
|
#include <lib_id.h>
|
2016-07-02 02:37:40 +00:00
|
|
|
#include <thread>
|
2017-09-23 09:20:10 +00:00
|
|
|
#include <utility>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aLibNickname,
|
|
|
|
const wxString& aFootprintName )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
if( aFootprintName.IsEmpty() )
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
for( std::unique_ptr<FOOTPRINT_INFO>& fp : m_list )
|
2018-07-26 14:38:30 +00:00
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
if( aLibNickname == fp->GetLibNickname() && aFootprintName == fp->GetFootprintName() )
|
2020-11-07 14:31:50 +00:00
|
|
|
return fp.get();
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
2013-12-10 23:41:34 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aFootprintName )
|
2018-07-29 00:11:39 +00:00
|
|
|
{
|
|
|
|
if( aFootprintName.IsEmpty() )
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2018-07-29 00:11:39 +00:00
|
|
|
|
|
|
|
LIB_ID fpid;
|
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, nullptr,
|
2021-06-28 23:44:07 +00:00
|
|
|
wxString::Format( wxT( "'%s' is not a valid LIB_ID." ), aFootprintName ) );
|
2018-07-29 00:11:39 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName() );
|
2018-07-29 00:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
|
|
|
|
{
|
|
|
|
return aLibrary == m_nickname;
|
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
2020-10-15 22:39:33 +00:00
|
|
|
bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs )
|
|
|
|
{
|
|
|
|
int retv = StrNumCmp( lhs.m_nickname, rhs.m_nickname, false );
|
|
|
|
|
|
|
|
if( retv != 0 )
|
|
|
|
return retv < 0;
|
|
|
|
|
|
|
|
// Technically footprint names are not case sensitive because the file name is used
|
|
|
|
// as the footprint name. On windows this would be problematic because windows does
|
|
|
|
// not support case sensitive file names by default. This should not cause any issues
|
|
|
|
// and allow for a future change to use the name defined in the footprint file.
|
|
|
|
return StrNumCmp( lhs.m_fpname, rhs.m_fpname, false ) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
void FOOTPRINT_LIST::DisplayErrors( wxTopLevelWindow* aWindow )
|
|
|
|
{
|
2021-01-09 12:08:04 +00:00
|
|
|
// @todo: go to a more HTML !<table>! ? centric output, possibly with recommendations
|
|
|
|
// for remedy of errors. Add numeric error codes to PARSE_ERROR, and switch on them for
|
|
|
|
// remedies, etc. Full access is provided to everything in every exception!
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
HTML_MESSAGE_BOX dlg( aWindow, _( "Load Error" ) );
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
dlg.MessageSet( _( "Errors were encountered loading footprints:" ) );
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
wxString msg;
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2020-11-24 13:43:55 +00:00
|
|
|
while( std::unique_ptr<IO_ERROR> error = PopError() )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2017-05-03 19:27:07 +00:00
|
|
|
wxString tmp = error->Problem();
|
|
|
|
|
|
|
|
// Preserve new lines in error messages so queued errors don't run together.
|
|
|
|
tmp.Replace( "\n", "<BR>" );
|
|
|
|
msg += wxT( "<p>" ) + tmp + wxT( "</p>" );
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
dlg.AddHTML_Text( msg );
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
dlg.ShowModal();
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-25 12:48:13 +00:00
|
|
|
static FOOTPRINT_LIST* get_instance_from_id( KIWAY& aKiway, int aId )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
void* ptr = nullptr;
|
2013-05-10 01:51:55 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
try
|
|
|
|
{
|
2021-06-29 11:45:02 +00:00
|
|
|
ptr = Kiface().IfaceOrAddress( aId );
|
2013-05-10 01:51:55 +00:00
|
|
|
|
2021-06-29 11:45:02 +00:00
|
|
|
if( !ptr )
|
|
|
|
{
|
|
|
|
KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB );
|
|
|
|
ptr = kiface->IfaceOrAddress( aId );
|
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2020-07-13 20:21:34 +00:00
|
|
|
return static_cast<FOOTPRINT_LIST*>( ptr );
|
2015-11-11 18:35:26 +00:00
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
catch( ... )
|
2015-07-17 13:13:31 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
return nullptr;
|
2015-07-17 13:13:31 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2018-03-25 12:48:13 +00:00
|
|
|
FOOTPRINT_LIST* FOOTPRINT_LIST::GetInstance( KIWAY& aKiway )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2018-08-04 23:07:25 +00:00
|
|
|
FOOTPRINT_LIST* footprintInfo = get_instance_from_id( aKiway, KIFACE_FOOTPRINT_LIST );
|
|
|
|
|
2021-05-14 21:23:40 +00:00
|
|
|
if( !footprintInfo )
|
2018-10-12 21:51:31 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2018-08-04 23:07:25 +00:00
|
|
|
if( !footprintInfo->GetCount() )
|
2020-12-11 01:08:51 +00:00
|
|
|
footprintInfo->ReadCacheFromFile( aKiway.Prj().GetProjectPath() + "fp-info-cache" );
|
2018-08-04 23:07:25 +00:00
|
|
|
|
|
|
|
return footprintInfo;
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|