Don't scroll to highlight an object already visible.
This commit is contained in:
parent
a221f7aa56
commit
46949abe4a
|
@ -836,9 +836,9 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
|
|||
|
||||
|
||||
// Find the first child dialog.
|
||||
wxWindow* findDialog( wxWindowList& aList )
|
||||
wxWindow* EDA_DRAW_FRAME::findDialog()
|
||||
{
|
||||
for( wxWindow* window : aList )
|
||||
for( wxWindow* window : GetChildren() )
|
||||
{
|
||||
if( dynamic_cast<DIALOG_SHIM*>( window ) )
|
||||
return window;
|
||||
|
@ -860,7 +860,7 @@ void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos )
|
|||
centerView = true;
|
||||
|
||||
// Center if we're behind an obscuring dialog, or within 10% of its edge
|
||||
wxWindow* dialog = findDialog( GetChildren() );
|
||||
wxWindow* dialog = findDialog();
|
||||
|
||||
if( dialog )
|
||||
{
|
||||
|
@ -882,7 +882,9 @@ void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos )
|
|||
GetCanvas()->GetView()->SetCenter( aPos, dialogRect );
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCanvas()->GetView()->SetCenter( aPos );
|
||||
}
|
||||
}
|
||||
|
||||
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( aPos );
|
||||
|
|
|
@ -462,6 +462,8 @@ protected:
|
|||
|
||||
void setupUnits( APP_SETTINGS_BASE* aCfg );
|
||||
|
||||
wxWindow* findDialog();
|
||||
|
||||
/**
|
||||
* Determines the Canvas type to load (with prompt if required) and initializes m_canvasType
|
||||
*/
|
||||
|
|
|
@ -216,7 +216,7 @@ public:
|
|||
|
||||
EDA_ITEM* GetItem( const KIID& aId ) const override;
|
||||
|
||||
void FocusOnItem( BOARD_ITEM* aItem );
|
||||
void FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
|
||||
|
||||
// General
|
||||
virtual void ReCreateOptToolbar() override { }
|
||||
|
|
|
@ -478,6 +478,8 @@ public:
|
|||
|
||||
SHAPE_POLY_SET();
|
||||
|
||||
SHAPE_POLY_SET( const BOX2D& aRect );
|
||||
|
||||
/**
|
||||
* Construct a SHAPE_POLY_SET with the first outline given by aOutline.
|
||||
*
|
||||
|
|
|
@ -64,6 +64,18 @@ SHAPE_POLY_SET::SHAPE_POLY_SET() :
|
|||
}
|
||||
|
||||
|
||||
SHAPE_POLY_SET::SHAPE_POLY_SET( const BOX2D& aRect ) :
|
||||
SHAPE( SH_POLY_SET )
|
||||
{
|
||||
NewOutline();
|
||||
Append( VECTOR2I( aRect.GetLeft(), aRect.GetTop() ) );
|
||||
Append( VECTOR2I( aRect.GetRight(), aRect.GetTop() ) );
|
||||
Append( VECTOR2I( aRect.GetRight(), aRect.GetBottom() ) );
|
||||
Append( VECTOR2I( aRect.GetLeft(), aRect.GetBottom() ) );
|
||||
Outline( 0 ).SetClosed( true );
|
||||
}
|
||||
|
||||
|
||||
SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_LINE_CHAIN& aOutline ) :
|
||||
SHAPE( SH_POLY_SET )
|
||||
{
|
||||
|
|
|
@ -389,17 +389,13 @@ void DIALOG_DRC::OnDRCItemSelected( wxDataViewEvent& aEvent )
|
|||
|
||||
WINDOW_THAWER thawer( m_frame );
|
||||
|
||||
m_frame->FocusOnItem( item );
|
||||
m_frame->GetCanvas()->Refresh();
|
||||
|
||||
if( ( violationLayers & board->GetVisibleLayers() ) == 0 )
|
||||
{
|
||||
m_frame->GetAppearancePanel()->SetLayerVisible( principalLayer, true );
|
||||
m_frame->GetCanvas()->Refresh();
|
||||
}
|
||||
|
||||
if( board->GetVisibleLayers().test( principalLayer ) )
|
||||
m_frame->SetActiveLayer( principalLayer );
|
||||
|
||||
m_frame->FocusOnItem( item, principalLayer );
|
||||
}
|
||||
|
||||
aEvent.Skip();
|
||||
|
|
|
@ -200,7 +200,7 @@ EDA_ITEM* PCB_BASE_FRAME::GetItem( const KIID& aId ) const
|
|||
}
|
||||
|
||||
|
||||
void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem )
|
||||
void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer )
|
||||
{
|
||||
static KIID lastBrightenedItemID( niluuid );
|
||||
|
||||
|
@ -270,7 +270,48 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem )
|
|||
|
||||
GetCanvas()->GetView()->Update( aItem );
|
||||
lastBrightenedItemID = aItem->m_Uuid;
|
||||
FocusOnLocation( aItem->GetFocusPosition() );
|
||||
|
||||
// Focus on the object's location. Prefer a visible part of the object to its anhcor
|
||||
// in order to keep from scrolling around.
|
||||
|
||||
wxPoint focusPt = aItem->GetFocusPosition();
|
||||
KIGFX::VIEW* view = GetCanvas()->GetView();
|
||||
SHAPE_POLY_SET viewportPoly( view->GetViewport() );
|
||||
wxWindow* dialog = findDialog();
|
||||
|
||||
if( dialog )
|
||||
{
|
||||
wxPoint dialogPos = GetCanvas()->ScreenToClient( dialog->GetScreenPosition() );
|
||||
SHAPE_POLY_SET dialogPoly( BOX2D( view->ToWorld( dialogPos, true ),
|
||||
view->ToWorld( dialog->GetSize(), false ) ) );
|
||||
|
||||
viewportPoly.BooleanSubtract( dialogPoly, SHAPE_POLY_SET::PM_FAST );
|
||||
}
|
||||
|
||||
SHAPE_POLY_SET itemPoly, clippedPoly;
|
||||
|
||||
if( aLayer == UNDEFINED_LAYER )
|
||||
aLayer = aItem->GetLayer();
|
||||
|
||||
aItem->TransformShapeWithClearanceToPolygon( itemPoly, aLayer, 0, Millimeter2iu( 0.1 ),
|
||||
ERROR_INSIDE );
|
||||
|
||||
clippedPoly.BooleanIntersection( itemPoly, viewportPoly, SHAPE_POLY_SET::PM_FAST );
|
||||
|
||||
if( !clippedPoly.IsEmpty() )
|
||||
itemPoly = clippedPoly;
|
||||
|
||||
BOX2I bbox = itemPoly.BBox();
|
||||
int step = std::min( bbox.GetWidth(), bbox.GetHeight() ) / 10;
|
||||
|
||||
while( !itemPoly.IsEmpty() )
|
||||
{
|
||||
focusPt = (wxPoint) itemPoly.BBox().Centre();
|
||||
itemPoly.Deflate( step, 4 );
|
||||
}
|
||||
|
||||
FocusOnLocation( focusPt );
|
||||
|
||||
GetCanvas()->Refresh();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue