2016-11-20 02:22:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2017-09-02 18:12:50 +00:00
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
|
2017-01-27 15:56:36 +00:00
|
|
|
* Copyright (C) 2012-2017 KiCad Developers, see change_log.txt for contributors.
|
2016-11-20 02:22:58 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIB_TABLE_BASE_H_
|
|
|
|
#define _LIB_TABLE_BASE_H_
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <boost/noncopyable.hpp>
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
|
|
|
#include <memory>
|
2016-11-20 02:22:58 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <properties.h>
|
|
|
|
#include <richio.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define FP_LATE_ENVVAR 1 ///< late=1/early=0 environment variable expansion
|
|
|
|
|
|
|
|
class OUTPUTFORMATTER;
|
2016-11-20 23:35:08 +00:00
|
|
|
class LIB_TABLE_LEXER;
|
|
|
|
class LIB_ID;
|
2016-11-20 02:22:58 +00:00
|
|
|
class LIB_TABLE_ROW;
|
2017-03-27 23:21:12 +00:00
|
|
|
class LIB_TABLE_GRID;
|
2016-11-20 02:22:58 +00:00
|
|
|
class IO_ERROR;
|
|
|
|
|
|
|
|
|
2017-03-27 23:21:12 +00:00
|
|
|
typedef boost::ptr_vector< LIB_TABLE_ROW > LIB_TABLE_ROWS;
|
|
|
|
typedef LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER;
|
|
|
|
typedef LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER;
|
|
|
|
|
|
|
|
|
2016-11-20 02:22:58 +00:00
|
|
|
/**
|
|
|
|
* Allows boost pointer containers to make clones of the data stored in them. Since they
|
|
|
|
* store pointers the data is cloned. Copying and assigning pointers would cause ownership
|
|
|
|
* issues if the standard C++ containers were used.
|
|
|
|
*/
|
|
|
|
LIB_TABLE_ROW* new_clone( const LIB_TABLE_ROW& aRow );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Hold a record identifying a library accessed by the appropriate plug in object in the
|
2016-11-20 02:22:58 +00:00
|
|
|
* #LIB_TABLE. This is an abstract base class from which to derive library specific rows.
|
|
|
|
*/
|
|
|
|
class LIB_TABLE_ROW : boost::noncopyable
|
|
|
|
{
|
|
|
|
public:
|
2020-09-16 10:27:46 +00:00
|
|
|
LIB_TABLE_ROW() :
|
|
|
|
enabled( true ),
|
|
|
|
m_loaded( false )
|
2016-11-20 02:22:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~LIB_TABLE_ROW()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aOptions,
|
|
|
|
const wxString& aDescr = wxEmptyString ) :
|
|
|
|
nickName( aNick ),
|
2017-11-15 05:48:31 +00:00
|
|
|
description( aDescr ),
|
2020-08-29 23:19:05 +00:00
|
|
|
enabled( true ),
|
|
|
|
m_loaded( false )
|
2016-11-20 02:22:58 +00:00
|
|
|
{
|
|
|
|
properties.reset();
|
|
|
|
SetOptions( aOptions );
|
|
|
|
SetFullURI( aURI );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==( const LIB_TABLE_ROW& r ) const;
|
|
|
|
|
2020-08-29 23:19:05 +00:00
|
|
|
bool operator!=( const LIB_TABLE_ROW& r ) const { return !( *this == r ); }
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the logical name of this library table row.
|
|
|
|
*/
|
2020-08-29 23:19:05 +00:00
|
|
|
const wxString& GetNickName() const { return nickName; }
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Change the logical name of this library, useful for an editor.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
void SetNickName( const wxString& aNickName ) { nickName = aNickName; }
|
|
|
|
|
2020-08-29 23:19:05 +00:00
|
|
|
/**
|
|
|
|
* @return true if the library was loaded without error
|
|
|
|
*/
|
|
|
|
bool GetIsLoaded() const { return m_loaded; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the row as being a loaded library
|
|
|
|
*/
|
|
|
|
void SetLoaded( bool aLoaded ) { m_loaded = aLoaded; };
|
|
|
|
|
2017-11-15 05:48:31 +00:00
|
|
|
/**
|
|
|
|
* @return the enabled status of this library row
|
|
|
|
*/
|
|
|
|
bool GetIsEnabled() const { return enabled; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the enabled status of this library
|
|
|
|
*/
|
|
|
|
void SetEnabled( bool aEnabled = true ) { enabled = aEnabled; }
|
|
|
|
|
2016-11-20 02:22:58 +00:00
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return the type of library represented by this row.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
virtual const wxString GetType() const = 0;
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Change the type of library represented by this row that must be implemented in the
|
|
|
|
* derived object to provide the library table row type.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
virtual void SetType( const wxString& aType ) = 0;
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return the full location specifying URI for the LIB, either in original UI form or
|
|
|
|
* in environment variable expanded form.
|
2016-11-20 02:22:58 +00:00
|
|
|
*
|
|
|
|
* @param aSubstituted Tells if caller wanted the substituted form, else not.
|
|
|
|
*/
|
|
|
|
const wxString GetFullURI( bool aSubstituted = false ) const;
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Change the full URI for the library.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
void SetFullURI( const wxString& aFullURI );
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return the options string, which may hold a password or anything else needed to
|
|
|
|
* instantiate the underlying library plugin.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
const wxString& GetOptions() const { return options; }
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Change the library options strings.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
void SetOptions( const wxString& aOptions );
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return the description of the library referenced by this row.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
const wxString& GetDescr() const { return description; }
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Change the description of the library referenced by this row.
|
2016-11-20 02:22:58 +00:00
|
|
|
*/
|
|
|
|
void SetDescr( const wxString& aDescr ) { description = aDescr; }
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return the constant #PROPERTIES for this library (#LIB_TABLE_ROW). These are
|
2016-11-20 02:22:58 +00:00
|
|
|
* the "options" in a table.
|
|
|
|
*/
|
|
|
|
const PROPERTIES* GetProperties() const { return properties.get(); }
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Serialize this object as utf8 text to an #OUTPUTFORMATTER, and tries to
|
2016-11-20 02:22:58 +00:00
|
|
|
* make it look good using multiple lines and indentation.
|
|
|
|
*
|
|
|
|
* @param out is an #OUTPUTFORMATTER
|
|
|
|
* @param nestLevel is the indentation level to base all lines of the output.
|
|
|
|
* Actual indentation will be 2 spaces for each nestLevel.
|
|
|
|
*/
|
2017-03-14 22:54:40 +00:00
|
|
|
void Format( OUTPUTFORMATTER* out, int nestLevel ) const;
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
LIB_TABLE_ROW* clone() const
|
|
|
|
{
|
|
|
|
return do_clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LIB_TABLE_ROW( const LIB_TABLE_ROW& aRow ) :
|
|
|
|
nickName( aRow.nickName ),
|
|
|
|
uri_user( aRow.uri_user ),
|
|
|
|
#if !FP_LATE_ENVVAR
|
|
|
|
uri_expanded( aRow.uri_expanded ),
|
|
|
|
#endif
|
|
|
|
options( aRow.options ),
|
2017-11-15 05:48:31 +00:00
|
|
|
description( aRow.description ),
|
2020-08-29 23:19:05 +00:00
|
|
|
enabled( aRow.enabled ),
|
|
|
|
m_loaded( aRow.m_loaded )
|
2016-11-20 02:22:58 +00:00
|
|
|
{
|
|
|
|
if( aRow.properties )
|
2019-12-05 13:43:55 +00:00
|
|
|
properties = std::make_unique<PROPERTIES>( *aRow.properties.get() );
|
2016-11-20 02:22:58 +00:00
|
|
|
else
|
|
|
|
properties.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator=( const LIB_TABLE_ROW& aRow );
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual LIB_TABLE_ROW* do_clone() const = 0;
|
|
|
|
|
|
|
|
void setProperties( PROPERTIES* aProperties );
|
|
|
|
|
|
|
|
wxString nickName;
|
|
|
|
wxString uri_user; ///< what user entered from UI or loaded from disk
|
|
|
|
|
|
|
|
#if !FP_LATE_ENVVAR
|
|
|
|
wxString uri_expanded; ///< from ExpandSubstitutions()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxString options;
|
|
|
|
wxString description;
|
|
|
|
|
2020-09-16 10:27:46 +00:00
|
|
|
bool enabled = true; ///< Whether the LIB_TABLE_ROW is enabled
|
|
|
|
bool m_loaded = false; ///< Whether the LIB_TABLE_ROW is loaded
|
2017-11-15 05:48:31 +00:00
|
|
|
|
2016-11-20 02:22:58 +00:00
|
|
|
std::unique_ptr< PROPERTIES > properties;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Manage #LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
|
2016-11-20 02:22:58 +00:00
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* This class owns the <b>library table</b>, which is like fstab in concept and maps
|
|
|
|
* logical library name to the library URI, type, and options. It is heavily based on
|
|
|
|
* the SWEET parser work done by Dick Hollenbeck and can be seen in new/sch_lib_table.h.
|
|
|
|
* A library table has the following columns:
|
|
|
|
* <ul>
|
|
|
|
* <li> Logical Library Name (Nickname)
|
|
|
|
* <li> Library Type, used to determine which plugin to load to access the library.
|
|
|
|
* <li> Library URI. The full URI to the library source, form dependent on Type.
|
|
|
|
* <li> Options, used for as yet to be defined information such as user names or passwords
|
|
|
|
* </ul>
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* The Library Type can be one of:
|
|
|
|
* <ul>
|
|
|
|
* <li> "file"
|
|
|
|
* <li> "ftp"
|
|
|
|
* <li> "http"
|
|
|
|
* </ul>
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* For now, the Library URI types needed to support the various types can be one of those
|
|
|
|
* shown below, which are typical of each type:
|
|
|
|
* <ul>
|
|
|
|
* <li> "file://C:/mylibdir"
|
|
|
|
* <li> "ftp://kicad.org/partlib/trunk"
|
|
|
|
* <li> "http://kicad.org/partlib"
|
|
|
|
* </ul>
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* The library table is built up from several additive entries (table fragments), and the
|
|
|
|
* final table is a (conceptual) merging of the table fragments. Two anticipated sources
|
|
|
|
* of the entries are a personal table saved in the KiCad configuration and a project
|
|
|
|
* resident table that resides in project file. The project footprint table entries are
|
|
|
|
* considered a higher priority in the final dynamically assembled library table. An row
|
|
|
|
* in the project file contribution to the library table takes precedence over the personal
|
|
|
|
* table if there is a collision of logical library names. Otherwise, the entries simply
|
|
|
|
* combine without issue to make up the applicable library table.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @author Wayne Stambaugh
|
|
|
|
*/
|
|
|
|
class LIB_TABLE : public PROJECT::_ELEM
|
|
|
|
{
|
2018-07-19 19:15:40 +00:00
|
|
|
friend class PANEL_FP_LIB_TABLE;
|
2017-03-27 23:21:12 +00:00
|
|
|
friend class LIB_TABLE_GRID;
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-03-14 22:54:40 +00:00
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate
|
2017-03-14 22:54:40 +00:00
|
|
|
* #LIB_TABLE_ROW objects.
|
|
|
|
*
|
|
|
|
* @param aLexer is the lexer to parse.
|
|
|
|
*
|
|
|
|
* @throw IO_ERROR if an I/O error occurs during parsing.
|
|
|
|
* @throw PARSER_ERROR if the lexer format to parse is invalid.
|
|
|
|
* @throw boost::bad_pointer if an any attempt to add an invalid pointer to the
|
|
|
|
* boost::ptr_vector.
|
|
|
|
* @throw boost::bad_index if an index outside the row table bounds is accessed.
|
|
|
|
*/
|
|
|
|
virtual void Parse( LIB_TABLE_LEXER* aLexer ) = 0;
|
2016-11-20 02:22:58 +00:00
|
|
|
|
2017-03-14 22:54:40 +00:00
|
|
|
/**
|
2017-06-13 23:47:05 +00:00
|
|
|
* Generate the table in s-expression format to \a aOutput with an indention level
|
2017-03-14 22:54:40 +00:00
|
|
|
* of \a aIndentLevel.
|
|
|
|
*
|
2017-06-13 23:47:05 +00:00
|
|
|
* @param aOutput is the #OUTPUTFORMATTER to format the table into.
|
2017-03-14 22:54:40 +00:00
|
|
|
* @param aIndentLevel is the indentation level (2 spaces) to indent.
|
|
|
|
*
|
|
|
|
* @throw IO_ERROR if an I/O error occurs during output.
|
|
|
|
* @throw boost::interprocess::lock_except if separate process attempt to access the table.
|
|
|
|
*/
|
|
|
|
virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const = 0;
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Build a library table by pre-pending this table fragment in front of \a aFallBackTable.
|
|
|
|
* Loading of this table fragment is done by using Parse().
|
2016-11-20 02:22:58 +00:00
|
|
|
*
|
|
|
|
* @param aFallBackTable is another LIB_TABLE which is searched only when
|
|
|
|
* a row is not found in this table. No ownership is
|
|
|
|
* taken of aFallBackTable.
|
|
|
|
*/
|
2019-02-03 11:44:52 +00:00
|
|
|
LIB_TABLE( LIB_TABLE* aFallBackTable = nullptr );
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
virtual ~LIB_TABLE();
|
|
|
|
|
|
|
|
/// Delete all rows.
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
rows.clear();
|
|
|
|
nickIndex.clear();
|
|
|
|
}
|
|
|
|
|
2019-02-03 11:44:52 +00:00
|
|
|
/**
|
|
|
|
* Compares this table against another.
|
|
|
|
*
|
|
|
|
* This compares the row *contents* against each other.
|
|
|
|
* Any fallback tables are not checked.
|
|
|
|
*/
|
2016-11-20 02:22:58 +00:00
|
|
|
bool operator==( const LIB_TABLE& r ) const
|
|
|
|
{
|
|
|
|
if( rows.size() == r.rows.size() )
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i )
|
|
|
|
;
|
|
|
|
|
|
|
|
if( i == rows.size() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=( const LIB_TABLE& r ) const { return !( *this == r ); }
|
|
|
|
|
2019-02-03 11:44:52 +00:00
|
|
|
/**
|
|
|
|
* Get the number of rows contained in the table
|
|
|
|
*/
|
2019-02-02 21:50:36 +00:00
|
|
|
unsigned GetCount() const
|
2019-02-03 11:44:52 +00:00
|
|
|
{
|
|
|
|
return rows.size();
|
|
|
|
}
|
2016-11-20 02:22:58 +00:00
|
|
|
|
2019-02-03 11:44:52 +00:00
|
|
|
/**
|
2019-02-02 21:50:36 +00:00
|
|
|
* Get the 'n'th #LIB_TABLE_ROW object
|
|
|
|
* @param aIndex index of row (must exist: from 0 to GetCount() - 1)
|
|
|
|
* @return reference to the row
|
2019-02-03 11:44:52 +00:00
|
|
|
*/
|
2019-02-02 21:50:36 +00:00
|
|
|
LIB_TABLE_ROW& At( unsigned aIndex )
|
2019-02-03 11:44:52 +00:00
|
|
|
{
|
2019-02-02 21:50:36 +00:00
|
|
|
return rows[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copydoc At()
|
|
|
|
*/
|
|
|
|
const LIB_TABLE_ROW& At( unsigned aIndex ) const
|
|
|
|
{
|
|
|
|
return rows[aIndex];
|
2019-02-03 11:44:52 +00:00
|
|
|
}
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return true if the table is empty.
|
2016-11-20 02:22:58 +00:00
|
|
|
*
|
|
|
|
* @param aIncludeFallback is used to determine if the fallback table should be
|
|
|
|
* included in the test.
|
|
|
|
*
|
|
|
|
* @return true if the footprint library table is empty.
|
|
|
|
*/
|
|
|
|
bool IsEmpty( bool aIncludeFallback = true );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the library description from @a aNickname, or an empty string
|
|
|
|
* if @a aNickname does not exist.
|
|
|
|
*/
|
|
|
|
const wxString GetDescription( const wxString& aNickname );
|
|
|
|
|
2017-09-01 20:42:20 +00:00
|
|
|
/**
|
|
|
|
* Test for the existence of \a aNickname in the library table.
|
|
|
|
*
|
2018-04-28 09:43:41 +00:00
|
|
|
* @param aCheckEnabled if true will only return true for enabled libraries
|
2017-09-01 20:42:20 +00:00
|
|
|
* @return true if a library \a aNickname exists in the table.
|
|
|
|
*/
|
2018-04-28 09:43:41 +00:00
|
|
|
bool HasLibrary( const wxString& aNickname, bool aCheckEnabled = false ) const;
|
2017-09-01 20:42:20 +00:00
|
|
|
|
2016-11-20 02:22:58 +00:00
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return the logical library names, all of them that are pertinent to
|
2016-11-20 02:22:58 +00:00
|
|
|
* a look up done on this LIB_TABLE.
|
|
|
|
*/
|
|
|
|
std::vector<wxString> GetLogicalLibs();
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
/**
|
|
|
|
* Return the full URI of the library mapped to \a aLibNickname.
|
|
|
|
*/
|
|
|
|
wxString GetFullURI( const wxString& aLibNickname, bool aExpandEnvVars = true ) const;
|
|
|
|
|
2016-11-20 02:22:58 +00:00
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Adds \a aRow if it does not already exist or if doReplace is true. If doReplace
|
2016-11-20 02:22:58 +00:00
|
|
|
* is not true and the key for aRow already exists, the function fails and returns false.
|
|
|
|
*
|
|
|
|
* The key for the table is the nickName, and all in this table must be unique.
|
|
|
|
*
|
|
|
|
* @param aRow is the new row to insert, or to forcibly add if doReplace is true.
|
|
|
|
* @param doReplace if true, means insert regardless of whether aRow's key already
|
|
|
|
* exists. If false, then fail if the key already exists.
|
|
|
|
*
|
|
|
|
* @return bool - true if the operation succeeded.
|
|
|
|
*/
|
|
|
|
bool InsertRow( LIB_TABLE_ROW* aRow, bool doReplace = false );
|
|
|
|
|
2019-04-18 21:00:04 +00:00
|
|
|
/**
|
|
|
|
* Removes a row from the table.
|
|
|
|
* @param aRow is the row to remove
|
|
|
|
* @return true if the row was found (and removed)
|
|
|
|
*/
|
|
|
|
bool RemoveRow( LIB_TABLE_ROW* aRow )
|
|
|
|
{
|
|
|
|
for( auto iter = rows.begin(); iter != rows.end(); ++iter )
|
|
|
|
{
|
|
|
|
if( *iter == *aRow )
|
|
|
|
{
|
|
|
|
rows.erase( iter, iter + 1 );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-20 02:22:58 +00:00
|
|
|
/**
|
|
|
|
* @return a #LIB_TABLE_ROW pointer if \a aURI is found in this table or in any chained
|
|
|
|
* fallBack table fragments, else NULL.
|
|
|
|
*/
|
|
|
|
const LIB_TABLE_ROW* FindRowByURI( const wxString& aURI );
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Load the library table using the path defined by \a aFileName aFallBackTable.
|
2016-11-20 02:22:58 +00:00
|
|
|
*
|
|
|
|
* @param aFileName contains the full path to the s-expression file.
|
|
|
|
*
|
|
|
|
* @throw IO_ERROR if an error occurs attempting to load the footprint library
|
|
|
|
* table.
|
|
|
|
*/
|
2017-06-08 21:47:21 +00:00
|
|
|
void Load( const wxString& aFileName );
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Write this library table to \a aFileName in s-expression form.
|
2016-11-20 02:22:58 +00:00
|
|
|
*
|
|
|
|
* @param aFileName is the name of the file to write to.
|
|
|
|
*/
|
2017-06-08 21:47:21 +00:00
|
|
|
void Save( const wxString& aFileName ) const;
|
2016-11-20 02:22:58 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Parses \a aOptionsList and places the result into a #PROPERTIES object which is
|
2016-11-20 02:22:58 +00:00
|
|
|
* returned. If the options field is empty, then the returned PROPERTIES will be
|
|
|
|
* a NULL pointer.
|
2017-09-02 18:12:50 +00:00
|
|
|
*
|
2016-11-20 02:22:58 +00:00
|
|
|
* <p>
|
|
|
|
* Typically aOptionsList comes from the "options" field within a LIB_TABLE_ROW and
|
|
|
|
* the format is simply a comma separated list of name value pairs. e.g.:
|
|
|
|
* [name1[=value1][|name2[=value2]]] etc. When using the UI to create or edit
|
|
|
|
* a library table, this formatting is handled for you.
|
|
|
|
* </p>
|
|
|
|
*/
|
|
|
|
static PROPERTIES* ParseOptions( const std::string& aOptionsList );
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Returns a list of options from the aProperties parameter.
|
2016-11-20 02:22:58 +00:00
|
|
|
*
|
2017-09-02 18:12:50 +00:00
|
|
|
* The name=value pairs will be separated with the '|' character. The =value portion may
|
|
|
|
* not be present. You might expect something like "name1=value1|name2=value2|flag_me".
|
2016-11-20 02:22:58 +00:00
|
|
|
* Notice that flag_me does not have a value. This is ok.
|
|
|
|
*
|
|
|
|
* @param aProperties is the PROPERTIES to format or NULL. If NULL the returned
|
|
|
|
* string will be empty.
|
|
|
|
*/
|
|
|
|
static UTF8 FormatOptions( const PROPERTIES* aProperties );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* Return a #LIB_TABLE_ROW if \a aNickname is found in this table or in any chained
|
2016-11-20 02:22:58 +00:00
|
|
|
* fallBack table fragment, else NULL.
|
|
|
|
*/
|
|
|
|
LIB_TABLE_ROW* findRow( const wxString& aNickname ) const;
|
|
|
|
|
|
|
|
void reindex()
|
|
|
|
{
|
|
|
|
nickIndex.clear();
|
|
|
|
|
|
|
|
for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
|
|
|
|
nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ensureIndex()
|
|
|
|
{
|
|
|
|
// The dialog lib table editor may not maintain the nickIndex.
|
|
|
|
// Lazy indexing may be required. To handle lazy indexing, we must enforce
|
|
|
|
// that "nickIndex" is either empty or accurate, but never inaccurate.
|
|
|
|
if( !nickIndex.size() )
|
|
|
|
reindex();
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_TABLE_ROWS rows;
|
|
|
|
|
|
|
|
/// this is a non-owning index into the LIB_TABLE_ROWS table
|
|
|
|
typedef std::map<wxString,int> INDEX; // "int" is std::vector array index
|
|
|
|
typedef INDEX::iterator INDEX_ITER;
|
|
|
|
typedef INDEX::const_iterator INDEX_CITER;
|
|
|
|
typedef INDEX::value_type INDEX_VALUE;
|
|
|
|
|
|
|
|
/// this particular key is the nickName within each row.
|
|
|
|
INDEX nickIndex;
|
|
|
|
|
|
|
|
LIB_TABLE* fallBack;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _LIB_TABLE_BASE_H_
|