From 147540b3bb57d73f0ebf536eb4b80792352ab999 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 7 Sep 2020 16:43:31 -0400 Subject: [PATCH] ADDED: Control to only show ratsnest for visible layers --- common/project/project_local_settings.cpp | 4 ++ include/pcb_display_options.h | 3 + include/project/board_project_settings.h | 7 +++ include/project/project_local_settings.h | 3 + pcbnew/pcb_display_options.cpp | 1 + pcbnew/pcb_painter.cpp | 3 + pcbnew/pcb_painter.h | 5 ++ pcbnew/pcbnew_config.cpp | 2 + pcbnew/ratsnest/ratsnest_viewitem.cpp | 18 ++++++ pcbnew/widgets/appearance_controls.cpp | 68 ++++++++++++++++++++--- pcbnew/widgets/appearance_controls.h | 7 ++- 11 files changed, 113 insertions(+), 8 deletions(-) diff --git a/common/project/project_local_settings.cpp b/common/project/project_local_settings.cpp index f70967115c..595d8207a2 100644 --- a/common/project/project_local_settings.cpp +++ b/common/project/project_local_settings.cpp @@ -150,6 +150,10 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( PROJECT* aProject, const wxStrin &m_NetColorMode, NET_COLOR_MODE::RATSNEST, NET_COLOR_MODE::OFF, NET_COLOR_MODE::ALL ) ); + m_params.emplace_back( new PARAM_ENUM( "board.ratsnest_display_mode", + &m_RatsnestMode, RATSNEST_MODE::ALL, RATSNEST_MODE::ALL, + RATSNEST_MODE::VISIBLE ) ); + // TODO: move the rest of PCB_DISPLAY_OPTIONS that are project-specific in here #if 0 m_params.emplace_back( new PARAM_ENUM( "board.zone_display_mode", diff --git a/include/pcb_display_options.h b/include/pcb_display_options.h index 95489f27ad..3e2b77c707 100644 --- a/include/pcb_display_options.h +++ b/include/pcb_display_options.h @@ -89,6 +89,9 @@ public: /// How to use color overrides on specific nets and netclasses NET_COLOR_MODE m_NetColorMode; + /// Ratsnest draw mode (all layers vs only visible layers) + RATSNEST_MODE m_RatsnestMode; + int m_MaxLinksShowed; // in track creation: number of hairwires shown bool m_ShowModuleRatsnest; // When moving a footprint: allows displaying a ratsnest bool m_ShowGlobalRatsnest; // If true, show all diff --git a/include/project/board_project_settings.h b/include/project/board_project_settings.h index 8fb08ed927..294b08f11e 100644 --- a/include/project/board_project_settings.h +++ b/include/project/board_project_settings.h @@ -101,6 +101,13 @@ enum class NET_COLOR_MODE ALL ///< Net/netclass colors are shown on all net copper }; +///> Determines how ratsnest lines are drawn +enum class RATSNEST_MODE +{ + ALL, ///< Ratsnest lines are drawn to items on all layers (default) + VISIBLE ///< Ratsnest lines are drawn to items on visible layers only +}; + /** * A saved set of layers that are visible */ diff --git a/include/project/project_local_settings.h b/include/project/project_local_settings.h index 3545be01ed..6075003f86 100644 --- a/include/project/project_local_settings.h +++ b/include/project/project_local_settings.h @@ -118,6 +118,9 @@ public: /// The current net color mode NET_COLOR_MODE m_NetColorMode; + /// The current ratsnest draw mode + RATSNEST_MODE m_RatsnestMode; + /// How zones are drawn (TODO: not yet used) ZONE_DISPLAY_MODE m_ZoneDisplayMode; diff --git a/pcbnew/pcb_display_options.cpp b/pcbnew/pcb_display_options.cpp index 6007c18c18..4083c1e94d 100644 --- a/pcbnew/pcb_display_options.cpp +++ b/pcbnew/pcb_display_options.cpp @@ -50,6 +50,7 @@ PCB_DISPLAY_OPTIONS::PCB_DISPLAY_OPTIONS() * 3 show netnames on tracks and pads */ m_ContrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL; m_NetColorMode = NET_COLOR_MODE::RATSNEST; + m_RatsnestMode = RATSNEST_MODE::ALL; m_MaxLinksShowed = 3; // in track creation: number of hairwires shown m_ShowModuleRatsnest = true; // When moving a footprint: allows displaying a ratsnest m_DisplayRatsnestLinesCurved = false; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 12b11012a2..21ecce2e86 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -64,6 +64,7 @@ PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS() m_sketchText = false; m_netColorMode = NET_COLOR_MODE::RATSNEST; m_contrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL; + m_ratsnestDisplayMode = RATSNEST_MODE::ALL; m_trackOpacity = 1.0; m_viaOpacity = 1.0; @@ -208,6 +209,8 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOption m_netColorMode = aOptions.m_NetColorMode; + m_ratsnestDisplayMode = aOptions.m_RatsnestMode; + m_trackOpacity = aOptions.m_TrackOpacity; m_viaOpacity = aOptions.m_ViaOpacity; m_padOpacity = aOptions.m_PadOpacity; diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index d01c9f2424..ee2437b23d 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -174,6 +174,9 @@ public: NET_COLOR_MODE GetNetColorMode() const { return m_netColorMode; } void SetNetColorMode( NET_COLOR_MODE aMode ) { m_netColorMode = aMode; } + RATSNEST_MODE GetRatsnestDisplayMode() const { return m_ratsnestDisplayMode; } + void SetRatsnestDisplayMode( RATSNEST_MODE aMode ) { m_ratsnestDisplayMode = aMode; } + std::map& GetNetclassColorMap() { return m_netclassColors; } std::map& GetNetColorMap() { return m_netColors; } @@ -238,6 +241,8 @@ protected: ///> How to display inactive layers (HIGH_CONTRAST_MODE:NORMAL, DIMMED or HIDDEN ) HIGH_CONTRAST_MODE m_contrastModeDisplay; + RATSNEST_MODE m_ratsnestDisplayMode; + // These opacity overrides multiply with any opacity in the base layer color double m_trackOpacity; ///< Opacity override for all tracks double m_viaOpacity; ///< Opacity override for all types of via diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index 426b7a254c..8158cfe1e2 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -133,6 +133,7 @@ bool PCB_EDIT_FRAME::LoadProjectSettings() PCB_DISPLAY_OPTIONS opts = GetDisplayOptions(); opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay; opts.m_NetColorMode = localSettings.m_NetColorMode; + opts.m_RatsnestMode = localSettings.m_RatsnestMode; opts.m_TrackOpacity = localSettings.m_TrackOpacity; opts.m_ViaOpacity = localSettings.m_ViaOpacity; opts.m_PadOpacity = localSettings.m_PadOpacity; @@ -179,6 +180,7 @@ void PCB_EDIT_FRAME::SaveProjectSettings() localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay; localSettings.m_NetColorMode = displayOpts.m_NetColorMode; + localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode; localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity; localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity; localSettings.m_PadOpacity = displayOpts.m_PadOpacity; diff --git a/pcbnew/ratsnest/ratsnest_viewitem.cpp b/pcbnew/ratsnest/ratsnest_viewitem.cpp index 193c9bf6b3..480dc4c3fc 100644 --- a/pcbnew/ratsnest/ratsnest_viewitem.cpp +++ b/pcbnew/ratsnest/ratsnest_viewitem.cpp @@ -87,6 +87,14 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const std::map& netclassColors = rs->GetNetclassColorMap(); const std::map& netclassMap = m_data->GetNetclassMap(); + const bool onlyVisibleLayers = rs->GetRatsnestDisplayMode() == RATSNEST_MODE::VISIBLE; + + LSET visibleLayers; + + for( PCB_LAYER_ID layer : LSET::AllCuMask().Seq() ) + if( aView->IsLayerVisible( layer ) ) + visibleLayers.set( layer ); + const bool curved_ratsnest = rs->GetCurvedRatsnestLinesEnabled(); // Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved) @@ -186,6 +194,16 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const show = sourceNode->Parent()->GetLocalRatsnestVisible() || targetNode->Parent()->GetLocalRatsnestVisible(); + if( onlyVisibleLayers && show ) + { + LSET sourceLayers = sourceNode->Parent()->GetLayerSet(); + LSET targetLayers = targetNode->Parent()->GetLayerSet(); + + if( !( sourceLayers & visibleLayers ).any() || + !( targetLayers & visibleLayers ).any() ) + show = false; + } + if ( enable && show ) { if ( source == target ) diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index 1b8e27a931..6e6ab37e03 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -609,16 +609,17 @@ void APPEARANCE_CONTROLS::createControls() m_paneNetDisplayOptions->Collapse(); m_paneNetDisplayOptions->SetBackgroundColour( m_notebook->GetThemeBackgroundColour() ); + wxWindow* netDisplayPane = m_paneNetDisplayOptions->GetPane(); wxBoxSizer* netDisplayOptionsSizer = new wxBoxSizer( wxVERTICAL ); - wxWindow* netDisplayPane = m_paneNetDisplayOptions->GetPane(); + //// Net color mode - m_staticTextNetDisplayTitle = new wxStaticText( netDisplayPane, wxID_ANY, _( "Net colors:" ), - wxDefaultPosition, wxDefaultSize, 0 ); - m_staticTextNetDisplayTitle->Wrap( -1 ); - m_staticTextNetDisplayTitle->SetToolTip( _( "Choose when to show net and netclass colors" ) ); + m_txtNetDisplayTitle = new wxStaticText( netDisplayPane, wxID_ANY, _( "Net colors:" ), + wxDefaultPosition, wxDefaultSize, 0 ); + m_txtNetDisplayTitle->Wrap( -1 ); + m_txtNetDisplayTitle->SetToolTip( _( "Choose when to show net and netclass colors" ) ); - netDisplayOptionsSizer->Add( m_staticTextNetDisplayTitle, 0, wxEXPAND | wxBOTTOM | wxLEFT, 2 ); + netDisplayOptionsSizer->Add( m_txtNetDisplayTitle, 0, wxEXPAND | wxBOTTOM | wxLEFT, 2 ); wxBoxSizer* netColorSizer = new wxBoxSizer( wxHORIZONTAL ); @@ -641,7 +642,35 @@ void APPEARANCE_CONTROLS::createControls() netColorSizer->Add( m_rbNetColorOff, 0, 0, 5 ); - netDisplayOptionsSizer->Add( netColorSizer, 0, wxEXPAND|wxBOTTOM, 5 ); + netDisplayOptionsSizer->Add( netColorSizer, 0, wxEXPAND | wxBOTTOM, 5 ); + + //// Ratsnest display + + m_txtRatsnestVisibility = new wxStaticText( netDisplayPane, wxID_ANY, _( "Ratsnest display:" ), + wxDefaultPosition, wxDefaultSize, 0 ); + m_txtRatsnestVisibility->Wrap( -1 ); + m_txtRatsnestVisibility->SetToolTip( _( "Choose what ratsnest lines to display" ) ); + + netDisplayOptionsSizer->Add( m_txtRatsnestVisibility, 0, wxEXPAND | wxBOTTOM | wxLEFT, 2 ); + + wxBoxSizer* ratsnestDisplayModeSizer = new wxBoxSizer( wxHORIZONTAL ); + + m_rbRatsnestAllLayers = new wxRadioButton( netDisplayPane, wxID_ANY, _( "All layers" ), + wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); + m_rbRatsnestAllLayers->SetToolTip( _( "Ratsnest lines are shown to items on all layers" ) ); + m_rbRatsnestAllLayers->SetValue( true ); + + ratsnestDisplayModeSizer->Add( m_rbRatsnestAllLayers, 0, wxRIGHT, 10 ); + + m_rbRatsnestVisibleLayers = new wxRadioButton( netDisplayPane, wxID_ANY, _( "Visible layers" ), + wxDefaultPosition, wxDefaultSize, 0 ); + m_rbRatsnestVisibleLayers->SetToolTip( _( "Ratsnest lines are shown to items on visible layers" ) ); + + ratsnestDisplayModeSizer->Add( m_rbRatsnestVisibleLayers, 0, wxRIGHT, 4 ); + + netDisplayOptionsSizer->Add( ratsnestDisplayModeSizer, 0, wxEXPAND | wxBOTTOM, 5 ); + + //// netDisplayPane->SetSizer( netDisplayOptionsSizer ); netDisplayPane->Layout(); @@ -662,6 +691,11 @@ void APPEARANCE_CONTROLS::createControls() m_rbNetColorOff->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onNetColorModeChanged, this ); m_rbNetColorRatsnest->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onNetColorModeChanged, this ); + + m_rbRatsnestAllLayers->Bind( wxEVT_RADIOBUTTON, + &APPEARANCE_CONTROLS::onRatsnestModeChanged, this ); + m_rbRatsnestVisibleLayers->Bind( wxEVT_RADIOBUTTON, + &APPEARANCE_CONTROLS::onRatsnestModeChanged, this ); } @@ -1048,6 +1082,11 @@ void APPEARANCE_CONTROLS::UpdateDisplayOptions() case NET_COLOR_MODE::OFF: m_rbNetColorOff->SetValue( true ); break; } + if( options.m_RatsnestMode == RATSNEST_MODE::ALL ) + m_rbRatsnestAllLayers->SetValue( true ); + else + m_rbRatsnestVisibleLayers->SetValue( true ); + wxASSERT( m_objectSettingsMap.count( LAYER_RATSNEST ) ); APPEARANCE_SETTING* ratsnest = m_objectSettingsMap.at( LAYER_RATSNEST ); ratsnest->ctl_visibility->SetValue( options.m_ShowGlobalRatsnest ); @@ -2360,6 +2399,21 @@ void APPEARANCE_CONTROLS::onNetColorModeChanged( wxCommandEvent& aEvent ) } +void APPEARANCE_CONTROLS::onRatsnestModeChanged( wxCommandEvent& aEvent ) +{ + PCB_DISPLAY_OPTIONS options = m_frame->GetDisplayOptions(); + + if( m_rbRatsnestAllLayers->GetValue() ) + options.m_RatsnestMode = RATSNEST_MODE::ALL; + else + options.m_RatsnestMode = RATSNEST_MODE::VISIBLE; + + m_frame->SetDisplayOptions( options ); + m_frame->GetCanvas()->RedrawRatsnest(); + passOnFocus(); +} + + void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent ) { KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); diff --git a/pcbnew/widgets/appearance_controls.h b/pcbnew/widgets/appearance_controls.h index 63ead754b2..c8805e2f35 100644 --- a/pcbnew/widgets/appearance_controls.h +++ b/pcbnew/widgets/appearance_controls.h @@ -349,10 +349,13 @@ private: // Net display options controls WX_COLLAPSIBLE_PANE* m_paneNetDisplayOptions; - wxStaticText* m_staticTextNetDisplayTitle; + wxStaticText* m_txtNetDisplayTitle; wxRadioButton* m_rbNetColorAll; wxRadioButton* m_rbNetColorRatsnest; wxRadioButton* m_rbNetColorOff; + wxStaticText* m_txtRatsnestVisibility; + wxRadioButton* m_rbRatsnestAllLayers; + wxRadioButton* m_rbRatsnestVisibleLayers; enum POPUP_ID { @@ -424,6 +427,8 @@ private: void onNetColorModeChanged( wxCommandEvent& aEvent ); + void onRatsnestModeChanged( wxCommandEvent& aEvent ); + void onNetclassContextMenu( wxCommandEvent& aEvent ); void handleBoardItemsChanged();