NETINFO_ITEMs are owned by BOARD.

Lifecylce management must go through BOARD_COMMIT (or at least
the frame's undo/redo lists).
This commit is contained in:
Jeff Young 2023-10-04 21:01:33 +01:00
parent 6136c2438d
commit 31c488bc23
16 changed files with 78 additions and 84 deletions

View File

@ -131,7 +131,7 @@ public:
return NO_NET; return NO_NET;
} }
void SetNetInfo( NETINFO_LIST* aNetInfoList ) void SetNetInfo( const NETINFO_LIST* aNetInfoList )
{ {
m_netinfoList = aNetInfoList; m_netinfoList = aNetInfoList;
rebuildList(); rebuildList();
@ -233,12 +233,10 @@ public:
BOARD* board = m_netinfoList->GetParent(); BOARD* board = m_netinfoList->GetParent();
NETINFO_ITEM *newnet = new NETINFO_ITEM( m_board, remainingName, 0 ); NETINFO_ITEM *newnet = new NETINFO_ITEM( m_board, remainingName, 0 );
// add the new netinfo through the board's function so that wxASSERT( board );
// board listeners get notified and things stay in sync.
if( board != nullptr ) if( board )
board->Add( newnet ); board->Add( newnet );
else
m_netinfoList->AppendNet( newnet );
rebuildList(); rebuildList();
@ -249,12 +247,10 @@ public:
} }
else else
{ {
// This indicates that the NETINFO_ITEM was not successfully appended // This indicates that the NETINFO_ITEM was not successfully appended to the
// to the list for unknown reasons // list for unknown reasons
if( board != nullptr ) if( board )
board->Remove( newnet ); board->Remove( newnet );
else
m_netinfoList->RemoveNet( newnet );
delete newnet; delete newnet;
} }
@ -540,7 +536,7 @@ protected:
int m_minPopupWidth; int m_minPopupWidth;
int m_maxPopupHeight; int m_maxPopupHeight;
NETINFO_LIST* m_netinfoList; const NETINFO_LIST* m_netinfoList;
wxString m_indeterminateLabel; wxString m_indeterminateLabel;
BOARD* m_board; BOARD* m_board;
@ -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 ); m_netSelectorPopup->SetNetInfo( aNetInfoList );
} }

View File

@ -465,7 +465,7 @@ void DISPLAY_FOOTPRINTS_FRAME::ReloadFootprint( FOOTPRINT* aFootprint )
return; return;
GetBoard()->DeleteAllFootprints(); GetBoard()->DeleteAllFootprints();
GetBoard()->GetNetInfo().RemoveUnusedNets(); GetBoard()->RemoveUnusedNets( nullptr );
GetCanvas()->GetView()->Clear(); GetCanvas()->GetView()->Clear();
@ -504,7 +504,7 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()
return; return;
GetBoard()->DeleteAllFootprints(); GetBoard()->DeleteAllFootprints();
GetBoard()->GetNetInfo().RemoveUnusedNets(); GetBoard()->RemoveUnusedNets( nullptr );
GetCanvas()->GetView()->Clear(); GetCanvas()->GetView()->Clear();
INFOBAR_REPORTER infoReporter( m_infoBar ); INFOBAR_REPORTER infoReporter( m_infoBar );

View File

@ -199,7 +199,7 @@ public:
return std::max( GetPenWidth(), aSettings->GetMinPenWidth() ); 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; return (LIB_SYMBOL*) m_parent;
} }

View File

@ -46,7 +46,7 @@ public:
~NET_SELECTOR() override; ~NET_SELECTOR() override;
void SetNetInfo( NETINFO_LIST* aNetInfoList ); void SetNetInfo( const NETINFO_LIST* aNetInfoList );
// Set to wxEmptyString to disallow indeterminate settings // Set to wxEmptyString to disallow indeterminate settings
void SetIndeterminateString( const wxString& aString ); void SetIndeterminateString( const wxString& aString );

View File

