From f3ad2463e2754de80402a4a6104074777dcdea6d Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 19 Nov 2013 11:24:45 -0600 Subject: [PATCH] *) Switch to later environment variable expansion in fp-lib-table. *) Save library nickname in APP so upon module editor re-entry last is re-used. *) Fix bug editing fp-lib-table Description field. --- common/fp_lib_table.cpp | 64 ++++++++++++++++++++++++++ include/fp_lib_table.h | 51 +++++--------------- pcbnew/dialogs/dialog_fp_lib_table.cpp | 3 +- pcbnew/module_editor_frame.h | 6 +-- pcbnew/moduleframe.cpp | 53 ++++++++++++++++++++- 5 files changed, 130 insertions(+), 47 deletions(-) diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index a789b11875..61166e4016 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -71,7 +71,71 @@ void FP_LIB_TABLE::ROW::SetType( const wxString& aType ) void FP_LIB_TABLE::ROW::SetFullURI( const wxString& aFullURI ) { uri_user = aFullURI; + +#if !FP_LATE_ENVVAR uri_expanded = FP_LIB_TABLE::ExpandSubstitutions( aFullURI ); +#endif +} + + +const wxString FP_LIB_TABLE::ROW::GetFullURI( bool aSubstituted ) const +{ + if( aSubstituted ) + { +#if !FP_LATE_ENVVAR // early expansion + return uri_expanded; + +#else // late expansion + return FP_LIB_TABLE::ExpandSubstitutions( uri_user ); +#endif + } + else + return uri_user; +} + + +FP_LIB_TABLE::ROW::ROW( const ROW& a ) : + nickName( a.nickName ), + type( a.type ), + options( a.options ), + description( a.description ), + properties( 0 ) +{ + // may call ExpandSubstitutions() + SetFullURI( a.uri_user ); + + if( a.properties ) + properties = new PROPERTIES( *a.properties ); +} + + +FP_LIB_TABLE::ROW& FP_LIB_TABLE::ROW::operator=( const ROW& r ) +{ + nickName = r.nickName; + type = r.type; + options = r.options; + description = r.description; + properties = r.properties ? new PROPERTIES( *r.properties ) : NULL; + + // may call ExpandSubstitutions() + SetFullURI( r.uri_user ); + + // Do not copy the PLUGIN, it is lazily created. Delete any existing + // destination plugin. + setPlugin( NULL ); + + return *this; +} + + +bool FP_LIB_TABLE::ROW::operator==( const ROW& r ) const +{ + return nickName == r.nickName + && uri_user == r.uri_user + && type == r.type + && options == r.options + && description == r.description + ; } diff --git a/include/fp_lib_table.h b/include/fp_lib_table.h index a433d4874d..4b7b3d9a43 100644 --- a/include/fp_lib_table.h +++ b/include/fp_lib_table.h @@ -27,13 +27,13 @@ #define FP_LIB_TABLE_H_ #include - #include #include - #include + +#define FP_LATE_ENVVAR 1 ///< late=1/early=0 environment variable expansion #define KISYSMOD "KISYSMOD" class wxFileName; @@ -122,44 +122,17 @@ public: SetType( aType ); } - ROW( const ROW& a ) : - nickName( a.nickName ), - uri_user( a.uri_user ), - uri_expanded( a.uri_expanded ), - type( a.type ), - options( a.options ), - description( a.description ), - properties( 0 ) - { - if( a.properties ) - properties = new PROPERTIES( *a.properties ); - } + ROW( const ROW& a ); ~ROW() { delete properties; } - ROW& operator=( const ROW& r ) - { - 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; + ROW& operator=( const ROW& r ); - // do not copy the PLUGIN, it is lazily created. - setPlugin( NULL ); - - return *this; - } - - bool operator==( const ROW& r ) const - { - return nickName==r.nickName && uri_user==r.uri_user && type==r.type && options==r.options; - } + /// Used in DIALOG_FP_LIB_TABLE for detecting an edit. + bool operator==( const ROW& r ) const; bool operator!=( const ROW& r ) const { return !( *this == r ); } @@ -196,13 +169,7 @@ public: * * @param aSubstituted Tells if caller wanted the substituted form, else not. */ - const wxString& GetFullURI( bool aSubstituted = false ) const - { - if( aSubstituted ) - return uri_expanded; - else - return uri_user; - } + const wxString GetFullURI( bool aSubstituted = false ) const; /** * Function SetFullURI @@ -280,7 +247,11 @@ public: wxString nickName; wxString uri_user; ///< what user entered from UI or loaded from disk + +#if !FP_LATE_ENVVAR wxString uri_expanded; ///< from ExpandSubstitutions() +#endif + LIB_T type; wxString options; wxString description; diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index 3c72ff204e..1304e67a0d 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -330,11 +330,12 @@ public: wxGrid* g = i==0 ? m_global_grid : m_project_grid; // all but COL_OPTIONS, which is edited with Option Editor anyways. - g->AutoSizeColumn( COL_NICKNAME, true ); + g->AutoSizeColumn( COL_NICKNAME, false ); g->AutoSizeColumn( COL_TYPE, false ); g->AutoSizeColumn( COL_URI, false ); g->AutoSizeColumn( COL_DESCR, false ); + // would set this to width of title, if it was easily known. g->SetColSize( COL_OPTIONS, 80 ); } diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index d022c55a2a..4d50de7b49 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -432,13 +432,11 @@ protected: */ void updateTitle(); - wxString m_lib_nick_name; - /// The library nickName is a short string, for now the same as the library path /// but without path and without extension. After library table support it becomes /// a lookup key. - wxString getLibNickName() const { return m_lib_nick_name; } - void setLibNickName( const wxString& aLibNickName ) { m_lib_nick_name = aLibNickName; } + const wxString& getLibNickName() const; + void setLibNickName( const wxString& aNickname ); #if !defined(USE_FP_LIB_TABLE) diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 25bb6a03a2..50dd1e9d4c 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -255,12 +255,28 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME() m_Pcb = 0; } -#if defined(USE_FP_LIB_TABLE) + +const wxString& FOOTPRINT_EDIT_FRAME::getLibNickName() const +{ + return wxGetApp().GetModuleLibraryNickname(); +} + + +void FOOTPRINT_EDIT_FRAME::setLibNickName( const wxString& aNickname ) +{ + wxGetApp().SetModuleLibraryNickname( aNickname ); +} + + +#if 1 && defined(USE_FP_LIB_TABLE) wxString FOOTPRINT_EDIT_FRAME::getLibPath() { try { - const FP_LIB_TABLE::ROW* row = GetFootprintLibraryTable()->FindRow( m_lib_nick_name ); + const wxString& nickname = getLibNickName(); + + const FP_LIB_TABLE::ROW* row = GetFootprintLibraryTable()->FindRow( nickname ); + return row->GetFullURI( true ); } catch( IO_ERROR ioe ) @@ -600,6 +616,8 @@ void FOOTPRINT_EDIT_FRAME::OnModify() void FOOTPRINT_EDIT_FRAME::updateTitle() { wxString title = _( "Module Editor " ); + +#if !defined(USE_FP_LIB_TABLE) wxString libPath = getLibPath(); if( !libPath ) @@ -633,5 +651,36 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() } } +#else + + wxString nickname = getLibNickName(); + + if( !nickname ) + { + L_none: + title += _( "(no active library)" ); + } + else + { + try + { + bool writable = m_footprintLibTable->IsFootprintLibWritable( nickname ); + + // no exception was thrown, this means libPath is valid, but it may be read only. + title = _( "Module Editor (active library: " ) + nickname + wxT( ")" ); + + if( !writable ) + title += _( " [Read Only]" ); + } + catch( IO_ERROR ioe ) + { + // user may be bewildered as to why after selecting a library it is not showing up + // in the title, we could show an error message, but that should have been done at time + // of libary selection UI. + goto L_none; + } + } +#endif + SetTitle( title ); }