Scale and zoom view to fit when cross-probing a net on the board

This commit is contained in:
Jon Evans 2018-01-06 21:30:31 -05:00 committed by Wayne Stambaugh
parent ca264f8982
commit 04beb20e3e
1 changed files with 47 additions and 2 deletions

View File

@ -21,6 +21,8 @@
#include <pcbnew_id.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <collectors.h>
#include <pcbnew.h>
@ -76,9 +78,52 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
if( IsGalCanvasActive() )
{
auto rs = m_toolManager->GetView()->GetPainter()->GetSettings();
auto view = m_toolManager->GetView();
auto rs = view->GetPainter()->GetSettings();
rs->SetHighlight( true, netcode );
m_toolManager->GetView()->UpdateAllLayersColor();
view->UpdateAllLayersColor();
BOX2I bbox;
bool first = true;
auto merge_area = [netcode, &bbox, &first]( BOARD_CONNECTED_ITEM* aItem )
{
if( aItem->GetNetCode() == netcode )
{
if( first )
{
bbox = aItem->GetBoundingBox();
first = false;
}
else
{
bbox.Merge( aItem->GetBoundingBox() );
}
}
};
for( auto zone : pcb->Zones() )
merge_area( zone );
for( auto track : pcb->Tracks() )
merge_area( track );
for( auto mod : pcb->Modules() )
for ( auto mod_pad : mod->Pads() )
merge_area( mod_pad );
if( netcode > 0 && bbox.GetWidth() > 0 && bbox.GetHeight() > 0 )
{
auto bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
auto screenSize = view->ToWorld( GetGalCanvas()->GetClientSize(), false );
double ratio = std::max( fabs( bbSize.x / screenSize.x ),
fabs( bbSize.y / screenSize.y ) );
double scale = view->GetScale() / ratio;
view->SetScale( scale );
view->SetCenter( bbox.Centre() );
}
GetGalCanvas()->Refresh();
}
else