2011-11-11 20:10:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file class_library.h
|
|
|
|
* @brief Definition for component library class.
|
|
|
|
*/
|
2008-09-13 18:59:57 +00:00
|
|
|
|
|
|
|
#ifndef CLASS_LIBRARY_H
|
|
|
|
#define CLASS_LIBRARY_H
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
#include <wx/filename.h>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_libentry.h>
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
class LINE_READER;
|
2011-11-01 15:06:26 +00:00
|
|
|
class OUTPUTFORMATTER;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
/*
|
|
|
|
* Component Library version and file header macros.
|
|
|
|
*/
|
|
|
|
#define LIB_VERSION_MAJOR 2
|
|
|
|
#define LIB_VERSION_MINOR 3
|
|
|
|
|
|
|
|
/* Must be the first line of component library (.lib) files. */
|
|
|
|
#define LIBFILE_IDENT "EESchema-LIBRARY Version"
|
|
|
|
|
|
|
|
#define LIB_VERSION( major, minor ) ( major * 100 + minor )
|
|
|
|
|
|
|
|
#define IS_LIB_CURRENT_VERSION( major, minor ) \
|
|
|
|
( \
|
|
|
|
LIB_VERSION( major1, minor1 ) == \
|
|
|
|
LIB_VERSION( LIB_VERSION_MAJOR, LIB_VERSION_MINOR) \
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Library versions 2.3 and lower use the old separate library (.lib) and
|
|
|
|
* document (.dcm) files. Component libraries after 2.3 merged the library
|
|
|
|
* and document files into a single library file. This macro checks if the
|
|
|
|
* library version supports the old format
|
|
|
|
*/
|
|
|
|
#define USE_OLD_DOC_FILE_FORMAT( major, minor ) \
|
|
|
|
( LIB_VERSION( major, minor ) <= LIB_VERSION( 2, 3 ) )
|
|
|
|
|
|
|
|
/* Must be the first line of component library document (.dcm) files. */
|
|
|
|
#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0"
|
|
|
|
|
|
|
|
#define DOC_EXT wxT( "dcm" )
|
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/* Helpers for creating a list of component libraries. */
|
|
|
|
class CMP_LIBRARY;
|
2009-10-08 13:19:28 +00:00
|
|
|
class wxRegEx;
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
typedef boost::ptr_vector< CMP_LIBRARY > CMP_LIBRARY_LIST;
|
|
|
|
|
|
|
|
extern bool operator<( const CMP_LIBRARY& item1, const CMP_LIBRARY& item2 );
|
|
|
|
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Class CMP_LIBRARY
|
|
|
|
* is used to load, save, search, and otherwise manipulate
|
2009-09-02 18:12:45 +00:00
|
|
|
* component library files.
|
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
class CMP_LIBRARY
|
2008-09-13 18:59:57 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
int type; ///< Library type indicator.
|
|
|
|
wxFileName fileName; ///< Library file name.
|
|
|
|
wxDateTime timeStamp; ///< Library save time and date.
|
|
|
|
int versionMajor; ///< Library major version number.
|
|
|
|
int versionMinor; ///< Library minor version number.
|
|
|
|
bool isCache; /**< False for the "standard" libraries,
|
|
|
|
True for the library cache */
|
|
|
|
wxString header; ///< first line of loaded library.
|
|
|
|
bool isModified; ///< Library modification status.
|
|
|
|
LIB_ALIAS_MAP aliases; ///< Map of aliases objects associated with the library.
|
2009-12-22 20:08:56 +00:00
|
|
|
|
|
|
|
static CMP_LIBRARY_LIST libraryList;
|
|
|
|
static wxArrayString libraryListSortOrder;
|
|
|
|
|
2010-09-09 17:37:25 +00:00
|
|
|
friend class LIB_COMPONENT;
|
2009-12-22 20:08:56 +00:00
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
public:
|
2009-12-15 21:11:05 +00:00
|
|
|
CMP_LIBRARY( int aType, const wxFileName& aFileName );
|
|
|
|
CMP_LIBRARY( int aType, const wxString& aFileName )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
CMP_LIBRARY( aType, wxFileName( aFileName ) );
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
~CMP_LIBRARY();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-09-18 17:10:54 +00:00
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function Save
|
2011-11-11 20:10:24 +00:00
|
|
|
* writes library to \a aFormatter.
|
2009-09-25 18:49:04 +00:00
|
|
|
*
|
2011-11-11 20:10:24 +00:00
|
|
|
* @param aFormatter An #OUTPUTFORMATTER object to write the library to.
|
|
|
|
* @return True if success writing to \a aFormatter.
|
2009-09-25 18:49:04 +00:00
|
|
|
*/
|
2011-11-11 20:10:24 +00:00
|
|
|
bool Save( OUTPUTFORMATTER& aFormatter );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
/**
|
2011-11-11 20:10:24 +00:00
|
|
|
* Function SaveDocs
|
|
|
|
* write the library document information to \a aFormatter.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
2011-11-11 20:10:24 +00:00
|
|
|
* @param aFormatter An #OUTPUTFORMATTER object to write the library documentation to.
|
|
|
|
* @return True if success writing to \a aFormatter.
|
2008-09-18 17:10:54 +00:00
|
|
|
*/
|
2011-11-11 20:10:24 +00:00
|
|
|
bool SaveDocs( OUTPUTFORMATTER& aFormatter );
|
2008-09-18 17:10:54 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/**
|
|
|
|
* Load library from file.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aErrorMsg - Error message if load fails.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return True if load was successful otherwise false.
|
2009-09-02 18:12:45 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
bool Load( wxString& aErrorMsg );
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LoadDocs( wxString& aErrorMsg );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-09-18 17:10:54 +00:00
|
|
|
private:
|
2011-11-01 15:06:26 +00:00
|
|
|
bool SaveHeader( OUTPUTFORMATTER& aFormatter );
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
bool LoadHeader( LINE_READER& aLineReader );
|
2009-12-15 21:11:05 +00:00
|
|
|
void LoadAliases( LIB_COMPONENT* aComponent );
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
public:
|
2009-08-27 11:41:56 +00:00
|
|
|
/**
|
|
|
|
* Get library entry status.
|
|
|
|
*
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return True if there are no entries in the library.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
bool IsEmpty() const
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
return aliases.empty();
|
2009-09-02 18:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function GetCount
|
|
|
|
* returns the number of entries in the library.
|
2009-09-02 18:12:45 +00:00
|
|
|
*
|
|
|
|
* @return The number of component and alias entries.
|
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
int GetCount() const
|
2009-09-02 18:12:45 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
return aliases.size();
|
2009-09-02 18:12:45 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
bool IsModified() const
|
2009-09-02 18:12:45 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return isModified;
|
2009-08-27 11:41:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool IsCache() const { return isCache; }
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void SetCache( void ) { isCache = true; }
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
/**
|
|
|
|
* Function IsReadOnly
|
|
|
|
* @return true if current user does not have write access to the library file.
|
|
|
|
*/
|
|
|
|
bool IsReadOnly() const { return !fileName.IsFileWritable(); }
|
|
|
|
|
|
|
|
/**
|
2009-08-27 11:41:56 +00:00
|
|
|
* Load a string array with the names of all the entries in this library.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aNames - String array to place entry names into.
|
|
|
|
* @param aSort - Sort names if true.
|
|
|
|
* @param aMakeUpperCase - Force entry names to upper case.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
void GetEntryNames( wxArrayString& aNames, bool aSort = true,
|
2011-08-12 17:43:16 +00:00
|
|
|
bool aMakeUpperCase =
|
2014-01-29 18:02:02 +00:00
|
|
|
#ifdef KICAD_KEEPCASE
|
2010-10-22 15:02:11 +00:00
|
|
|
false
|
2014-01-29 18:02:02 +00:00
|
|
|
#else
|
|
|
|
true
|
2010-10-22 15:02:11 +00:00
|
|
|
#endif
|
|
|
|
);
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load string array with entry names matching name and/or key word.
|
|
|
|
*
|
|
|
|
* This currently mimics the old behavior of calling KeyWordOk() and
|
|
|
|
* WildCompareString(). The names array will be populated with the
|
|
|
|
* library entry names that meat the search criteria on exit.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aNames - String array to place entry names into.
|
|
|
|
* @param aNameSearch - Name wild card search criteria.
|
|
|
|
* @param aKeySearch - Key word search criteria.
|
|
|
|
* @param aSort - Sort names if true.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2013-03-19 01:25:19 +00:00
|
|
|
void SearchEntryNames( std::vector<wxArrayString>& aNames,
|
2009-12-15 21:11:05 +00:00
|
|
|
const wxString& aNameSearch = wxEmptyString,
|
|
|
|
const wxString& aKeySearch = wxEmptyString,
|
|
|
|
bool aSort = true );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
/**
|
|
|
|
* Find components in library by key word regular expression search.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aNames - String array to place found component names into.
|
2010-09-09 17:37:25 +00:00
|
|
|
* @param aRe - Regular expression used to search component key words.
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aSort - Sort component name list.
|
2009-10-08 13:19:28 +00:00
|
|
|
*/
|
2010-10-04 18:54:14 +00:00
|
|
|
void SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe, bool aSort = true );
|
2009-10-08 13:19:28 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/**
|
2010-10-04 18:54:14 +00:00
|
|
|
* Checks \a aComponent for name conflict in the library.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
2010-10-04 18:54:14 +00:00
|
|
|
* @param aComponent - The component to check.
|
2010-12-14 15:56:30 +00:00
|
|
|
* @return True if a conflict exists. Otherwise false.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2010-10-04 18:54:14 +00:00
|
|
|
bool Conflicts( LIB_COMPONENT* aComponent );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-04 18:54:14 +00:00
|
|
|
* Find entry by name.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aName - Name of entry, case insensitive.
|
|
|
|
* @return Entry if found. NULL if not found.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2014-01-18 09:07:05 +00:00
|
|
|
LIB_ALIAS* FindEntry( const wxString& aName );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
/**
|
2010-09-09 17:37:25 +00:00
|
|
|
* Find component by \a aName.
|
2009-09-14 13:24:17 +00:00
|
|
|
*
|
2010-10-25 15:43:42 +00:00
|
|
|
* This is a helper for FindEntry so casting a LIB_ALIAS pointer to
|
2009-09-18 14:56:05 +00:00
|
|
|
* a LIB_COMPONENT pointer is not required.
|
2009-09-14 13:24:17 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aName - Name of component, case insensitive.
|
|
|
|
* @return Component if found. NULL if not found.
|
2009-09-14 13:24:17 +00:00
|
|
|
*/
|
2014-01-18 09:07:05 +00:00
|
|
|
LIB_COMPONENT* FindComponent( const wxString& aName );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
/**
|
2010-09-09 17:37:25 +00:00
|
|
|
* Find alias by \a nName.
|
2009-09-14 13:24:17 +00:00
|
|
|
*
|
2010-10-25 15:43:42 +00:00
|
|
|
* This is a helper for FindEntry so casting a LIB_ALIAS pointer to
|
2009-09-18 14:56:05 +00:00
|
|
|
* a LIB_ALIAS pointer is not required.
|
2009-09-14 13:24:17 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aName - Name of alias, case insensitive.
|
|
|
|
* @return Alias if found. NULL if not found.
|
2009-09-14 13:24:17 +00:00
|
|
|
*/
|
2014-01-18 09:07:05 +00:00
|
|
|
LIB_ALIAS* FindAlias( const wxString& aName )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
return (LIB_ALIAS*) FindEntry( aName );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-09-09 17:37:25 +00:00
|
|
|
* Add a new \a aAlias entry to the library.
|
2009-09-14 13:24:17 +00:00
|
|
|
*
|
|
|
|
* First check if a component or alias with the same name already exists
|
|
|
|
* in the library and add alias if no conflict occurs. Once the alias
|
|
|
|
* is added to the library it is owned by the library. Deleting the
|
|
|
|
* alias pointer will render the library unstable. Use RemoveEntry to
|
|
|
|
* remove the alias from the library.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aAlias - Alias to add to library.
|
|
|
|
* @return True if alias added to library. False if a conflict exists.
|
2009-09-14 13:24:17 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
bool AddAlias( LIB_ALIAS* aAlias );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/**
|
2010-09-09 17:37:25 +00:00
|
|
|
* Add \a aComponent entry to library.
|
2010-02-13 13:16:09 +00:00
|
|
|
* Note a component can have an alias list,
|
|
|
|
* so these alias will be added in library.
|
|
|
|
* Conflicts can happen if aliases are already existing.
|
|
|
|
* User is asked to choose what alias is removed (existing, or new)
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aComponent - Component to add.
|
|
|
|
* @return Added component if successful.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_COMPONENT* AddComponent( LIB_COMPONENT* aComponent );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-04 18:54:14 +00:00
|
|
|
* Safely remove \a aEntry from the library and return the next entry.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
2010-10-04 18:54:14 +00:00
|
|
|
* The next entry returned depends on the entry being removed. If the entry being
|
|
|
|
* remove also removes the component, then the next entry from the list is returned.
|
|
|
|
* If the entry being used only removes an alias from a component, then the next alias
|
|
|
|
* of the component is returned.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aEntry - Entry to remove from library.
|
2010-10-04 18:54:14 +00:00
|
|
|
* @return The next entry in the library or NULL if the library is empty.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* RemoveEntry( LIB_ALIAS* aEntry );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
/**
|
|
|
|
* Replace an existing component entry in the library.
|
2010-02-13 13:16:09 +00:00
|
|
|
* Note a component can have an alias list,
|
|
|
|
* so these alias will be added in library (and previously existing alias removed)
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aOldComponent - The component to replace.
|
|
|
|
* @param aNewComponent - The new component.
|
2009-09-14 13:24:17 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_COMPONENT* ReplaceComponent( LIB_COMPONENT* aOldComponent,
|
|
|
|
LIB_COMPONENT* aNewComponent );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
/**
|
|
|
|
* Return the first entry in the library.
|
|
|
|
*
|
|
|
|
* @return The first entry or NULL if the library has no entries.
|
|
|
|
*/
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* GetFirstEntry();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
/**
|
2010-09-09 17:37:25 +00:00
|
|
|
* Find next library entry by \a aName.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
|
|
|
* If the name of the entry is the last entry in the library, the first
|
|
|
|
* entry in the list is returned.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aName - Name of current entry.
|
|
|
|
* @return Next entry if entry name is found. Otherwise NULL.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2014-01-18 09:07:05 +00:00
|
|
|
LIB_ALIAS* GetNextEntry( const wxString& aName );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-09 17:37:25 +00:00
|
|
|
* Find previous library entry by \a aName.
|
2009-08-27 11:41:56 +00:00
|
|
|
*
|
|
|
|
* If the name of the entry is the first entry in the library, the last
|
|
|
|
* entry in the list is returned.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aName - Name of current entry.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return Previous entry if entry name is found, otherwise NULL.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2014-01-18 09:07:05 +00:00
|
|
|
LIB_ALIAS* GetPreviousEntry( const wxString& aName );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the file name without path or extension.
|
|
|
|
*
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return Name of library file.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
wxString GetName() const { return fileName.GetName(); }
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function GetFullFileName
|
|
|
|
* returns the full file library name with path and extension.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2010-07-31 23:57:36 +00:00
|
|
|
* @return wxString - Full library file name with path and extension.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
wxString GetFullFileName() { return fileName.GetFullPath(); }
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function GetLogicalName
|
2010-08-04 19:14:51 +00:00
|
|
|
* returns the logical name of the library.
|
|
|
|
* @return wxString - The logical name of this library.
|
2010-07-31 23:57:36 +00:00
|
|
|
*/
|
2010-08-04 19:14:51 +00:00
|
|
|
wxString GetLogicalName()
|
|
|
|
{
|
|
|
|
/* for now is the filename without path or extension.
|
|
|
|
|
|
|
|
Technically the library should not know its logical name!
|
|
|
|
This will eventually come out of a pair of lookup tables using a
|
|
|
|
reverse lookup using the full name or library pointer as a key.
|
|
|
|
Search will be by project lookup table and then user lookup table if
|
|
|
|
not found.
|
|
|
|
*/
|
|
|
|
return fileName.GetName();
|
|
|
|
}
|
2010-07-31 23:57:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetFileName
|
|
|
|
* sets the component library file name.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aFileName - New library file name.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
void SetFileName( const wxFileName aFileName )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aFileName != fileName )
|
|
|
|
fileName = aFileName;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following static methods are for manipulating the list of
|
|
|
|
* component libraries. This eliminates the need for yet another
|
|
|
|
* global variable ( formerly g_LibraryList ) and gives some measure
|
|
|
|
* of safety from abusing the library list.
|
|
|
|
*/
|
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
/**
|
|
|
|
* Function LibraryExists
|
|
|
|
* tests for existence of a library.
|
2009-12-22 20:08:56 +00:00
|
|
|
*
|
|
|
|
* @param aLibptr - aLibptr.
|
2010-07-31 23:57:36 +00:00
|
|
|
* @return bool - true if exists, else false
|
2009-12-22 20:08:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static bool LibraryExists( const CMP_LIBRARY* aLibptr );
|
2010-07-31 23:57:36 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function LoadLibrary
|
|
|
|
* loads a component library file.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aFileName - File name of the component library to load.
|
|
|
|
* @param aErrorMsg - Error message if the component library failed to load.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return Library object if library file loaded successfully,
|
|
|
|
* otherwise NULL.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2010-10-04 18:54:14 +00:00
|
|
|
static CMP_LIBRARY* LoadLibrary( const wxFileName& aFileName, wxString& aErrorMsg );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function AddLibrary
|
2010-09-09 17:37:25 +00:00
|
|
|
* adds a component library to the library list.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aFileName - File name object of component library.
|
|
|
|
* @param aErrorMsg - Error message if the component library failed to load.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return True if library loaded properly otherwise false.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
static bool AddLibrary( const wxFileName& aFileName, wxString& aErrorMsg );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function AddLibrary
|
2010-09-09 17:37:25 +00:00
|
|
|
* inserts a component library into the library list.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aFileName - File name object of component library.
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aErrorMsg - Error message if the component library failed to load.
|
|
|
|
* @param aIterator - Iterator to insert library in front of.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return True if library loaded properly otherwise false.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
static bool AddLibrary( const wxFileName& aFileName, wxString& aErrorMsg,
|
|
|
|
CMP_LIBRARY_LIST::iterator& aIterator );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function RemoveLibrary
|
|
|
|
* removes a component library from the library list.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aName - Name of component library to remove.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
static void RemoveLibrary( const wxString& aName );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
static void RemoveAllLibraries() { libraryList.clear(); }
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function FindLibrary
|
|
|
|
* finds a component library by \a aName.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aName - Library file name without path or extension to find.
|
|
|
|
* @return Component library if found, otherwise NULL.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
static CMP_LIBRARY* FindLibrary( const wxString& aName );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function GetLibraryNames
|
|
|
|
* returns the list of component library file names without path and extension.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aSorted - Sort the list of name if true. Otherwise use the
|
|
|
|
* library load order.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return The list of library names.
|
2009-08-27 11:41:56 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
static wxArrayString GetLibraryNames( bool aSorted = true );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function FindLibraryComponent
|
|
|
|
* searches all libraries in the list for a component.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
|
|
|
* A component object will always be returned. If the entry found
|
|
|
|
* is an alias. The root component will be found and returned.
|
|
|
|
*
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aComponentName - Name of component to search for.
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aLibraryName - Name of the library to search for component.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return The component object if found, otherwise NULL.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
static LIB_COMPONENT* FindLibraryComponent( const wxString& aComponentName,
|
|
|
|
const wxString& aLibraryName = wxEmptyString );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function FindLibraryEntry
|
|
|
|
* searches all libraries in the list for an entry.
|
2009-09-18 14:56:05 +00:00
|
|
|
*
|
|
|
|
* The object can be either a component or an alias.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aEntryName - Name of entry to search for.
|
|
|
|
* @param aLibraryName - Name of the library to search.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @return The entry object if found, otherwise NULL.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2010-10-25 15:43:42 +00:00
|
|
|
static LIB_ALIAS* FindLibraryEntry( const wxString& aEntryName,
|
|
|
|
const wxString& aLibraryName = wxEmptyString );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 23:57:36 +00:00
|
|
|
* Function RemoveCacheLibrary
|
|
|
|
* removes all cache libraries from library list.
|
2009-09-18 14:56:05 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
static void RemoveCacheLibrary();
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
static int GetLibraryCount() { return libraryList.size(); }
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
static CMP_LIBRARY_LIST& GetLibraryList()
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return libraryList;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
static void SetSortOrder( const wxArrayString& aSortOrder )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
libraryListSortOrder = aSortOrder;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static wxArrayString& GetSortOrder( void )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return libraryListSortOrder;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
2008-09-13 18:59:57 +00:00
|
|
|
};
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Case insensitive library name comparison.
|
|
|
|
*/
|
2014-01-18 09:07:05 +00:00
|
|
|
extern bool operator==( const CMP_LIBRARY& aLibrary, const wxString& aName );
|
|
|
|
extern bool operator!=( const CMP_LIBRARY& aLibrary, const wxString& aName );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
#endif // CLASS_LIBRARY_H
|