Eeschema: implement schematic I/O plugin symbol library parser.

* Write SCH_LEGACY_PLUGIN_CACHE object for handling the legacy symbol library
  file format.

* Write legacy symbol library file parser.

* Write code to transfer cache to PART_LIB object so existing library save
  code can be used for round trip testing.  This is temporary until Eeschema
  is updated to use the plugin for library management rather than PART_LIB.

* Add LIB_XXXX object helper functions where there was no way to set the member
  variables of an object.

* Give the cache object friend status to some object where there are incredibly
  byzantine ways of setting text in LIB_XXXX objects.
This commit is contained in:
Wayne Stambaugh 2016-08-18 19:23:10 -04:00
parent cac571c056
commit eaa7f3f114
13 changed files with 1383 additions and 33 deletions

View File

@ -304,7 +304,12 @@ void LIB_PART::SetName( const wxString& aName )
{
m_name = aName;
GetValueField().SetText( aName );
m_aliases[0]->SetName( aName );
// The LIB_ALIAS that is the LIB_PART name has to be created so create it.
if( m_aliases.size() == 0 )
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
else
m_aliases[0]->SetName( aName );
}

View File

@ -184,6 +184,7 @@ class LIB_PART : public EDA_ITEM
{
friend class PART_LIB;
friend class LIB_ALIAS;
friend class SCH_LEGACY_PLUGIN_CACHE;
PART_SPTR m_me; ///< http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
wxString m_name;
@ -240,6 +241,8 @@ public:
PART_LIB* GetLib() { return m_library; }
void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
size_t GetAliasCount() const { return m_aliases.size(); }

View File

@ -42,6 +42,7 @@
#include <general.h>
#include <class_library.h>
#include <sch_legacy_plugin.h>
#include <wx/tokenzr.h>
#include <wx/regex.h>
@ -710,10 +711,18 @@ PART_LIB* PART_LIB::LoadLibrary( const wxString& aFileName ) throw( IO_ERROR, bo
{
std::unique_ptr<PART_LIB> lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, aFileName ) );
wxBusyCursor ShowWait;
wxBusyCursor ShowWait; // Do we want UI elements in PART_LIB?
wxString errorMsg;
#ifdef USE_SCH_IO_MANAGER
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
wxArrayString tmp;
pi->EnumerateSymbolLib( tmp, aFileName );
pi->TransferCache( *lib.get() );
#else
if( !lib->Load( errorMsg ) )
THROW_IO_ERROR( errorMsg );
@ -727,6 +736,7 @@ PART_LIB* PART_LIB::LoadLibrary( const wxString& aFileName ) throw( IO_ERROR, bo
THROW_IO_ERROR( errorMsg );
#endif
}
#endif
PART_LIB* ret = lib.release();
@ -742,6 +752,7 @@ PART_LIB* PART_LIBS::AddLibrary( const wxString& aFileName ) throw( IO_ERROR, bo
wxFileName fn = aFileName;
// Don't reload the library if it is already loaded.
lib = FindLibrary( fn.GetName() );
if( lib )
return lib;
#endif
@ -1061,6 +1072,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject ) throw( IO_ERROR, boost::ba
try
{
cache_lib = AddLibrary( cache_name );
if( cache_lib )
cache_lib->SetCache();
}

View File

@ -41,6 +41,7 @@
class LINE_READER;
class OUTPUTFORMATTER;
class SCH_LEGACY_PLUGIN;
/*
@ -353,6 +354,7 @@ class PART_LIB
friend class LIB_PART;
friend class PART_LIBS;
friend class SCH_LEGACY_PLUGIN;
public:
PART_LIB( int aType, const wxString& aFileName );

View File

@ -137,6 +137,22 @@ public:
void SetWidth( int aWidth ) { m_Width = aWidth; }
void SetRadius( int aRadius ) { m_Radius = aRadius; }
int GetRadius() const { return m_Radius; }
void SetFirstRadiusAngle( int aAngle ) { m_t1 = aAngle; }
int GetFirstRadiusAngle() const { return m_t1; }
void SetSecondRadiusAngle( int aAngle ) { m_t2 = aAngle; }
int GetSecondRadiusAngle() const { return m_t2; }
void SetStart( const wxPoint& aPoint ) { m_ArcStart = aPoint; }
void SetEnd( const wxPoint& aPoint ) { m_ArcEnd = aPoint; }
wxString GetSelectMenuText() const;
BITMAP_DEF GetMenuImage() const { return add_arc_xpm; }

View File

@ -63,7 +63,7 @@ public:
bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
void AddPoint( const wxPoint& aPoint );
void AddPoint( const wxPoint& aPoint ) { m_BezierPoints.push_back( aPoint ); }
void SetOffset( const wxPoint& aOffset );

View File

@ -98,6 +98,10 @@ public:
void SetWidth( int aWidth ) { m_Width = aWidth; }
void SetRadius( int aRadius ) { m_Radius = aRadius; }
int GetRadius() const { return m_Radius; }
wxString GetSelectMenuText() const;
BITMAP_DEF GetMenuImage() const { return add_circle_xpm; }

View File

@ -33,6 +33,9 @@
#include <lib_draw_item.h>
class SCH_LEGACY_PLUGIN_CACHE;
/**
* Class LIB_FIELD
* is used in symbol libraries. At least MANDATORY_FIELDS are always present
@ -81,6 +84,8 @@ class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
*/
void calcEdit( const wxPoint& aPosition );
friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
public:
LIB_FIELD( int idfield = 2 );

View File

@ -102,6 +102,10 @@ public:
void SetWidth( int aWidth ) { m_Width = aWidth; }
void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
wxPoint GetEnd() const { return m_End; }
wxString GetSelectMenuText() const;
BITMAP_DEF GetMenuImage() const { return add_rectangle_xpm; }

View File

@ -32,6 +32,7 @@ class SCH_SCREEN;
class SCH_PLUGIN;
class KIWAY;
class LIB_PART;
class PART_LIB;
class PROPERTIES;
@ -253,24 +254,26 @@ public:
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolEnumerate
* returns a list of symbol names contained within the library at @a aLibraryPath.
* Function EnumerateSymbolLib
* returns a list of #LIB_PART alias names contained within the library @a aLibraryPath.
*
* @param aAliasNameList is an array to populate with the #LIB_ALIAS names associated with
* the library.
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
* or URL containing one or more #LIB_PART objects.
* @param aProperties is an associative array that can be used to tell the plugin anything
* needed about how to perform with respect to @a aLibraryPath. The
* caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @param aProperties is an associative array that can be used to tell the
* plugin anything needed about how to perform with respect to @a aLibraryPath.
* The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @return wxArrayString - is the array of available footprint names inside
* a library
*
* @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
* @throw IO_ERROR if the library cannot be found, the part library cannot be loaded.
*/
virtual wxArrayString SymbolEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
virtual void EnumerateSymbolLib( wxArrayString& aAliasNameList,
const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
// Temporary for testing using PART_LIB instead of SCH_PLUGIN.
virtual void TransferCache( PART_LIB& aTarget );
/**
* Function SymbolLoad

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,9 @@ class SCH_TEXT;
class SCH_COMPONENT;
class SCH_FIELD;
class PROPERTIES;
class SCH_LEGACY_PLUGIN_CACHE;
class LIB_PART;
class PART_LIB;
/**
@ -58,6 +61,9 @@ class SCH_LEGACY_PLUGIN : public SCH_PLUGIN
{
public:
SCH_LEGACY_PLUGIN();
virtual ~SCH_LEGACY_PLUGIN() {}
const wxString GetName() const
{
return wxT( "Eeschema-Legacy" );
@ -76,10 +82,12 @@ public:
void Format( SCH_SCREEN* aScreen );
//-----</PLUGIN IMPLEMENTATION>---------------------------------------------
void EnumerateSymbolLib( wxArrayString& aAliasNameList,
const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
SCH_LEGACY_PLUGIN();
virtual ~SCH_LEGACY_PLUGIN() {}
// Temporary for testing using PART_LIB instead of SCH_PLUGIN.
void TransferCache( PART_LIB& aTarget );
private:
void loadHierarchy( SCH_SHEET* aSheet );
@ -105,6 +113,8 @@ private:
void saveLine( SCH_LINE* aLine );
void saveText( SCH_TEXT* aText );
void cacheLib( const wxString& aLibraryFileName );
protected:
int m_version; ///< Version of file being loaded.
wxString m_error; ///< For throwing exceptions
@ -113,6 +123,7 @@ protected:
KIWAY* m_kiway; ///< Required for path to legacy component libraries.
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
FILE_OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects.
SCH_LEGACY_PLUGIN_CACHE* m_cache;
/// initialize PLUGIN like a constructor would.
void init( KIWAY* aKiway, const PROPERTIES* aProperties = NULL );

View File

@ -58,12 +58,19 @@ void SCH_PLUGIN::Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY*
}
wxArrayString SCH_PLUGIN::SymbolEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
void SCH_PLUGIN::EnumerateSymbolLib( wxArrayString& aAliasNameList,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
}
void SCH_PLUGIN::TransferCache( PART_LIB& aTarget )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
return wxArrayString();
}