diff --git a/common/widgets/net_selector.cpp b/common/widgets/net_selector.cpp index 4e514651c5..636e1b74c2 100644 --- a/common/widgets/net_selector.cpp +++ b/common/widgets/net_selector.cpp @@ -131,7 +131,7 @@ public: return NO_NET; } - void SetNetInfo( NETINFO_LIST* aNetInfoList ) + void SetNetInfo( const NETINFO_LIST* aNetInfoList ) { m_netinfoList = aNetInfoList; rebuildList(); @@ -233,12 +233,10 @@ public: BOARD* board = m_netinfoList->GetParent(); NETINFO_ITEM *newnet = new NETINFO_ITEM( m_board, remainingName, 0 ); - // add the new netinfo through the board's function so that - // board listeners get notified and things stay in sync. - if( board != nullptr ) + wxASSERT( board ); + + if( board ) board->Add( newnet ); - else - m_netinfoList->AppendNet( newnet ); rebuildList(); @@ -249,12 +247,10 @@ public: } else { - // This indicates that the NETINFO_ITEM was not successfully appended - // to the list for unknown reasons - if( board != nullptr ) + // This indicates that the NETINFO_ITEM was not successfully appended to the + // list for unknown reasons + if( board ) board->Remove( newnet ); - else - m_netinfoList->RemoveNet( newnet ); delete newnet; } @@ -534,21 +530,21 @@ protected: } protected: - wxTextValidator* m_filterValidator; - wxTextCtrl* m_filterCtrl; - wxListBox* m_listBox; - int m_minPopupWidth; - int m_maxPopupHeight; + wxTextValidator* m_filterValidator; + wxTextCtrl* m_filterCtrl; + wxListBox* m_listBox; + int m_minPopupWidth; + int m_maxPopupHeight; - NETINFO_LIST* m_netinfoList; - wxString m_indeterminateLabel; - BOARD* m_board; + const NETINFO_LIST* m_netinfoList; + wxString m_indeterminateLabel; + BOARD* m_board; - int m_selectedNetcode; + int m_selectedNetcode; std::map m_unescapedNetNameMap; - wxEvtHandler* m_focusHandler; + wxEvtHandler* m_focusHandler; }; @@ -609,7 +605,7 @@ void NET_SELECTOR::onKeyDown( wxKeyEvent& aEvt ) } -void NET_SELECTOR::SetNetInfo( NETINFO_LIST* aNetInfoList ) +void NET_SELECTOR::SetNetInfo( const NETINFO_LIST* aNetInfoList ) { m_netSelectorPopup->SetNetInfo( aNetInfoList ); } diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 1a95de1189..7c460b8547 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -465,7 +465,7 @@ void DISPLAY_FOOTPRINTS_FRAME::ReloadFootprint( FOOTPRINT* aFootprint ) return; GetBoard()->DeleteAllFootprints(); - GetBoard()->GetNetInfo().RemoveUnusedNets(); + GetBoard()->RemoveUnusedNets( nullptr ); GetCanvas()->GetView()->Clear(); @@ -504,7 +504,7 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() return; GetBoard()->DeleteAllFootprints(); - GetBoard()->GetNetInfo().RemoveUnusedNets(); + GetBoard()->RemoveUnusedNets( nullptr ); GetCanvas()->GetView()->Clear(); INFOBAR_REPORTER infoReporter( m_infoBar ); diff --git a/eeschema/lib_item.h b/eeschema/lib_item.h index e1bdec3cde..3f61330c70 100644 --- a/eeschema/lib_item.h +++ b/eeschema/lib_item.h @@ -199,7 +199,7 @@ public: return std::max( GetPenWidth(), aSettings->GetMinPenWidth() ); } - LIB_SYMBOL* GetParent() const + LIB_SYMBOL* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type { return (LIB_SYMBOL*) m_parent; } diff --git a/include/widgets/net_selector.h b/include/widgets/net_selector.h index b3a789b538..ce411311cc 100644 --- a/include/widgets/net_selector.h +++ b/include/widgets/net_selector.h @@ -46,7 +46,7 @@ public: ~NET_SELECTOR() override; - void SetNetInfo( NETINFO_LIST* aNetInfoList ); + void SetNetInfo( const NETINFO_LIST* aNetInfoList ); // Set to wxEmptyString to disallow indeterminate settings void SetIndeterminateString( const wxString& aString ); diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 3553c639d8..21ddce8882 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -1163,6 +1163,12 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID ) const return group; } + for( NETINFO_ITEM* netInfo : m_NetInfo ) + { + if( netInfo->m_Uuid == aID ) + return netInfo; + } + if( m_Uuid == aID ) return const_cast( this ); diff --git a/pcbnew/board.h b/pcbnew/board.h index c9d64d71c1..9da833cce3 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -805,9 +805,9 @@ public: return m_NetInfo; } - NETINFO_LIST& GetNetInfo() + void RemoveUnusedNets( BOARD_COMMIT* aCommit ) { - return m_NetInfo; + m_NetInfo.RemoveUnusedNets( aCommit ); } #ifndef SWIG diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index b25d477e4b..cea5eb5656 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -370,7 +370,7 @@ bool DIALOG_COPPER_ZONE::TransferDataToWindow() void DIALOG_COPPER_ZONE::readNetInformation() { - NETINFO_LIST& netInfoList = m_Parent->GetBoard()->GetNetInfo(); + const NETINFO_LIST& netInfoList = m_Parent->GetBoard()->GetNetInfo(); m_netInfoItemList.clear(); m_netInfoItemList.reserve( netInfoList.GetNetCount() ); diff --git a/pcbnew/dialogs/dialog_net_inspector.cpp b/pcbnew/dialogs/dialog_net_inspector.cpp index 3ca5e04d29..1aaaae52f3 100644 --- a/pcbnew/dialogs/dialog_net_inspector.cpp +++ b/pcbnew/dialogs/dialog_net_inspector.cpp @@ -2112,9 +2112,9 @@ void DIALOG_NET_INSPECTOR::onRenameNet( wxCommandEvent& aEvent ) // is easier. auto removed_item = m_data_model->deleteItem( m_data_model->findItem( net ) ); - m_brd->GetNetInfo().RemoveNet( net ); + m_brd->Remove( net ); net->SetNetname( fullNetName ); - m_brd->GetNetInfo().AppendNet( net ); + m_brd->Add( net ); m_frame->OnModify(); if( netFilterMatches( net ) ) diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index b80d0f527e..74ac039d3f 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -1058,7 +1058,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) selectionTool->ClearSelection( true /* quiet mode */ ); GetBoard()->DeleteAllFootprints(); - GetBoard()->GetNetInfo().RemoveUnusedNets(); + GetBoard()->RemoveUnusedNets( nullptr ); FOOTPRINT* footprint = PROJECT_PCB::PcbFootprintLibs( &Prj() )->FootprintLoad( getCurNickname(), getCurFootprintName() ); diff --git a/pcbnew/netinfo.h b/pcbnew/netinfo.h index 11d605c0ff..f86ae1da53 100644 --- a/pcbnew/netinfo.h +++ b/pcbnew/netinfo.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -36,27 +36,16 @@ #include - -class wxDC; -class LINE_READER; class EDA_DRAW_FRAME; class PAD; class PCB_TRACK; class BOARD; class BOARD_ITEM; +class BOARD_COMMIT; class MSG_PANEL_ITEM; class PCB_BASE_FRAME; -/*****************************/ -/* flags for a RATSNEST_ITEM */ -/*****************************/ -#define CH_VISIBLE 1 /* Visible */ -#define CH_UNROUTABLE 2 /* Don't use autorouter. */ -#define CH_ROUTE_REQ 4 /* Must be routed by the autorouter. */ -#define CH_ACTIF 8 /* Not routed. */ -#define LOCAL_RATSNEST_ITEM 0x8000 /* Line between two pads of a single footprint. */ - DECL_VEC_FOR_SWIG( PADS_VEC, PAD* ) DECL_VEC_FOR_SWIG( TRACKS_VEC, PCB_TRACK* ) @@ -175,7 +164,7 @@ public: */ void Clear(); - BOARD* GetParent() const + BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type { return m_parent; } @@ -360,22 +349,6 @@ public: */ unsigned GetNetCount() const { return m_netNames.size(); } - /** - * Add \a aNewElement to the end of the net list. Negative net code means it is going to be - * auto-assigned. - */ - void AppendNet( NETINFO_ITEM* aNewElement ); - - /** - * Remove a net from the net list. - */ - void RemoveNet( NETINFO_ITEM* aNet ); - void RemoveUnusedNets(); - - /** - * @return the number of pads in board. - */ - /// Return the name map, at least for python. const NETNAMES_MAP& NetsByName() const { return m_netNames; } @@ -471,6 +444,19 @@ public: return m_parent; } +protected: // Access is through the BOARD, which is a friend class + /** + * Add \a aNewElement to the end of the net list. Negative net code means it is going to be + * auto-assigned. + */ + void AppendNet( NETINFO_ITEM* aNewElement ); + + /** + * Remove a net from the net list. + */ + void RemoveNet( NETINFO_ITEM* aNet ); + void RemoveUnusedNets( BOARD_COMMIT* aCommit ); + private: /** * Delete the list of nets (and free memory). diff --git a/pcbnew/netinfo_list.cpp b/pcbnew/netinfo_list.cpp index 621bbd9819..80f3f55cd2 100644 --- a/pcbnew/netinfo_list.cpp +++ b/pcbnew/netinfo_list.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -113,19 +114,24 @@ void NETINFO_LIST::RemoveNet( NETINFO_ITEM* aNet ) } -void NETINFO_LIST::RemoveUnusedNets() +void NETINFO_LIST::RemoveUnusedNets( BOARD_COMMIT* aCommit ) { - NETCODES_MAP existingNets = m_netCodes; + NETCODES_MAP existingNets = m_netCodes; + std::vector unusedNets; m_netCodes.clear(); m_netNames.clear(); - for( std::pair item : existingNets ) + for( const auto& [ netCode, netInfo ] : existingNets ) { - if( item.second->IsCurrent() ) + if( netInfo->IsCurrent() ) { - m_netNames.insert( std::make_pair( item.second->GetNetname(), item.second ) ); - m_netCodes.insert( std::make_pair( item.first, item.second ) ); + m_netNames.insert( std::make_pair( netInfo->GetNetname(), netInfo ) ); + m_netCodes.insert( std::make_pair( netCode, netInfo ) ); + } + else if( aCommit ) + { + aCommit->Removed( netInfo ); } } } diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp index 706e7ee4fb..19a81882e5 100644 --- a/pcbnew/netlist_reader/board_netlist_updater.cpp +++ b/pcbnew/netlist_reader/board_netlist_updater.cpp @@ -1239,7 +1239,7 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) } } - m_board->GetNetInfo().RemoveUnusedNets(); + m_board->RemoveUnusedNets( &m_commit ); // When new footprints are added, the automatic zone refill is disabled because: // * it creates crashes when calculating dynamic ratsnests if auto refill is enabled. diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index ec4f393259..30ccbbb29d 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -60,7 +60,7 @@ bool PCB_EDIT_FRAME::LoadProjectSettings() KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings(); KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast( rs ); - NETINFO_LIST& nets = GetBoard()->GetNetInfo(); + const NETINFO_LIST& nets = GetBoard()->GetNetInfo(); std::set& hiddenNets = renderSettings->GetHiddenNets(); hiddenNets.clear(); @@ -154,9 +154,9 @@ void PCB_EDIT_FRAME::SaveProjectLocalSettings() // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS std::shared_ptr& netSettings = project.NetSettings(); - NETINFO_LIST& nets = GetBoard()->GetNetInfo(); - KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings(); - KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast( rs ); + const NETINFO_LIST& nets = GetBoard()->GetNetInfo(); + KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings(); + KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast( rs ); netSettings->m_NetColorAssignments.clear(); @@ -224,7 +224,7 @@ void PCB_EDIT_FRAME::saveProjectSettings() localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth; // Net display settings - NETINFO_LIST& nets = GetBoard()->GetNetInfo(); + const NETINFO_LIST& nets = GetBoard()->GetNetInfo(); KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings(); KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast( rs ); diff --git a/pcbnew/specctra_import_export/specctra_export.cpp b/pcbnew/specctra_import_export/specctra_export.cpp index 4c457a61b9..7b81499564 100644 --- a/pcbnew/specctra_import_export/specctra_export.cpp +++ b/pcbnew/specctra_import_export/specctra_export.cpp @@ -1446,10 +1446,10 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //---------------------------- { - PIN_REF empty( m_pcb->m_network ); - std::string componentId; - int highestNetCode = 0; - NETINFO_LIST& netInfo = aBoard->GetNetInfo(); + PIN_REF empty( m_pcb->m_network ); + std::string componentId; + int highestNetCode = 0; + const NETINFO_LIST& netInfo = aBoard->GetNetInfo(); // find the highest numbered netCode within the board. for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i ) diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index cb8f7af413..63692cd3b3 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -2946,12 +2946,12 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) int selectPossibleNetsByPopMenu( std::list& aNetcodeList ) { - ACTION_MENU menu( true ); - NETINFO_LIST& netInfo = m_board->GetNetInfo(); - std::map menuIDNetCodeMap; - int menuID = 1; + ACTION_MENU menu( true ); + const NETINFO_LIST& netInfo = m_board->GetNetInfo(); + std::map menuIDNetCodeMap; + int menuID = 1; - for( auto& netcode : aNetcodeList ) + for( int netcode : aNetcodeList ) { wxString menuText; if( menuID < 10 ) diff --git a/qa/tests/pcbnew/test_libeval_compiler.cpp b/qa/tests/pcbnew/test_libeval_compiler.cpp index 4cac3ec07b..dada07850a 100644 --- a/qa/tests/pcbnew/test_libeval_compiler.cpp +++ b/qa/tests/pcbnew/test_libeval_compiler.cpp @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE( IntrospectedProperties ) BOARD brd; - NETINFO_LIST& netInfo = brd.GetNetInfo(); + const NETINFO_LIST& netInfo = brd.GetNetInfo(); std::shared_ptr netclass1( new NETCLASS( "HV" ) ); std::shared_ptr netclass2( new NETCLASS( "otherClass" ) );