@ -1163,6 +1163,12 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID ) const
return group; return group;
} }
for( NETINFO_ITEM* netInfo : m_NetInfo )
{
if( netInfo->m_Uuid == aID )
return netInfo;
}
if( m_Uuid == aID ) if( m_Uuid == aID )
return const_cast<BOARD*>( this ); return const_cast<BOARD*>( this );

View File

@ -805,9 +805,9 @@ public:
return m_NetInfo; return m_NetInfo;
} }
NETINFO_LIST& GetNetInfo() void RemoveUnusedNets( BOARD_COMMIT* aCommit )
{ {
return m_NetInfo; m_NetInfo.RemoveUnusedNets( aCommit );
} }
#ifndef SWIG #ifndef SWIG

View File

@ -370,7 +370,7 @@ bool DIALOG_COPPER_ZONE::TransferDataToWindow()
void DIALOG_COPPER_ZONE::readNetInformation() 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.clear();
m_netInfoItemList.reserve( netInfoList.GetNetCount() ); m_netInfoItemList.reserve( netInfoList.GetNetCount() );

View File

@ -2112,9 +2112,9 @@ void DIALOG_NET_INSPECTOR::onRenameNet( wxCommandEvent& aEvent )
// is easier. // is easier.
auto removed_item = m_data_model->deleteItem( m_data_model->findItem( net ) ); auto removed_item = m_data_model->deleteItem( m_data_model->findItem( net ) );
m_brd->GetNetInfo().RemoveNet( net ); m_brd->Remove( net );
net->SetNetname( fullNetName ); net->SetNetname( fullNetName );
m_brd->GetNetInfo().AppendNet( net ); m_brd->Add( net );
m_frame->OnModify(); m_frame->OnModify();
if( netFilterMatches( net ) ) if( netFilterMatches( net ) )

View File

@ -1058,7 +1058,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
selectionTool->ClearSelection( true /* quiet mode */ ); selectionTool->ClearSelection( true /* quiet mode */ );
GetBoard()->DeleteAllFootprints(); GetBoard()->DeleteAllFootprints();
GetBoard()->GetNetInfo().RemoveUnusedNets(); GetBoard()->RemoveUnusedNets( nullptr );
FOOTPRINT* footprint = PROJECT_PCB::PcbFootprintLibs( &Prj() )->FootprintLoad( getCurNickname(), FOOTPRINT* footprint = PROJECT_PCB::PcbFootprintLibs( &Prj() )->FootprintLoad( getCurNickname(),
getCurFootprintName() ); getCurFootprintName() );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -36,27 +36,16 @@
#include <string_utils.h> #include <string_utils.h>
class wxDC;
class LINE_READER;
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
class PAD; class PAD;
class PCB_TRACK; class PCB_TRACK;
class BOARD; class BOARD;
class BOARD_ITEM; class BOARD_ITEM;
class BOARD_COMMIT;
class MSG_PANEL_ITEM; class MSG_PANEL_ITEM;
class PCB_BASE_FRAME; 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( PADS_VEC, PAD* )
DECL_VEC_FOR_SWIG( TRACKS_VEC, PCB_TRACK* ) DECL_VEC_FOR_SWIG( TRACKS_VEC, PCB_TRACK* )
@ -175,7 +164,7 @@ public:
*/ */
void Clear(); void Clear();
BOARD* GetParent() const BOARD* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
{ {
return m_parent; return m_parent;
} }
@ -360,22 +349,6 @@ public:
*/ */
unsigned GetNetCount() const { return m_netNames.size(); } 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. /// Return the name map, at least for python.
const NETNAMES_MAP& NetsByName() const { return m_netNames; } const NETNAMES_MAP& NetsByName() const { return m_netNames; }
@ -471,6 +444,19 @@ public:
return m_parent; 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: private:
/** /**
* Delete the list of nets (and free memory). * Delete the list of nets (and free memory).

View File

@ -22,6 +22,7 @@
*/ */
#include <board.h> #include <board.h>
#include <board_commit.h>
#include <footprint.h> #include <footprint.h>
#include <macros.h> #include <macros.h>
#include <pad.h> #include <pad.h>
@ -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<NETINFO_ITEM*> unusedNets;
m_netCodes.clear(); m_netCodes.clear();
m_netNames.clear(); m_netNames.clear();
for( std::pair<const int, NETINFO_ITEM*> 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_netNames.insert( std::make_pair( netInfo->GetNetname(), netInfo ) );
m_netCodes.insert( std::make_pair( item.first, item.second ) ); m_netCodes.insert( std::make_pair( netCode, netInfo ) );
}
else if( aCommit )
{
aCommit->Removed( netInfo );
} }
} }
} }

