Only expand lib tree when filtering.
This commit is contained in:
parent
7c8e74c156
commit
06446bb80e
|
@ -31,10 +31,10 @@
|
|||
// increase this score. This way, an empty search string will result in all components being
|
||||
// displayed as they have the minimum score. However, in that case, we avoid expanding all the
|
||||
// nodes asd the result is very unspecific.
|
||||
static const unsigned kLowestDefaultScore = 1;
|
||||
static const int kLowestDefaultScore = 1;
|
||||
|
||||
|
||||
void LIB_TREE_NODE::ResetScore( std::function<bool( LIB_TREE_NODE& aNode )>* aFilter )
|
||||
void LIB_TREE_NODE::ResetScore( std::function<int( LIB_TREE_NODE& aNode )>* aFilter )
|
||||
{
|
||||
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
||||
child->ResetScore( aFilter );
|
||||
|
@ -219,17 +219,15 @@ void LIB_TREE_NODE_LIB_ID::Update( LIB_TREE_ITEM* aItem )
|
|||
}
|
||||
|
||||
|
||||
void LIB_TREE_NODE_LIB_ID::ResetScore( std::function<bool( LIB_TREE_NODE& aNode )>* aFilter )
|
||||
void LIB_TREE_NODE_LIB_ID::ResetScore( std::function<int( LIB_TREE_NODE& aNode )>* aFilter )
|
||||
{
|
||||
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
||||
child->ResetScore( aFilter );
|
||||
|
||||
if( !aFilter )
|
||||
m_Score = kLowestDefaultScore;
|
||||
else if( (*aFilter)(*this) )
|
||||
m_Score = kLowestDefaultScore + 1;
|
||||
if( aFilter )
|
||||
m_Score = kLowestDefaultScore + (*aFilter)(*this);
|
||||
else
|
||||
m_Score = 0;
|
||||
m_Score = kLowestDefaultScore;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -102,13 +102,12 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
|
|||
|
||||
if( aFilter->GetFilterPowerSymbols() )
|
||||
{
|
||||
// Note: there is only a single filter ever used for symbols (the power filter),
|
||||
// so the code simply sets a flag based on the filter being non-null. The filter
|
||||
// is not (at present) actually called.
|
||||
static std::function<bool( LIB_TREE_NODE& )> powerFilter =
|
||||
[]( LIB_TREE_NODE& ) -> bool
|
||||
// HACK ALERT: the only filter ever used for symbols is the power filter, so we
|
||||
// sometimes just look for the function pointer being non-null.
|
||||
static std::function<int( LIB_TREE_NODE& )> powerFilter =
|
||||
[]( LIB_TREE_NODE& ) -> int
|
||||
{
|
||||
return true;
|
||||
return 0;
|
||||
};
|
||||
|
||||
adapter->SetFilter( &powerFilter );
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
/**
|
||||
* Initialize score to kLowestDefaultScore, recursively.
|
||||
*/
|
||||
virtual void ResetScore( std::function<bool( LIB_TREE_NODE& aNode )>* aFilter );
|
||||
virtual void ResetScore( std::function<int( LIB_TREE_NODE& aNode )>* aFilter );
|
||||
|
||||
/**
|
||||
* Store intrinsic ranks on all children of this node. See m_IntrinsicRank
|
||||
|
@ -211,7 +211,7 @@ public:
|
|||
*/
|
||||
void Update( LIB_TREE_ITEM* aItem );
|
||||
|
||||
void ResetScore( std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
|
||||
void ResetScore( std::function<int( LIB_TREE_NODE& aNode )>* aFilter ) override;
|
||||
|
||||
/**
|
||||
* Perform the actual search.
|
||||
|
|
|
@ -141,12 +141,12 @@ public:
|
|||
*
|
||||
* @param aFilter if SYM_FILTER_POWER, only power parts are loaded
|
||||
*/
|
||||
void SetFilter( std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) { m_filter = aFilter; }
|
||||
void SetFilter( std::function<int( LIB_TREE_NODE& aNode )>* aFilter ) { m_filter = aFilter; }
|
||||
|
||||
/**
|
||||
* Return the active filter.
|
||||
*/
|
||||
std::function<bool( LIB_TREE_NODE& aNode )>* GetFilter() const { return m_filter; }
|
||||
std::function<int( LIB_TREE_NODE& aNode )>* GetFilter() const { return m_filter; }
|
||||
|
||||
void SetSortMode( SORT_MODE aMode ) { m_sort_mode = aMode; }
|
||||
SORT_MODE GetSortMode() const { return m_sort_mode; }
|
||||
|
@ -415,7 +415,7 @@ private:
|
|||
|
||||
wxDataViewCtrl* m_widget;
|
||||
|
||||
std::function<bool( LIB_TREE_NODE& aNode )>* m_filter;
|
||||
std::function<int( LIB_TREE_NODE& aNode )>* m_filter;
|
||||
|
||||
std::vector<wxDataViewColumn*> m_columns;
|
||||
std::map<wxString, wxDataViewColumn*> m_colNameMap;
|
||||
|
|
|
@ -37,9 +37,9 @@ DIALOG_FOOTPRINT_CHOOSER::DIALOG_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aParent,
|
|||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
||||
m_chooserPanel = new PANEL_FOOTPRINT_CHOOSER( aParent, this, aFootprintHistoryList,
|
||||
// Filter
|
||||
[]( LIB_TREE_NODE& aNode ) -> bool
|
||||
[]( LIB_TREE_NODE& aNode ) -> int
|
||||
{
|
||||
return true;
|
||||
return 0;
|
||||
},
|
||||
// Close handler
|
||||
[this]()
|
||||
|
|
|
@ -83,7 +83,7 @@ FOOTPRINT_CHOOSER_FRAME::FOOTPRINT_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aPare
|
|||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
||||
m_chooserPanel = new PANEL_FOOTPRINT_CHOOSER( this, this, s_FootprintHistoryList,
|
||||
// Filter
|
||||
[this]( LIB_TREE_NODE& aNode ) -> bool
|
||||
[this]( LIB_TREE_NODE& aNode ) -> int
|
||||
{
|
||||
return filterFootprint( aNode );
|
||||
},
|
||||
|
@ -158,37 +158,53 @@ FOOTPRINT_CHOOSER_FRAME::~FOOTPRINT_CHOOSER_FRAME()
|
|||
}
|
||||
}
|
||||
|
||||
bool FOOTPRINT_CHOOSER_FRAME::filterFootprint( LIB_TREE_NODE& aNode )
|
||||
int FOOTPRINT_CHOOSER_FRAME::filterFootprint( LIB_TREE_NODE& aNode )
|
||||
{
|
||||
bool filtering = false;
|
||||
|
||||
auto patternMatch =
|
||||
[]( LIB_ID& id, std::vector<std::unique_ptr<EDA_PATTERN_MATCH>>& filters ) -> bool
|
||||
{
|
||||
// The matching is case insensitive
|
||||
wxString name;
|
||||
|
||||
for( const std::unique_ptr<EDA_PATTERN_MATCH>& filter : filters )
|
||||
{
|
||||
name.Empty();
|
||||
|
||||
// If the filter contains a ':' then include the library name in the pattern
|
||||
if( filter->GetPattern().Contains( wxS( ":" ) ) )
|
||||
name = id.GetUniStringLibNickname().Lower() + wxS( ":" );
|
||||
|
||||
name += id.GetUniStringLibItemName().Lower();
|
||||
|
||||
if( filter->Find( name ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
if( m_pinCount > 0 && m_filterByPinCount->GetValue() )
|
||||
{
|
||||
filtering = true;
|
||||
|
||||
if( aNode.m_PinCount != m_pinCount )
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( !m_fpFilters.empty() && m_filterByFPFilters->GetValue() )
|
||||
{
|
||||
// The matching is case insensitive
|
||||
wxString name;
|
||||
filtering = true;
|
||||
|
||||
for( const std::unique_ptr<EDA_PATTERN_MATCH>& each_filter : m_fpFilters )
|
||||
{
|
||||
name.Empty();
|
||||
|
||||
// If the filter contains a ':' character, include the library name in the pattern
|
||||
if( each_filter->GetPattern().Contains( wxS( ":" ) ) )
|
||||
name = aNode.m_LibId.GetUniStringLibNickname().Lower() + wxS( ":" );
|
||||
|
||||
name += aNode.m_LibId.GetUniStringLibItemName().Lower();
|
||||
|
||||
if( each_filter->Find( name ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
if( !patternMatch( aNode.m_LibId, m_fpFilters ) )
|
||||
return -1;
|
||||
}
|
||||
|
||||
return true;
|
||||
if( filtering )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ protected:
|
|||
FOOTPRINT_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
||||
|
||||
private:
|
||||
bool filterFootprint( LIB_TREE_NODE& aNode );
|
||||
int filterFootprint( LIB_TREE_NODE& aNode );
|
||||
|
||||
void OnPaint( wxPaintEvent& aEvent );
|
||||
void OnOK( wxCommandEvent& aEvent );
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
PANEL_FOOTPRINT_CHOOSER::PANEL_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aFrame, wxTopLevelWindow* aParent,
|
||||
const wxArrayString& aFootprintHistoryList,
|
||||
std::function<bool( LIB_TREE_NODE& )> aFilter,
|
||||
std::function<int( LIB_TREE_NODE& )> aFilter,
|
||||
std::function<void()> aCloseHandler ) :
|
||||
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
|
||||
m_hsplitter( nullptr ),
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
*/
|
||||
PANEL_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aFrame, wxTopLevelWindow* aParent,
|
||||
const wxArrayString& aFootprintHistoryList,
|
||||
std::function<bool( LIB_TREE_NODE& )> aFilter,
|
||||
std::function<int( LIB_TREE_NODE& )> aFilter,
|
||||
std::function<void()> aCloseHandler );
|
||||
|
||||
~PANEL_FOOTPRINT_CHOOSER();
|
||||
|
@ -94,7 +94,7 @@ protected:
|
|||
LIB_TREE* m_tree;
|
||||
|
||||
PCB_BASE_FRAME* m_frame;
|
||||
std::function<bool( LIB_TREE_NODE& )> m_filter;
|
||||
std::function<int( LIB_TREE_NODE& )> m_filter;
|
||||
std::function<void()> m_closeHandler;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue