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>
|
2016-04-08 16:45:11 +00:00
|
|
|
* Copyright (C) 1992-2016 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
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2016-01-10 21:44:37 +00:00
|
|
|
/**
|
|
|
|
No. concurrent threads doing "http(s) GET". More than 6 is not significantly
|
|
|
|
faster, less than 6 is likely slower. Main thread is in this count, so if
|
|
|
|
set to 1 then no temp threads are created.
|
|
|
|
*/
|
|
|
|
#define READER_THREADS 6
|
2013-12-09 18:09:58 +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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2013-05-10 01:51:55 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <footprint_info.h>
|
2012-04-16 03:18:41 +00:00
|
|
|
#include <io_mgr.h>
|
2013-05-28 16:54:59 +00:00
|
|
|
#include <fp_lib_table.h>
|
2013-09-14 20:33:22 +00:00
|
|
|
#include <fpid.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_module.h>
|
2013-12-12 16:01:03 +00:00
|
|
|
#include <boost/thread.hpp>
|
2016-04-08 16:45:11 +00:00
|
|
|
#include <html_messagebox.h>
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2013-12-10 23:41:34 +00:00
|
|
|
static wxString ToHTMLFragment( const IO_ERROR* aDerivative )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
@todo
|
|
|
|
|
|
|
|
1) change up IO_ERROR so it keeps linenumbers, source file name and
|
|
|
|
error message in separate strings.
|
|
|
|
|
|
|
|
2) Add a summarizing virtual member like
|
|
|
|
virtual wxString What()
|
|
|
|
to combine all portions of an IO_ERROR's text into a single wxString.
|
|
|
|
|
|
|
|
3) Do same for PARSE_ERROR.
|
|
|
|
|
|
|
|
4) Add a "reason or error category" to IO_ERROR and thereby also PARSE_ERROR?
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
msg += "
|
|
|
|
|
|
|
|
for( int i=0; i<aCount; ++i )
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString* sl = wxStringSplit( aList, wxChar( '\n' ) );
|
|
|
|
|
|
|
|
|
|
|
|
delete sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString msg = wxT( "<ul>" );
|
|
|
|
|
|
|
|
for ( unsigned ii = 0; ii < strings_list->GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
msg += wxT( "<li>" );
|
|
|
|
msg += strings_list->Item( ii ) + wxT( "</li>" );
|
|
|
|
}
|
|
|
|
|
|
|
|
msg += wxT( "</ul>" );
|
|
|
|
|
|
|
|
m_htmlWindow->AppendToPage( msg );
|
|
|
|
|
|
|
|
delete strings_list;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
void FOOTPRINT_INFO::load()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-12-12 16:01:03 +00:00
|
|
|
FP_LIB_TABLE* fptable = m_owner->GetTable();
|
2013-05-10 01:51:55 +00:00
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
wxASSERT( fptable );
|
2013-05-10 01:51:55 +00:00
|
|
|
|
2016-05-22 17:39:20 +00:00
|
|
|
std::unique_ptr<MODULE> footprint( fptable->FootprintLoad( m_nickname, m_fpname ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-05-22 17:39:20 +00:00
|
|
|
if( footprint.get() == NULL ) // Should happen only with malformed/broken libraries
|
2015-11-11 18:35:26 +00:00
|
|
|
{
|
2015-07-17 13:13:31 +00:00
|
|
|
m_pad_count = 0;
|
2015-11-11 18:35:26 +00:00
|
|
|
m_unique_pad_count = 0;
|
|
|
|
}
|
2015-07-17 13:13:31 +00:00
|
|
|
else
|
|
|
|
{
|
2016-05-22 17:39:20 +00:00
|
|
|
m_pad_count = footprint->GetPadCount( DO_NOT_INCLUDE_NPTH );
|
|
|
|
m_unique_pad_count = footprint->GetUniquePadCount( DO_NOT_INCLUDE_NPTH );
|
|
|
|
m_keywords = footprint->GetKeywords();
|
|
|
|
m_doc = footprint->GetDescription();
|
2012-04-17 06:13:22 +00:00
|
|
|
|
2015-07-17 13:13:31 +00:00
|
|
|
// tell ensure_loaded() I'm loaded.
|
|
|
|
m_loaded = true;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
void FOOTPRINT_LIST::loader_job( const wxString* aNicknameList, int aJobZ )
|
|
|
|
{
|
|
|
|
for( int i=0; i<aJobZ; ++i )
|
|
|
|
{
|
|
|
|
const wxString& nickname = aNicknameList[i];
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
wxArrayString fpnames = m_lib_table->FootprintEnumerate( nickname );
|
|
|
|
|
|
|
|
for( unsigned ni=0; ni<fpnames.GetCount(); ++ni )
|
|
|
|
{
|
2013-12-12 16:01:03 +00:00
|
|
|
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO( this, nickname, fpnames[ni] );
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
addItem( fpinfo );
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const PARSE_ERROR& pe )
|
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
// m_errors.push_back is not thread safe, lock its MUTEX.
|
2013-12-09 18:09:58 +00:00
|
|
|
MUTLOCK lock( m_errors_lock );
|
|
|
|
|
|
|
|
++m_error_count; // modify only under lock
|
|
|
|
m_errors.push_back( new IO_ERROR( pe ) );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
MUTLOCK lock( m_errors_lock );
|
|
|
|
|
|
|
|
++m_error_count;
|
|
|
|
m_errors.push_back( new IO_ERROR( ioe ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Catch anything unexpected and map it into the expected.
|
|
|
|
// Likely even more important since this function runs on GUI-less
|
|
|
|
// worker threads.
|
|
|
|
catch( const std::exception& se )
|
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
// This is a round about way to do this, but who knows what THROW_IO_ERROR()
|
2013-12-09 18:09:58 +00:00
|
|
|
// may be tricked out to do someday, keep it in the game.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( se.what() );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
MUTLOCK lock( m_errors_lock );
|
|
|
|
|
|
|
|
++m_error_count;
|
|
|
|
m_errors.push_back( new IO_ERROR( ioe ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
bool FOOTPRINT_LIST::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2013-09-22 00:28:02 +00:00
|
|
|
bool retv = true;
|
|
|
|
|
2013-12-09 18:09:58 +00:00
|
|
|
m_lib_table = aTable;
|
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
// Clear data before reading files
|
2013-12-09 18:09:58 +00:00
|
|
|
m_error_count = 0;
|
|
|
|
m_errors.clear();
|
|
|
|
m_list.clear();
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
if( aNickname )
|
|
|
|
// single footprint
|
|
|
|
loader_job( aNickname, 1 );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector< wxString > nicknames;
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
// do all of them
|
|
|
|
nicknames = aTable->GetLogicalLibs();
|
|
|
|
|
2014-01-21 06:59:32 +00:00
|
|
|
// Even though the PLUGIN API implementation is the place for the
|
|
|
|
// locale toggling, in order to keep LOCAL_IO::C_count at 1 or greater
|
|
|
|
// for the duration of all helper threads, we increment by one here via instantiation.
|
|
|
|
// Only done here because of the multi-threaded nature of this code.
|
|
|
|
// Without this C_count skips in and out of "equal to zero" and causes
|
|
|
|
// needless locale toggling among the threads, based on which of them
|
|
|
|
// are in a PLUGIN::FootprintLoad() function. And that is occasionally
|
|
|
|
// none of them.
|
|
|
|
LOCALE_IO top_most_nesting;
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
// Something which will not invoke a thread copy constructor, one of many ways obviously:
|
|
|
|
typedef boost::ptr_vector< boost::thread > MYTHREADS;
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
MYTHREADS threads;
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2016-01-10 21:44:37 +00:00
|
|
|
unsigned jobz = (nicknames.size() + READER_THREADS - 1) / READER_THREADS;
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
// Give each thread JOBZ nicknames to process. The last portion of, or if the entire
|
|
|
|
// size() is small, I'll do myself.
|
|
|
|
for( unsigned i=0; i<nicknames.size(); )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2016-01-10 21:44:37 +00:00
|
|
|
if( i + jobz >= nicknames.size() ) // on the last iteration of this for(;;)
|
2013-12-10 23:41:34 +00:00
|
|
|
{
|
|
|
|
jobz = nicknames.size() - i;
|
|
|
|
|
2016-01-10 21:44:37 +00:00
|
|
|
// Only a little bit to do, I'll do it myself on current thread.
|
|
|
|
// I am part of the READER_THREADS count.
|
2013-12-10 23:41:34 +00:00
|
|
|
loader_job( &nicknames[i], jobz );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-10 21:44:37 +00:00
|
|
|
// Delegate the job to a temporary thread created here.
|
2013-12-10 23:41:34 +00:00
|
|
|
threads.push_back( new boost::thread( &FOOTPRINT_LIST::loader_job,
|
|
|
|
this, &nicknames[i], jobz ) );
|
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
i += jobz;
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|
2013-12-10 23:41:34 +00:00
|
|
|
|
|
|
|
// Wait for all the worker threads to complete, it does not matter in what order
|
|
|
|
// we wait for them as long as a full sweep is made. Think of the great race,
|
|
|
|
// everyone must finish.
|
|
|
|
for( unsigned i=0; i<threads.size(); ++i )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
threads[i].join();
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
m_list.sort();
|
2013-12-09 18:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The result of this function can be a blend of successes and failures, whose
|
|
|
|
// mix is given by the Count()s of the two lists. The return value indicates whether
|
|
|
|
// an abort occurred, even true does not necessarily mean full success, although
|
|
|
|
// false definitely means failure.
|
|
|
|
|
|
|
|
return retv;
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
2013-06-07 12:15:32 +00:00
|
|
|
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName )
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
2014-12-07 17:19:52 +00:00
|
|
|
if( aFootprintName.IsEmpty() )
|
|
|
|
return NULL;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( FOOTPRINT_INFO& fp : m_list )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
|
|
|
FPID fpid;
|
|
|
|
|
2013-09-17 00:52:08 +00:00
|
|
|
wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL,
|
2013-10-31 21:30:57 +00:00
|
|
|
wxString::Format( wxT( "'%s' is not a valid FPID." ),
|
2013-09-14 20:33:22 +00:00
|
|
|
GetChars( aFootprintName ) ) );
|
|
|
|
|
2014-01-02 02:17:07 +00:00
|
|
|
wxString libNickname = fpid.GetLibNickname();
|
|
|
|
wxString footprintName = fpid.GetFootprintName();
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
if( libNickname == fp.GetNickname() && footprintName == fp.GetFootprintName() )
|
|
|
|
return &fp;
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
2013-12-12 16:01:03 +00:00
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 12:15:32 +00:00
|
|
|
bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
|
|
|
|
{
|
2013-10-31 21:30:57 +00:00
|
|
|
return aLibrary == m_nickname;
|
2013-06-07 12:15:32 +00:00
|
|
|
}
|
2013-12-09 18:09:58 +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!
|
|
|
|
|
|
|
|
HTML_MESSAGE_BOX dlg( aWindow, _( "Load Error" ) );
|
|
|
|
|
2016-04-08 16:45:11 +00:00
|
|
|
dlg.MessageSet( _( "Errors were encountered loading footprints:" ) );
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2016-04-08 16:45:11 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i<m_errors.size(); ++i )
|
|
|
|
{
|
2016-09-20 15:59:43 +00:00
|
|
|
msg += wxT( "<p>" ) + m_errors[i].Problem() + wxT( "</p>" );
|
2016-04-08 16:45:11 +00:00
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
dlg.AddHTML_Text( msg );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|