Add hittesting for worksheets in Pcbnew and Eeschema.
Fixes https://gitlab.com/kicad/code/kicad/issues/4282
This commit is contained in:
parent
055ab92797
commit
199bb2ffb0
common/page_layout
eeschema
include
pcbnew
|
@ -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 );
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <sch_line.h>
|
||||
#include <sch_bus_entry.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <ws_proxy_view_item.h>
|
||||
#include <eeschema_id.h>
|
||||
#include <status_popup.h>
|
||||
#include <wx/gdicmn.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <class_edge_mod.h>
|
||||
#include <collectors.h>
|
||||
#include <pcb_edit_frame.h>
|
||||
#include <ws_proxy_view_item.h>
|
||||
#include <kiway.h>
|
||||
#include <footprint_edit_frame.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 )
|
||||
{
|
||||
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
||||
|
||||
const auto& selection = m_selectionTool->RequestSelection(
|
||||
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
||||
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() )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue