Commit ec7f26f5 authored by Dick Hollenbeck's avatar Dick Hollenbeck

FP_LIB_TABLE::ROW::SetFullURI() does environment variable substitution up front.

We can now remove a few calls to FP_LIB_TABLE::ExpandSubstitutions( const wxString& aString )
since its being done in above function.

DIALOG_FP_LIB_TABLE now handles table to copy cut copy paste from global to
project and reverse.  Fixed a problem with cursor position management when
switching between tables.
parent 248788f3
......@@ -51,6 +51,13 @@ void FP_LIB_TABLE::ROW::SetType( const wxString& aType )
}
void FP_LIB_TABLE::ROW::SetFullURI( const wxString& aFullURI )
{
uri_user = aFullURI;
uri_expanded = FP_LIB_TABLE::ExpandSubstitutions( aFullURI );
}
FP_LIB_TABLE::FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable ) :
fallBack( aFallBackTable )
{
......@@ -407,7 +414,7 @@ const FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRowByURI( const wxString& aURI )
for( unsigned i = 0; i < cur->rows.size(); i++ )
{
wxString uri = ExpandSubstitutions( cur->rows[i].GetFullURI() );
wxString uri = cur->rows[i].GetFullURI( true );
if( wxFileName::GetPathSeparator() == wxChar( '\\' ) && uri.Find( wxChar( '/' ) ) >= 0 )
uri.Replace( wxT( "/" ), wxT( "\\" ) );
......@@ -461,16 +468,17 @@ const FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const wxString& aLibraryNickName
THROW_IO_ERROR( msg );
}
/* enable this when FP_LIB_TABLE::Footprint*() functions are put into use.
#if 0 // enable this as soon as FP_LIB_TABLE::FindRow() is not being used outside
// this class, and FP_LIB_TABLE::Footprint*() functions are put into use.
if( !row->plugin )
row->setPlugin( IO_MGR::PluginFind( row->type ) );
*/
#endif
return row;
}
const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString aString )
const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString& aString )
{
// We reserve the right to do this another way, by providing our own member
// function.
......@@ -604,7 +612,7 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
for( unsigned i = 0; i < cur->rows.size(); i++ )
{
wxString uri = ExpandSubstitutions( cur->rows[i].GetFullURI() );
wxString uri = cur->rows[i].GetFullURI( true );
if( wxFileName::GetPathSeparator() == wxChar( '\\' )
&& uri.Find( wxChar( '/' ) ) >= 0 )
......@@ -616,6 +624,7 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
break;
}
}
} while( ( cur = cur->fallBack ) != 0 && libNickname.IsEmpty() );
if( libNickname.IsEmpty() )
......
......@@ -112,17 +112,18 @@ public:
ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
const wxString& aOptions, const wxString& aDescr = wxEmptyString ) :
nickName( aNick ),
uri( aURI ),
options( aOptions ),
description( aDescr ),
properties( 0 )
{
SetOptions( aOptions ),
SetFullURI( aURI );
SetType( aType );
}
ROW( const ROW& a ) :
nickName( a.nickName ),
uri( a.uri ),
uri_user( a.uri_user ),
uri_expanded( a.uri_expanded ),
type( a.type ),
options( a.options ),
description( a.description ),
......@@ -139,22 +140,23 @@ public:
ROW& operator=( const ROW& r )
{
nickName = r.nickName;
uri = r.uri;
type = r.type;
options = r.options;
nickName = r.nickName;
uri_user = r.uri_user;
uri_expanded = r.uri_expanded;
type = r.type;
options = r.options;
description = r.description;
properties = r.properties ? new PROPERTIES( *r.properties ) : NULL;
description = r.description;
properties = r.properties ? new PROPERTIES( *r.properties ) : NULL;
setPlugin( NULL ); // do not copy the PLUGIN, it is lazily created.
// do not copy the PLUGIN, it is lazily created.
// setPlugin( NULL );
return *this;
}
bool operator==( const ROW& r ) const
{
return nickName==r.nickName && uri==r.uri && type==r.type && options==r.options;
return nickName==r.nickName && uri_user==r.uri_user && type==r.type && options==r.options;
}
bool operator!=( const ROW& r ) const { return !( *this == r ); }
......@@ -187,23 +189,24 @@ public:
/**
* Function GetFullURI
* returns the full location specifying URI for the LIB.
* returns the full location specifying URI for the LIB, either in original
* UI form or in environment variable expanded form.
*
* @param doEnvVarSubs tells this function to do the substitution, else not.
* @param aSubstituted Tells if caller wanted the substituted form, else not.
*/
const wxString GetFullURI( bool doEnvVarSubs = false ) const
const wxString& GetFullURI( bool aSubstituted = false ) const
{
if( doEnvVarSubs )
return FP_LIB_TABLE::ExpandSubstitutions( uri );
if( aSubstituted )
return uri_expanded;
else
return uri;
return uri_user;
}
/**
* Function SetFullURI
* changes the full URI for the library.
*/
void SetFullURI( const wxString& aFullURI ) { uri = aFullURI; }
void SetFullURI( const wxString& aFullURI );
/**
* Function GetOptions
......@@ -274,7 +277,8 @@ public:
}
wxString nickName;
wxString uri;
wxString uri_user; ///< what user entered from UI or loaded from disk
wxString uri_expanded; ///< from ExpandSubstitutions()
LIB_T type;
wxString options;
wxString description;
......@@ -524,7 +528,7 @@ public:
* This enables (fp_lib_table)s to have platform dependent environment
* variables in them, allowing for a uniform table across platforms.
*/
static const wxString ExpandSubstitutions( const wxString aString );
static const wxString ExpandSubstitutions( const wxString& aString );
/**
* Function LoadGlobalTable
......
This diff is collapsed.
......@@ -221,7 +221,7 @@ BOARD* IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName,
BOARD* aAppendToMe, const PROPERTIES* aProperties )
{
// release the PLUGIN even if an exception is thrown.
PLUGIN::RELEASER pi = PluginFind( aFileType );
PLUGIN::RELEASER pi( PluginFind( aFileType ) );
if( (PLUGIN*) pi ) // test pi->plugin
{
......@@ -235,7 +235,7 @@ BOARD* IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName,
void IO_MGR::Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
{
// release the PLUGIN even if an exception is thrown.
PLUGIN::RELEASER pi = PluginFind( aFileType );
PLUGIN::RELEASER pi( PluginFind( aFileType ) );
if( (PLUGIN*) pi ) // test pi->plugin
{
......
......@@ -405,7 +405,11 @@ public:
API functions which take one.
*/
virtual ~PLUGIN() {};
virtual ~PLUGIN()
{
//printf( "~%s", __func__ );
};
/**
* Class RELEASER
......@@ -419,6 +423,9 @@ public:
// private assignment operator so it's illegal
RELEASER& operator=( RELEASER& aOther ) { return *this; }
// private copy constructor so it's illegal
RELEASER( const RELEASER& aOther ) {}
public:
RELEASER( PLUGIN* aPlugin = NULL ) :
plugin( aPlugin )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment