From 7ccdca5cedb1f2194a67564beaf9395b33639441 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 30 Jan 2017 20:31:19 -0500 Subject: [PATCH] Use library ID to store library symbol information in the schematic symbol. Use LIB_ID instead of wxString for storing the library symbol information in the schematic symbol in preparation for the upcoming symbol library table implementation. Change the FindLibAlias and FindLibPart functions in the PART_LIBS object instead of wxString. Please note that only the library ID name is used to search the list of libraries. The library nickname is ignored. Once the symbol library table is implemented and full LIB_IDs are defined, the library search code will no longer be used and will only be kept to load older schematics that have not been converted. Move SCH_LEGACY_PLUGIN_CACHE definition so that the legacy plugin knows how to properly delete the cache object. --- eeschema/class_library.cpp | 8 +- eeschema/class_library.h | 8 +- .../dialog_edit_component_in_schematic.cpp | 37 ++-- eeschema/dialogs/dialog_edit_one_field.cpp | 4 +- eeschema/dialogs/dialog_rescue_each.cpp | 4 +- eeschema/edit_component_in_schematic.cpp | 8 +- eeschema/getpart.cpp | 13 +- eeschema/libarch.cpp | 6 +- .../netlist_exporters/netlist_exporter.cpp | 6 +- .../netlist_exporter_generic.cpp | 7 +- .../netlist_exporter_orcadpcb2.cpp | 4 +- eeschema/onrightclick.cpp | 8 +- eeschema/project_rescue.cpp | 25 ++- eeschema/sch_component.cpp | 39 ++-- eeschema/sch_component.h | 13 +- eeschema/sch_legacy_plugin.cpp | 169 +++++++++--------- eeschema/sch_reference_list.h | 3 +- eeschema/sch_screen.cpp | 2 +- eeschema/sch_sheet_path.cpp | 6 +- eeschema/schedit.cpp | 2 +- eeschema/schframe.cpp | 2 +- 21 files changed, 199 insertions(+), 175 deletions(-) diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 4fb7e2a318..2bde3860f9 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -396,7 +396,7 @@ wxArrayString PART_LIBS::GetLibraryNames( bool aSorted ) } -LIB_PART* PART_LIBS::FindLibPart( const wxString& aPartName, const wxString& aLibraryName ) +LIB_PART* PART_LIBS::FindLibPart( const LIB_ID& aLibId, const wxString& aLibraryName ) { LIB_PART* part = NULL; @@ -405,7 +405,7 @@ LIB_PART* PART_LIBS::FindLibPart( const wxString& aPartName, const wxString& aLi if( !aLibraryName.IsEmpty() && lib.GetName() != aLibraryName ) continue; - part = lib.FindPart( aPartName ); + part = lib.FindPart( aLibId.GetLibItemName() ); if( part ) break; @@ -415,7 +415,7 @@ LIB_PART* PART_LIBS::FindLibPart( const wxString& aPartName, const wxString& aLi } -LIB_ALIAS* PART_LIBS::FindLibraryAlias( const wxString& aEntryName, const wxString& aLibraryName ) +LIB_ALIAS* PART_LIBS::FindLibraryAlias( const LIB_ID& aLibId, const wxString& aLibraryName ) { LIB_ALIAS* entry = NULL; @@ -424,7 +424,7 @@ LIB_ALIAS* PART_LIBS::FindLibraryAlias( const wxString& aEntryName, const wxStri if( !aLibraryName.IsEmpty() && lib.GetName() != aLibraryName ) continue; - entry = lib.FindAlias( aEntryName ); + entry = lib.FindAlias( aLibId.GetLibItemName() ); if( entry ) break; diff --git a/eeschema/class_library.h b/eeschema/class_library.h index e667030867..67c8fdf290 100644 --- a/eeschema/class_library.h +++ b/eeschema/class_library.h @@ -40,6 +40,7 @@ #include +class LIB_ID; class LINE_READER; class OUTPUTFORMATTER; class SCH_LEGACY_PLUGIN; @@ -274,12 +275,11 @@ public: * A part object will always be returned. If the entry found * is an alias. The root part will be found and returned. * - * @param aPartName - Name of part to search for. + * @param aLibId - The #LIB_ID of the symbol to search for. * @param aLibraryName - Name of the library to search for part. * @return LIB_PART* - The part object if found, otherwise NULL. */ - LIB_PART* FindLibPart( const wxString& aPartName, - const wxString& aLibraryName = wxEmptyString ); + LIB_PART* FindLibPart( const LIB_ID& aLibId, const wxString& aLibraryName = wxEmptyString ); /** * Function FindLibraryEntry @@ -291,7 +291,7 @@ public: * @param aLibraryName - Name of the library to search. * @return The entry object if found, otherwise NULL. */ - LIB_ALIAS* FindLibraryAlias( const wxString& aEntryName, + LIB_ALIAS* FindLibraryAlias( const LIB_ID& aLibId, const wxString& aLibraryName = wxEmptyString ); /** diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index b93946d8df..f10bccb73d 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.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 @@ -335,30 +335,33 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCancelButtonClick( wxCommandEvent& ev void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions() { - wxString newname = chipnameTextCtrl->GetValue(); + LIB_ID id; + wxString tmp = chipnameTextCtrl->GetValue(); + + tmp.Replace( wxT( " " ), wxT( "_" ) ); + + id.SetLibItemName( tmp ); // Save current flags which could be modified by next change settings STATUS_FLAGS flags = m_cmp->GetFlags(); - newname.Replace( wxT( " " ), wxT( "_" ) ); - - if( newname.IsEmpty() ) + if( id.empty() ) { DisplayError( NULL, _( "No Component Name!" ) ); } - else if( newname != m_cmp->m_part_name ) + else if( id != m_cmp->GetLibId() ) { PART_LIBS* libs = Prj().SchLibs(); - if( libs->FindLibraryAlias( newname ) == NULL ) + if( libs->FindLibraryAlias( id ) == NULL ) { - wxString msg = wxString::Format( _( - "Component '%s' not found!" ), GetChars( newname ) ); + wxString msg = wxString::Format( _( "Component '%s' not found!" ), + GetChars( id.Format() ) ); DisplayError( this, msg ); } else // Change component from lib! { - m_cmp->SetPartName( newname, libs ); + m_cmp->SetLibId( id, libs ); } } @@ -433,7 +436,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event // save old cmp in undo list if not already in edit, or moving ... // or the component to be edited is part of a block - if( m_cmp->m_Flags == 0 + if( m_cmp->GetFlags() == 0 || m_parent->GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK ) m_parent->SaveCopyInUndoList( m_cmp, UR_CHANGED ); @@ -481,10 +484,10 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event m_FieldsBuf[i].Offset( m_cmp->m_Pos ); } - LIB_PART* entry = Prj().SchLibs()->FindLibPart( m_cmp->m_part_name ); + LIB_PART* entry = Prj().SchLibs()->FindLibPart( m_cmp->GetLibId() ); if( entry && entry->IsPower() ) - m_FieldsBuf[VALUE].SetText( m_cmp->m_part_name ); + m_FieldsBuf[VALUE].SetText( m_cmp->GetLibId().GetLibItemName() ); // copy all the fields back, and change the length of m_Fields. m_cmp->SetFields( m_FieldsBuf ); @@ -673,7 +676,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent which came from the component. */ - m_part = Prj().SchLibs()->FindLibPart( m_cmp->m_part_name ); + m_part = Prj().SchLibs()->FindLibPart( m_cmp->GetLibId() ); #if 0 && defined(DEBUG) for( int i = 0; iGetFieldCount(); ++i ) @@ -1077,7 +1080,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() convertCheckBox->Enable( false ); // Set the component's library name. - chipnameTextCtrl->SetValue( m_cmp->m_part_name ); + chipnameTextCtrl->SetValue( m_cmp->GetLibId().Format() ); // Set the component's unique ID time stamp. m_textCtrlTimeStamp->SetValue( wxString::Format( wxT( "%8.8lX" ), @@ -1093,10 +1096,10 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) if( !m_cmp ) return; - if( LIB_PART* part = Prj().SchLibs()->FindLibPart( m_cmp->m_part_name ) ) + if( LIB_PART* part = Prj().SchLibs()->FindLibPart( m_cmp->GetLibId() ) ) { // save old cmp in undo list if not already in edit, or moving ... - if( m_cmp->m_Flags == 0 ) + if( m_cmp->GetFlags() == 0 ) m_parent->SaveCopyInUndoList( m_cmp, UR_CHANGED ); INSTALL_UNBUFFERED_DC( dc, m_parent->GetCanvas() ); diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 1f1189ec3e..d65f997cda 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -277,10 +277,10 @@ DIALOG_SCH_EDIT_ONE_FIELD::DIALOG_SCH_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, wxASSERT_MSG( component != NULL && component->Type() == SCH_COMPONENT_T, wxT( "Invalid schematic field parent item." ) ); - const LIB_PART* part = GetParent()->Prj().SchLibs()->FindLibPart( component->GetPartName() ); + const LIB_PART* part = GetParent()->Prj().SchLibs()->FindLibPart( component->GetLibId() ); wxASSERT_MSG( part, wxT( "Library part for component <" ) + - component->GetPartName() + wxT( "> could not be found." ) ); + component->GetLibId().Format() + wxT( "> could not be found." ) ); m_isPower = part->IsPower(); diff --git a/eeschema/dialogs/dialog_rescue_each.cpp b/eeschema/dialogs/dialog_rescue_each.cpp index 363b915e49..1aa9550a86 100644 --- a/eeschema/dialogs/dialog_rescue_each.cpp +++ b/eeschema/dialogs/dialog_rescue_each.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Chris Pavlina - * Copyright (C) 2015-2016 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2017 Kicad Developers, see AUTHORS.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 @@ -152,7 +152,7 @@ void DIALOG_RESCUE_EACH::PopulateInstanceList() wxVector data; for( SCH_COMPONENT* each_component : *m_Rescuer->GetComponents() ) { - if( each_component->GetPartName() != selected_part.GetRequestedName() ) + if( each_component->GetLibId().Format() != UTF8( selected_part.GetRequestedName() ) ) continue; SCH_FIELD* valueField = each_component->GetField( 1 ); diff --git a/eeschema/edit_component_in_schematic.cpp b/eeschema/edit_component_in_schematic.cpp index 4efe1f1fde..9ea4798164 100644 --- a/eeschema/edit_component_in_schematic.cpp +++ b/eeschema/edit_component_in_schematic.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2008-2016 Wayne Stambaugh - * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2008-2017 Wayne Stambaugh + * Copyright (C) 2004-2017 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 @@ -52,10 +52,10 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField ) wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T, wxT( "Invalid schematic field parent item." ) ); - LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetPartName() ); + LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetLibId() ); wxCHECK_RET( part, wxT( "Library part for component <" ) + - component->GetPartName() + wxT( "> could not be found." ) ); + component->GetLibId().GetLibItemName() + wxT( "> could not be found." ) ); // Save old component in undo list if not already in edit, or moving. if( aField->GetFlags() == 0 ) diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 958bc1006f..c580076cf0 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2008-2012 Wayne Stambaugh - * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2008-2017 Wayne Stambaugh + * Copyright (C) 2004-2017 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 @@ -228,7 +228,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, // 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 - component->SetPartName( name ); + LIB_ID libId; + + libId.SetLibItemName( name ); + component->SetLibId( libId ); // Be sure the link to the corresponding LIB_PART is OK: component->Resolve( Prj().SchLibs() ); @@ -304,7 +307,7 @@ void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent ) int unit = aEvent.GetId() + 1 - ID_POPUP_SCH_SELECT_UNIT1; - if( LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetPartName() ) ) + if( LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetLibId() ) ) { int unitCount = part->GetUnitCount(); @@ -350,7 +353,7 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC ) if( !DrawComponent ) return; - if( LIB_PART* part = Prj().SchLibs()->FindLibPart( DrawComponent->GetPartName() ) ) + if( LIB_PART* part = Prj().SchLibs()->FindLibPart( DrawComponent->GetLibId() ) ) { if( !part->HasConversion() ) { diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index 65dd4b3373..fca00f2ca2 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -81,13 +81,13 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) SCH_COMPONENT* component = (SCH_COMPONENT*) item; // If not already saved in the new cache, add it. - if( !libCache->FindAlias( component->GetPartName() ) ) + if( !libCache->FindAlias( component->GetLibId().GetLibItemName() ) ) { LIB_PART* part = NULL; try { - part = libs->FindLibPart( component->GetPartName() ); + part = libs->FindLibPart( component->GetLibId() ); if( part ) { @@ -98,7 +98,7 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) catch( ... /* IO_ERROR ioe */ ) { msg.Printf( _( "Failed to add symbol %s to library file '%s'" ), - component->GetPartName(), aFileName ); + wxString( component->GetLibId().GetLibItemName() ), aFileName ); DisplayError( this, msg ); return false; } diff --git a/eeschema/netlist_exporters/netlist_exporter.cpp b/eeschema/netlist_exporters/netlist_exporter.cpp index d53b19d276..e29991b5dc 100644 --- a/eeschema/netlist_exporters/netlist_exporter.cpp +++ b/eeschema/netlist_exporters/netlist_exporter.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.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 @@ -125,7 +125,7 @@ SCH_COMPONENT* NETLIST_EXPORTER::findNextComponent( EDA_ITEM* aItem, SCH_SHEET_P // (several sheets pointing to 1 screen), this will be erroneously be // toggled. - LIB_PART* part = m_libs->FindLibPart( comp->GetPartName() ); + LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() ); if( !part ) continue; @@ -184,7 +184,7 @@ SCH_COMPONENT* NETLIST_EXPORTER::findNextComponentAndCreatePinList( EDA_ITEM* // (several sheets pointing to 1 screen), this will be erroneously be // toggled. - LIB_PART* part = m_libs->FindLibPart( comp->GetPartName() ); + LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() ); if( !part ) continue; diff --git a/eeschema/netlist_exporters/netlist_exporter_generic.cpp b/eeschema/netlist_exporters/netlist_exporter_generic.cpp index 398e62fc8a..5d38b07f2f 100644 --- a/eeschema/netlist_exporters/netlist_exporter_generic.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_generic.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.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 @@ -169,11 +169,12 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents() // "logical" library name, which is in anticipation of a better search // algorithm for parts based on "logical_lib.part" and where logical_lib // is merely the library name minus path and extension. - LIB_PART* part = m_libs->FindLibPart( comp->GetPartName() ); + LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() ); if( part ) xlibsource->AddAttribute( sLib, part->GetLib()->GetLogicalName() ); - xlibsource->AddAttribute( sPart, comp->GetPartName() ); + // We only want the symbol name, not the full LIB_ID. + xlibsource->AddAttribute( sPart, comp->GetLibId().GetLibItemName() ); XNODE* xsheetpath; diff --git a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp index 1fe6f16ee1..70aea4e484 100644 --- a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.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 @@ -81,7 +81,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns // Get the Component FootprintFilter and put the component in // cmpList if filter is present - LIB_PART* part = m_libs->FindLibPart( comp->GetPartName() ); + LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() ); if( part ) { diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index b99e025f1a..793f181a09 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2008-2014 Wayne Stambaugh - * Copyright (C) 2004-2014 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2008-2017 Wayne Stambaugh + * Copyright (C) 2004-2017 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 @@ -357,7 +357,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, PART_LIBS* } wxString msg; - LIB_ALIAS* libEntry = aLibs->FindLibraryAlias( Component->GetPartName() ); + LIB_ALIAS* libEntry = aLibs->FindLibraryAlias( Component->GetLibId() ); if( !Component->GetFlags() ) { @@ -412,7 +412,7 @@ void AddMenusForEditComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, PART_L wxString msg; LIB_PART* part = NULL; - LIB_ALIAS* libEntry = aLibs->FindLibraryAlias( Component->GetPartName() ); + LIB_ALIAS* libEntry = aLibs->FindLibraryAlias( Component->GetLibId() ); if( libEntry ) part = libEntry->GetPart(); diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index 6ad3c33426..018d110196 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -238,7 +238,7 @@ public: for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) ) { - wxString part_name( each_component->GetPartName() ); + wxString part_name( each_component->GetLibId().GetLibItemName() ); LIB_ALIAS* case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( part_name ); std::vector case_insensitive_matches; @@ -288,9 +288,13 @@ public: { for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() ) { - if( each_component->GetPartName() != m_requested_name ) + if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) ) continue; - each_component->SetPartName( m_new_name ); + + LIB_ID libId; + + libId.SetLibItemName( m_new_name ); + each_component->SetLibId( libId ); each_component->ClearFlags(); aRescuer->LogRescue( each_component, m_requested_name, m_new_name ); } @@ -324,7 +328,7 @@ public: for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) ) { - wxString part_name( each_component->GetPartName() ); + 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 ); @@ -404,9 +408,13 @@ public: for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() ) { - if( each_component->GetPartName() != m_requested_name ) + if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) ) continue; - each_component->SetPartName( m_new_name ); + + LIB_ID libId; + + libId.SetLibItemName( m_new_name ); + each_component->SetLibId( libId ); each_component->ClearFlags(); aRescuer->LogRescue( each_component, m_requested_name, m_new_name ); } @@ -479,7 +487,10 @@ void RESCUER::UndoRescues() { for( RESCUE_LOG& each_logitem : m_rescue_log ) { - each_logitem.component->SetPartName( each_logitem.old_name ); + LIB_ID libId; + + libId.SetLibItemName( each_logitem.old_name ); + each_logitem.component->SetLibId( libId ); each_logitem.component->ClearFlags(); } } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index f7b6738d13..1ea194b385 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.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 @@ -130,7 +130,7 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, m_unit = unit; m_convert = convert; - m_part_name = aPart.GetName(); + m_lib_id.SetLibItemName( aPart.GetName() ); m_part = aPart.SharedPtr(); m_currentSheetPath = NULL; m_fieldsAutoplaced = AUTOPLACED_NO; @@ -187,9 +187,8 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, msg += wxT( "?" ); SetRef( sheet, msg ); - // Use the schematic component name instead of the library value field - // name. - GetField( VALUE )->SetText( GetPartName() ); + // Use the schematic component name instead of the library value field name. + GetField( VALUE )->SetText( GetLibId().GetLibItemName() ); } @@ -201,7 +200,7 @@ SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aComponent ) : m_Pos = aComponent.m_Pos; m_unit = aComponent.m_unit; m_convert = aComponent.m_convert; - m_part_name = aComponent.m_part_name; + m_lib_id = aComponent.m_lib_id; m_part = aComponent.m_part; SetTimeStamp( aComponent.m_TimeStamp ); @@ -257,11 +256,11 @@ EDA_ITEM* SCH_COMPONENT::Clone() const } -void SCH_COMPONENT::SetPartName( const wxString& aName, PART_LIBS* aLibs ) +void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId, PART_LIBS* aLibs ) { - if( m_part_name != aName ) + if( m_lib_id != aLibId ) { - m_part_name = aName; + m_lib_id = aLibId; SetModified(); if( aLibs ) @@ -276,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_part_name ) ) + if( LIB_PART* part = aLibs->FindLibPart( m_lib_id.GetLibItemName() ) ) { m_part = part->SharedPtr(); return true; @@ -722,7 +721,7 @@ void SCH_COMPONENT::SwapData( SCH_ITEM* aItem ) SCH_COMPONENT* component = (SCH_COMPONENT*) aItem; - std::swap( m_part_name, component->m_part_name ); + std::swap( m_lib_id, component->m_lib_id ); std::swap( m_part, component->m_part ); std::swap( m_Pos, component->m_Pos ); std::swap( m_unit, component->m_unit ); @@ -1007,7 +1006,7 @@ void SCH_COMPONENT::Show( int nestLevel, std::ostream& os ) const NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << " ref=\"" << TO_UTF8( GetField( 0 )->GetName() ) << '"' << " chipName=\"" - << TO_UTF8( GetPartName() ) << '"' << m_Pos + << GetLibId().Format() << '"' << m_Pos << " layer=\"" << m_Layer << '"' << ">\n"; @@ -1055,7 +1054,7 @@ bool SCH_COMPONENT::Save( FILE* f ) const name1 = toUTFTildaText( GetField( REFERENCE )->GetText() ); } - wxString part_name = GetPartName(); + wxString part_name = GetLibId().GetLibItemName(); if( part_name.size() ) { @@ -1200,14 +1199,14 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg ) if( partname != NULL_STRING ) { - SetPartName( partname ); + m_lib_id.SetLibItemName( partname ); if( !newfmt ) GetField( VALUE )->SetText( partname ); } else { - m_part_name.Empty(); + m_lib_id.clear(); GetField( VALUE )->Empty(); GetField( VALUE )->SetTextAngle( TEXT_ANGLE_HORIZ ); GetField( VALUE )->SetVisible( false ); @@ -1529,7 +1528,7 @@ void SCH_COMPONENT::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList ) // part and alias can differ if alias is not the root if( PART_SPTR part = m_part.lock() ) { - LIB_ALIAS* alias = part->GetAlias( GetPartName() ); + LIB_ALIAS* alias = part->GetAlias( GetLibId().GetLibItemName() ); if( !alias ) return; @@ -1544,7 +1543,7 @@ void SCH_COMPONENT::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList ) aList.push_back( MSG_PANEL_ITEM( msg, GetField( VALUE )->GetShownText(), DARKCYAN ) ); // Display component reference in library and library - aList.push_back( MSG_PANEL_ITEM( _( "Component" ), GetPartName(), BROWN ) ); + aList.push_back( MSG_PANEL_ITEM( _( "Component" ), GetLibId().GetLibItemName(), BROWN ) ); if( alias->GetName() != part->GetName() ) aList.push_back( MSG_PANEL_ITEM( _( "Alias of" ), part->GetName(), BROWN ) ); @@ -1783,7 +1782,7 @@ void SCH_COMPONENT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const { wxCHECK_RET( 0, wxT( "Cannot add connection points to list. Cannot find component <" ) + - GetPartName() + wxT( "> in any of the loaded libraries." ) ); + GetLibId().GetLibItemName() + wxT( "> in any of the loaded libraries." ) ); } } @@ -1806,7 +1805,7 @@ wxString SCH_COMPONENT::GetSelectMenuText() const { wxString tmp; tmp.Printf( _( "Component %s, %s" ), - GetChars( GetPartName() ), + GetChars( GetLibId().GetLibItemName() ), GetChars( GetField( REFERENCE )->GetShownText() ) ); return tmp; } @@ -1981,7 +1980,7 @@ SCH_ITEM& SCH_COMPONENT::operator=( const SCH_ITEM& aItem ) SCH_COMPONENT* c = (SCH_COMPONENT*) &aItem; - m_part_name = c->m_part_name; + m_lib_id = c->m_lib_id; m_part = c->m_part; m_Pos = c->m_Pos; m_unit = c->m_unit; diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 47e7c14d28..9d94bbac39 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -3,8 +3,8 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014 Dick Hollenbeck, dick@softplc.com - * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2017 Wayne Stambaugh + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.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 @@ -32,6 +32,7 @@ #ifndef COMPONENT_CLASS_H #define COMPONENT_CLASS_H +#include #include #include @@ -73,7 +74,9 @@ public: private: wxPoint m_Pos; - wxString m_part_name; ///< Name to look for in the library, i.e. "74LS00". + + ///< Name and library where symbol was loaded from, i.e. "74xx:74LS00". + LIB_ID m_lib_id; int m_unit; ///< The unit for multiple part per package components. int m_convert; ///< The alternate body style for components that have more than @@ -158,8 +161,8 @@ public: */ bool IsMovableFromAnchorPoint() override { return false; } - void SetPartName( const wxString& aName, PART_LIBS* aLibs=NULL ); - const wxString& GetPartName() const { return m_part_name; } + void SetLibId( const LIB_ID& aName, PART_LIBS* aLibs=NULL ); + const LIB_ID& GetLibId() const { return m_lib_id; } /** * Function Resolve diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index b11520f104..613b8ee759 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -464,6 +464,87 @@ static void parseQuotedString( wxString& aString, FILE_LINE_READER& aReader, } +/** + * Class SCH_LEGACY_PLUGIN_CACHE + * is a cache assistant for the part library portion of the #SCH_PLUGIN API, and only for the + * #SCH_LEGACY_PLUGIN, so therefore is private to this implementation file, i.e. not placed + * into a header. + */ +class SCH_LEGACY_PLUGIN_CACHE +{ + wxFileName m_libFileName; // Absolute path and file name is required here. + wxDateTime m_fileModTime; + LIB_ALIAS_MAP m_aliases; // Map of names of LIB_ALIAS pointers. + bool m_isWritable; + bool m_isModified; + int m_modHash; // Keep track of the modification status of the library. + int m_versionMajor; + int m_versionMinor; + int m_libType; // Is this cache a component or symbol library. + + LIB_PART* loadPart( FILE_LINE_READER& aReader ); + void loadHeader( FILE_LINE_READER& aReader ); + void loadAliases( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + void loadField( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + void loadDrawEntries( std::unique_ptr< LIB_PART >& aPart, + FILE_LINE_READER& aReader ); + void loadFootprintFilters( std::unique_ptr< LIB_PART >& aPart, + FILE_LINE_READER& aReader ); + void loadDocs(); + LIB_ARC* loadArc( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + LIB_CIRCLE* loadCircle( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + LIB_TEXT* loadText( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + LIB_RECTANGLE* loadRectangle( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + LIB_PIN* loadPin( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + LIB_POLYLINE* loadPolyLine( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + LIB_BEZIER* loadBezier( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); + + FILL_T parseFillMode( FILE_LINE_READER& aReader, const char* aLine, + const char** aOutput ); + bool checkForDuplicates( wxString& aAliasName ); + LIB_ALIAS* removeAlias( LIB_ALIAS* aAlias ); + + void saveDocFile(); + + friend SCH_LEGACY_PLUGIN; + +public: + SCH_LEGACY_PLUGIN_CACHE( const wxString& aLibraryPath ); + ~SCH_LEGACY_PLUGIN_CACHE(); + + int GetModifyHash() const { return m_modHash; } + + // Most all functions in this class throw IO_ERROR exceptions. There are no + // error codes nor user interface calls from here, nor in any SCH_PLUGIN objects. + // Catch these exceptions higher up please. + + /// Save the entire library to file m_libFileName; + void Save( bool aSaveDocFile = true ); + + void Load(); + + void AddSymbol( const LIB_PART* aPart ); + + void DeleteAlias( const wxString& aAliasName ); + + void DeleteSymbol( const wxString& aAliasName ); + + wxDateTime GetLibModificationTime(); + + bool IsFile( const wxString& aFullPathAndFileName ) const; + + bool IsFileChanged() const; + + void SetModified( bool aModified = true ) { m_isModified = aModified; } + + wxString GetLogicalName() const { return m_libFileName.GetName(); } + + void SetFileName( const wxString& aFileName ) { m_libFileName = aFileName; } + + wxString GetFileName() const { return m_libFileName.GetFullPath(); } +}; + + SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN() { init( NULL ); @@ -1224,7 +1305,10 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( FILE_LINE_READER& aReader ) parseUnquotedString( libName, aReader, line, &line ); libName.Replace( "~", " " ); - component->SetPartName( libName ); + + LIB_ID libId( libName ); + + component->SetLibId( libId ); wxString refDesignator; @@ -1584,7 +1668,7 @@ void SCH_LEGACY_PLUGIN::saveComponent( SCH_COMPONENT* aComponent ) name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() ); } - wxString part_name = aComponent->GetPartName(); + wxString part_name = aComponent->GetLibId().GetLibItemName(); if( part_name.size() ) { @@ -1925,87 +2009,6 @@ void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText ) } -/** - * Class SCH_LEGACY_PLUGIN_CACHE - * is a cache assistant for the part library portion of the #SCH_PLUGIN API, and only for the - * #SCH_LEGACY_PLUGIN, so therefore is private to this implementation file, i.e. not placed - * into a header. - */ -class SCH_LEGACY_PLUGIN_CACHE -{ - wxFileName m_libFileName; // Absolute path and file name is required here. - wxDateTime m_fileModTime; - LIB_ALIAS_MAP m_aliases; // Map of names of LIB_ALIAS pointers. - bool m_isWritable; - bool m_isModified; - int m_modHash; // Keep track of the modification status of the library. - int m_versionMajor; - int m_versionMinor; - int m_libType; // Is this cache a component or symbol library. - - LIB_PART* loadPart( FILE_LINE_READER& aReader ); - void loadHeader( FILE_LINE_READER& aReader ); - void loadAliases( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - void loadField( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - void loadDrawEntries( std::unique_ptr< LIB_PART >& aPart, - FILE_LINE_READER& aReader ); - void loadFootprintFilters( std::unique_ptr< LIB_PART >& aPart, - FILE_LINE_READER& aReader ); - void loadDocs(); - LIB_ARC* loadArc( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - LIB_CIRCLE* loadCircle( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - LIB_TEXT* loadText( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - LIB_RECTANGLE* loadRectangle( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - LIB_PIN* loadPin( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - LIB_POLYLINE* loadPolyLine( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - LIB_BEZIER* loadBezier( std::unique_ptr< LIB_PART >& aPart, FILE_LINE_READER& aReader ); - - FILL_T parseFillMode( FILE_LINE_READER& aReader, const char* aLine, - const char** aOutput ); - bool checkForDuplicates( wxString& aAliasName ); - LIB_ALIAS* removeAlias( LIB_ALIAS* aAlias ); - - void saveDocFile(); - - friend SCH_LEGACY_PLUGIN; - -public: - SCH_LEGACY_PLUGIN_CACHE( const wxString& aLibraryPath ); - ~SCH_LEGACY_PLUGIN_CACHE(); - - int GetModifyHash() const { return m_modHash; } - - // Most all functions in this class throw IO_ERROR exceptions. There are no - // error codes nor user interface calls from here, nor in any SCH_PLUGIN objects. - // Catch these exceptions higher up please. - - /// Save the entire library to file m_libFileName; - void Save( bool aSaveDocFile = true ); - - void Load(); - - void AddSymbol( const LIB_PART* aPart ); - - void DeleteAlias( const wxString& aAliasName ); - - void DeleteSymbol( const wxString& aAliasName ); - - wxDateTime GetLibModificationTime(); - - bool IsFile( const wxString& aFullPathAndFileName ) const; - - bool IsFileChanged() const; - - void SetModified( bool aModified = true ) { m_isModified = aModified; } - - wxString GetLogicalName() const { return m_libFileName.GetName(); } - - void SetFileName( const wxString& aFileName ) { m_libFileName = aFileName; } - - wxString GetFileName() const { return m_libFileName.GetFullPath(); } -}; - - SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE( const wxString& aFullPathAndFileName ) : m_libFileName( aFullPathAndFileName ), m_isWritable( true ), diff --git a/eeschema/sch_reference_list.h b/eeschema/sch_reference_list.h index 29500b448c..2e39440450 100644 --- a/eeschema/sch_reference_list.h +++ b/eeschema/sch_reference_list.h @@ -152,7 +152,8 @@ public: int CompareLibName( const SCH_REFERENCE& item ) const { - return m_RootCmp->GetPartName().Cmp( item.m_RootCmp->GetPartName() ); + return m_RootCmp->GetLibId().GetLibItemName().compare( + item.m_RootCmp->GetLibId().GetLibItemName() ); } /** diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index dcc8a7f487..113da38ad4 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -646,7 +646,7 @@ LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponen { pin = NULL; - LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetPartName() ); + LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetLibId() ); if( !part ) continue; diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 74023b0746..577d40a768 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -194,7 +194,7 @@ void SCH_SHEET_PATH::AnnotatePowerSymbols( PART_LIBS* aLibs, int* aReference ) continue; SCH_COMPONENT* component = (SCH_COMPONENT*) item; - LIB_PART* part = aLibs->FindLibPart( component->GetPartName() ); + LIB_PART* part = aLibs->FindLibPart( component->GetLibId() ); if( !part || !part->IsPower() ) continue; @@ -232,7 +232,7 @@ void SCH_SHEET_PATH::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aRefer if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) ) continue; - LIB_PART* part = aLibs->FindLibPart( component->GetPartName() ); + LIB_PART* part = aLibs->FindLibPart( component->GetLibId() ); if( part ) { @@ -263,7 +263,7 @@ void SCH_SHEET_PATH::GetMultiUnitComponents( PART_LIBS* aLibs, if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) ) continue; - LIB_PART* part = aLibs->FindLibPart( component->GetPartName() ); + LIB_PART* part = aLibs->FindLibPart( component->GetLibId() ); if( part && part->GetUnitCount() > 1 ) { diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index cf35ea0464..46bfa3db1e 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -299,7 +299,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { if( PART_LIBS* libs = Prj().SchLibs() ) { - LIB_ALIAS* entry = libs->FindLibraryAlias( ( (SCH_COMPONENT*) item )->GetPartName() ); + LIB_ALIAS* entry = libs->FindLibraryAlias( ( (SCH_COMPONENT*) item )->GetLibId() ); if( entry && !!entry->GetDocFileName() ) { diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index d6ff2a92eb..be5b110b84 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -1180,7 +1180,7 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) { if( PART_LIBS* libs = Prj().SchLibs() ) { - LIB_ALIAS* entry = libs->FindLibraryAlias( component->GetPartName() ); + LIB_ALIAS* entry = libs->FindLibraryAlias( component->GetLibId() ); if( !entry ) // Should not occur return;