From aaf99eb0cc1a4b7b9d73b122e2bb4c3afd090cee Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 10 Jul 2022 01:30:52 +0300 Subject: [PATCH] Performance optimizations. --- eeschema/connection_graph.cpp | 15 ++++++--- eeschema/hierarch.cpp | 52 +++++++++++++++++++++++++++---- eeschema/hierarch.h | 2 ++ eeschema/sch_connection.cpp | 5 +-- eeschema/sch_sheet_path.cpp | 12 ++++--- pcbnew/pad.cpp | 7 ++--- pcbnew/tools/pcb_point_editor.cpp | 30 +++++++++--------- pcbnew/tools/pcb_point_editor.h | 6 ++-- 8 files changed, 91 insertions(+), 38 deletions(-) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index f91803110d..1af5510186 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -315,7 +315,7 @@ const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) if( it != m_driver_name_cache.end() ) 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 ); } @@ -1029,6 +1029,7 @@ void CONNECTION_GRAPH::processSubGraphs() [&suffix]( SCH_CONNECTION* aConn ) -> wxString { wxString newName; + wxString suffixStr = std::to_wstring( suffix ); // 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 @@ -1042,14 +1043,14 @@ void CONNECTION_GRAPH::processSubGraphs() wxString oldName = aConn->Name().AfterFirst( '{' ); - newName = wxString::Format( "%s_%u{%s", prefix, suffix, oldName ); + newName << prefix << wxT( "_" ) << suffixStr << wxT( "{" ) << oldName; aConn->ConfigureFromLabel( newName ); } else { - newName = wxString::Format( "%s_%u", aConn->Name(), suffix ); - aConn->SetSuffix( wxString::Format( "_%u", suffix ) ); + newName << aConn->Name() << wxT( "_" ) << suffixStr; + aConn->SetSuffix( wxString( wxT( "_" ) ) << suffixStr ); } suffix++; @@ -1724,8 +1725,14 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph ) continue; } + const KIID& last_parent_uuid = aParent->m_sheet.Last()->m_Uuid; + 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; pin_path.push_back( pin->GetParent() ); diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index d1c9417aab..2f57cd6a72 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -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 ); + m_events_bound = false; + 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() { + 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 selectSheet = [&]( const wxTreeItemId& id ) { wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) ); @@ -148,6 +167,15 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection() }; 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,9 +183,16 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree() { Freeze(); - // Disable selection events - Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); - Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + 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; + } m_list.clear(); m_list.push_back( &m_frame->Schematic().Root() ); @@ -173,9 +208,14 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree() m_tree->ExpandAll(); - // Enable selection events - Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); - Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + 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; + } Thaw(); } diff --git a/eeschema/hierarch.h b/eeschema/hierarch.h index 3685e49423..58738b2040 100644 --- a/eeschema/hierarch.h +++ b/eeschema/hierarch.h @@ -112,6 +112,8 @@ private: SCH_SHEET_PATH m_list; SCH_EDIT_FRAME* m_frame; HIERARCHY_TREE* m_tree; + + bool m_events_bound; }; #endif // HIERARCH_H diff --git a/eeschema/sch_connection.cpp b/eeschema/sch_connection.cpp index de33f8b690..89e2921c4e 100644 --- a/eeschema/sch_connection.cpp +++ b/eeschema/sch_connection.cpp @@ -350,7 +350,8 @@ wxString SCH_CONNECTION::Name( bool aIgnoreSheet ) const void SCH_CONNECTION::recacheName() { - m_cached_name = m_name.IsEmpty() ? "" : m_prefix + m_name + m_suffix; + m_cached_name = + m_name.IsEmpty() ? wxT( "" ) : wxString( m_prefix ) << m_name << m_suffix; bool prepend_path = true; @@ -374,7 +375,7 @@ void SCH_CONNECTION::recacheName() } 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; } diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 89393312b5..484deb0af4 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -297,16 +297,20 @@ wxString SCH_SHEET_PATH::PathHumanReadable( bool aUseShortRootName ) const if( !empty() && at( 0 )->GetScreen() ) fileName = at( 0 )->GetScreen()->GetFileName(); - wxFileName fn = fileName; - if( aUseShortRootName ) - s = wxT( "/" ); // Use only the short name in netlists + { + s = wxT( "/" ); // Use only the short name in netlists + } else + { + wxFileName fn = fileName; + s = fn.GetName() + wxT( "/" ); + } // Start at 1 since we've already processed the root sheet. for( unsigned i = 1; i < size(); i++ ) - s = s + at( i )->GetFields()[ SHEETNAME ].GetShownText() + wxT( "/" ); + s << at( i )->GetFields()[SHEETNAME].GetShownText() << wxT( "/" ); return s; } diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index 49829b5053..d5f675287b 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -194,10 +194,9 @@ LSET PAD::ApertureMask() bool PAD::IsFlipped() const { - if( GetParent() && GetParent()->GetLayer() == B_Cu ) - return true; + FOOTPRINT* parent = GetParent(); - return false; + return ( parent && parent->GetLayer() == B_Cu ); } @@ -1437,7 +1436,7 @@ const BOX2I PAD::ViewBBox() const FOOTPRINT* PAD::GetParent() const { - return dynamic_cast( m_parent ); + return dyn_cast( m_parent ); } diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index b9723a5e87..8e2de49a24 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -119,10 +119,6 @@ void PCB_POINT_EDITOR::Reset( RESET_REASON aReason ) m_editPoints.reset(); m_altConstraint.reset(); getViewControls()->SetAutoPan( false ); - - m_statusPopup = std::make_unique( getEditFrame() ); - m_statusPopup->SetTextColor( wxColour( 255, 0, 0 ) ); - m_statusPopup->SetText( _( "Self-intersecting polygons are not allowed." ) ); } @@ -1616,18 +1612,22 @@ bool PCB_POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const { bool valid = !aPoly.IsSelfIntersecting(); - if( m_statusPopup ) + if( !m_statusPopup ) { - if( valid ) - { - m_statusPopup->Hide(); - } - else - { - wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 ); - m_statusPopup->Move( p ); - m_statusPopup->PopupFor( 1500 ); - } + m_statusPopup.reset( new STATUS_TEXT_POPUP( getEditFrame() ) ); + m_statusPopup->SetTextColor( wxColour( 255, 0, 0 ) ); + m_statusPopup->SetText( _( "Self-intersecting polygons are not allowed." ) ); + } + + if( valid ) + { + m_statusPopup->Hide(); + } + else + { + wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 ); + m_statusPopup->Move( p ); + m_statusPopup->PopupFor( 1500 ); } return valid; diff --git a/pcbnew/tools/pcb_point_editor.h b/pcbnew/tools/pcb_point_editor.h index 6bcdd6178f..a789edef0b 100644 --- a/pcbnew/tools/pcb_point_editor.h +++ b/pcbnew/tools/pcb_point_editor.h @@ -162,9 +162,9 @@ private: ///< Change the edit method to an alternative method ( currently, arcs only ) int changeEditMethod( const TOOL_EVENT& aEvent ); - PCB_SELECTION_TOOL* m_selectionTool; - std::unique_ptr m_statusPopup; - std::shared_ptr m_editPoints; + PCB_SELECTION_TOOL* m_selectionTool; + mutable std::unique_ptr m_statusPopup; + std::shared_ptr m_editPoints; EDIT_POINT* m_editedPoint; EDIT_POINT* m_hoveredPoint;