Performance optimizations.

This commit is contained in:
Alex 2022-07-10 01:30:52 +03:00 committed by Seth Hillbrand
parent 3081023b5e
commit aaf99eb0cc
8 changed files with 91 additions and 38 deletions

View File

@ -315,7 +315,7 @@ const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem )
if( it != m_driver_name_cache.end() ) if( it != m_driver_name_cache.end() )
return it->second; return it->second;
m_driver_name_cache[aItem] = driverName( aItem ); m_driver_name_cache.emplace( aItem, driverName( aItem ) );
return m_driver_name_cache.at( aItem ); return m_driver_name_cache.at( aItem );
} }
@ -1029,6 +1029,7 @@ void CONNECTION_GRAPH::processSubGraphs()
[&suffix]( SCH_CONNECTION* aConn ) -> wxString [&suffix]( SCH_CONNECTION* aConn ) -> wxString
{ {
wxString newName; wxString newName;
wxString suffixStr = std::to_wstring( suffix );
// For group buses with a prefix, we can add the suffix to the prefix. // For group buses with a prefix, we can add the suffix to the prefix.
// If they don't have a prefix, we force the creation of a prefix so that // If they don't have a prefix, we force the creation of a prefix so that
@ -1042,14 +1043,14 @@ void CONNECTION_GRAPH::processSubGraphs()
wxString oldName = aConn->Name().AfterFirst( '{' ); wxString oldName = aConn->Name().AfterFirst( '{' );
newName = wxString::Format( "%s_%u{%s", prefix, suffix, oldName ); newName << prefix << wxT( "_" ) << suffixStr << wxT( "{" ) << oldName;
aConn->ConfigureFromLabel( newName ); aConn->ConfigureFromLabel( newName );
} }
else else
{ {
newName = wxString::Format( "%s_%u", aConn->Name(), suffix ); newName << aConn->Name() << wxT( "_" ) << suffixStr;
aConn->SetSuffix( wxString::Format( "_%u", suffix ) ); aConn->SetSuffix( wxString( wxT( "_" ) ) << suffixStr );
} }
suffix++; suffix++;
@ -1724,8 +1725,14 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph )
continue; continue;
} }
const KIID& last_parent_uuid = aParent->m_sheet.Last()->m_Uuid;
for( SCH_SHEET_PIN* pin : candidate->m_hier_pins ) for( SCH_SHEET_PIN* pin : candidate->m_hier_pins )
{ {
// If the last sheet UUIDs won't match, no need to check the full path
if( pin->GetParent()->m_Uuid != last_parent_uuid )
continue;
SCH_SHEET_PATH pin_path = path; SCH_SHEET_PATH pin_path = path;
pin_path.push_back( pin->GetParent() ); pin_path.push_back( pin->GetParent() );

View File

@ -91,7 +91,15 @@ HIERARCHY_NAVIG_PANEL::HIERARCHY_NAVIG_PANEL( SCH_EDIT_FRAME* aParent ) : WX_PAN
sizer->Add( m_tree, 1, wxEXPAND, wxBORDER_NONE, 0 ); sizer->Add( m_tree, 1, wxEXPAND, wxBORDER_NONE, 0 );
m_events_bound = false;
UpdateHierarchyTree(); UpdateHierarchyTree();
// Enable selection events
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
m_events_bound = true;
} }
@ -127,6 +135,17 @@ void HIERARCHY_NAVIG_PANEL::buildHierarchyTree( SCH_SHEET_PATH* aList, const wxT
void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection() void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection()
{ {
bool eventsWereBound = m_events_bound;
if( eventsWereBound )
{
// Disable selection events
Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
m_events_bound = false;
}
std::function<void( const wxTreeItemId& )> selectSheet = [&]( const wxTreeItemId& id ) std::function<void( const wxTreeItemId& )> selectSheet = [&]( const wxTreeItemId& id )
{ {
wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) ); wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
@ -148,6 +167,15 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection()
}; };
selectSheet( m_tree->GetRootItem() ); selectSheet( m_tree->GetRootItem() );
if( eventsWereBound )
{
// Enable selection events
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
m_events_bound = true;
}
} }
@ -155,10 +183,17 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree()
{ {
Freeze(); Freeze();
bool eventsWereBound = m_events_bound;
if( eventsWereBound )
{
// Disable selection events // Disable selection events
Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
m_events_bound = false;
}
m_list.clear(); m_list.clear();
m_list.push_back( &m_frame->Schematic().Root() ); m_list.push_back( &m_frame->Schematic().Root() );
@ -173,10 +208,15 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree()
m_tree->ExpandAll(); m_tree->ExpandAll();
if( eventsWereBound )
{
// Enable selection events // Enable selection events
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this );
m_events_bound = true;
}
Thaw(); Thaw();
} }

View File

@ -112,6 +112,8 @@ private:
SCH_SHEET_PATH m_list; SCH_SHEET_PATH m_list;
SCH_EDIT_FRAME* m_frame; SCH_EDIT_FRAME* m_frame;
HIERARCHY_TREE* m_tree; HIERARCHY_TREE* m_tree;
bool m_events_bound;
}; };
#endif // HIERARCH_H #endif // HIERARCH_H

