From cb77e68076e335ee2719acb0e1ac5afb8499137d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 23 Jul 2022 14:08:51 +0100 Subject: [PATCH] Don't assume a SCH_EDIT_FRAME in EE_SELECTION_TOOL. It's also used in the symbol editor. But in any case, pins of other units have no business being in an SCH_SYMBOL anyway. Fixes https://gitlab.com/kicad/code/kicad/issues/12076 --- eeschema/sch_symbol.cpp | 15 ++++++-- eeschema/tools/ee_selection_tool.cpp | 56 +++++++--------------------- 2 files changed, 26 insertions(+), 45 deletions(-) diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 23811ff14d..43a0047ef1 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -343,7 +343,10 @@ void SCH_SYMBOL::UpdatePins() { wxASSERT( libPin->Type() == LIB_PIN_T ); - if( libPin->GetConvert() && m_convert && ( m_convert != libPin->GetConvert() ) ) + if( libPin->GetConvert() && m_convert && m_convert != libPin->GetConvert() ) + continue; + + if( libPin->GetUnit() && m_unit && m_unit != libPin->GetUnit() ) continue; m_pins.push_back( std::make_unique( libPin, this ) ); @@ -369,7 +372,7 @@ void SCH_SYMBOL::SetUnit( int aUnit ) { if( m_unit != aUnit ) { - m_unit = aUnit; + UpdateUnit( aUnit ); SetModified(); } } @@ -377,7 +380,13 @@ void SCH_SYMBOL::SetUnit( int aUnit ) void SCH_SYMBOL::UpdateUnit( int aUnit ) { - m_unit = aUnit; + if( m_unit != aUnit ) + { + m_unit = aUnit; + + // The unit may have a different pins so the update the pin map. + UpdatePins(); + } } diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index aa349585cc..4bcd4b0aaf 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -1218,11 +1218,7 @@ bool EE_SELECTION_TOOL::selectMultiple() { bool cancelled = false; // Was the tool canceled while it was running? m_multiple = true; // Multiple selection mode is active - KIGFX::VIEW* view = getView(); - SCH_EDIT_FRAME* editFrame = dynamic_cast( m_frame ); - - if( !editFrame ) - return cancelled; + KIGFX::VIEW* view = getView(); KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); @@ -1279,49 +1275,25 @@ bool EE_SELECTION_TOOL::selectMultiple() view->Query( area.ViewBBox(), nearbyViewItems ); // Build lists of nearby items and their children - std::unordered_set nearbyItems; - std::vector nearbyChildren; - std::vector flaggedItems; + std::vector nearbyItems; + std::vector nearbyChildren; + std::vector flaggedItems; for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : nearbyViewItems ) { - EDA_ITEM* item = dynamic_cast( pair.first ); - - if( !item ) - continue; - - item->ClearFlags( CANDIDATE ); - auto emplaceRet = nearbyItems.emplace( item ); - - if( !emplaceRet.second ) - continue; // Item already in set - - if( SCH_SYMBOL* symbol = dynamic_cast( item ) ) + if( EDA_ITEM* item = dynamic_cast( pair.first ) ) { - int unit = symbol->GetUnitSelection( &editFrame->Schematic().CurrentSheet() ); + item->ClearFlags( CANDIDATE ); + nearbyItems.push_back( item ); - symbol->RunOnChildren( - [&]( SCH_ITEM* aChild ) - { - // Filter pins by unit - SCH_PIN* pin = dyn_cast( aChild ); - - if( pin && unit && pin->GetLibPin()->GetUnit() - && ( pin->GetLibPin()->GetUnit() != unit ) ) + if( SCH_ITEM* sch_item = dynamic_cast( item ) ) + { + sch_item->RunOnChildren( + [&]( SCH_ITEM* aChild ) { - return; - } - - nearbyChildren.push_back( aChild ); - } ); - } - else if( SCH_ITEM* sch_item = dynamic_cast( item ) ) - { - sch_item->RunOnChildren( - [&]( SCH_ITEM* aChild ) - { - nearbyChildren.push_back( aChild ); - } ); + nearbyChildren.push_back( aChild ); + } ); + } } }