View File

@ -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: // When new footprints are added, the automatic zone refill is disabled because:
// * it creates crashes when calculating dynamic ratsnests if auto refill is enabled. // * it creates crashes when calculating dynamic ratsnests if auto refill is enabled.

View File

@ -60,7 +60,7 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings(); KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings();
KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs ); KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
NETINFO_LIST& nets = GetBoard()->GetNetInfo(); const NETINFO_LIST& nets = GetBoard()->GetNetInfo();
std::set<int>& hiddenNets = renderSettings->GetHiddenNets(); std::set<int>& hiddenNets = renderSettings->GetHiddenNets();
hiddenNets.clear(); hiddenNets.clear();
@ -154,7 +154,7 @@ void PCB_EDIT_FRAME::SaveProjectLocalSettings()
// Save render settings that aren't stored in PCB_DISPLAY_OPTIONS // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
std::shared_ptr<NET_SETTINGS>& netSettings = project.NetSettings(); std::shared_ptr<NET_SETTINGS>& netSettings = project.NetSettings();
NETINFO_LIST& nets = GetBoard()->GetNetInfo(); const NETINFO_LIST& nets = GetBoard()->GetNetInfo();
KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings(); KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings();
KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs ); KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
@ -224,7 +224,7 @@ void PCB_EDIT_FRAME::saveProjectSettings()
localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth; localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth;
// Net display settings // Net display settings
NETINFO_LIST& nets = GetBoard()->GetNetInfo(); const NETINFO_LIST& nets = GetBoard()->GetNetInfo();
KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings(); KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings();
KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs ); KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );

View File

@ -1449,7 +1449,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
PIN_REF empty( m_pcb->m_network ); PIN_REF empty( m_pcb->m_network );
std::string componentId; std::string componentId;
int highestNetCode = 0; int highestNetCode = 0;
NETINFO_LIST& netInfo = aBoard->GetNetInfo(); const NETINFO_LIST& netInfo = aBoard->GetNetInfo();
// find the highest numbered netCode within the board. // find the highest numbered netCode within the board.
for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i ) for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )

View File

@ -2947,11 +2947,11 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
int selectPossibleNetsByPopMenu( std::list<int>& aNetcodeList ) int selectPossibleNetsByPopMenu( std::list<int>& aNetcodeList )
{ {
ACTION_MENU menu( true ); ACTION_MENU menu( true );
NETINFO_LIST& netInfo = m_board->GetNetInfo(); const NETINFO_LIST& netInfo = m_board->GetNetInfo();
std::map<int, int> menuIDNetCodeMap; std::map<int, int> menuIDNetCodeMap;
int menuID = 1; int menuID = 1;
for( auto& netcode : aNetcodeList ) for( int netcode : aNetcodeList )
{ {
wxString menuText; wxString menuText;
if( menuID < 10 ) if( menuID < 10 )

View File

@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE( IntrospectedProperties )
BOARD brd; BOARD brd;
NETINFO_LIST& netInfo = brd.GetNetInfo(); const NETINFO_LIST& netInfo = brd.GetNetInfo();
std::shared_ptr<NETCLASS> netclass1( new NETCLASS( "HV" ) ); std::shared_ptr<NETCLASS> netclass1( new NETCLASS( "HV" ) );
std::shared_ptr<NETCLASS> netclass2( new NETCLASS( "otherClass" ) ); std::shared_ptr<NETCLASS> netclass2( new NETCLASS( "otherClass" ) );