From eb06b35852ca2d84fe0f579b35bc70e369d722ae Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 11 Feb 2017 13:43:41 -0500 Subject: [PATCH] Eeschema: fix schematic I/O plugin symbol name issue. LIB_ID was changing the symbol name due to the parser dropping everything past the first '/' character which is interpreted by LIB_ID as the item version. Add flag to ignore this in LIB_ID::SetLibItemName() and add a new ctor so the library nickname, item name, and revision can be set as required to prevent the standard LIB_ID parsing. Fix a few places where PART_LIBS functions FindLibraryAlias() and FindLibPar() were translating wxString symbol names to LIB_IDs where the LIB_ID parser was truncating the symbol name. --- common/lib_id.cpp | 13 +++++++++++-- eeschema/component_tree_search_container.cpp | 2 +- .../dialog_edit_component_in_schematic.cpp | 2 +- eeschema/getpart.cpp | 15 +++++++++------ eeschema/libedit.cpp | 2 +- eeschema/libeditframe.cpp | 2 +- eeschema/project_rescue.cpp | 16 +++++++++------- eeschema/sch_component.cpp | 6 +++--- eeschema/sch_legacy_plugin.cpp | 2 +- eeschema/selpart.cpp | 3 ++- eeschema/viewlibs.cpp | 6 ++++-- include/lib_id.h | 15 ++++++++++++++- 12 files changed, 57 insertions(+), 27 deletions(-) diff --git a/common/lib_id.cpp b/common/lib_id.cpp index a7be36c6c6..859bff288d 100644 --- a/common/lib_id.cpp +++ b/common/lib_id.cpp @@ -207,6 +207,15 @@ LIB_ID::LIB_ID( const wxString& aId ) throw( PARSE_ERROR ) } +LIB_ID::LIB_ID( const wxString& aLibName, const wxString& aLibItemName, + const wxString& aRevision ) : + nickname( aLibName ), + item_name( aLibItemName ), + revision( aRevision ) +{ +} + + int LIB_ID::SetLibNickname( const UTF8& aLogical ) { int offset = okLogical( aLogical ); @@ -220,11 +229,11 @@ int LIB_ID::SetLibNickname( const UTF8& aLogical ) } -int LIB_ID::SetLibItemName( const UTF8& aLibItemName ) +int LIB_ID::SetLibItemName( const UTF8& aLibItemName, bool aTestForRev ) { int separation = int( aLibItemName.find_first_of( "/" ) ); - if( separation != -1 ) + if( aTestForRev && separation != -1 ) { item_name = aLibItemName.substr( 0, separation-1 ); return separation; diff --git a/eeschema/component_tree_search_container.cpp b/eeschema/component_tree_search_container.cpp index d4d4ff9738..fed8967147 100644 --- a/eeschema/component_tree_search_container.cpp +++ b/eeschema/component_tree_search_container.cpp @@ -171,7 +171,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddAliasList( const wxString& aNodeName, if( aOptionalLib ) a = aOptionalLib->FindAlias( aName ); else - a = m_libs->FindLibraryAlias( aName, wxEmptyString ); + a = m_libs->FindLibraryAlias( LIB_ID( wxEmptyString, aName ), wxEmptyString ); if( a == NULL ) continue; diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index f10bccb73d..e1a25a872c 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -340,7 +340,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions() tmp.Replace( wxT( " " ), wxT( "_" ) ); - id.SetLibItemName( tmp ); + id.SetLibItemName( tmp, false ); // Save current flags which could be modified by next change settings STATUS_FLAGS flags = m_cmp->GetFlags(); diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index c580076cf0..0ae7cb2d8f 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -157,7 +157,8 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const SCHLIB_FILTER* aFilte search_container.SetPreselectNode( aHighlight, /* aUnit */ 0 ); const int deMorgan = aConvert ? *aConvert : 1; - dialogTitle.Printf( _( "Choose Component (%d items loaded)" ), search_container.GetComponentsCount() ); + dialogTitle.Printf( _( "Choose Component (%d items loaded)" ), + search_container.GetComponentsCount() ); DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, &search_container, deMorgan ); if( dlg.ShowModal() == wxID_CANCEL ) @@ -174,7 +175,9 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const SCHLIB_FILTER* aFilte if( !cmpName.empty() ) { AddHistoryComponentName( aHistoryList, cmpName ); - if ( aUnit ) aHistoryLastUnit = *aUnit; + + if ( aUnit ) + aHistoryLastUnit = *aUnit; } return cmpName; @@ -210,7 +213,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, if( aFilter ) libsource = aFilter->GetLibSource(); - LIB_PART* part = Prj().SchLibs()->FindLibPart( name, libsource ); + LIB_PART* part = Prj().SchLibs()->FindLibPart( LIB_ID( wxEmptyString, name ), libsource ); if( !part ) { @@ -222,15 +225,15 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, return NULL; } - SCH_COMPONENT* component = new SCH_COMPONENT( *part, m_CurrentSheet, unit, convert, - GetCrossHairPosition(), true ); + SCH_COMPONENT* component = new SCH_COMPONENT( *part, m_CurrentSheet, unit, convert, + GetCrossHairPosition(), true ); // Set the m_ChipName value, from component name in lib, for aliases // Note if part is found, and if name is an alias of a component, // alias exists because its root component was found LIB_ID libId; - libId.SetLibItemName( name ); + libId.SetLibItemName( name, false ); component->SetLibId( libId ); // Be sure the link to the corresponding LIB_PART is OK: diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index a11283d07e..dfbeca66cd 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -154,7 +154,7 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) { // Not found in the active library: search inside the full list // (can happen when using Viewlib to load a component) - libEntry = Prj().SchLibs()->FindLibraryAlias( cmp_name ); + libEntry = Prj().SchLibs()->FindLibraryAlias( LIB_ID( wxEmptyString, cmp_name ) ); if( libEntry ) { diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index 7f0fcc83ea..f3aa1ae5fd 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -986,7 +986,7 @@ LIB_PART* LIB_EDIT_FRAME::GetCurPart() wxString name = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_PART ); LIB_PART* part; - if( !!name && ( part = Prj().SchLibs()->FindLibPart( name ) ) ) + if( !!name && ( part = Prj().SchLibs()->FindLibPart( LIB_ID( wxEmptyString, name ) ) ) ) { // clone it from the PART_LIB and own it. m_my_part = new LIB_PART( *part ); diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index 018d110196..1ca4dc078b 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -239,8 +239,8 @@ public: for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) ) { wxString part_name( each_component->GetLibId().GetLibItemName() ); - - LIB_ALIAS* case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( part_name ); + LIB_ID id( wxEmptyString, part_name ); + LIB_ALIAS* case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( id ); std::vector case_insensitive_matches; aRescuer.GetLibs()->FindLibraryNearEntries( case_insensitive_matches, part_name ); @@ -293,7 +293,7 @@ public: LIB_ID libId; - libId.SetLibItemName( m_new_name ); + libId.SetLibItemName( m_new_name, false ); each_component->SetLibId( libId ); each_component->ClearFlags(); aRescuer->LogRescue( each_component, m_requested_name, m_new_name ); @@ -330,8 +330,10 @@ public: { wxString part_name( each_component->GetLibId().GetLibItemName() ); - LIB_PART* cache_match = find_component( part_name, aRescuer.GetLibs(), /* aCached */ true ); - LIB_PART* lib_match = aRescuer.GetLibs()->FindLibPart( part_name ); + LIB_PART* cache_match = find_component( part_name, + aRescuer.GetLibs(), /* aCached */ true ); + LIB_ID id( wxEmptyString, part_name ); + LIB_PART* lib_match = aRescuer.GetLibs()->FindLibPart( id ); // Test whether there is a conflict if( !cache_match || !lib_match ) @@ -413,7 +415,7 @@ public: LIB_ID libId; - libId.SetLibItemName( m_new_name ); + libId.SetLibItemName( m_new_name, false ); each_component->SetLibId( libId ); each_component->ClearFlags(); aRescuer->LogRescue( each_component, m_requested_name, m_new_name ); @@ -489,7 +491,7 @@ void RESCUER::UndoRescues() { LIB_ID libId; - libId.SetLibItemName( each_logitem.old_name ); + libId.SetLibItemName( each_logitem.old_name, false ); each_logitem.component->SetLibId( libId ); each_logitem.component->ClearFlags(); } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 1ea194b385..72795d71e2 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -130,7 +130,7 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, m_unit = unit; m_convert = convert; - m_lib_id.SetLibItemName( aPart.GetName() ); + m_lib_id.SetLibItemName( aPart.GetName(), false ); m_part = aPart.SharedPtr(); m_currentSheetPath = NULL; m_fieldsAutoplaced = AUTOPLACED_NO; @@ -275,7 +275,7 @@ bool SCH_COMPONENT::Resolve( PART_LIBS* aLibs ) { // I've never been happy that the actual individual PART_LIB is left up to // flimsy search path ordering. None-the-less find a part based on that design: - if( LIB_PART* part = aLibs->FindLibPart( m_lib_id.GetLibItemName() ) ) + if( LIB_PART* part = aLibs->FindLibPart( m_lib_id ) ) { m_part = part->SharedPtr(); return true; @@ -1199,7 +1199,7 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg ) if( partname != NULL_STRING ) { - m_lib_id.SetLibItemName( partname ); + m_lib_id.SetLibItemName( partname, false ); if( !newfmt ) GetField( VALUE )->SetText( partname ); diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 613b8ee759..f6ffa137f3 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -1306,7 +1306,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( FILE_LINE_READER& aReader ) parseUnquotedString( libName, aReader, line, &line ); libName.Replace( "~", " " ); - LIB_ID libId( libName ); + LIB_ID libId( wxEmptyString, libName ); component->SetLibId( libId ); diff --git a/eeschema/selpart.cpp b/eeschema/selpart.cpp index 5ed2975f06..8cd825cf95 100644 --- a/eeschema/selpart.cpp +++ b/eeschema/selpart.cpp @@ -44,7 +44,8 @@ static void DisplayCmpDocAndKeywords( wxString& aName, void* aData ) wxASSERT( libs ); - LIB_ALIAS* part = libs->FindLibraryAlias( aName ); + LIB_ID id( wxEmptyString, aName ); + LIB_ALIAS* part = libs->FindLibraryAlias( id ); if( !part ) return; diff --git a/eeschema/viewlibs.cpp b/eeschema/viewlibs.cpp index 88a578b8c1..8bd06b19a7 100644 --- a/eeschema/viewlibs.cpp +++ b/eeschema/viewlibs.cpp @@ -114,7 +114,8 @@ void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent ) void LIB_VIEW_FRAME::onViewSymbolDocument( wxCommandEvent& aEvent ) { - LIB_ALIAS* entry = Prj().SchLibs()->FindLibraryAlias( m_entryName, m_libraryName ); + LIB_ID id( wxEmptyString, m_entryName ); + LIB_ALIAS* entry = Prj().SchLibs()->FindLibraryAlias( id, m_libraryName ); if( entry && !entry->GetDocFileName().IsEmpty() ) { @@ -185,7 +186,8 @@ void LIB_VIEW_FRAME::DisplayLibInfos() void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { - LIB_ALIAS* entry = Prj().SchLibs()->FindLibraryAlias( m_entryName, m_libraryName ); + LIB_ID id( wxEmptyString, m_entryName ); + LIB_ALIAS* entry = Prj().SchLibs()->FindLibraryAlias( id, m_libraryName ); if( !entry ) return; diff --git a/include/lib_id.h b/include/lib_id.h index ca38ceef54..4826128198 100644 --- a/include/lib_id.h +++ b/include/lib_id.h @@ -74,6 +74,19 @@ public: LIB_ID( const wxString& aId ) throw( PARSE_ERROR ); + /** + * This LIB_ID ctor is a special version which ignores the parsing due to symbol + * names allowing '/' as a valid character. This was causing the symbol names to + * be truncated at the first occurrence of '/' in the symbol name. + * + * @param aLibName is the library nickname used to look up the library item in the #LIB_TABLE. + * @param aLibItemName is the name of the library item which is not parsed by the standard + * LIB_ID::Parse() function. + * @param aRevision is the revision of the library item. + */ + LIB_ID( const wxString& aLibName, const wxString& aLibItemName, + const wxString& aRevision = wxEmptyString ); + /** * Function Parse * @@ -124,7 +137,7 @@ public: * into the parameter at which an error was detected, usually because it * contained '/'. */ - int SetLibItemName( const UTF8& aLibItemName ); + int SetLibItemName( const UTF8& aLibItemName, bool aTestForRev = true ); int SetRevision( const UTF8& aRevision );