Skip to content

Cross Probe only does "Zoom to Fit" at extreme ratios

When cross probing, you can choose to have Eeschema and Pcbnew perform a "Zoom to Fit". In testing commit e03f6a3b I found that it only does the "Zoom to Fit" when there is an extreme ratio between the component size as currently displayed and the screen size.

Description

In looking at the code on the Eeschema side, I see this in eeschema/cross-probing.cpp:

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 );
}

In the screenshot, Eeschema decided that the current size of the component was big enough and didn't perform the "Zoom to Fit" after clicking on the part in Pcbnew on the right. It's perhaps hard to tell since the component is so small on screen, but the 3 pin connector to the right of the chip has been selected as a result of cross probing. Clearly it should have zoomed in to make it bigger:

Cross_Probe_-_Doesn_t_Zoom_to_Fit

Here's the key variable values at the moment the code above was called:

bbox x:691017 y:69598

bsize x:967423 y:346004

screenSize x:3267024.2 y:3316010.722

ratio 0.296117

The code will only perform the "Zoom to Fit" if ratio is < 0.1 or > 1.0. Something is going wrong with this comparison. The comment says it's trying to avoid doing a "Zoom to Fit" every time, but this is too too extreme in the opposite direction.

Steps to reproduce

  1. Open Eeschema and Pcbnew from KiCad
  2. Load a document and click the "Home" key in each to make sure both windows are showing their entire document
  3. Make sure the "Zoom to Fit" option is checked in "Preferences" for both Eeschema and Pcbnew.
  4. Click on a part in Pcbnew to perform cross probing
  5. Notice that Eechema doesn't zoom.
  6. Zoom the Eeschema window so the view is very tiny
  7. Click on the part in Pcbnew and see that Eeschema does do the "Zoom to Fit"

KiCad Version

Application: KiCad

Version: (5.99.0-2670-ge03f6a3b4-dirty), debug build

Libraries:
	wxWidgets 3.0.5
	libcurl/7.70.0 OpenSSL/1.1.1g (Schannel) zlib/1.2.11 brotli/1.0.7 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.40.0

Platform: Windows 8 (build 9200), 64-bit edition, 64 bit, Little endian, wxMSW

Build Info:
	Date: Aug 10 2020 18:00:26
	wxWidgets: 3.0.5 (wchar_t,wx containers,compatible with 2.8)
	Boost: 1.73.0
	OCE: 6.9.1
	Curl: 7.70.0
	Compiler: GCC 10.2.0 with C++ ABI 1014

Build settings:
	KICAD_SCRIPTING=OFF
	KICAD_SCRIPTING_MODULES=OFF
	KICAD_SCRIPTING_PYTHON3=OFF
	KICAD_SCRIPTING_WXPYTHON=OFF
	KICAD_SCRIPTING_WXPYTHON_PHOENIX=OFF
	KICAD_SCRIPTING_ACTION_MENU=OFF
	BUILD_GITHUB_PLUGIN=OFF
	KICAD_USE_OCE=ON
	KICAD_SPICE=OFF
	KICAD_STDLIB_DEBUG=OFF
	KICAD_STDLIB_LIGHT_DEBUG=OFF
	KICAD_SANITIZE=OFF
Edited by Peter Montgomery