Performance enhancements for cross-probing.

While found when profiling cross-probing, many of these will also
improve other things.
This commit is contained in:
Jeff Young 2019-09-27 19:57:14 +01:00
parent 25dee38f70
commit 4bf2b6a9f7
7 changed files with 118 additions and 49 deletions

View File

@ -92,7 +92,9 @@ EDA_TEXT::EDA_TEXT( const wxString& text ) :
{
int sz = Mils2iu( DEFAULT_SIZE_TEXT );
SetTextSize( wxSize( sz, sz ) );
m_shown_text = UnescapeString( text );
if( !text.IsEmpty() )
m_shown_text = UnescapeString( text );
}
@ -116,6 +118,13 @@ void EDA_TEXT::SetText( const wxString& aText )
}
void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
{
m_text = aSrc.m_text;
m_shown_text = aSrc.m_shown_text;
}
void EDA_TEXT::SetEffects( const EDA_TEXT& aSrc )
{
m_e = aSrc.m_e;

View File

@ -98,7 +98,6 @@ void LIB_FIELD::Init( int id )
// template fieldsnames' initial visibility is controlled by the template fieldname config.
if( id == DATASHEET || id == FOOTPRINT )
SetVisible( false );
}
@ -179,7 +178,7 @@ void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
{
aTarget->m_name = m_name;
aTarget->SetText( GetText() );
aTarget->CopyText( *this );
aTarget->SetEffects( *this );
aTarget->SetParent( m_Parent );
}

View File

@ -1925,6 +1925,18 @@ void SCH_COMPONENT::ClearHighlightedPins()
}
bool SCH_COMPONENT::HasHighlightedPins()
{
for( const SCH_PIN& pin : m_pins )
{
if( pin.IsHighlighted() )
return true;
}
return false;
}
void SCH_COMPONENT::HighlightPin( LIB_PIN* aPin )
{
if( m_pinMap.count( aPin ) )
@ -1932,14 +1944,32 @@ void SCH_COMPONENT::HighlightPin( LIB_PIN* aPin )
}
void SCH_COMPONENT::ClearAllHighlightFlags()
bool SCH_COMPONENT::ClearAllHighlightFlags()
{
ClearFlags( HIGHLIGHTED );
bool retVal = false;
if( IsHighlighted() )
{
ClearFlags( HIGHLIGHTED );
retVal = true;
}
// Clear the HIGHLIGHTED flag of pins
ClearHighlightedPins();
if( HasHighlightedPins() )
{
ClearHighlightedPins();
retVal = true;
}
// Clear the HIGHLIGHTED flag of other items, currently only fields
for( SCH_FIELD& each_field : m_Fields )
each_field.ClearFlags( HIGHLIGHTED );
{
if( each_field.IsHighlighted() )
{
each_field.ClearFlags( HIGHLIGHTED );
retVal = true;
}
}
return retVal;
}

View File

@ -325,10 +325,9 @@ public:
void SetTimeStamp( timestamp_t aNewTimeStamp );
/**
* Clear the HIGHLIGHTED flag of all items of the component
* (fields, pins ...)
* Clear the HIGHLIGHTED flag of all items of the component (fields, pins ...)
*/
void ClearAllHighlightFlags();
bool ClearAllHighlightFlags();
const EDA_RECT GetBoundingBox() const override;
@ -640,6 +639,8 @@ public:
void ClearHighlightedPins();
bool HasHighlightedPins();
void HighlightPin( LIB_PIN* aPin );
private:

View File

@ -189,10 +189,12 @@ void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin )
if( aItem && aItem->Type() == SCH_COMPONENT_T && aPin )
{
static_cast<SCH_COMPONENT*>( aItem )->HighlightPin( aPin );
Update( aItem, REPAINT );
}
else if( aItem )
{
aItem->SetFlags( HIGHLIGHTED );
Update( aItem, REPAINT );
}
else
{
@ -204,7 +206,11 @@ void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin )
if( eitem )
{
eitem->ClearFlags( HIGHLIGHTED );
if( eitem->IsHighlighted() )
{
eitem->ClearFlags( HIGHLIGHTED );
Update( eitem, REPAINT );
}
if( eitem->Type() == SCH_COMPONENT_T )
{
@ -214,9 +220,6 @@ void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin )
}
}
}
// ugly but I guess OK for the moment...
UpdateAllItems( ALL );
}
}; // namespace KIGFX

