From 75cda5021d72011f2de54cadbca32581a5319fa9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 28 Jul 2017 16:03:15 +0200 Subject: [PATCH] Assure that NETINFO_ITEMs have a NETCLASS object assigned Fixes: lp:1705896 * https://bugs.launchpad.net/kicad/+bug/1705896 --- pcbnew/class_netclass.cpp | 5 ++--- pcbnew/class_netclass.h | 8 +++----- pcbnew/class_netinfo.h | 17 +++-------------- pcbnew/class_netinfo_item.cpp | 15 +++++++++++++-- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/pcbnew/class_netclass.cpp b/pcbnew/class_netclass.cpp index 8be795da09..4a094609e0 100644 --- a/pcbnew/class_netclass.cpp +++ b/pcbnew/class_netclass.cpp @@ -86,7 +86,6 @@ NETCLASS::~NETCLASS() NETCLASSES::NETCLASSES() { - m_Default = std::make_shared( NETCLASS::Default ); } @@ -102,7 +101,7 @@ bool NETCLASSES::Add( NETCLASSPTR aNetClass ) if( name == NETCLASS::Default ) { // invoke operator=(), which is currently generated by compiler. - m_Default = aNetClass; + GetDefault() = aNetClass; return true; } @@ -142,7 +141,7 @@ NETCLASSPTR NETCLASSES::Remove( const wxString& aNetName ) NETCLASSPTR NETCLASSES::Find( const wxString& aName ) const { if( aName == NETCLASS::Default ) - return m_Default; + return GetDefault(); NETCLASS_MAP::const_iterator found = m_NetClasses.find( aName ); diff --git a/pcbnew/class_netclass.h b/pcbnew/class_netclass.h index 6bcdd8a33e..b50df52de8 100644 --- a/pcbnew/class_netclass.h +++ b/pcbnew/class_netclass.h @@ -235,9 +235,6 @@ private: /// all the NETCLASSes except the default one. NETCLASS_MAP m_NetClasses; - /// the default NETCLASS. - NETCLASSPTR m_Default; - public: NETCLASSES(); ~NETCLASSES(); @@ -272,9 +269,10 @@ public: * Function GetDefault * @return the default net class. */ - NETCLASSPTR GetDefault() const + NETCLASSPTR& GetDefault() const { - return m_Default; + static NETCLASSPTR defNetClass = std::make_shared( NETCLASS::Default ); + return defNetClass; } /** diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index ca3082eeef..3ed89459c5 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -78,9 +78,6 @@ private: wxString m_ShortNetname; ///< short net name, like vout from /mysheet/mysubsheet/vout - wxString m_NetClassName; // Net Class name. if void this is equivalent - // to "default" (the first - // item of the net classes list NETCLASSPTR m_NetClass; BOARD* m_parent; ///< The parent board the net belongs to. @@ -120,15 +117,7 @@ public: * Function SetClass * sets \a aNetclass into this NET */ - void SetClass( NETCLASSPTR aNetClass ) - { - m_NetClass = aNetClass; - - if( aNetClass ) - m_NetClassName = aNetClass->GetName(); - else - m_NetClassName = NETCLASS::Default; - } + void SetClass( NETCLASSPTR aNetClass ); NETCLASSPTR GetNetClass() { @@ -139,9 +128,9 @@ public: * Function GetClassName * returns the class name */ - const wxString& GetClassName() const + wxString GetClassName() const { - return m_NetClassName; + return m_NetClass ? m_NetClass->GetName() : NETCLASS::Default; } #if 1 diff --git a/pcbnew/class_netinfo_item.cpp b/pcbnew/class_netinfo_item.cpp index 3e4547f253..4259f61d94 100644 --- a/pcbnew/class_netinfo_item.cpp +++ b/pcbnew/class_netinfo_item.cpp @@ -53,8 +53,12 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCo BOARD_ITEM( aParent, PCB_NETINFO_T ), m_NetCode( aNetCode ), m_Netname( aNetName ), m_ShortNetname( m_Netname.AfterLast( '/' ) ) { - m_parent = aParent; - m_NetClassName = NETCLASS::Default; + m_parent = aParent; + + if( aParent ) + m_NetClass = aParent->GetDesignSettings().m_NetClasses.GetDefault(); + else + m_NetClass = std::make_shared( "" ); } @@ -75,6 +79,13 @@ void NETINFO_ITEM::Draw( EDA_DRAW_PANEL* panel, } +void NETINFO_ITEM::SetClass( NETCLASSPTR aNetClass ) +{ + wxCHECK( m_parent, /* void */ ); + m_NetClass = aNetClass ? aNetClass : m_parent->GetDesignSettings().m_NetClasses.GetDefault(); +} + + void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) { wxString txt;