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>
|
2020-11-07 14:31:50 +00:00
|
|
|
* Copyright (C) 1992-2020 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>
|
2020-10-25 13:14:52 +00:00
|
|
|
#include <dialogs/html_messagebox.h>
|
2020-10-15 22:39:33 +00:00
|
|
|
#include <kicad_string.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>
|
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() )
|
|
|
|
return NULL;
|
|
|
|
|
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
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
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() )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
LIB_ID fpid;
|
|
|
|
|
|
|
|
wxCHECK_MSG( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) < 0, NULL,
|
|
|
|
wxString::Format( wxT( "\"%s\" is not a valid LIB_ID." ), aFootprintName ) );
|
|
|
|
|
2020-11-07 14:31:50 +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 )
|
|
|
|
{
|
|
|
|
// @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-07 14:31:50 +00:00
|
|
|
while( const 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
|
|
|
|
{
|
|
|
|
KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB );
|
2013-05-10 01:51:55 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
ptr = kiface->IfaceOrAddress( aId );
|
|
|
|
|
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 );
|
|
|
|
|
2018-10-12 21:51:31 +00:00
|
|
|
if( ! footprintInfo )
|
|
|
|
return nullptr;
|
|
|
|
|
2018-08-04 23:07:25 +00:00
|
|
|
if( !footprintInfo->GetCount() )
|
|
|
|
{
|
|
|
|
wxTextFile footprintInfoCache( aKiway.Prj().GetProjectPath() + "fp-info-cache" );
|
|
|
|
footprintInfo->ReadCacheFromFile( &footprintInfoCache );
|
|
|
|
}
|
|
|
|
|
|
|
|
return footprintInfo;
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FOOTPRINT_ASYNC_LOADER::FOOTPRINT_ASYNC_LOADER() : m_list( nullptr )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2017-11-09 17:51:06 +00:00
|
|
|
m_total_libs = 0;
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
2018-06-04 20:44:43 +00:00
|
|
|
FOOTPRINT_ASYNC_LOADER::~FOOTPRINT_ASYNC_LOADER()
|
|
|
|
{
|
|
|
|
// This is NOP if the load has finished
|
|
|
|
Abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
void FOOTPRINT_ASYNC_LOADER::SetList( FOOTPRINT_LIST* aList )
|
|
|
|
{
|
|
|
|
m_list = aList;
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
2013-06-07 12:15:32 +00:00
|
|
|
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
void FOOTPRINT_ASYNC_LOADER::Start( FP_LIB_TABLE* aTable, wxString const* aNickname,
|
|
|
|
unsigned aNThreads )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
// Capture the FP_LIB_TABLE into m_last_table. Formatting it as a string instead of storing the
|
|
|
|
// raw data avoids having to pull in the FP-specific parts.
|
|
|
|
STRING_FORMATTER sof;
|
|
|
|
aTable->Format( &sof, 0 );
|
|
|
|
m_last_table = sof.GetString();
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
m_list->StartWorkers( aTable, aNickname, this, aNThreads );
|
|
|
|
}
|
2013-09-14 20:33:22 +00:00
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
bool FOOTPRINT_ASYNC_LOADER::Join()
|
|
|
|
{
|
|
|
|
if( m_list )
|
|
|
|
{
|
|
|
|
bool rv = m_list->JoinWorkers();
|
|
|
|
m_list = nullptr;
|
|
|
|
return rv;
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
else
|
|
|
|
return true;
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-23 15:52:48 +00:00
|
|
|
void FOOTPRINT_ASYNC_LOADER::Abort()
|
|
|
|
{
|
|
|
|
if( m_list )
|
|
|
|
{
|
|
|
|
m_list->StopWorkers();
|
|
|
|
m_list = nullptr;
|
|
|
|
}
|
|
|
|
}
|