View File

@ -205,6 +205,8 @@ public:
void SwapText( EDA_TEXT& aTradingPartner );
void CopyText( const EDA_TEXT& aSrc );
/**
* Helper function used in search and replace dialog
* performs a text replace using the find and replace criteria in \a aSearchData.

View File

@ -307,6 +307,7 @@ PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aCli
if ( aConfirmLockedItems && CheckLock() == SELECTION_LOCKED )
{
ClearSelection();
return m_selection;
}
if( aClientFilter )
@ -387,9 +388,10 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
bool* aSelectionCancelledFlag,
CLIENT_SELECTION_FILTER aClientFilter )
{
auto guide = getCollectorsGuide();
GENERAL_COLLECTOR collector;
auto displayOpts = (PCB_DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
GENERAL_COLLECTORS_GUIDE guide = getCollectorsGuide();
GENERAL_COLLECTOR collector;
PCB_DISPLAY_OPTIONS* displayOpts = (PCB_DISPLAY_OPTIONS*) m_frame->GetDisplayOptions();
bool cleared = false;
guide.SetIgnoreZoneFills( displayOpts->m_DisplayZonesMode != 0 );
@ -433,7 +435,15 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
}
if( !m_additive && !m_subtractive && !m_exclusive_or )
ClearSelection();
{
if( m_selection.GetSize() > 0 )
{
// Don't fire an event now as it will end up redundant if we fire a SelectedEvent
// or an UnselectedEvent.
cleared = true;
ClearSelection( true );
}
}
if( collector.GetCount() == 1 )
{
@ -453,6 +463,9 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
}
}
if( cleared )
m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
return false;
}
@ -461,7 +474,7 @@ bool SELECTION_TOOL::selectCursor( bool aForceSelect, CLIENT_SELECTION_FILTER aC
{
if( aForceSelect || m_selection.Empty() )
{
ClearSelection();
ClearSelection( true /*quiet mode*/ );
selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
}
@ -478,6 +491,9 @@ bool SELECTION_TOOL::selectMultiple()
KIGFX::PREVIEW::SELECTION_AREA area;
view->Add( &area );
bool anyAdded = false;
bool anySubtracted = false;
while( TOOL_EVENT* evt = Wait() )
{
if( evt->IsCancelInteractive() || evt->IsActivate() )
@ -489,7 +505,13 @@ bool SELECTION_TOOL::selectMultiple()
if( evt->IsDrag( BUT_LEFT ) )
{
if( !m_additive && !m_subtractive && !m_exclusive_or )
ClearSelection();
{
if( m_selection.GetSize() > 0 )
{
anySubtracted = true;
ClearSelection( true /*quiet mode*/ );
}
}
// Start drawing a selection box
area.SetOrigin( evt->DragOrigin() );
@ -527,8 +549,6 @@ bool SELECTION_TOOL::selectMultiple()
* Right > Left : Select objects that are crossed by selection
*/
bool windowSelection = width >= 0 ? true : false;
bool anyAdded = false;
bool anySubtracted = false;
if( view->IsMirroredX() )
windowSelection = !windowSelection;
@ -565,8 +585,7 @@ bool SELECTION_TOOL::selectMultiple()
// Inform other potentially interested tools
if( anyAdded )
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
if( anySubtracted )
else if( anySubtracted )
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
break; // Stop waiting for events
@ -732,9 +751,8 @@ void SELECTION_TOOL::UnbrightenItem( BOARD_ITEM* aItem )
void connectedTrackFilter( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
{
/* Narrow the collection down to a single TRACK item for a trivial
* connection, or multiple TRACK items for non-trivial connections.
*/
// Narrow the collection down to a single TRACK item for a trivial connection, or
// multiple TRACK items for non-trivial connections.
for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
{
if( !dynamic_cast<TRACK*>( aCollector[i] ) )
@ -792,9 +810,8 @@ int SELECTION_TOOL::expandConnection( const TOOL_EVENT& aEvent )
void connectedItemFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector )
{
/* Narrow the collection down to a single BOARD_CONNECTED_ITEM for each
* represented net. All other items types are removed.
*/
// Narrow the collection down to a single BOARD_CONNECTED_ITEM for each represented net.
// All other items types are removed.
std::set<int> representedNets;
for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
@ -1032,7 +1049,7 @@ void SELECTION_TOOL::zoomFitSelection()
int SELECTION_TOOL::selectSheetContents( const TOOL_EVENT& aEvent )
{
ClearSelection();
ClearSelection( true /*quiet mode*/ );
wxString* sheetpath = aEvent.Parameter<wxString*>();
selectAllItemsOnSheet( *sheetpath );
@ -1063,7 +1080,7 @@ int SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent )
auto mod = dynamic_cast<MODULE*>( item );
ClearSelection();
ClearSelection( true /*quiet mode*/ );
// get the lowest subsheet name for this.
wxString sheetPath = mod->GetPath();
@ -1082,7 +1099,15 @@ int SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent )
void SELECTION_TOOL::findCallback( BOARD_ITEM* aItem )
{
ClearSelection();
bool cleared = false;
if( m_selection.GetSize() > 0 )
{
// Don't fire an event now; most of the time it will be redundant as we're about to
// fire a SelectedEvent.
cleared = true;
ClearSelection( true /*quiet mode*/ );
}
if( aItem )
{
@ -1092,6 +1117,10 @@ void SELECTION_TOOL::findCallback( BOARD_ITEM* aItem )
// Inform other potentially interested tools
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
}
else if( cleared )
{
m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
}
m_frame->GetCanvas()->ForceRefresh();
}
@ -1192,34 +1221,32 @@ static bool itemIsIncludedByFilter( const BOARD_ITEM& aItem,
int SELECTION_TOOL::filterSelection( const TOOL_EVENT& aEvent )
{
auto& opts = m_priv->m_filterOpts;
DIALOG_BLOCK_OPTIONS dlg( m_frame, opts, false, _( "Filter selection" ) );
const BOARD& board = *getModel<BOARD>();
DIALOG_BLOCK_OPTIONS::OPTIONS& opts = m_priv->m_filterOpts;
DIALOG_BLOCK_OPTIONS dlg( m_frame, opts, false, _( "Filter selection" ) );
const int cmd = dlg.ShowModal();
if( cmd != wxID_OK )
return 0;
const auto& board = *getModel<BOARD>();
// copy current selection
auto selection = m_selection.GetItems();
std::deque<EDA_ITEM*> selection = m_selection.GetItems();
// clear current selection
ClearSelection();
ClearSelection( true /*quiet mode*/ );
// copy selection items from the saved selection
// according to the dialog options
for( auto i : selection )
// re-select items from the saved selection according to the dialog options
for( EDA_ITEM* i : selection )
{
auto item = static_cast<BOARD_ITEM*>( i );
bool include = itemIsIncludedByFilter( *item, board, opts );
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
bool include = itemIsIncludedByFilter( *item, board, opts );
if( include )
{
select( item );
}
}
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
return 0;
}
@ -1642,14 +1669,12 @@ void SELECTION_TOOL::select( BOARD_ITEM* aItem )
}
highlight( aItem, SELECTED, &m_selection );
view()->Update( &m_selection );
}
void SELECTION_TOOL::unselect( BOARD_ITEM* aItem )
{
unhighlight( aItem, SELECTED, &m_selection );
view()->Update( &m_selection );
if( m_selection.Empty() )
m_locked = true;