From 199bb2ffb0706056303abbfd247fc87efbaa2db0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 3 May 2020 00:06:43 +0100 Subject: [PATCH] Add hittesting for worksheets in Pcbnew and Eeschema. Fixes https://gitlab.com/kicad/code/kicad/issues/4282 --- common/page_layout/ws_proxy_view_item.cpp | 51 ++++++++++++++++------- eeschema/sch_view.h | 2 + eeschema/tools/sch_edit_tool.cpp | 11 ++++- include/ws_proxy_view_item.h | 5 +++ pcbnew/pcb_draw_panel_gal.h | 2 + pcbnew/tools/edit_tool.cpp | 18 ++++---- pcbnew/undo_redo.cpp | 1 - 7 files changed, 67 insertions(+), 23 deletions(-) diff --git a/common/page_layout/ws_proxy_view_item.cpp b/common/page_layout/ws_proxy_view_item.cpp index 0e31efaa42..7a63f9231d 100644 --- a/common/page_layout/ws_proxy_view_item.cpp +++ b/common/page_layout/ws_proxy_view_item.cpp @@ -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(); - auto settings = aView->GetPainter()->GetSettings(); - wxString fileName( m_fileName.c_str(), wxConvUTF8 ); - wxString sheetName( m_sheetName.c_str(), wxConvUTF8 ); - WS_DRAW_ITEM_LIST drawList; + RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings(); + wxString fileName( m_fileName.c_str(), wxConvUTF8 ); + wxString sheetName( m_sheetName.c_str(), wxConvUTF8 ); - drawList.SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() ); + aDrawList->SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() ); // Adjust the scaling factor for worksheet items: // worksheet items coordinates and sizes are stored in mils, // and must be scaled to the same units as the caller - drawList.SetMilsToIUfactor( m_mils2IUscalefactor ); - drawList.SetSheetNumber( m_sheetNumber ); - drawList.SetSheetCount( m_sheetCount ); - drawList.SetFileName( fileName ); - drawList.SetSheetName( sheetName ); - drawList.SetProject( m_project ); + aDrawList->SetMilsToIUfactor( m_mils2IUscalefactor ); + aDrawList->SetSheetNumber( m_sheetNumber ); + aDrawList->SetSheetCount( m_sheetCount ); + aDrawList->SetFileName( fileName ); + aDrawList->SetSheetName( sheetName ); + aDrawList->SetProject( m_project ); + + aDrawList->BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock ); +} - drawList.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 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; +} diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index c60063f596..44ca986d3a 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -98,6 +98,8 @@ public: void HideWorksheet(); + WS_PROXY_VIEW_ITEM* GetWorksheet() const { return m_worksheet.get(); } + void HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin = nullptr ); private: diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index cfd97ddd80..d63ea314c5 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -1235,7 +1236,15 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) 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; } diff --git a/include/ws_proxy_view_item.h b/include/ws_proxy_view_item.h index 84be559494..f6e4372368 100644 --- a/include/ws_proxy_view_item.h +++ b/include/ws_proxy_view_item.h @@ -34,6 +34,7 @@ class WS_DRAW_ITEM_LINE; class WS_DRAW_ITEM_RECT; class WS_DRAW_ITEM_TEXT; class WS_DRAW_ITEM_BITMAP; +class WS_DRAW_ITEM_LIST; namespace KIGFX { @@ -101,7 +102,11 @@ public: return wxT( "WS_PROXY_VIEW_ITEM" ); } + bool HitTestWorksheetItems( VIEW* aView, const wxPoint& aPosition ); + protected: + void buildDrawList( VIEW* aView, WS_DRAW_ITEM_LIST* aDrawList ) const; + /// the factor between mils (units used in worksheet and internal units) /// it is the value IU_PER_MILS used in the caller int m_mils2IUscalefactor; diff --git a/pcbnew/pcb_draw_panel_gal.h b/pcbnew/pcb_draw_panel_gal.h index 3b2065c5d8..50e737a44f 100644 --- a/pcbnew/pcb_draw_panel_gal.h +++ b/pcbnew/pcb_draw_panel_gal.h @@ -60,6 +60,8 @@ public: */ 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 /** * Updates the color settings in the painter and GAL diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 5e2dcab323..8de49a4b34 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -576,9 +577,8 @@ int EDIT_TOOL::ChangeTrackWidth( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { - PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); - - const auto& selection = m_selectionTool->RequestSelection( + PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); + const PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { 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 ); dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR } - else if( selection.Size() == 0 ) - { - m_toolMgr->RunAction( ACTIONS::pageSettings ); - } else if( selection.Size() == 1 ) { // Display properties dialog @@ -605,6 +601,14 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) // Notify other tools of the changes 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() ) { diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index 6f87cae447..320481ebbe 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -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; item->Restore( this ); *item = alt_item; - GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true ); } break;