From 5ef6001e06359ba90e612ece19904d381e39d9f3 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Fri, 29 Jan 2016 11:29:56 +0100 Subject: [PATCH] pcbnew: support for removing NETINFO_ITEMS from BOARD for proper netlist undo --- pcbnew/class_board.cpp | 19 +++++++++---------- pcbnew/class_board_connected_item.cpp | 4 ++-- pcbnew/class_module.cpp | 2 +- pcbnew/class_netinfo.h | 14 ++++++++++---- pcbnew/class_netinfolist.cpp | 26 ++++++++++++++++++++++++-- pcbnew/dialogs/dialog_update_pcb.cpp | 16 +++++++++++++--- 6 files changed, 59 insertions(+), 22 deletions(-) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index a0563821d1..6ebf7ce95e 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -672,6 +672,10 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) switch( aBoardItem->Type() ) { + case PCB_NETINFO_T: + aBoardItem->SetParent( this ); + m_NetInfo.AppendNet( (NETINFO_ITEM*) aBoardItem ); + // this one uses a vector case PCB_MARKER_T: aBoardItem->SetParent( this ); @@ -737,10 +741,6 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) aBoardItem->SetParent( this ); break; - case PCB_NETINFO_T: - m_NetInfo.AppendNet( (NETINFO_ITEM *) aBoardItem ); - break; - // other types may use linked list default: { @@ -763,6 +763,10 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) switch( aBoardItem->Type() ) { + case PCB_NETINFO_T: + m_NetInfo.RemoveNet ( (NETINFO_ITEM*) aBoardItem ); + break; + case PCB_MARKER_T: // find the item in the vector, then remove it @@ -811,11 +815,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) m_Drawings.Remove( aBoardItem ); break; - case PCB_NETINFO_T: - printf( "Unimpl! remove netinfo!\n" ); - assert( false ); - break; - // other types may use linked list default: wxFAIL_MSG( wxT( "BOARD::Remove() needs more ::Type() support" ) ); @@ -1261,7 +1260,7 @@ NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const wxASSERT( m_NetInfo.GetNetCount() > 0 ); // net zero should exist if( aNetcode == NETINFO_LIST::UNCONNECTED && m_NetInfo.GetNetCount() == 0 ) - return &NETINFO_LIST::ORPHANED; + return &NETINFO_LIST::ORPHANED_ITEM; else return m_NetInfo.GetNetItem( aNetcode ); } diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index 166667454a..0843728163 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -35,7 +35,7 @@ #include BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : - BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED ), + BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED_ITEM ), m_Subnet( 0 ), m_ZoneSubnet( 0 ) { } @@ -59,7 +59,7 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert ) if( ( aNetCode >= 0 ) && board ) m_netinfo = board->FindNet( aNetCode ); else - m_netinfo = &NETINFO_LIST::ORPHANED; + m_netinfo = &NETINFO_LIST::ORPHANED_ITEM; if( !aNoAssert ) assert( m_netinfo ); diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index b44f8d1481..4b6c88988c 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -186,7 +186,7 @@ void MODULE::ClearAllNets() // Force the ORPHANED dummy net info for all pads. // ORPHANED dummy net does not depend on a board for( D_PAD* pad = Pads(); pad; pad = pad->Next() ) - pad->SetNetCode( NETINFO_LIST::FORCE_ORPHANED ); + pad->SetNetCode( NETINFO_LIST::ORPHANED ); } diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index 3f0a5fba39..cc07b40656 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -291,12 +291,18 @@ public: unsigned GetNetCount() const { return m_netNames.size(); } /** - * Function Append - * adds \a aNewElement to the end of the list. Negative net code means it is going to be + * Function AppendNet + * adds \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 ); + + /** + * Function RemoveNet + * Removes a new from the net list. + */ + void RemoveNet( NETINFO_ITEM* aNet ); /** * Function GetPadCount * @return the number of pads in board @@ -348,11 +354,11 @@ public: ///> Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED ///> (typically -1) when calling SetNetCode od board connected items - static const int FORCE_ORPHANED; + static const int ORPHANED; ///> NETINFO_ITEM meaning that there was no net assigned for an item, as there was no ///> board storing net list available. - static NETINFO_ITEM ORPHANED; + static NETINFO_ITEM ORPHANED_ITEM; #if defined(DEBUG) void Show() const; diff --git a/pcbnew/class_netinfolist.cpp b/pcbnew/class_netinfolist.cpp index 74b11bfa8d..6b66cfaadf 100644 --- a/pcbnew/class_netinfolist.cpp +++ b/pcbnew/class_netinfolist.cpp @@ -69,6 +69,28 @@ void NETINFO_LIST::clear() } +void NETINFO_LIST::RemoveNet( NETINFO_ITEM* aNet ) +{ + for( NETCODES_MAP::iterator i = m_netCodes.begin(); i != m_netCodes.end(); ++i ) + { + if ( i->second == aNet ) + { + m_netCodes.erase(i); + break; + } + } + + for( NETNAMES_MAP::iterator i = m_netNames.begin(); i != m_netNames.end(); ++i ) + { + if ( i->second == aNet ) + { + m_netNames.erase(i); + break; + } + } +} + + void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement ) { // if there is a net with such name then just assign the correct number @@ -295,6 +317,6 @@ NETINFO_ITEM* NETINFO_MAPPING::iterator::operator->() const const int NETINFO_LIST::UNCONNECTED = 0; -const int NETINFO_LIST::FORCE_ORPHANED = -1; +const int NETINFO_LIST::ORPHANED = -1; -NETINFO_ITEM NETINFO_LIST::ORPHANED = NETINFO_ITEM( NULL, wxEmptyString, NETINFO_LIST::UNCONNECTED ); +NETINFO_ITEM NETINFO_LIST::ORPHANED_ITEM = NETINFO_ITEM( NULL, wxEmptyString, NETINFO_LIST::UNCONNECTED ); \ No newline at end of file diff --git a/pcbnew/dialogs/dialog_update_pcb.cpp b/pcbnew/dialogs/dialog_update_pcb.cpp index 4a361a1d89..beb55421e8 100644 --- a/pcbnew/dialogs/dialog_update_pcb.cpp +++ b/pcbnew/dialogs/dialog_update_pcb.cpp @@ -52,13 +52,23 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) toolManager->RunAction( COMMON_ACTIONS::selectionClear, true ); } - m_frame->LoadFootprints( *m_netlist, &reporter ); + try { + m_frame->LoadFootprints( *m_netlist, &reporter ); + } + catch( IO_ERROR &error ) + { + wxString msg; + + reporter.Report( _( "Failed to load one or more footprints. Please add the missing libraries in PCBNew configuration. " + "The PCB will not update completely." ), REPORTER::RPT_ERROR ); + reporter.Report( error.errorText, REPORTER::RPT_INFO ); + } BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() ); updater.SetReporter ( &reporter ); updater.SetIsDryRun( aDryRun); - updater.SetLookupByTimestamp( true ); + updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() ); updater.SetDeleteUnusedComponents ( true ); updater.SetReplaceFootprints( true ); updater.SetDeleteSinglePadNets ( false ); @@ -94,7 +104,7 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event ) { - + PerformUpdate( true ); } void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event )