From bd19c580f4b13633b7ede32372a46a28a58ad831 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 27 Jun 2020 22:48:48 -0400 Subject: [PATCH] Add configuration for cross-probing behavior Fixes https://gitlab.com/kicad/code/kicad/-/issues/2317 --- common/settings/app_settings.cpp | 9 + eeschema/cross-probing.cpp | 32 ++- .../panel_eeschema_display_options.cpp | 8 + .../panel_eeschema_display_options_base.cpp | 20 ++ .../panel_eeschema_display_options_base.fbp | 206 +++++++++++++++++ .../panel_eeschema_display_options_base.h | 3 + include/settings/app_settings.h | 12 + pcbnew/cross-probing.cpp | 30 ++- pcbnew/dialogs/panel_display_options.cpp | 13 ++ pcbnew/dialogs/panel_display_options_base.cpp | 20 ++ pcbnew/dialogs/panel_display_options_base.fbp | 210 +++++++++++++++++- pcbnew/dialogs/panel_display_options_base.h | 3 + 12 files changed, 553 insertions(+), 13 deletions(-) diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index fe6fc92f26..f28964f473 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -99,6 +99,15 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaV m_params.emplace_back( new PARAM( "appearance.color_theme", &m_ColorTheme, "user" ) ); addParamsForWindow( &m_Window, "window" ); + + m_params.emplace_back( new PARAM( + "cross_probing.center_on_items", &m_CrossProbing.center_on_items, true ) ); + + m_params.emplace_back( + new PARAM( "cross_probing.zoom_to_fit", &m_CrossProbing.zoom_to_fit, true ) ); + + m_params.emplace_back( new PARAM( + "cross_probing.auto_highlight", &m_CrossProbing.auto_highlight, true ) ); } diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index c7793331bb..35fa486030 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,8 @@ SCH_ITEM* SCH_EDITOR_CONTROL::FindComponentAndItem( const wxString& aReference, break; } + CROSS_PROBING_SETTINGS& crossProbingSettings = m_frame->eeconfig()->m_CrossProbing; + if( component ) { if( *sheetWithComponentFound != m_frame->GetCurrentSheet() ) @@ -112,8 +115,28 @@ SCH_ITEM* SCH_EDITOR_CONTROL::FindComponentAndItem( const wxString& aReference, delta = component->GetTransform().TransformCoordinate( pos ); pos = delta + component->GetPosition(); - m_frame->GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( pos, false ); - m_frame->CenterScreen( pos, false ); + if( crossProbingSettings.center_on_items ) + { + m_frame->GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( pos, false ); + m_frame->CenterScreen( pos, false ); + + if( crossProbingSettings.zoom_to_fit ) + { + EDA_RECT bbox = component->GetBoundingBox(); + + wxSize bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize(); + VECTOR2D screenSize = getView()->GetViewport().GetSize(); + + screenSize.x = std::max( 10.0, screenSize.x ); + screenSize.y = std::max( 10.0, screenSize.y ); + double ratio = std::max( fabs( bbSize.x / screenSize.x ), + fabs( bbSize.y / screenSize.y ) ); + + // Try not to zoom on every cross-probe; it gets very noisy + if( ratio < 0.1 || ratio > 1.0 ) + getView()->SetScale( getView()->GetScale() / ratio ); + } + } } /* Print diag */ @@ -167,8 +190,13 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) if( idcmd == NULL ) return; + CROSS_PROBING_SETTINGS& crossProbingSettings = eeconfig()->m_CrossProbing; + if( strcmp( idcmd, "$NET:" ) == 0 ) { + if( !crossProbingSettings.auto_highlight ) + return; + wxString netName = FROM_UTF8( text ); if( auto sg = Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) ) diff --git a/eeschema/dialogs/panel_eeschema_display_options.cpp b/eeschema/dialogs/panel_eeschema_display_options.cpp index 51dc13c398..bb4f3ba445 100644 --- a/eeschema/dialogs/panel_eeschema_display_options.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options.cpp @@ -60,6 +60,10 @@ bool PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataToWindow() m_checkSelFillShapes->SetValue( cfg->m_Selection.fill_shapes ); m_selWidthCtrl->SetValue( cfg->m_Selection.thickness ); + m_checkCrossProbeCenter->SetValue( cfg->m_CrossProbing.center_on_items ); + m_checkCrossProbeZoom->SetValue( cfg->m_CrossProbing.zoom_to_fit ); + m_checkCrossProbeAutoHighlight->SetValue( cfg->m_CrossProbing.auto_highlight ); + m_galOptsPanel->TransferDataToWindow(); return true; @@ -79,6 +83,10 @@ bool PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataFromWindow() cfg->m_Selection.fill_shapes = m_checkSelFillShapes->GetValue(); cfg->m_Selection.thickness = KiROUND( m_selWidthCtrl->GetValue() ); + cfg->m_CrossProbing.center_on_items = m_checkCrossProbeCenter->GetValue(); + cfg->m_CrossProbing.zoom_to_fit = m_checkCrossProbeZoom->GetValue(); + cfg->m_CrossProbing.auto_highlight = m_checkCrossProbeAutoHighlight->GetValue(); + // Update canvas m_frame->GetRenderSettings()->m_ShowHiddenPins = m_checkShowHiddenPins->GetValue(); m_frame->GetRenderSettings()->m_ShowHiddenText = m_checkShowHiddenFields->GetValue(); diff --git a/eeschema/dialogs/panel_eeschema_display_options_base.cpp b/eeschema/dialogs/panel_eeschema_display_options_base.cpp index 5530781de1..948b9c8a34 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options_base.cpp @@ -74,6 +74,26 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE::PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE( wxWind bRightColumn->Add( sbSizer3, 1, wxEXPAND|wxTOP, 5 ); + wxStaticBoxSizer* sbSizer31; + sbSizer31 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Cross-probing") ), wxVERTICAL ); + + m_checkCrossProbeCenter = new wxCheckBox( sbSizer31->GetStaticBox(), wxID_ANY, _("Center view on cross-probed items"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkCrossProbeCenter->SetValue(true); + sbSizer31->Add( m_checkCrossProbeCenter, 0, wxALL, 5 ); + + m_checkCrossProbeZoom = new wxCheckBox( sbSizer31->GetStaticBox(), wxID_ANY, _("Zoom to fit cross-probed items"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkCrossProbeZoom->SetValue(true); + sbSizer31->Add( m_checkCrossProbeZoom, 0, wxALL, 5 ); + + m_checkCrossProbeAutoHighlight = new wxCheckBox( sbSizer31->GetStaticBox(), wxID_ANY, _("Highlight cross-probed nets"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkCrossProbeAutoHighlight->SetValue(true); + m_checkCrossProbeAutoHighlight->SetToolTip( _("Highlight nets when they are highlighted in the PCB editor") ); + + sbSizer31->Add( m_checkCrossProbeAutoHighlight, 0, wxALL, 5 ); + + + bRightColumn->Add( sbSizer31, 1, wxEXPAND|wxTOP, 5 ); + bPanelSizer->Add( bRightColumn, 1, wxEXPAND|wxRIGHT|wxLEFT, 10 ); diff --git a/eeschema/dialogs/panel_eeschema_display_options_base.fbp b/eeschema/dialogs/panel_eeschema_display_options_base.fbp index 920a01f03b..1bc06ca96b 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.fbp +++ b/eeschema/dialogs/panel_eeschema_display_options_base.fbp @@ -690,6 +690,212 @@ + + 5 + wxEXPAND|wxTOP + 1 + + wxID_ANY + Cross-probing + + sbSizer31 + wxVERTICAL + 1 + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Center view on cross-probed items + + 0 + + + 0 + + 1 + m_checkCrossProbeCenter + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Zoom to fit cross-probed items + + 0 + + + 0 + + 1 + m_checkCrossProbeZoom + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Highlight cross-probed nets + + 0 + + + 0 + + 1 + m_checkCrossProbeAutoHighlight + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Highlight nets when they are highlighted in the PCB editor + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + diff --git a/eeschema/dialogs/panel_eeschema_display_options_base.h b/eeschema/dialogs/panel_eeschema_display_options_base.h index 4953a0171c..278c93f7fb 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.h +++ b/eeschema/dialogs/panel_eeschema_display_options_base.h @@ -42,6 +42,9 @@ class PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE : public wxPanel wxStaticText* m_selWidthLabel; wxSpinCtrlDouble* m_selWidthCtrl; wxStaticText* m_highlightColorNote; + wxCheckBox* m_checkCrossProbeCenter; + wxCheckBox* m_checkCrossProbeZoom; + wxCheckBox* m_checkCrossProbeAutoHighlight; public: diff --git a/include/settings/app_settings.h b/include/settings/app_settings.h index 8054143c06..ee1fe0b491 100644 --- a/include/settings/app_settings.h +++ b/include/settings/app_settings.h @@ -24,6 +24,16 @@ #include #include +/** + * Cross-probing behavior + */ +struct CROSS_PROBING_SETTINGS +{ + bool center_on_items; ///< Automatically pan to cross-probed items + bool zoom_to_fit; ///< Zoom to fit items (ignored if center_on_items is off) + bool auto_highlight; ///< Automatically turn on highlight mode in the target frame +}; + /** * Common cursor settings, available to every frame */ @@ -128,6 +138,8 @@ public: virtual bool MigrateFromLegacy( wxConfigBase* aCfg ) override; public: + CROSS_PROBING_SETTINGS m_CrossProbing; + FIND_REPLACE m_FindReplace; GRAPHICS m_Graphics; diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index 84fbc556e1..335a83273e 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,8 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) D_PAD* pad = NULL; BOARD* pcb = GetBoard(); + CROSS_PROBING_SETTINGS& crossProbingSettings = GetPcbNewSettings()->m_CrossProbing; + KIGFX::VIEW* view = m_toolManager->GetView(); KIGFX::RENDER_SETTINGS* renderSettings = view->GetPainter()->GetSettings(); @@ -88,6 +91,9 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) if( strcmp( idcmd, "$NET:" ) == 0 ) { + if( !crossProbingSettings.auto_highlight ) + return; + wxString net_name = FROM_UTF8( text ); NETINFO_ITEM* netinfo = pcb->FindNet( net_name ); @@ -103,6 +109,9 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) } if( strcmp( idcmd, "$NETS:" ) == 0 ) { + if( !crossProbingSettings.auto_highlight ) + return; + wxStringTokenizer netsTok = wxStringTokenizer( FROM_UTF8( text ), "," ); bool first = true; @@ -235,22 +244,25 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) } }; - for( auto zone : pcb->Zones() ) - merge_area( zone ); + if( crossProbingSettings.center_on_items ) + { + for( auto zone : pcb->Zones() ) + merge_area( zone ); - for( auto track : pcb->Tracks() ) - merge_area( track ); + for( auto track : pcb->Tracks() ) + merge_area( track ); - for( auto mod : pcb->Modules() ) - for ( auto mod_pad : mod->Pads() ) - merge_area( mod_pad ); + for( auto mod : pcb->Modules() ) + for( auto mod_pad : mod->Pads() ) + merge_area( mod_pad ); + } } else { renderSettings->SetHighlight( false ); } - if( bbox.GetWidth() > 0 && bbox.GetHeight() > 0 ) + if( crossProbingSettings.center_on_items && bbox.GetWidth() > 0 && bbox.GetHeight() > 0 ) { auto bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize(); auto screenSize = view->ToWorld( GetCanvas()->GetClientSize(), false ); @@ -260,7 +272,7 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) fabs( bbSize.y / screenSize.y ) ); // Try not to zoom on every cross-probe; it gets very noisy - if( ratio < 0.1 || ratio > 1.0 ) + if( crossProbingSettings.zoom_to_fit && ( ratio < 0.1 || ratio > 1.0 ) ) view->SetScale( view->GetScale() / ratio ); view->SetCenter( bbox.Centre() ); diff --git a/pcbnew/dialogs/panel_display_options.cpp b/pcbnew/dialogs/panel_display_options.cpp index a9fcfc6a0d..f39d440693 100644 --- a/pcbnew/dialogs/panel_display_options.cpp +++ b/pcbnew/dialogs/panel_display_options.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,12 @@ bool PANEL_DISPLAY_OPTIONS::TransferDataToWindow() m_OptDisplayPadNumber->SetValue( displ_opts.m_DisplayPadNum ); m_OptDisplayPadNoConn->SetValue( pcbEdit->IsElementVisible( LAYER_NO_CONNECTS ) ); m_ShowNetNamesOption->SetSelection( displ_opts.m_DisplayNetNamesMode ); + + CROSS_PROBING_SETTINGS& crossProbing = pcbEdit->GetPcbNewSettings()->m_CrossProbing; + + m_checkCrossProbeCenter->SetValue( crossProbing.center_on_items ); + m_checkCrossProbeZoom->SetValue( crossProbing.zoom_to_fit ); + m_checkCrossProbeAutoHighlight->SetValue( crossProbing.auto_highlight ); } m_galOptsPanel->TransferDataToWindow(); @@ -108,6 +115,12 @@ bool PANEL_DISPLAY_OPTIONS::TransferDataFromWindow() pcbEdit->SetDisplayOptions( displ_opts ); settings->LoadDisplayOptions( displ_opts, pcbEdit->ShowPageLimits() ); pcbEdit->SetElementVisibility( LAYER_RATSNEST, displ_opts.m_ShowGlobalRatsnest ); + + CROSS_PROBING_SETTINGS& crossProbing = pcbEdit->GetPcbNewSettings()->m_CrossProbing; + + crossProbing.center_on_items = m_checkCrossProbeCenter->GetValue(); + crossProbing.zoom_to_fit = m_checkCrossProbeZoom->GetValue(); + crossProbing.auto_highlight = m_checkCrossProbeAutoHighlight->GetValue(); } view->RecacheAllItems(); diff --git a/pcbnew/dialogs/panel_display_options_base.cpp b/pcbnew/dialogs/panel_display_options_base.cpp index e982680b29..49ad6b7ac6 100644 --- a/pcbnew/dialogs/panel_display_options_base.cpp +++ b/pcbnew/dialogs/panel_display_options_base.cpp @@ -70,6 +70,26 @@ PANEL_DISPLAY_OPTIONS_BASE::PANEL_DISPLAY_OPTIONS_BASE( wxWindow* parent, wxWind pcbOptionsSizer->Add( sbClearance, 0, wxBOTTOM|wxEXPAND|wxTOP, 5 ); + wxStaticBoxSizer* sbSizer3; + sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( pcbPage, wxID_ANY, _("Cross-probing") ), wxVERTICAL ); + + m_checkCrossProbeCenter = new wxCheckBox( sbSizer3->GetStaticBox(), wxID_ANY, _("Center view on cross-probed items"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkCrossProbeCenter->SetValue(true); + sbSizer3->Add( m_checkCrossProbeCenter, 0, wxALL, 5 ); + + m_checkCrossProbeZoom = new wxCheckBox( sbSizer3->GetStaticBox(), wxID_ANY, _("Zoom to fit cross-probed items"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkCrossProbeZoom->SetValue(true); + sbSizer3->Add( m_checkCrossProbeZoom, 0, wxALL, 5 ); + + m_checkCrossProbeAutoHighlight = new wxCheckBox( sbSizer3->GetStaticBox(), wxID_ANY, _("Highlight cross-probed nets"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkCrossProbeAutoHighlight->SetValue(true); + m_checkCrossProbeAutoHighlight->SetToolTip( _("Highlight nets when they are highlighted in the schematic editor") ); + + sbSizer3->Add( m_checkCrossProbeAutoHighlight, 0, wxALL, 5 ); + + + pcbOptionsSizer->Add( sbSizer3, 1, wxEXPAND|wxTOP, 5 ); + pcbPage->SetSizer( pcbOptionsSizer ); pcbPage->Layout(); diff --git a/pcbnew/dialogs/panel_display_options_base.fbp b/pcbnew/dialogs/panel_display_options_base.fbp index b45c30e4dd..5f1a7040df 100644 --- a/pcbnew/dialogs/panel_display_options_base.fbp +++ b/pcbnew/dialogs/panel_display_options_base.fbp @@ -452,11 +452,11 @@ - + 5 wxBOTTOM|wxEXPAND|wxTOP 0 - + wxID_ANY Clearance Outlines @@ -596,6 +596,212 @@ + + 5 + wxEXPAND|wxTOP + 1 + + wxID_ANY + Cross-probing + + sbSizer3 + wxVERTICAL + 1 + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Center view on cross-probed items + + 0 + + + 0 + + 1 + m_checkCrossProbeCenter + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Zoom to fit cross-probed items + + 0 + + + 0 + + 1 + m_checkCrossProbeZoom + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Highlight cross-probed nets + + 0 + + + 0 + + 1 + m_checkCrossProbeAutoHighlight + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Highlight nets when they are highlighted in the schematic editor + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + diff --git a/pcbnew/dialogs/panel_display_options_base.h b/pcbnew/dialogs/panel_display_options_base.h index ebd0919933..3dd9e09428 100644 --- a/pcbnew/dialogs/panel_display_options_base.h +++ b/pcbnew/dialogs/panel_display_options_base.h @@ -44,6 +44,9 @@ class PANEL_DISPLAY_OPTIONS_BASE : public wxPanel wxCheckBox* m_OptDisplayPadNoConn; wxRadioBox* m_OptDisplayTracksClearance; wxCheckBox* m_OptDisplayPadClearence; + wxCheckBox* m_checkCrossProbeCenter; + wxCheckBox* m_checkCrossProbeZoom; + wxCheckBox* m_checkCrossProbeAutoHighlight; public: