From 3a41f8ed0305cf8add264022c18b6fcc81aec37b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 20 May 2014 11:29:37 +0200 Subject: [PATCH] Fixes the bug that causes pcbnew crash, when there are multiple net classes and the plot dialog was opened. Changed NETCLASS* to boost::shared_ptr. --- include/class_board_design_settings.h | 2 +- pcbnew/autorouter/routing_matrix.cpp | 2 +- pcbnew/class_board.cpp | 2 +- pcbnew/class_board_connected_item.cpp | 14 ++--- pcbnew/class_board_connected_item.h | 2 +- pcbnew/class_board_design_settings.cpp | 12 ++-- pcbnew/class_netclass.cpp | 57 ++++++------------- pcbnew/class_netclass.h | 26 +++++---- pcbnew/class_netinfo.h | 10 ++-- pcbnew/class_netinfo_item.cpp | 1 - pcbnew/class_track.cpp | 4 +- pcbnew/class_zone.cpp | 2 +- pcbnew/dialogs/dialog_design_rules.cpp | 18 +++--- .../dialog_global_edit_tracks_and_vias.cpp | 2 +- pcbnew/dialogs/dialog_plot.h | 2 +- pcbnew/drc.cpp | 4 +- pcbnew/drc_clearance_test_functions.cpp | 2 +- pcbnew/drc_stuff.h | 4 +- pcbnew/eagle_plugin.cpp | 2 +- pcbnew/editrack.cpp | 2 +- pcbnew/legacy_plugin.cpp | 18 +++--- pcbnew/legacy_plugin.h | 3 +- pcbnew/pcb_parser.cpp | 12 ++-- pcbnew/router/pns_router.cpp | 2 +- pcbnew/router/router_tool.cpp | 2 +- pcbnew/specctra.h | 3 +- pcbnew/specctra_export.cpp | 8 +-- 27 files changed, 97 insertions(+), 121 deletions(-) diff --git a/include/class_board_design_settings.h b/include/class_board_design_settings.h index 8d04fe0922..28201dd866 100644 --- a/include/class_board_design_settings.h +++ b/include/class_board_design_settings.h @@ -105,7 +105,7 @@ public: * Function GetDefault * @return the default netclass. */ - inline NETCLASS* GetDefault() const + inline NETCLASSPTR GetDefault() const { return m_NetClasses.GetDefault(); } diff --git a/pcbnew/autorouter/routing_matrix.cpp b/pcbnew/autorouter/routing_matrix.cpp index ee1890bf2a..8c9e3b2cbd 100644 --- a/pcbnew/autorouter/routing_matrix.cpp +++ b/pcbnew/autorouter/routing_matrix.cpp @@ -201,7 +201,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) LAYER_MSK layerMask; // use the default NETCLASS? - NETCLASS* nc = aPcb->GetDesignSettings().GetDefault(); + NETCLASSPTR nc = aPcb->GetDesignSettings().GetDefault(); int trackWidth = nc->GetTrackWidth(); int clearance = nc->GetClearance(); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 2fc5fa7d3e..9a1456a7b0 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -91,7 +91,7 @@ BOARD::BOARD() : m_Layer[layer].m_Type = LT_UNDEFINED; } - NETCLASS* defaultClass = m_designSettings.GetDefault(); + NETCLASSPTR defaultClass = m_designSettings.GetDefault(); defaultClass->SetDescription( _( "This is the default net class." ) ); // Initialize default values in default netclass. diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index 0b91036802..eaaa3390ca 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -89,7 +89,7 @@ const wxString& BOARD_CONNECTED_ITEM::GetShortNetname() const int BOARD_CONNECTED_ITEM::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const { - NETCLASS* myclass = GetNetClass(); + NETCLASSPTR myclass = GetNetClass(); // DO NOT use wxASSERT, because GetClearance is called inside an OnPaint event // and a call to wxASSERT can crash the application. @@ -116,7 +116,7 @@ int BOARD_CONNECTED_ITEM::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const } -NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const +NETCLASSPTR BOARD_CONNECTED_ITEM::GetNetClass() const { // It is important that this be implemented without any sequential searching. // Simple array lookups should be fine, performance-wise. @@ -128,10 +128,11 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const if( board == NULL ) // Should not occur { DBG(printf( "%s: NULL board,type %d", __func__, Type() );) - return NULL; + + return NETCLASSPTR(); } - NETCLASS* netclass = NULL; + NETCLASSPTR netclass; NETINFO_ITEM* net = board->FindNet( GetNetCode() ); if( net ) @@ -151,15 +152,12 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const wxString BOARD_CONNECTED_ITEM::GetNetClassName() const { wxString name; - NETCLASS* myclass = GetNetClass(); + NETCLASSPTR myclass = GetNetClass(); if( myclass ) name = myclass->GetName(); else - { - BOARD* board = GetBoard(); name = NETCLASS::Default; - } return name; } diff --git a/pcbnew/class_board_connected_item.h b/pcbnew/class_board_connected_item.h index 2742fa3106..a3972185d0 100644 --- a/pcbnew/class_board_connected_item.h +++ b/pcbnew/class_board_connected_item.h @@ -142,7 +142,7 @@ public: * Function GetNetClass * returns the NETCLASS for this item. */ - NETCLASS* GetNetClass() const; + boost::shared_ptr GetNetClass() const; /** * Function GetNetClassName diff --git a/pcbnew/class_board_design_settings.cpp b/pcbnew/class_board_design_settings.cpp index aac977d827..b4017ae21d 100644 --- a/pcbnew/class_board_design_settings.cpp +++ b/pcbnew/class_board_design_settings.cpp @@ -176,8 +176,8 @@ void BOARD_DESIGN_SETTINGS::AppendConfigs( PARAM_CFG_ARRAY* aResult ) bool BOARD_DESIGN_SETTINGS::SetCurrentNetClass( const wxString& aNetClassName ) { - NETCLASS* netClass = m_NetClasses.Find( aNetClassName ); - bool lists_sizes_modified = false; + NETCLASSPTR netClass = m_NetClasses.Find( aNetClassName ); + bool lists_sizes_modified = false; // if not found (should not happen) use the default if( netClass == NULL ) @@ -229,7 +229,7 @@ int BOARD_DESIGN_SETTINGS::GetBiggestClearanceValue() //Read list of Net Classes for( NETCLASSES::const_iterator nc = m_NetClasses.begin(); nc != m_NetClasses.end(); nc++ ) { - NETCLASS* netclass = nc->second; + NETCLASSPTR netclass = nc->second; clearance = std::max( clearance, netclass->GetClearance() ); } @@ -244,7 +244,7 @@ int BOARD_DESIGN_SETTINGS::GetSmallestClearanceValue() //Read list of Net Classes for( NETCLASSES::const_iterator nc = m_NetClasses.begin(); nc != m_NetClasses.end(); nc++ ) { - NETCLASS* netclass = nc->second; + NETCLASSPTR netclass = nc->second; clearance = std::min( clearance, netclass->GetClearance() ); } @@ -254,7 +254,7 @@ int BOARD_DESIGN_SETTINGS::GetSmallestClearanceValue() int BOARD_DESIGN_SETTINGS::GetCurrentMicroViaSize() { - NETCLASS* netclass = m_NetClasses.Find( m_currentNetClassName ); + NETCLASSPTR netclass = m_NetClasses.Find( m_currentNetClassName ); return netclass->GetuViaDiameter(); } @@ -262,7 +262,7 @@ int BOARD_DESIGN_SETTINGS::GetCurrentMicroViaSize() int BOARD_DESIGN_SETTINGS::GetCurrentMicroViaDrill() { - NETCLASS* netclass = m_NetClasses.Find( m_currentNetClassName ); + NETCLASSPTR netclass = m_NetClasses.Find( m_currentNetClassName ); return netclass->GetuViaDrill(); } diff --git a/pcbnew/class_netclass.cpp b/pcbnew/class_netclass.cpp index daa72ff32b..e300f6087f 100644 --- a/pcbnew/class_netclass.cpp +++ b/pcbnew/class_netclass.cpp @@ -23,6 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include @@ -84,52 +85,25 @@ NETCLASS::~NETCLASS() } -NETCLASSES::NETCLASSES() : - m_Default( NETCLASS::Default ) +NETCLASSES::NETCLASSES() { + m_Default = boost::make_shared( NETCLASS::Default ); } NETCLASSES::~NETCLASSES() { - Clear(); } -void NETCLASSES::Clear() -{ - // Although std::map<> will destroy the items that it contains, in this - // case we have NETCLASS* (pointers) and "destroying" a pointer does not - // delete the object that the pointer points to. - - // this NETCLASSES is owner of its NETCLASS pointers, - // so delete NETCLASSes pointed to by them. - for( iterator i = begin(); i!=end(); ) - { - // http://www.sgi.com/tech/stl/Map.html says: - // "Erasing an element from a map also does not invalidate any iterators, - // except, of course, for iterators that actually point to the element that - // is being erased." - - iterator e = i++; // copy, then advance. - - delete e->second; // delete the NETCLASS, which 'second' points to. - - m_NetClasses.erase( e ); - } -} - - -bool NETCLASSES::Add( NETCLASS* aNetClass ) +bool NETCLASSES::Add( NETCLASSPTR aNetClass ) { const wxString& name = aNetClass->GetName(); if( name == NETCLASS::Default ) { // invoke operator=(), which is currently generated by compiler. - m_Default = *aNetClass; - - delete aNetClass; // we own aNetClass, must delete it since we copied it. + m_Default = aNetClass; return true; } @@ -139,6 +113,7 @@ bool NETCLASSES::Add( NETCLASS* aNetClass ) { // name not found, take ownership m_NetClasses[name] = aNetClass; + return true; } else @@ -150,30 +125,30 @@ bool NETCLASSES::Add( NETCLASS* aNetClass ) } -NETCLASS* NETCLASSES::Remove( const wxString& aNetName ) +NETCLASSPTR NETCLASSES::Remove( const wxString& aNetName ) { NETCLASSMAP::iterator found = m_NetClasses.find( aNetName ); if( found != m_NetClasses.end() ) { - NETCLASS* netclass = found->second; + boost::shared_ptr netclass = found->second; m_NetClasses.erase( found ); return netclass; } - return NULL; + return NETCLASSPTR(); } -NETCLASS* NETCLASSES::Find( const wxString& aName ) const +NETCLASSPTR NETCLASSES::Find( const wxString& aName ) const { if( aName == NETCLASS::Default ) - return (NETCLASS*) &m_Default; + return m_Default; NETCLASSMAP::const_iterator found = m_NetClasses.find( aName ); if( found == m_NetClasses.end() ) - return NULL; + return NETCLASSPTR(); else return found->second; } @@ -197,9 +172,9 @@ void BOARD::SynchronizeNetsAndNetClasses() // and therefore bogus netclass memberships will be deleted in logic below this loop. for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz ) { - NETCLASS* netclass = clazz->second; + NETCLASSPTR netclass = clazz->second; - for( NETCLASS::iterator member = netclass->begin(); member != netclass->end(); ++member ) + for( NETCLASS::const_iterator member = netclass->begin(); member != netclass->end(); ++member ) { const wxString& netname = *member; @@ -222,7 +197,7 @@ void BOARD::SynchronizeNetsAndNetClasses() for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz ) { - NETCLASS* netclass = clazz->second; + NETCLASSPTR netclass = clazz->second; netclass->Clear(); } @@ -236,7 +211,7 @@ void BOARD::SynchronizeNetsAndNetClasses() // because of the std:map<> this should be fast, and because of // prior logic, netclass should not be NULL. - NETCLASS* netclass = netClasses.Find( classname ); + NETCLASSPTR netclass = netClasses.Find( classname ); wxASSERT( netclass ); diff --git a/pcbnew/class_netclass.h b/pcbnew/class_netclass.h index 0d79013df8..74a915d635 100644 --- a/pcbnew/class_netclass.h +++ b/pcbnew/class_netclass.h @@ -33,6 +33,7 @@ #include #include +#include #include @@ -210,6 +211,7 @@ public: #endif }; +typedef boost::shared_ptr NETCLASSPTR; /** * Class NETCLASSES @@ -220,13 +222,13 @@ public: class NETCLASSES { private: - typedef std::map NETCLASSMAP; + typedef std::map NETCLASSMAP; /// all the NETCLASSes except the default one. NETCLASSMAP m_NetClasses; /// the default NETCLASS. - NETCLASS m_Default; + NETCLASSPTR m_Default; public: NETCLASSES(); @@ -236,7 +238,10 @@ public: * Function Clear * destroys any contained NETCLASS instances except the Default one. */ - void Clear(); + void Clear() + { + m_NetClasses.clear(); + } typedef NETCLASSMAP::iterator iterator; iterator begin() { return m_NetClasses.begin(); } @@ -259,9 +264,9 @@ public: * Function GetDefault * @return the default net class. */ - NETCLASS* GetDefault() const + NETCLASSPTR GetDefault() const { - return (NETCLASS*) &m_Default; + return m_Default; } /** @@ -271,24 +276,23 @@ public: * @return true if the name within aNetclass is unique and it could be inserted OK, * else false because the name was not unique and caller still owns aNetclass. */ - bool Add( NETCLASS* aNetclass ); + bool Add( NETCLASSPTR aNetclass ); /** * Function Remove * removes a NETCLASS from this container but does not destroy/delete it. * @param aNetName is the name of the net to delete, and it may not be NETCLASS::Default. - * @return NETCLASS* - the NETCLASS associated with aNetName if found and removed, else NULL. - * You have to delete the returned value if you intend to destroy the NETCLASS. + * @return NETCLASSPTR - the NETCLASS associated with aNetName if found and removed, else NULL. */ - NETCLASS* Remove( const wxString& aNetName ); + NETCLASSPTR Remove( const wxString& aNetName ); /** * Function Find * searches this container for a NETCLASS given by \a aName. * @param aName is the name of the NETCLASS to search for. - * @return NETCLASS* - if found, else NULL. + * @return NETCLASSPTR - if found, else NULL. */ - NETCLASS* Find( const wxString& aName ) const; + NETCLASSPTR Find( const wxString& aName ) const; }; diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index 88e77df440..253ca9c48b 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -452,7 +452,7 @@ private: wxString m_NetClassName; // Net Class name. if void this is equivalent // to "default" (the first // item of the net classes list - NETCLASS* m_NetClass; + NETCLASSPTR m_NetClass; BOARD_ITEM* m_parent; ///< The parent board item object the net belongs to. @@ -474,9 +474,9 @@ public: * Function SetClass * sets \a aNetclass into this NET */ - void SetClass( const NETCLASS* aNetClass ) + void SetClass( NETCLASSPTR aNetClass ) { - m_NetClass = (NETCLASS*) aNetClass; + m_NetClass = aNetClass; if( aNetClass ) m_NetClassName = aNetClass->GetName(); @@ -484,7 +484,7 @@ public: m_NetClassName = NETCLASS::Default; } - NETCLASS* GetNetClass() + NETCLASSPTR GetNetClass() { return m_NetClass; } @@ -630,7 +630,7 @@ public: // general buffer of ratsnest m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net - SetClass( NULL ); + SetClass( NETCLASSPTR() ); } }; diff --git a/pcbnew/class_netinfo_item.cpp b/pcbnew/class_netinfo_item.cpp index 447cf8a503..d4917568e6 100644 --- a/pcbnew/class_netinfo_item.cpp +++ b/pcbnew/class_netinfo_item.cpp @@ -58,7 +58,6 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int a m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net m_NetClassName = NETCLASS::Default; - m_NetClass = NULL; } diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index ace8ca96ef..c9f19462ba 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -226,7 +226,7 @@ int VIA::GetDrillValue() const return m_Drill; // Use the default value from the Netclass - NETCLASS* netclass = GetNetClass(); + NETCLASSPTR netclass = GetNetClass(); if( GetViaType() == VIA_MICROVIA ) return netclass->GetuViaDrill(); @@ -1008,7 +1008,7 @@ void TRACK::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) } } - NETCLASS* netclass = GetNetClass(); + NETCLASSPTR netclass = GetNetClass(); if( netclass ) { diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index a6b360f98a..6c2008bf73 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -548,7 +548,7 @@ int ZONE_CONTAINER::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const // "zone clearance" setting in the zone properties dialog. (At least // until there is a UI boolean for this.) - NETCLASS* myClass = GetNetClass(); + NETCLASSPTR myClass = GetNetClass(); if( myClass ) myClearance = std::max( myClearance, myClass->GetClearance() ); diff --git a/pcbnew/dialogs/dialog_design_rules.cpp b/pcbnew/dialogs/dialog_design_rules.cpp index 13f6da13c9..9ba9f05f6b 100644 --- a/pcbnew/dialogs/dialog_design_rules.cpp +++ b/pcbnew/dialogs/dialog_design_rules.cpp @@ -46,6 +46,8 @@ #include #include +#include + // Column labels for net lists #define NET_TITLE _( "Net" ) #define CLASS_TITLE _( "Class" ) @@ -221,10 +223,10 @@ void DIALOG_DESIGN_RULES::InitDialogRules() // @todo go fix m_Pcb->SynchronizeNetsAndNetClasses() so that the netcode==0 is not present in the BOARD::m_NetClasses NETCLASSES& netclasses = m_BrdSettings->m_NetClasses; - NETCLASS* netclass = netclasses.GetDefault(); + NETCLASSPTR netclass = netclasses.GetDefault(); // Initialize list of nets for Default Net Class - for( NETCLASS::const_iterator name = netclass->begin(); name != netclass->end(); ++name ) + for( NETCLASS::iterator name = netclass->begin(); name != netclass->end(); ++name ) { m_AllNets.push_back( NETCUP( *name, netclass->GetName() ) ); } @@ -446,7 +448,7 @@ void DIALOG_DESIGN_RULES::InitializeRulesSelectionBoxes() /* Initialize the rules list from board */ -static void class2gridRow( wxGrid* grid, int row, NETCLASS* nc ) +static void class2gridRow( wxGrid* grid, int row, NETCLASSPTR nc ) { wxString msg; @@ -494,14 +496,14 @@ void DIALOG_DESIGN_RULES::InitRulesList() int row = 1; for( NETCLASSES::iterator i = netclasses.begin(); i!=netclasses.end(); ++i, ++row ) { - NETCLASS* netclass = i->second; + NETCLASSPTR netclass = i->second; class2gridRow( m_grid, row, netclass ); } } -static void gridRow2class( wxGrid* grid, int row, NETCLASS* nc ) +static void gridRow2class( wxGrid* grid, int row, NETCLASSPTR nc ) { #define MYCELL( col ) \ ValueFromString( g_UserUnit, grid->GetCellValue( row, col ) ) @@ -530,7 +532,7 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard() // Copy other NetClasses : for( int row = 1; row < m_grid->GetNumberRows(); ++row ) { - NETCLASS* nc = new NETCLASS( m_grid->GetRowLabelValue( row ) ); + NETCLASSPTR nc = boost::make_shared( m_grid->GetRowLabelValue( row ) ); if( !m_BrdSettings->m_NetClasses.Add( nc ) ) { @@ -540,7 +542,7 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard() msg.Printf( wxT( "CopyRulesListToBoard(): The NetClass \"%s\" already exists. Skip" ), GetChars( m_grid->GetRowLabelValue( row ) ) ); wxMessageBox( msg ); - delete nc; + continue; } @@ -550,7 +552,7 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard() // Now read all nets and push them in the corresponding netclass net buffer for( NETCUPS::const_iterator netcup = m_AllNets.begin(); netcup != m_AllNets.end(); ++netcup ) { - NETCLASS* nc = netclasses.Find( netcup->clazz ); + NETCLASSPTR nc = netclasses.Find( netcup->clazz ); wxASSERT( nc ); nc->Add( netcup->net ); } diff --git a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp index 5f3afd55f1..3697dd6cba 100644 --- a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp +++ b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp @@ -48,7 +48,7 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::MyInit() BOARD* board = m_Parent->GetBoard(); BOARD_DESIGN_SETTINGS& dsnSettings = board->GetDesignSettings(); NETCLASSES& netclasses = dsnSettings.m_NetClasses; - NETCLASS* netclass = netclasses.GetDefault(); + NETCLASSPTR netclass = netclasses.GetDefault(); NETINFO_ITEM* net = board->FindNet( m_Netcode ); if( net ) diff --git a/pcbnew/dialogs/dialog_plot.h b/pcbnew/dialogs/dialog_plot.h index 4be5e712d5..d198a9a023 100644 --- a/pcbnew/dialogs/dialog_plot.h +++ b/pcbnew/dialogs/dialog_plot.h @@ -42,7 +42,7 @@ private: PCB_EDIT_FRAME* m_parent; BOARD* m_board; BOARD_DESIGN_SETTINGS m_brdSettings; - wxConfigBase* m_config; + wxConfigBase* m_config; std::vector m_layerList; // List to hold CheckListBox layer numbers double m_XScaleAdjust; // X scale factor adjust to compensate // plotter X scaling error diff --git a/pcbnew/drc.cpp b/pcbnew/drc.cpp index 67c451c721..62ffcf4153 100644 --- a/pcbnew/drc.cpp +++ b/pcbnew/drc.cpp @@ -295,7 +295,7 @@ void DRC::updatePointers() } -bool DRC::doNetClass( NETCLASS* nc, wxString& msg ) +bool DRC::doNetClass( NETCLASSPTR nc, wxString& msg ) { bool ret = true; @@ -412,7 +412,7 @@ bool DRC::testNetClasses() for( NETCLASSES::const_iterator i = netclasses.begin(); i != netclasses.end(); ++i ) { - NETCLASS* nc = i->second; + NETCLASSPTR nc = i->second; if( !doNetClass( nc, msg ) ) ret = false; diff --git a/pcbnew/drc_clearance_test_functions.cpp b/pcbnew/drc_clearance_test_functions.cpp index ed48f149ab..31df052a2a 100644 --- a/pcbnew/drc_clearance_test_functions.cpp +++ b/pcbnew/drc_clearance_test_functions.cpp @@ -153,7 +153,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) int net_code_ref; wxPoint shape_pos; - NETCLASS* netclass = aRefSeg->GetNetClass(); + NETCLASSPTR netclass = aRefSeg->GetNetClass(); BOARD_DESIGN_SETTINGS& dsnSettings = m_pcb->GetDesignSettings(); /* In order to make some calculations more easier or faster, diff --git a/pcbnew/drc_stuff.h b/pcbnew/drc_stuff.h index 927e94936a..569fcd87ad 100644 --- a/pcbnew/drc_stuff.h +++ b/pcbnew/drc_stuff.h @@ -29,8 +29,8 @@ #ifndef _DRC_STUFF_H #define _DRC_STUFF_H - #include +#include #define OK_DRC 0 #define BAD_DRC 1 @@ -283,7 +283,7 @@ private: //---------------------------------------------- - bool doNetClass( NETCLASS* aNetClass, wxString& msg ); + bool doNetClass( boost::shared_ptr aNetClass, wxString& msg ); /** * Function doPadToPadsDrc diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index 2e59478403..4e48b04098 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -1146,7 +1146,7 @@ BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const if( m_rules->mdWireWire ) { - NETCLASS* defaultNetclass = designSettings.GetDefault(); + NETCLASSPTR defaultNetclass = designSettings.GetDefault(); int clearance = KiROUND( m_rules->mdWireWire ); if( clearance < defaultNetclass->GetClearance() ) diff --git a/pcbnew/editrack.cpp b/pcbnew/editrack.cpp index 715ac98f8d..02f02f782c 100644 --- a/pcbnew/editrack.cpp +++ b/pcbnew/editrack.cpp @@ -685,7 +685,7 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo if ( g_FirstTrackSegment == NULL ) return; - NETCLASS* netclass = g_FirstTrackSegment->GetNetClass(); + NETCLASSPTR netclass = g_FirstTrackSegment->GetNetClass(); if( showTrackClearanceMode != DO_NOT_SHOW_CLEARANCE ) DisplayOpt.ShowTrackClearanceMode = SHOW_CLEARANCE_ALWAYS; diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index f2f174267b..e6ba98c812 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -86,6 +86,8 @@ #include #include +#include + typedef LEGACY_PLUGIN::BIU BIU; @@ -632,7 +634,7 @@ void LEGACY_PLUGIN::loadSHEET() void LEGACY_PLUGIN::loadSETUP() { - NETCLASS* netclass_default = m_board->GetDesignSettings().GetDefault(); + NETCLASSPTR netclass_default = m_board->GetDesignSettings().GetDefault(); // TODO Orson: is it really necessary to first operate on a copy and then apply it? // would not it be better to use reference here and apply all the changes instantly? BOARD_DESIGN_SETTINGS bds = m_board->GetDesignSettings(); @@ -2113,7 +2115,7 @@ void LEGACY_PLUGIN::loadNETCLASS() // yet since that would bypass duplicate netclass name checking within the BOARD. // store it temporarily in an auto_ptr until successfully inserted into the BOARD // just before returning. - auto_ptr nc( new NETCLASS( wxEmptyString ) ); + NETCLASSPTR nc = boost::make_shared( wxEmptyString ); while( ( line = READLINE( m_reader ) ) != NULL ) { @@ -2175,11 +2177,7 @@ void LEGACY_PLUGIN::loadNETCLASS() else if( TESTLINE( "$EndNCLASS" ) ) { - if( m_board->GetDesignSettings().m_NetClasses.Add( nc.get() ) ) - { - nc.release(); - } - else + if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) ) { // Must have been a name conflict, this is a bad board file. // User may have done a hand edit to the file. @@ -2985,7 +2983,7 @@ void LEGACY_PLUGIN::saveSHEET( const BOARD* aBoard ) const void LEGACY_PLUGIN::saveSETUP( const BOARD* aBoard ) const { const BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); - NETCLASS* netclass_default = bds.GetDefault(); + NETCLASSPTR netclass_default = bds.GetDefault(); fprintf( m_fp, "$SETUP\n" ); @@ -3170,7 +3168,7 @@ void LEGACY_PLUGIN::saveNETCLASSES( const NETCLASSES* aNetClasses ) const // the rest will be alphabetical in the *.brd file. for( NETCLASSES::const_iterator it = aNetClasses->begin(); it != aNetClasses->end(); ++it ) { - NETCLASS* netclass = it->second; + NETCLASSPTR netclass = it->second; saveNETCLASS( netclass ); } @@ -3178,7 +3176,7 @@ void LEGACY_PLUGIN::saveNETCLASSES( const NETCLASSES* aNetClasses ) const } -void LEGACY_PLUGIN::saveNETCLASS( const NETCLASS* nc ) const +void LEGACY_PLUGIN::saveNETCLASS( const NETCLASSPTR nc ) const { fprintf( m_fp, "$NCLASS\n" ); fprintf( m_fp, "Name %s\n", EscapedUTF8( nc->GetName() ).c_str() ); diff --git a/pcbnew/legacy_plugin.h b/pcbnew/legacy_plugin.h index a9efbaa053..ee05599591 100644 --- a/pcbnew/legacy_plugin.h +++ b/pcbnew/legacy_plugin.h @@ -26,6 +26,7 @@ */ #include +#include #include @@ -256,7 +257,7 @@ protected: void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const; void saveNETCLASSES( const NETCLASSES* aNetClasses ) const; - void saveNETCLASS( const NETCLASS* aNetclass ) const; + void saveNETCLASS( const boost::shared_ptr aNetclass ) const; void savePCB_TEXT( const TEXTE_PCB* aText ) const; void savePCB_TARGET( const PCB_TARGET* aTarget ) const; diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 547120fa9b..a96034c48d 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -51,6 +51,8 @@ #include #include +#include + void PCB_PARSER::init() { @@ -808,7 +810,7 @@ void PCB_PARSER::parseSetup() throw( IO_ERROR, PARSE_ERROR ) wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as setup." ) ); T token; - NETCLASS* defaultNetClass = m_board->GetDesignSettings().GetDefault(); + NETCLASSPTR defaultNetClass = m_board->GetDesignSettings().GetDefault(); // TODO Orson: is it really necessary to first operate on a copy and then apply it? // would not it be better to use reference here and apply all the changes instantly? BOARD_DESIGN_SETTINGS designSettings = m_board->GetDesignSettings(); @@ -1082,7 +1084,7 @@ void PCB_PARSER::parseNETCLASS() throw( IO_ERROR, PARSE_ERROR ) T token; - std::auto_ptr nc( new NETCLASS( wxEmptyString ) ); + NETCLASSPTR nc = boost::make_shared( wxEmptyString ); // Read netclass name (can be a name or just a number like track width) NeedSYMBOLorNUMBER(); @@ -1135,11 +1137,7 @@ void PCB_PARSER::parseNETCLASS() throw( IO_ERROR, PARSE_ERROR ) NeedRIGHT(); } - if( m_board->GetDesignSettings().m_NetClasses.Add( nc.get() ) ) - { - nc.release(); - } - else + if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) ) { // Must have been a name conflict, this is a bad board file. // User may have done a hand edit to the file. diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index b233cba9ea..7508ead1e6 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -72,7 +72,7 @@ public: continue; wxString netClassName = ni->GetClassName(); - NETCLASS* nc = aBoard->GetDesignSettings().m_NetClasses.Find( netClassName ); + NETCLASSPTR nc = aBoard->GetDesignSettings().m_NetClasses.Find( netClassName ); int clearance = nc->GetClearance(); m_clearanceCache[i] = clearance; TRACE( 1, "Add net %d netclass %s clearance %d", i % netClassName.mb_str() % diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index eace67a44f..583fd477e4 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -269,7 +269,7 @@ int& aViaDiameter, int& aViaDrill ) BOARD* board = getModel( PCB_T ); BOARD_DESIGN_SETTINGS &bds = board->GetDesignSettings(); - NETCLASS* netClass = NULL; + NETCLASSPTR netClass; NETINFO_ITEM* ni = board->FindNet( aNetCode ); if( ni ) diff --git a/pcbnew/specctra.h b/pcbnew/specctra.h index d2a5104d95..2a584864bb 100644 --- a/pcbnew/specctra.h +++ b/pcbnew/specctra.h @@ -31,6 +31,7 @@ // see http://www.boost.org/libs/ptr_container/doc/ptr_set.html #include +#include #include #include @@ -3813,7 +3814,7 @@ class SPECCTRA_DB : public SPECCTRA_LEXER * Function exportNETCLASS * exports \a aNetClass to the DSN file. */ - void exportNETCLASS( NETCLASS* aNetClass, BOARD* aBoard ); + void exportNETCLASS( boost::shared_ptr aNetClass, BOARD* aBoard ); //----------------------------------------------------------- diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 089925576c..d81d2c66ec 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -1476,7 +1476,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR ) //------------------------------------------------------------- { char rule[80]; - NETCLASS* defaultClass = aBoard->GetDesignSettings().m_NetClasses.GetDefault(); + NETCLASSPTR defaultClass = aBoard->GetDesignSettings().GetDefault(); int defaultTrackWidth = defaultClass->GetTrackWidth(); int defaultClearance = defaultClass->GetClearance(); @@ -1854,7 +1854,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR ) // Add the via from the Default netclass first. The via container // in pcb->library preserves the sequence of addition. - NETCLASS* netclass = nclasses.GetDefault(); + NETCLASSPTR netclass = nclasses.GetDefault(); PADSTACK* via = makeVia( netclass->GetViaDiameter(), netclass->GetViaDrill(), m_top_via_layer, m_bot_via_layer ); @@ -2046,13 +2046,13 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) throw( IO_ERROR ) for( NETCLASSES::iterator nc = nclasses.begin(); nc != nclasses.end(); ++nc ) { - NETCLASS* netclass = nc->second; + NETCLASSPTR netclass = nc->second; exportNETCLASS( netclass, aBoard ); } } -void SPECCTRA_DB::exportNETCLASS( NETCLASS* aNetClass, BOARD* aBoard ) +void SPECCTRA_DB::exportNETCLASS( NETCLASSPTR aNetClass, BOARD* aBoard ) { /* From page 11 of specctra spec: *