View File

@ -350,7 +350,8 @@ wxString SCH_CONNECTION::Name( bool aIgnoreSheet ) const
void SCH_CONNECTION::recacheName() void SCH_CONNECTION::recacheName()
{ {
m_cached_name = m_name.IsEmpty() ? "<NO NET>" : m_prefix + m_name + m_suffix; m_cached_name =
m_name.IsEmpty() ? wxT( "<NO NET>" ) : wxString( m_prefix ) << m_name << m_suffix;
bool prepend_path = true; bool prepend_path = true;
@ -374,7 +375,7 @@ void SCH_CONNECTION::recacheName()
} }
m_cached_name_with_path = m_cached_name_with_path =
prepend_path ? m_sheet.PathHumanReadable() + m_cached_name : m_cached_name; prepend_path ? m_sheet.PathHumanReadable() << m_cached_name : m_cached_name;
} }

View File

@ -297,16 +297,20 @@ wxString SCH_SHEET_PATH::PathHumanReadable( bool aUseShortRootName ) const
if( !empty() && at( 0 )->GetScreen() ) if( !empty() && at( 0 )->GetScreen() )
fileName = at( 0 )->GetScreen()->GetFileName(); fileName = at( 0 )->GetScreen()->GetFileName();
if( aUseShortRootName )
{
s = wxT( "/" ); // Use only the short name in netlists
}
else
{
wxFileName fn = fileName; wxFileName fn = fileName;
if( aUseShortRootName )
s = wxT( "/" ); // Use only the short name in netlists
else
s = fn.GetName() + wxT( "/" ); s = fn.GetName() + wxT( "/" );
}
// Start at 1 since we've already processed the root sheet. // Start at 1 since we've already processed the root sheet.
for( unsigned i = 1; i < size(); i++ ) for( unsigned i = 1; i < size(); i++ )
s = s + at( i )->GetFields()[ SHEETNAME ].GetShownText() + wxT( "/" ); s << at( i )->GetFields()[SHEETNAME].GetShownText() << wxT( "/" );
return s; return s;
} }

View File

@ -194,10 +194,9 @@ LSET PAD::ApertureMask()
bool PAD::IsFlipped() const bool PAD::IsFlipped() const
{ {
if( GetParent() && GetParent()->GetLayer() == B_Cu ) FOOTPRINT* parent = GetParent();
return true;
return false; return ( parent && parent->GetLayer() == B_Cu );
} }
@ -1437,7 +1436,7 @@ const BOX2I PAD::ViewBBox() const
FOOTPRINT* PAD::GetParent() const FOOTPRINT* PAD::GetParent() const
{ {
return dynamic_cast<FOOTPRINT*>( m_parent ); return dyn_cast<FOOTPRINT*>( m_parent );
} }

View File

@ -119,10 +119,6 @@ void PCB_POINT_EDITOR::Reset( RESET_REASON aReason )
m_editPoints.reset(); m_editPoints.reset();
m_altConstraint.reset(); m_altConstraint.reset();
getViewControls()->SetAutoPan( false ); getViewControls()->SetAutoPan( false );
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( getEditFrame<PCB_BASE_EDIT_FRAME>() );
m_statusPopup->SetTextColor( wxColour( 255, 0, 0 ) );
m_statusPopup->SetText( _( "Self-intersecting polygons are not allowed." ) );
} }
@ -1616,8 +1612,13 @@ bool PCB_POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const
{ {
bool valid = !aPoly.IsSelfIntersecting(); bool valid = !aPoly.IsSelfIntersecting();
if( m_statusPopup ) if( !m_statusPopup )
{ {
m_statusPopup.reset( new STATUS_TEXT_POPUP( getEditFrame<PCB_BASE_EDIT_FRAME>() ) );
m_statusPopup->SetTextColor( wxColour( 255, 0, 0 ) );
m_statusPopup->SetText( _( "Self-intersecting polygons are not allowed." ) );
}
if( valid ) if( valid )
{ {
m_statusPopup->Hide(); m_statusPopup->Hide();
@ -1628,7 +1629,6 @@ bool PCB_POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const
m_statusPopup->Move( p ); m_statusPopup->Move( p );
m_statusPopup->PopupFor( 1500 ); m_statusPopup->PopupFor( 1500 );
} }
}
return valid; return valid;
} }

View File

@ -163,7 +163,7 @@ private:
int changeEditMethod( const TOOL_EVENT& aEvent ); int changeEditMethod( const TOOL_EVENT& aEvent );
PCB_SELECTION_TOOL* m_selectionTool; PCB_SELECTION_TOOL* m_selectionTool;
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup; mutable std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
std::shared_ptr<EDIT_POINTS> m_editPoints; std::shared_ptr<EDIT_POINTS> m_editPoints;
EDIT_POINT* m_editedPoint; EDIT_POINT* m_editedPoint;