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>
|
2017-03-23 00:59:25 +00:00
|
|
|
* Copyright (C) 1992-2017 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
|
|
|
|
*/
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2011-02-05 18:00:05 +00:00
|
|
|
/**
|
2011-02-22 20:59:16 +00:00
|
|
|
* @file footprint_info.cpp
|
2011-02-05 18:00:05 +00:00
|
|
|
*/
|
2009-11-05 19:26:52 +00:00
|
|
|
|
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
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <class_module.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <common.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <fctsys.h>
|
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>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <html_messagebox.h>
|
|
|
|
#include <io_mgr.h>
|
|
|
|
#include <kiface_ids.h>
|
|
|
|
#include <kiway.h>
|
2016-11-20 23:35:08 +00:00
|
|
|
#include <lib_id.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <macros.h>
|
|
|
|
#include <pgm_base.h>
|
2016-07-02 02:37:40 +00:00
|
|
|
#include <thread>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
if( aFootprintName.IsEmpty() )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for( auto& fp : m_list )
|
|
|
|
{
|
|
|
|
LIB_ID fpid;
|
2013-12-10 23:41:34 +00:00
|
|
|
|
2017-07-24 19:02:59 +00:00
|
|
|
wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL,
|
2017-03-23 00:59:25 +00:00
|
|
|
wxString::Format(
|
2017-12-15 11:37:46 +00:00
|
|
|
wxT( "\"%s\" is not a valid LIB_ID." ), GetChars( aFootprintName ) ) );
|
2013-12-10 23:41:34 +00:00
|
|
|
|
2017-07-24 19:02:59 +00:00
|
|
|
wxString libNickname = fpid.GetLibNickname();
|
|
|
|
wxString footprintName = fpid.GetLibItemName();
|
2013-12-10 23:41:34 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
if( libNickname == fp->GetNickname() && footprintName == fp->GetFootprintName() )
|
|
|
|
return &*fp;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
while( auto 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
static std::unique_ptr<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
|
|
|
if( !kiface )
|
|
|
|
return nullptr;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
ptr = kiface->IfaceOrAddress( aId );
|
|
|
|
|
|
|
|
if( !ptr )
|
|
|
|
return nullptr;
|
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
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
return std::unique_ptr<FOOTPRINT_LIST>( (FOOTPRINT_LIST*) ( ptr ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
std::unique_ptr<FOOTPRINT_LIST> FOOTPRINT_LIST::GetInstance( KIWAY& aKiway )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
return get_instance_from_id( aKiway, KIFACE_NEW_FOOTPRINT_LIST );
|
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_started = false;
|
|
|
|
m_total_libs = 0;
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-23 00:59:25 +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
|
|
|
m_started = true;
|
2014-12-07 17:19:52 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
int FOOTPRINT_ASYNC_LOADER::GetProgress() const
|
2013-06-07 12:15:32 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
if( !m_started )
|
|
|
|
return 0;
|
|
|
|
else if( m_total_libs == 0 || !m_list )
|
|
|
|
return 100;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int loaded = m_list->CountFinished();
|
|
|
|
int prog = ( 100 * loaded ) / m_total_libs;
|
|
|
|
|
|
|
|
if( loaded == m_total_libs )
|
|
|
|
return 100;
|
|
|
|
else if( loaded < m_total_libs && prog >= 100 )
|
|
|
|
return 99;
|
|
|
|
else if( prog <= 0 )
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return prog;
|
|
|
|
}
|
2013-06-07 12:15:32 +00:00
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
void FOOTPRINT_ASYNC_LOADER::SetCompletionCallback( std::function<void()> aCallback )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
m_completion_cb = aCallback;
|
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
bool FOOTPRINT_ASYNC_LOADER::IsSameTable( FP_LIB_TABLE* aOther )
|
|
|
|
{
|
|
|
|
STRING_FORMATTER sof;
|
|
|
|
aOther->Format( &sof, 0 );
|
|
|
|
return m_last_table == sof.GetString();
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|