diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp index cd84f0e396..573f5bf0d2 100644 --- a/common/project/net_settings.cpp +++ b/common/project/net_settings.cpp @@ -177,6 +177,8 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : } }, {} ) ); + + m_params.emplace_back( new PARAM_LIST( "hidden_nets", &m_HiddenNets, {} ) ); } diff --git a/include/project/net_settings.h b/include/project/net_settings.h index e3a3f393aa..82466707f7 100644 --- a/include/project/net_settings.h +++ b/include/project/net_settings.h @@ -50,6 +50,12 @@ public: */ std::map m_PcbNetColors; + /** + * A list of netnames that have been manually hidden in the board editor. + * Currently, hiding nets means hiding the ratsnest for those nets. + */ + std::vector m_HiddenNets; + public: /** * Parses a bus vector (e.g. A[7..0]) into name, begin, and end. diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 13991af5cc..6c497a1f73 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -528,9 +528,6 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in mgr->LoadProject( pro.GetFullPath() ); } - - // load project settings before BOARD - LoadProjectSettings(); } if( is_new ) @@ -648,6 +645,9 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in GetBoard()->BuildConnectivity(); Compile_Ratsnest( true ); + // Load project settings after setting up board; some of them depend on the nets list + LoadProjectSettings(); + onBoardLoaded(); // Refresh the 3D view, if any diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 6a2fd72fff..f179fcb228 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -218,9 +218,16 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOption } -void PCB_RENDER_SETTINGS::LoadNetSettings( const NET_SETTINGS& aSettings ) +void PCB_RENDER_SETTINGS::LoadNetSettings( const NET_SETTINGS& aSettings, + const NETINFO_LIST& aList ) { - m_netColors = aSettings.m_PcbNetColors; + m_netColors.clear(); + + for( const auto& pair : aSettings.m_PcbNetColors ) + { + if( NETINFO_ITEM* net = aList.GetNetItem( pair.first ) ) + m_netColors[net->GetNet()] = pair.second; + } m_netclassColors.clear(); @@ -229,6 +236,14 @@ void PCB_RENDER_SETTINGS::LoadNetSettings( const NET_SETTINGS& aSettings ) if( pair.second->GetPcbColor() != COLOR4D::UNSPECIFIED ) m_netclassColors[pair.first] = pair.second->GetPcbColor(); } + + m_hiddenNets.clear(); + + for( const wxString& hidden : aSettings.m_HiddenNets ) + { + if( NETINFO_ITEM* net = aList.GetNetItem( hidden ) ) + m_hiddenNets.insert( net->GetNet() ); + } } @@ -300,8 +315,8 @@ const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer // Apply net color overrides if( conItem && m_netColorMode == NET_COLOR_MODE::ALL ) { - if( m_netColors.count( conItem->GetNetname() ) ) - return m_netColors.at( conItem->GetNetname() ); + if( m_netColors.count( conItem->GetNetCode() ) ) + return m_netColors.at( conItem->GetNetCode() ); else if( m_netclassColors.count( conItem->GetNetClassName() ) ) return m_netclassColors.at( conItem->GetNetClassName() ); } diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index e6cf965c6a..e63120b72c 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -49,6 +49,7 @@ class DIMENSION; class PCB_TARGET; class MARKER_PCB; class NET_SETTINGS; +class NETINFO_LIST; namespace KIGFX { @@ -107,8 +108,9 @@ public: /** * Loads net-specific render settings * @param aSettings is the NET_SETTINGS for the current proejct + * @param aList is the list of nets in the board */ - void LoadNetSettings( const NET_SETTINGS& aSettings ); + void LoadNetSettings( const NET_SETTINGS& aSettings, const NETINFO_LIST& aList ); virtual void LoadColors( const COLOR_SETTINGS* aSettings ) override; @@ -185,7 +187,10 @@ public: std::map& GetNetclassColorMap() { return m_netclassColors; } - std::map& GetNetColorMap() { return m_netColors; } + std::map& GetNetColorMap() { return m_netColors; } + + std::set& GetHiddenNets() { return m_hiddenNets; } + const std::set& GetHiddenNets() const { return m_hiddenNets; } protected: ///> Flag determining if items on a given layer should be drawn as an outline or a filled item @@ -238,8 +243,11 @@ protected: ///> Overrides for specific netclass colors std::map m_netclassColors; - ///> Overrides for specific net colors - std::map m_netColors; + ///> Overrides for specific net colors, stored as netcodes for the ratsnest to access easily + std::map m_netColors; + + ///> Set of net codes that should not have their ratsnest displayed + std::set m_hiddenNets; }; diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index e429af0dec..f30e2c1509 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -100,7 +100,7 @@ bool PCB_EDIT_FRAME::LoadProjectSettings() KIGFX::PCB_RENDER_SETTINGS* rs = static_cast( GetCanvas()->GetView()->GetPainter()->GetSettings() ); - rs->LoadNetSettings( project.NetSettings() ); + rs->LoadNetSettings( project.NetSettings(), GetBoard()->GetNetInfo() ); PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings(); diff --git a/pcbnew/ratsnest/ratsnest_viewitem.cpp b/pcbnew/ratsnest/ratsnest_viewitem.cpp index 36f37b26d8..5f3cc6a12c 100644 --- a/pcbnew/ratsnest/ratsnest_viewitem.cpp +++ b/pcbnew/ratsnest/ratsnest_viewitem.cpp @@ -81,15 +81,19 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const bool colorByNet = rs->GetNetColorMode() != PCB_RENDER_SETTINGS::NET_COLOR_MODE::OFF; - std::set highlightedNets = rs->GetHighlightNetCodes(); + std::set highlightedNets = rs->GetHighlightNetCodes(); + const std::set& hiddenNets = rs->GetHiddenNets(); gal->SetStrokeColor( color.Brightened(0.5) ); const bool curved_ratsnest = rs->GetCurvedRatsnestLinesEnabled(); // Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved) - for( const auto& l : m_data->GetDynamicRatsnest() ) + for( const RN_DYNAMIC_LINE& l : m_data->GetDynamicRatsnest() ) { + if( hiddenNets.count( l.netCode ) ) + continue; + if ( l.a == l.b ) { gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y - CROSS_SIZE ), @@ -116,6 +120,9 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const for( int i = 1 /* skip "No Net" at [0] */; i < m_data->GetNetCount(); ++i ) { + if( hiddenNets.count( i ) ) + continue; + RN_NET* net = m_data->GetRatsnestForNet( i ); if( !net )