From b5df0ad3eb5e979664699074871e087b01b229bf Mon Sep 17 00:00:00 2001 From: Emmanuel Vera Date: Thu, 17 Jul 2025 13:10:35 +0000 Subject: [PATCH] Update power filter for power symbols placement --- eeschema/widgets/panel_symbol_chooser.cpp | 20 +++++++++++++++----- eeschema/widgets/panel_symbol_chooser.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/eeschema/widgets/panel_symbol_chooser.cpp b/eeschema/widgets/panel_symbol_chooser.cpp index 4fc26d0f5f..6d0dd6cdeb 100644 --- a/eeschema/widgets/panel_symbol_chooser.cpp +++ b/eeschema/widgets/panel_symbol_chooser.cpp @@ -50,7 +50,7 @@ wxString PANEL_SYMBOL_CHOOSER::g_symbolSearchString; wxString PANEL_SYMBOL_CHOOSER::g_powerSearchString; - +SCH_BASE_FRAME* PANEL_SYMBOL_CHOOSER::m_frame = nullptr; PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent, const SYMBOL_LIBRARY_FILTER* aFilter, @@ -67,13 +67,14 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP m_fp_preview( nullptr ), m_tree( nullptr ), m_details( nullptr ), - m_frame( aFrame ), m_acceptHandler( std::move( aAcceptHandler ) ), m_escapeHandler( std::move( aEscapeHandler ) ), m_showPower( false ), m_allow_field_edits( aAllowFieldEdits ), m_show_footprints( aShowFootprints ) { + m_frame = aFrame; + SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() ); COMMON_SETTINGS::SESSION& session = Pgm().GetCommonSettings()->m_Session; PROJECT_FILE& project = m_frame->Prj().GetProjectFile(); @@ -110,12 +111,19 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP if( aFilter->GetFilterPowerSymbols() ) { - // HACK ALERT: when loading symbols we presume that *any* filter is a power symbol - // filter. So the filter only needs to return true for libraries. static std::function powerFilter = []( LIB_TREE_NODE& aNode ) -> bool { - return true; + if (PANEL_SYMBOL_CHOOSER::m_frame) + { + LIB_SYMBOL* symbol = PANEL_SYMBOL_CHOOSER::m_frame->GetLibSymbol(aNode.m_LibId); + + if (symbol && symbol->IsPower()) + return true; + + } + + return false; }; adapter->SetFilter( &powerFilter ); @@ -341,6 +349,8 @@ PANEL_SYMBOL_CHOOSER::~PANEL_SYMBOL_CHOOSER() cfg->m_SymChooserPanel.sort_mode = m_tree->GetSortMode(); } + + m_frame = nullptr; } diff --git a/eeschema/widgets/panel_symbol_chooser.h b/eeschema/widgets/panel_symbol_chooser.h index 1a47437ce3..ea61f62651 100644 --- a/eeschema/widgets/panel_symbol_chooser.h +++ b/eeschema/widgets/panel_symbol_chooser.h @@ -167,7 +167,7 @@ protected: LIB_TREE* m_tree; HTML_WINDOW* m_details; - SCH_BASE_FRAME* m_frame; + static SCH_BASE_FRAME* m_frame; // Must be static becuase used in a static function std::function m_acceptHandler; std::function m_escapeHandler;