diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index aeef024279..7829b04656 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -275,22 +275,6 @@ int LIB_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) } -static bool deleteItem( SCH_BASE_FRAME* aFrame, const VECTOR2D& aPosition ) -{ - EE_SELECTION_TOOL* selectionTool = aFrame->GetToolManager()->GetTool(); - wxCHECK( selectionTool, false ); - - aFrame->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true ); - - EDA_ITEM* item = selectionTool->SelectPoint( aPosition ); - - if( item ) - aFrame->GetToolManager()->RunAction( EE_ACTIONS::doDelete, true ); - - return true; -} - - #define HITTEST_THRESHOLD_PIXELS 5 @@ -339,7 +323,7 @@ int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) } } ); - picker->SetFinalizeHandler( [&]( const int& aFinalState ) + picker->SetFinalizeHandler( [this] ( const int& aFinalState ) { if( m_pickerItem ) m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 3ac01f9fa3..21c46d2950 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -349,21 +349,70 @@ static bool deleteItem( PL_EDITOR_FRAME* aFrame, const VECTOR2D& aPosition ) } +#define HITTEST_THRESHOLD_PIXELS 5 + + int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); PL_PICKER_TOOL* picker = m_toolMgr->GetTool(); - wxCHECK( picker, 0 ); + m_pickerItem = nullptr; - picker->SetClickHandler( std::bind( deleteItem, m_frame, std::placeholders::_1 ) ); - - picker->SetFinalizeHandler( [&]( const int& aFinalState ) + picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool + { + if( m_pickerItem ) { - if( aFinalState == PL_PICKER_TOOL::EVT_CANCEL ) - m_frame->ClearToolStack(); - } ); + PL_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + selectionTool->UnbrightenItem( m_pickerItem ); + selectionTool->AddItemToSel( m_pickerItem, true ); + m_toolMgr->RunAction( ACTIONS::doDelete, true ); + m_pickerItem = nullptr; + } + + return true; + } ); + + picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) + { + int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); + EDA_ITEM* item = nullptr; + + for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() ) + { + for( WS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() ) + { + if( drawItem->HitTest( (wxPoint) aPos, threshold ) ) + { + item = drawItem; + break; + } + } + } + + if( m_pickerItem != item ) + { + PL_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + + if( m_pickerItem ) + selectionTool->UnbrightenItem( m_pickerItem ); + + m_pickerItem = item; + + if( m_pickerItem ) + selectionTool->BrightenItem( m_pickerItem ); + } + } ); + + picker->SetFinalizeHandler( [this] ( const int& aFinalState ) + { + if( m_pickerItem ) + m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); + + if( aFinalState == PL_PICKER_TOOL::EVT_CANCEL ) + m_frame->ClearToolStack(); + } ); picker->Activate(); Wait(); diff --git a/pagelayout_editor/tools/pl_edit_tool.h b/pagelayout_editor/tools/pl_edit_tool.h index 3848962c67..5f43de9e53 100644 --- a/pagelayout_editor/tools/pl_edit_tool.h +++ b/pagelayout_editor/tools/pl_edit_tool.h @@ -89,6 +89,8 @@ private: ///> Last cursor position (needed for getModificationPoint() to avoid changes ///> of edit reference point). VECTOR2I m_cursor; + + EDA_ITEM* m_pickerItem; }; #endif //PL_EDIT_TOOL_H diff --git a/pagelayout_editor/tools/pl_picker_tool.cpp b/pagelayout_editor/tools/pl_picker_tool.cpp index c0c9d94c0a..66fc7f6d5f 100644 --- a/pagelayout_editor/tools/pl_picker_tool.cpp +++ b/pagelayout_editor/tools/pl_picker_tool.cpp @@ -103,6 +103,21 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) setControls(); } + else if( evt->IsMotion() ) + { + if( m_motionHandler ) + { + try + { + (*m_motionHandler)( cursorPos ); + } + catch( std::exception& e ) + { + std::cerr << "PL_PICKER_TOOL motion handler error: " << e.what() << std::endl; + } + } + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { if( m_cancelHandler ) @@ -163,6 +178,7 @@ void PL_PICKER_TOOL::resetPicker() m_autoPanning = false; m_picked = NULLOPT; + m_motionHandler = NULLOPT; m_clickHandler = NULLOPT; m_cancelHandler = NULLOPT; m_finalizeHandler = NULLOPT; diff --git a/pagelayout_editor/tools/pl_picker_tool.h b/pagelayout_editor/tools/pl_picker_tool.h index 94f4085ceb..48834cfd56 100644 --- a/pagelayout_editor/tools/pl_picker_tool.h +++ b/pagelayout_editor/tools/pl_picker_tool.h @@ -45,6 +45,7 @@ public: ///> Event handler types. typedef std::function CLICK_HANDLER; + typedef std::function MOTION_HANDLER; typedef std::function CANCEL_HANDLER; typedef std::function FINALIZE_HANDLER; @@ -83,6 +84,16 @@ public: m_clickHandler = aHandler; } + /** + * Function SetMotionHandler() + * Sets a handler for mouse motion. Used for roll-over highlighting. + */ + inline void SetMotionHandler( MOTION_HANDLER aHandler ) + { + wxASSERT( !m_motionHandler ); + m_motionHandler = aHandler; + } + /** * Function SetCancelHandler() * Sets a handler for cancel events (ESC or context-menu Cancel). @@ -120,6 +131,7 @@ private: bool m_autoPanning; OPT m_clickHandler; + OPT m_motionHandler; OPT m_cancelHandler; OPT m_finalizeHandler; diff --git a/pagelayout_editor/tools/pl_selection_tool.cpp b/pagelayout_editor/tools/pl_selection_tool.cpp index 3ff2f01e0d..5b98a237a2 100644 --- a/pagelayout_editor/tools/pl_selection_tool.cpp +++ b/pagelayout_editor/tools/pl_selection_tool.cpp @@ -462,6 +462,18 @@ void PL_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode ) } +void PL_SELECTION_TOOL::BrightenItem( EDA_ITEM* aItem ) +{ + highlight( aItem, BRIGHTENED ); +} + + +void PL_SELECTION_TOOL::UnbrightenItem( EDA_ITEM* aItem ) +{ + unhighlight( aItem, BRIGHTENED ); +} + + int PL_SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent ) { ClearSelection(); diff --git a/pagelayout_editor/tools/pl_selection_tool.h b/pagelayout_editor/tools/pl_selection_tool.h index 42903bf767..16a9e5737b 100644 --- a/pagelayout_editor/tools/pl_selection_tool.h +++ b/pagelayout_editor/tools/pl_selection_tool.h @@ -102,6 +102,9 @@ public: int RemoveItemsFromSel( const TOOL_EVENT& aEvent ); void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false ); + void BrightenItem( EDA_ITEM* aItem ); + void UnbrightenItem( EDA_ITEM* aItem ); + ///> Clear current selection event handler. int ClearSelection( const TOOL_EVENT& aEvent );