From bf2b3b0b0f650cc5dcf2e72605dc75db56b871ce Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 2 Apr 2024 17:10:23 +0100 Subject: [PATCH] Deconflict some LIB_TREE_ITEM APIs so they can remain non-const. (The non-const is required by FOOTPRINT_INFO, which must load footrpints to get some of the data.) --- common/footprint_info.cpp | 2 +- common/lib_tree_model.cpp | 6 +++--- cvpcb/cvpcb_mainframe.cpp | 2 +- eeschema/generate_alias_info.cpp | 2 +- eeschema/lib_symbol.cpp | 12 ++++++------ eeschema/lib_symbol.h | 20 +++++++++++--------- eeschema/sch_io/database/sch_io_database.cpp | 4 +++- eeschema/sch_io/http_lib/sch_io_http_lib.cpp | 9 +++++++-- include/footprint_info.h | 4 ++-- include/lib_tree_item.h | 4 ++-- pcbnew/footprint_info_impl.cpp | 2 +- pcbnew/widgets/panel_footprint_chooser.cpp | 2 +- 12 files changed, 39 insertions(+), 30 deletions(-) diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index 995d0d0002..18935ed30a 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -83,7 +83,7 @@ std::vector FOOTPRINT_INFO::GetSearchTerms() // Also include keywords as one long string, just in case terms.emplace_back( SEARCH_TERM( GetKeywords(), 1 ) ); - terms.emplace_back( SEARCH_TERM( GetDescription(), 1 ) ); + terms.emplace_back( SEARCH_TERM( GetDesc(), 1 ) ); return terms; } diff --git a/common/lib_tree_model.cpp b/common/lib_tree_model.cpp index 3d4678e787..cfe9c651f1 100644 --- a/common/lib_tree_model.cpp +++ b/common/lib_tree_model.cpp @@ -193,7 +193,7 @@ LIB_TREE_NODE_ITEM::LIB_TREE_NODE_ITEM( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* a m_LibId.SetLibItemName( aItem->GetName() ); m_Name = aItem->GetName(); - m_Desc = aItem->GetDescription(); + m_Desc = aItem->GetDesc(); m_Footprint = aItem->GetFootprint(); m_PinCount = aItem->GetPinCount(); @@ -221,11 +221,11 @@ LIB_TREE_NODE_UNIT& LIB_TREE_NODE_ITEM::AddUnit( LIB_TREE_ITEM* aItem, int aUnit void LIB_TREE_NODE_ITEM::Update( LIB_TREE_ITEM* aItem ) { - m_LibId.SetLibNickname( aItem->GetLibId().GetLibNickname() ); + m_LibId.SetLibNickname( aItem->GetLIB_ID().GetLibNickname() ); m_LibId.SetLibItemName( aItem->GetName() ); m_Name = aItem->GetName(); - m_Desc = aItem->GetDescription(); + m_Desc = aItem->GetDesc(); aItem->GetChooserFields( m_Fields ); diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index f12b9d1757..78a76c8693 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -842,7 +842,7 @@ void CVPCB_MAINFRAME::DisplayStatus() if( fp ) // can be NULL if no netlist loaded { msg = wxString::Format( _( "Description: %s; Keywords: %s" ), - fp->GetDescription(), + fp->GetDesc(), fp->GetKeywords() ); } diff --git a/eeschema/generate_alias_info.cpp b/eeschema/generate_alias_info.cpp index cb2e6ffef6..7284121d27 100644 --- a/eeschema/generate_alias_info.cpp +++ b/eeschema/generate_alias_info.cpp @@ -126,7 +126,7 @@ protected: if( parent ) { root_name = parent->GetName(); - root_desc = parent->GetDescription(); + root_desc = parent->GetDesc(); } m_html.Replace( wxS( "__ALIASOF__" ), wxString::Format( AliasOfFormat, diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index d9ad097948..a30f66353d 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -1349,7 +1349,7 @@ LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, bool aCaseInsensit const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, - const bool aCaseInsensitive ) const + bool aCaseInsensitive ) const { for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) { @@ -1370,7 +1370,7 @@ const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, } -LIB_FIELD& LIB_SYMBOL::GetValueField() +LIB_FIELD& LIB_SYMBOL::GetValueField() const { LIB_FIELD* field = GetFieldById( VALUE_FIELD ); wxASSERT( field != nullptr ); @@ -1378,7 +1378,7 @@ LIB_FIELD& LIB_SYMBOL::GetValueField() } -LIB_FIELD& LIB_SYMBOL::GetReferenceField() +LIB_FIELD& LIB_SYMBOL::GetReferenceField() const { LIB_FIELD* field = GetFieldById( REFERENCE_FIELD ); wxASSERT( field != nullptr ); @@ -1386,7 +1386,7 @@ LIB_FIELD& LIB_SYMBOL::GetReferenceField() } -LIB_FIELD& LIB_SYMBOL::GetFootprintField() +LIB_FIELD& LIB_SYMBOL::GetFootprintField() const { LIB_FIELD* field = GetFieldById( FOOTPRINT_FIELD ); wxASSERT( field != nullptr ); @@ -1394,7 +1394,7 @@ LIB_FIELD& LIB_SYMBOL::GetFootprintField() } -LIB_FIELD& LIB_SYMBOL::GetDatasheetField() +LIB_FIELD& LIB_SYMBOL::GetDatasheetField() const { LIB_FIELD* field = GetFieldById( DATASHEET_FIELD ); wxASSERT( field != nullptr ); @@ -1402,7 +1402,7 @@ LIB_FIELD& LIB_SYMBOL::GetDatasheetField() } -LIB_FIELD& LIB_SYMBOL::GetDescriptionField() +LIB_FIELD& LIB_SYMBOL::GetDescriptionField() const { LIB_FIELD* field = GetFieldById( DESCRIPTION_FIELD ); wxASSERT( field != nullptr ); diff --git a/eeschema/lib_symbol.h b/eeschema/lib_symbol.h index 68312ca2e4..36a65d80ac 100644 --- a/eeschema/lib_symbol.h +++ b/eeschema/lib_symbol.h @@ -159,8 +159,10 @@ public: virtual void SetName( const wxString& aName ); wxString GetName() const override { return m_name; } - LIB_ID& LibId() { return m_libId; } - LIB_ID GetLibId() const override { return m_libId; } + LIB_ID GetLIB_ID() const override { return m_libId; } + wxString GetDesc() override { return GetDescription(); } + + const LIB_ID& GetLibId() const { return m_libId; } void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; } LIB_ID GetSourceLibId() const { return m_sourceLibId; } @@ -175,7 +177,7 @@ public: } ///< Gets the Description field text value */ - wxString GetDescription() override + wxString GetDescription() const { if( GetDescriptionField().GetText().IsEmpty() && IsAlias() ) { @@ -318,7 +320,7 @@ public: LIB_FIELD* FindField( const wxString& aFieldName, bool aCaseInsensitive = false ); const LIB_FIELD* FindField( const wxString& aFieldName, - const bool aCaseInsensitive = false ) const; + bool aCaseInsensitive = false ) const; /** * Return pointer to the requested field. @@ -329,19 +331,19 @@ public: LIB_FIELD* GetFieldById( int aId ) const; /** Return reference to the value field. */ - LIB_FIELD& GetValueField(); + LIB_FIELD& GetValueField() const; /** Return reference to the reference designator field. */ - LIB_FIELD& GetReferenceField(); + LIB_FIELD& GetReferenceField() const; /** Return reference to the footprint field */ - LIB_FIELD& GetFootprintField(); + LIB_FIELD& GetFootprintField() const; /** Return reference to the datasheet field. */ - LIB_FIELD& GetDatasheetField(); + LIB_FIELD& GetDatasheetField() const; /** Return reference to the description field. */ - LIB_FIELD& GetDescriptionField(); + LIB_FIELD& GetDescriptionField() const; wxString GetPrefix(); diff --git a/eeschema/sch_io/database/sch_io_database.cpp b/eeschema/sch_io/database/sch_io_database.cpp index f53722f433..c734f967a6 100644 --- a/eeschema/sch_io/database/sch_io_database.cpp +++ b/eeschema/sch_io/database/sch_io_database.cpp @@ -462,7 +462,9 @@ std::unique_ptr SCH_IO_DATABASE::loadSymbolFromRow( const wxString& symbol->SetName( aSymbolName ); } - symbol->LibId().SetSubLibraryName( aTable.name ); + LIB_ID libId = symbol->GetLibId(); + libId.SetSubLibraryName( aTable.name );; + symbol->SetLibId( libId ); if( aRow.count( aTable.footprints_col ) ) { diff --git a/eeschema/sch_io/http_lib/sch_io_http_lib.cpp b/eeschema/sch_io/http_lib/sch_io_http_lib.cpp index ed159bafe4..e3247bf54d 100644 --- a/eeschema/sch_io/http_lib/sch_io_http_lib.cpp +++ b/eeschema/sch_io/http_lib/sch_io_http_lib.cpp @@ -380,7 +380,9 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbo symbol = originalSymbol->Duplicate(); symbol->SetSourceLibId( symbolId ); - symbol->LibId().SetSubLibraryName( aCategory.name ); + LIB_ID libId = symbol->GetLibId(); + libId.SetSubLibraryName( aCategory.name ); + symbol->SetLibId( libId ); } else if( !symbolId.IsValid() ) { @@ -403,7 +405,10 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbo // Actual symbol not found: return metadata only; error will be // indicated in the symbol chooser symbol = new LIB_SYMBOL( aSymbolName ); - symbol->LibId().SetSubLibraryName( aCategory.name ); + + LIB_ID libId = symbol->GetLibId(); + libId.SetSubLibraryName( aCategory.name ); + symbol->SetLibId( libId ); } symbol->SetExcludedFromBOM( aPart.exclude_from_bom ); diff --git a/include/footprint_info.h b/include/footprint_info.h index 93003b0c43..0a83426bdf 100644 --- a/include/footprint_info.h +++ b/include/footprint_info.h @@ -74,12 +74,12 @@ public: int GetPinCount() override { return GetUniquePadCount(); } - LIB_ID GetLibId() const override + LIB_ID GetLIB_ID() const override { return LIB_ID( m_nickname, m_fpname ); } - wxString GetDescription() override + wxString GetDesc() override { ensure_loaded(); return m_doc; diff --git a/include/lib_tree_item.h b/include/lib_tree_item.h index c26871db7f..e926c8bb24 100644 --- a/include/lib_tree_item.h +++ b/include/lib_tree_item.h @@ -44,11 +44,11 @@ public: { } - virtual LIB_ID GetLibId() const = 0; + virtual LIB_ID GetLIB_ID() const = 0; virtual wxString GetName() const = 0; virtual wxString GetLibNickname() const = 0; - virtual wxString GetDescription() = 0; + virtual wxString GetDesc() = 0; /** * Retrieves a key/value map of the fields on this item that should be exposed to the library diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp index 8f7596a4e1..d731109035 100644 --- a/pcbnew/footprint_info_impl.cpp +++ b/pcbnew/footprint_info_impl.cpp @@ -323,7 +323,7 @@ void FOOTPRINT_LIST_IMPL::WriteCacheToFile( const wxString& aFilePath ) { txtStream << fpinfo->GetLibNickname() << endl; txtStream << fpinfo->GetName() << endl; - txtStream << EscapeString( fpinfo->GetDescription(), CTX_LINE ) << endl; + txtStream << EscapeString( fpinfo->GetDesc(), CTX_LINE ) << endl; txtStream << EscapeString( fpinfo->GetKeywords(), CTX_LINE ) << endl; txtStream << wxString::Format( wxT( "%d" ), fpinfo->GetOrderNum() ) << endl; txtStream << wxString::Format( wxT( "%u" ), fpinfo->GetPadCount() ) << endl; diff --git a/pcbnew/widgets/panel_footprint_chooser.cpp b/pcbnew/widgets/panel_footprint_chooser.cpp index b320794c29..a021b8e5c0 100644 --- a/pcbnew/widgets/panel_footprint_chooser.cpp +++ b/pcbnew/widgets/panel_footprint_chooser.cpp @@ -96,7 +96,7 @@ PANEL_FOOTPRINT_CHOOSER::PANEL_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aFrame, wxTopL historyInfos, false, true ); if( historyInfos.size() ) - adapter->SetPreselectNode( historyInfos[0]->GetLibId(), 0 ); + adapter->SetPreselectNode( historyInfos[0]->GetLIB_ID(), 0 ); adapter->SetFilter( &m_filter ); adapter->AddLibraries( m_frame );