Add hittesting for worksheets in Pcbnew and Eeschema.

Fixes https://gitlab.com/kicad/code/kicad/issues/4282
This commit is contained in:
Jeff Young 2020-05-03 00:06:43 +01:00
parent 055ab92797
commit 199bb2ffb0
7 changed files with 67 additions and 23 deletions

View File

@ -65,26 +65,34 @@ const BOX2I WS_PROXY_VIEW_ITEM::ViewBBox() const
} }
void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const void WS_PROXY_VIEW_ITEM::buildDrawList( VIEW* aView, WS_DRAW_ITEM_LIST* aDrawList ) const
{ {
auto gal = aView->GetGAL(); RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
auto settings = aView->GetPainter()->GetSettings(); wxString fileName( m_fileName.c_str(), wxConvUTF8 );
wxString fileName( m_fileName.c_str(), wxConvUTF8 ); wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
WS_DRAW_ITEM_LIST drawList;
drawList.SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() ); aDrawList->SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() );
// Adjust the scaling factor for worksheet items: // Adjust the scaling factor for worksheet items:
// worksheet items coordinates and sizes are stored in mils, // worksheet items coordinates and sizes are stored in mils,
// and must be scaled to the same units as the caller // and must be scaled to the same units as the caller
drawList.SetMilsToIUfactor( m_mils2IUscalefactor ); aDrawList->SetMilsToIUfactor( m_mils2IUscalefactor );
drawList.SetSheetNumber( m_sheetNumber ); aDrawList->SetSheetNumber( m_sheetNumber );
drawList.SetSheetCount( m_sheetCount ); aDrawList->SetSheetCount( m_sheetCount );
drawList.SetFileName( fileName ); aDrawList->SetFileName( fileName );
drawList.SetSheetName( sheetName ); aDrawList->SetSheetName( sheetName );
drawList.SetProject( m_project ); aDrawList->SetProject( m_project );
drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock ); aDrawList->BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock );
}
void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
{
GAL* gal = aView->GetGAL();
RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
WS_DRAW_ITEM_LIST drawList;
buildDrawList( aView, &drawList );
// Draw the title block normally even if the view is flipped // Draw the title block normally even if the view is flipped
bool flipped = gal->IsFlippedX(); bool flipped = gal->IsFlippedX();
@ -124,3 +132,18 @@ void WS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
} }
bool WS_PROXY_VIEW_ITEM::HitTestWorksheetItems( VIEW* aView, const wxPoint& aPosition )
{
int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
WS_DRAW_ITEM_LIST drawList;
buildDrawList( aView, &drawList );
for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
{
if( item->HitTest( aPosition, accuracy ) )
return true;
}
return false;
}

View File

@ -98,6 +98,8 @@ public:
void HideWorksheet(); void HideWorksheet();
WS_PROXY_VIEW_ITEM* GetWorksheet() const { return m_worksheet.get(); }
void HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin = nullptr ); void HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin = nullptr );
private: private:

View File

@ -40,6 +40,7 @@
#include <sch_line.h> #include <sch_line.h>
#include <sch_bus_entry.h> #include <sch_bus_entry.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <ws_proxy_view_item.h>
#include <eeschema_id.h> #include <eeschema_id.h>
#include <status_popup.h> #include <status_popup.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
@ -1235,7 +1236,15 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
if( selection.Empty() ) if( selection.Empty() )
{ {
m_toolMgr->RunAction( ACTIONS::pageSettings ); if( getView()->IsLayerVisible( LAYER_SCHEMATIC_WORKSHEET ) )
{
KIGFX::WS_PROXY_VIEW_ITEM* worksheet = m_frame->GetCanvas()->GetView()->GetWorksheet();
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
if( worksheet && worksheet->HitTestWorksheetItems( getView(), (wxPoint) cursorPos ) )
m_toolMgr->RunAction( ACTIONS::pageSettings );
}
return 0; return 0;
} }

View File

@ -34,6 +34,7 @@ class WS_DRAW_ITEM_LINE;
class WS_DRAW_ITEM_RECT; class WS_DRAW_ITEM_RECT;
class WS_DRAW_ITEM_TEXT; class WS_DRAW_ITEM_TEXT;
class WS_DRAW_ITEM_BITMAP; class WS_DRAW_ITEM_BITMAP;
class WS_DRAW_ITEM_LIST;
namespace KIGFX namespace KIGFX
{ {
@ -101,7 +102,11 @@ public:
return wxT( "WS_PROXY_VIEW_ITEM" ); return wxT( "WS_PROXY_VIEW_ITEM" );
} }
bool HitTestWorksheetItems( VIEW* aView, const wxPoint& aPosition );
protected: protected:
void buildDrawList( VIEW* aView, WS_DRAW_ITEM_LIST* aDrawList ) const;
/// the factor between mils (units used in worksheet and internal units) /// the factor between mils (units used in worksheet and internal units)
/// it is the value IU_PER_MILS used in the caller /// it is the value IU_PER_MILS used in the caller
int m_mils2IUscalefactor; int m_mils2IUscalefactor;

View File

@ -60,6 +60,8 @@ public:
*/ */
void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ); void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet );
KIGFX::WS_PROXY_VIEW_ITEM* GetWorksheet() const { return m_worksheet.get(); }
// TODO(JE) Look at optimizing this out // TODO(JE) Look at optimizing this out
/** /**
* Updates the color settings in the painter and GAL * Updates the color settings in the painter and GAL

View File

@ -30,6 +30,7 @@
#include <class_edge_mod.h> #include <class_edge_mod.h>
#include <collectors.h> #include <collectors.h>
#include <pcb_edit_frame.h> #include <pcb_edit_frame.h>
#include <ws_proxy_view_item.h>
#include <kiway.h> #include <kiway.h>
#include <footprint_edit_frame.h> #include <footprint_edit_frame.h>
#include <array_creator.h> #include <array_creator.h>
@ -576,9 +577,8 @@ int EDIT_TOOL::ChangeTrackWidth( const TOOL_EVENT& aEvent )
int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
{ {
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
const PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection(
const auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
{ {
EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS );
@ -590,10 +590,6 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit ); DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
} }
else if( selection.Size() == 0 )
{
m_toolMgr->RunAction( ACTIONS::pageSettings );
}
else if( selection.Size() == 1 ) else if( selection.Size() == 1 )
{ {
// Display properties dialog // Display properties dialog
@ -605,6 +601,14 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
// Notify other tools of the changes // Notify other tools of the changes
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified ); m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
} }
else if( selection.Size() == 0 && getView()->IsLayerVisible( LAYER_WORKSHEET ) )
{
KIGFX::WS_PROXY_VIEW_ITEM* worksheet = editFrame->GetCanvas()->GetWorksheet();
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
if( worksheet && worksheet->HitTestWorksheetItems( getView(), (wxPoint) cursorPos ) )
m_toolMgr->RunAction( ACTIONS::pageSettings );
}
if( selection.IsHover() ) if( selection.IsHover() )
{ {

View File

@ -556,7 +556,6 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool
WS_PROXY_UNDO_ITEM* item = (WS_PROXY_UNDO_ITEM*) eda_item; WS_PROXY_UNDO_ITEM* item = (WS_PROXY_UNDO_ITEM*) eda_item;
item->Restore( this ); item->Restore( this );
*item = alt_item; *item = alt_item;
GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
} }
break; break;