From 968ca7c5c3c4f0e54b7c6a34b8804c17412bac28 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 6 Apr 2024 10:00:26 +0100 Subject: [PATCH] SNR --- eeschema/lib_symbol.cpp | 39 ++++++++++++++++++--------------------- eeschema/sch_item.cpp | 6 ------ eeschema/sch_item.h | 19 +++++-------------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index f55057a8f1..6c3659ee30 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -68,7 +68,7 @@ std::vector LIB_SYMBOL::GetSearchTerms() } -void LIB_SYMBOL::GetChooserFields( std::map& aColumnMap ) +void LIB_SYMBOL::GetChooserFields( std::map& aColumnMap ) { for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) { @@ -912,7 +912,7 @@ void LIB_SYMBOL::PlotFields( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT void LIB_SYMBOL::FixupDrawItems() { std::vector potential_top_items; - std::vector bottom_items; + std::vector bottom_items; for( LIB_ITEM& item : m_drawings ) { @@ -937,7 +937,6 @@ void LIB_SYMBOL::FixupDrawItems() return a->GetBoundingBox().GetArea() > b->GetBoundingBox().GetArea(); } ); - for( LIB_SHAPE* item : potential_top_items ) { for( LIB_ITEM* bottom_item : bottom_items ) @@ -1028,8 +1027,8 @@ int LIB_SYMBOL::GetPinCount() { std::vector pinList; - GetPins( pinList, 0, 1 ); // All units, but a single convert - return pinList.size(); + GetPins( pinList, 0 /* all units */, 1 /* single body style */ ); + return (int) pinList.size(); } @@ -1204,10 +1203,10 @@ void LIB_SYMBOL::SetFields( const std::vector& aFields ) { deleteAllFields(); - for( size_t ii = 0; ii < aFields.size(); ++ii ) + for( const LIB_FIELD& src : aFields ) { // drawings is a ptr_vector, new and copy an object on the heap. - LIB_FIELD* field = new LIB_FIELD( aFields[ ii ] ); + LIB_FIELD* field = new LIB_FIELD( src ); field->SetParent( this ); m_drawings.push_back( field ); @@ -1290,16 +1289,17 @@ const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, { for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) { + const LIB_FIELD& field = static_cast( item ); + if( aCaseInsensitive ) { - if( static_cast( &item )->GetCanonicalName().Upper() - == aFieldName.Upper() ) - return static_cast( &item ); + if( field.GetCanonicalName().Upper() == aFieldName.Upper() ) + return &field; } else { - if( static_cast( &item )->GetCanonicalName() == aFieldName ) - return static_cast( &item ); + if( field.GetCanonicalName() == aFieldName ) + return &field; } } @@ -1387,9 +1387,7 @@ int LIB_SYMBOL::UpdateFieldOrdinals() for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) { - LIB_FIELD* field = dynamic_cast( &item ); - - wxCHECK2( field, continue ); + LIB_FIELD* field = static_cast( &item ); // Mandatory fields were already resolved always have the same ordinal values. if( field->IsMandatory() ) @@ -1605,7 +1603,7 @@ void LIB_SYMBOL::SetHasAlternateBodyStyle( bool aHasAlternate, bool aDuplicatePi { if( aDuplicatePins ) { - std::vector< LIB_ITEM* > tmp; // Temporarily store the duplicated pins here. + std::vector tmp; // Temporarily store the duplicated pins here. for( LIB_ITEM& item : m_drawings ) { @@ -1615,21 +1613,20 @@ void LIB_SYMBOL::SetHasAlternateBodyStyle( bool aHasAlternate, bool aDuplicatePi if( item.m_bodyStyle == 1 ) { - LIB_ITEM* newItem = (LIB_ITEM*) item.Duplicate(); + LIB_ITEM* newItem = static_cast( item.Duplicate() ); newItem->m_bodyStyle = 2; tmp.push_back( newItem ); } } // Transfer the new pins to the LIB_SYMBOL. - for( unsigned i = 0; i < tmp.size(); i++ ) - m_drawings.push_back( tmp[i] ); + for( LIB_ITEM* item : tmp ) + m_drawings.push_back( item ); } } else { - // Delete converted shape items because the converted shape does - // not exist + // Delete converted shape items because the converted shape does not exist LIB_ITEMS_CONTAINER::ITERATOR i = m_drawings.begin(); while( i != m_drawings.end() ) diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index e0c1297429..f75c80ef50 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -81,12 +81,6 @@ SCH_ITEM& SCH_ITEM::operator=( const SCH_ITEM& aItem ) SCH_ITEM::~SCH_ITEM() { - // Do not let the connections container go out of scope with any objects or they - // will be deleted by the container will cause the Eeschema to crash. These objects - // are owned by the sheet object container. - if( !m_connections.empty() ) - m_connections.clear(); - for( const auto& it : m_connection_map ) delete it.second; } diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 03506ca745..ccde21c2cb 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -388,14 +388,6 @@ public: */ virtual std::vector GetConnectionPoints() const { return {}; } - /** - * Clears all of the connection items from the list. - * - * The vector release method is used to prevent the item pointers from being deleted. - * Do not use the vector erase method on the connection list. - */ - void ClearConnections() { m_connections.clear(); } - /** * Test the item to see if it is connected to \a aPoint. * @@ -578,18 +570,17 @@ private: protected: SCH_LAYER_ID m_layer; - EDA_ITEMS m_connections; // List of items connected to this item. - FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement - VECTOR2I m_storedPos; // a temporary variable used in some move commands - // to store a initial pos of the item or mouse cursor + FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement + VECTOR2I m_storedPos; // temp variable used in some move commands to store + // an initial position of the item or mouse cursor /// Store pointers to other items that are connected to this one, per sheet. std::map m_connected_items; /// Store connectivity information, per sheet. - std::unordered_map m_connection_map; + std::unordered_map m_connection_map; - bool m_connectivity_dirty; + bool m_connectivity_dirty; }; #ifndef SWIG