diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 10fb73af46..a6be995f02 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -379,6 +379,7 @@ set( COMMON_SRCS tool/edit_constraints.cpp tool/edit_points.cpp tool/grid_menu.cpp + tool/picker_tool.cpp tool/selection_conditions.cpp tool/tool_action.cpp tool/tool_base.cpp diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index c9fc1eade7..7bb7610f58 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -481,6 +481,9 @@ TOOL_ACTION ACTIONS::measureTool( "common.InteractiveEdit.measureTool", _( "Measure Tool" ), _( "Interactively measure distance between points" ), measurement_xpm, AF_ACTIVATE ); +TOOL_ACTION ACTIONS::pickerTool( "common.InteractivePicker.pickerTool", + AS_GLOBAL, 0, "", "", "", NULL, AF_ACTIVATE ); + TOOL_ACTION ACTIONS::show3DViewer( "common.Control.show3DViewer", AS_GLOBAL, MD_ALT + '3', LEGACY_HK_NAME( "3D Viewer" ), diff --git a/pagelayout_editor/tools/pl_picker_tool.cpp b/common/tool/picker_tool.cpp similarity index 74% rename from pagelayout_editor/tools/pl_picker_tool.cpp rename to common/tool/picker_tool.cpp index 494d4170c1..e9d938a56a 100644 --- a/pagelayout_editor/tools/pl_picker_tool.cpp +++ b/common/tool/picker_tool.cpp @@ -21,25 +21,22 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include -#include -#include +#include +#include #include -#include +#include -PL_PICKER_TOOL::PL_PICKER_TOOL() : - TOOL_INTERACTIVE( "plEditor.InteractivePicker" ), - m_frame( nullptr ) +PICKER_TOOL::PICKER_TOOL() + : TOOL_INTERACTIVE( "common.InteractivePicker" ) { resetPicker(); } -bool PL_PICKER_TOOL::Init() +bool PICKER_TOOL::Init() { - m_frame = getEditFrame(); + m_frame = getEditFrame(); auto& ctxMenu = m_menu.GetMenu(); @@ -54,22 +51,24 @@ bool PL_PICKER_TOOL::Init() } -void PL_PICKER_TOOL::Reset( RESET_REASON aReason ) -{ -} - - -int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) +int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); int finalize_state = WAIT_CANCEL; + std::string tool = *aEvent.Parameter(); + m_frame->PushTool( tool ); + Activate(); + + // To many things are off-grid in LibEdit; turn snapping off. + bool snap = !m_frame->IsType( FRAME_SCH_LIB_EDITOR ); + setControls(); while( TOOL_EVENT* evt = Wait() ) { - m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE ); - VECTOR2I cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) ); + m_frame->GetCanvas()->SetCursor( m_cursor ); + VECTOR2D cursorPos = controls->GetCursorPosition( snap && !evt->Modifier( MD_ALT ) ); if( evt->IsClick( BUT_LEFT ) ) { @@ -85,7 +84,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } catch( std::exception& e ) { - std::cerr << "PL_PICKER_TOOL click handler error: " << e.what() << std::endl; + std::cerr << "PICKER_TOOL click handler error: " << e.what() << std::endl; finalize_state = EXCEPTION_CANCEL; break; } @@ -110,7 +109,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } catch( std::exception& e ) { - std::cerr << "PL_PICKER_TOOL motion handler error: " << e.what() << std::endl; + std::cerr << "PICKER_TOOL motion handler error: " << e.what() << std::endl; } } } @@ -125,11 +124,12 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } catch( std::exception& e ) { - std::cerr << "PL_PICKER_TOOL cancel handler error: " << e.what() << std::endl; + std::cerr << "PICKER_TOOL cancel handler error: " << e.what() << std::endl; } } - // Activating a new tool may have alternate finalization from canceling the current tool + // Activating a new tool may have alternate finalization from canceling the current + // tool if( evt->IsActivate() ) finalize_state = END_ACTIVATE; else @@ -153,33 +153,36 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } catch( std::exception& e ) { - std::cerr << "PL_PICKER_TOOL finalize handler error: " << e.what() << std::endl; + std::cerr << "PICKER_TOOL finalize handler error: " << e.what() << std::endl; } } resetPicker(); controls->ForceCursorPosition( false ); + m_frame->PopTool( tool ); return 0; } -void PL_PICKER_TOOL::setTransitions() +void PICKER_TOOL::setTransitions() { - Go( &PL_PICKER_TOOL::Main, PL_ACTIONS::pickerTool.MakeEvent() ); + Go( &PICKER_TOOL::Main, ACTIONS::pickerTool.MakeEvent() ); } -void PL_PICKER_TOOL::resetPicker() +void PICKER_TOOL::resetPicker() { + m_cursor = wxStockCursor( wxCURSOR_ARROW ); + m_picked = NULLOPT; - m_motionHandler = NULLOPT; m_clickHandler = NULLOPT; + m_motionHandler = NULLOPT; m_cancelHandler = NULLOPT; m_finalizeHandler = NULLOPT; } -void PL_PICKER_TOOL::setControls() +void PICKER_TOOL::setControls() { KIGFX::VIEW_CONTROLS* controls = getViewControls(); diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index a592e4a5c9..44ecc428d9 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -220,7 +220,6 @@ set( EESCHEMA_SRCS tools/backanno.cpp tools/ee_actions.cpp tools/ee_inspection_tool.cpp - tools/ee_picker_tool.cpp tools/ee_point_editor.cpp tools/ee_selection.cpp tools/ee_selection_tool.cpp diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 1df8e99918..15a9022bb1 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -45,11 +45,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -218,7 +218,7 @@ void LIB_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new COMMON_TOOLS ); m_toolManager->RegisterTool( new ZOOM_TOOL ); m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); - m_toolManager->RegisterTool( new EE_PICKER_TOOL ); + m_toolManager->RegisterTool( new PICKER_TOOL ); m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); m_toolManager->RegisterTool( new LIB_PIN_TOOL ); m_toolManager->RegisterTool( new LIB_DRAWING_TOOLS ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 5a56791468..985a929845 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -54,10 +54,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -336,7 +336,7 @@ void SCH_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new COMMON_TOOLS ); m_toolManager->RegisterTool( new ZOOM_TOOL ); m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); - m_toolManager->RegisterTool( new EE_PICKER_TOOL ); + m_toolManager->RegisterTool( new PICKER_TOOL ); m_toolManager->RegisterTool( new SCH_DRAWING_TOOLS ); m_toolManager->RegisterTool( new SCH_LINE_WIRE_BUS_TOOL ); m_toolManager->RegisterTool( new SCH_MOVE_TOOL ); diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index 6778bbcf4d..7455862dd0 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -60,12 +60,6 @@ TOOL_ACTION EE_ACTIONS::showMarkerInfo( "eeschema.InspectionTool.showMarkerInfo" info_xpm ); -// EE_PICKER -// -TOOL_ACTION EE_ACTIONS::pickerTool( "eeschema.InteractivePicker", - AS_GLOBAL, 0, "", "", "", NULL, AF_ACTIVATE ); - - // EE_POINT_EDITOR // TOOL_ACTION EE_ACTIONS::pointEditorAddCorner( "eeschema.PointEditor.addCorner", diff --git a/eeschema/tools/ee_picker_tool.cpp b/eeschema/tools/ee_picker_tool.cpp deleted file mode 100644 index b9d4f61eab..0000000000 --- a/eeschema/tools/ee_picker_tool.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include - - -EE_PICKER_TOOL::EE_PICKER_TOOL() - : EE_TOOL_BASE( "eeschema.InteractivePicker" ) -{ - resetPicker(); -} - - -int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) -{ - KIGFX::VIEW_CONTROLS* controls = getViewControls(); - int finalize_state = WAIT_CANCEL; - - // To many things are off-grid in LibEdit; turn snapping off. - bool snap = !m_isLibEdit; - - setControls(); - - while( TOOL_EVENT* evt = Wait() ) - { - m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE ); - VECTOR2D cursorPos = controls->GetCursorPosition( snap && !evt->Modifier( MD_ALT ) ); - - if( evt->IsClick( BUT_LEFT ) ) - { - bool getNext = false; - - if( m_clickHandler ) - { - try - { - getNext = (*m_clickHandler)( cursorPos ); - } - catch( std::exception& e ) - { - std::cerr << "EE_PICKER_TOOL click handler error: " << e.what() << std::endl; - finalize_state = EXCEPTION_CANCEL; - break; - } - } - - if( !getNext ) - { - finalize_state = CLICK_CANCEL; - break; - } - else - setControls(); - } - - else if( evt->IsMotion() ) - { - if( m_motionHandler ) - { - try - { - (*m_motionHandler)( cursorPos ); - } - catch( std::exception& e ) - { - std::cerr << "EE_PICKER_TOOL motion handler error: " << e.what() << std::endl; - } - } - } - - else if( evt->IsCancelInteractive() || evt->IsActivate() ) - { - if( m_cancelHandler ) - { - try - { - (*m_cancelHandler)(); - } - catch( std::exception& e ) - { - std::cerr << "EE_PICKER_TOOL cancel handler error: " << e.what() << std::endl; - } - } - - // Activating a new tool may have alternate finalization from canceling the current tool - if( evt->IsActivate() ) - finalize_state = END_ACTIVATE; - else - finalize_state = EVT_CANCEL; - - break; - } - else if( evt->IsClick( BUT_RIGHT ) ) - { - m_menu.ShowContextMenu(); - } - else - evt->SetPassEvent(); - } - - if( m_finalizeHandler ) - { - try - { - (*m_finalizeHandler)( finalize_state ); - } - catch( std::exception& e ) - { - std::cerr << "EE_PICKER_TOOL finalize handler error: " << e.what() << std::endl; - } - } - - resetPicker(); - controls->ForceCursorPosition( false ); - return 0; -} - - -void EE_PICKER_TOOL::setTransitions() -{ - Go( &EE_PICKER_TOOL::Main, EE_ACTIONS::pickerTool.MakeEvent() ); -} - - -void EE_PICKER_TOOL::resetPicker() -{ - m_clickHandler = NULLOPT; - m_motionHandler = NULLOPT; - m_cancelHandler = NULLOPT; - m_finalizeHandler = NULLOPT; -} - - -void EE_PICKER_TOOL::setControls() -{ - KIGFX::VIEW_CONTROLS* controls = getViewControls(); - - controls->CaptureCursor( false ); - controls->SetAutoPan( false ); -} diff --git a/eeschema/tools/ee_picker_tool.h b/eeschema/tools/ee_picker_tool.h deleted file mode 100644 index df59083657..0000000000 --- a/eeschema/tools/ee_picker_tool.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef EE_PICKER_TOOL_H -#define EE_PICKER_TOOL_H - -#include -#include - - -class SCH_BASE_FRAME; - - -class EE_PICKER_TOOL : public EE_TOOL_BASE -{ -public: - EE_PICKER_TOOL(); - ~EE_PICKER_TOOL() {} - - ///> Event handler types. - typedef std::function CLICK_HANDLER; - typedef std::function MOTION_HANDLER; - typedef std::function CANCEL_HANDLER; - typedef std::function FINALIZE_HANDLER; - - enum pickerEndState - { - WAIT_CANCEL, - CLICK_CANCEL, - END_ACTIVATE, - EVT_CANCEL, - EXCEPTION_CANCEL - }; - - ///> Main event loop. - int Main( const TOOL_EVENT& aEvent ); - - /** - * Function SetClickHandler() - * Sets a handler for mouse click event. Handler may decide to receive further click by - * returning true. - */ - inline void SetClickHandler( CLICK_HANDLER aHandler ) - { - wxASSERT( !m_clickHandler ); - 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). - */ - inline void SetCancelHandler( CANCEL_HANDLER aHandler ) - { - wxASSERT( !m_cancelHandler ); - m_cancelHandler = aHandler; - } - - /** - * Function SetFinalizeHandler() - * Sets a handler for the finalize event. Takes the state of the exit from the Main loop - */ - inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler ) - { - wxASSERT( !m_finalizeHandler ); - m_finalizeHandler = aHandler; - } - -private: - ///> Reinitializes tool to its initial state. - void resetPicker(); - - ///> Applies the requested VIEW_CONTROLS settings. - void setControls(); - - ///> @copydoc TOOL_INTERACTIVE::setTransitions(); - void setTransitions() override; - -private: - OPT m_clickHandler; - OPT m_motionHandler; - OPT m_cancelHandler; - OPT m_finalizeHandler; -}; - -#endif /* EE_PICKER_TOOL_H */ diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index 519197b7aa..8ee95c2581 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -22,8 +22,8 @@ */ #include +#include #include -#include #include #include #include @@ -280,62 +280,62 @@ int LIB_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { + std::string tool = aEvent.GetCommandStr().get(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); - - EE_PICKER_TOOL* picker = m_toolMgr->GetTool(); m_pickerItem = nullptr; - picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool - { - if( m_pickerItem ) - { - EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - selectionTool->UnbrightenItem( m_pickerItem ); - selectionTool->AddItemToSel( m_pickerItem, true ); - m_toolMgr->RunAction( EE_ACTIONS::doDelete, true ); - m_pickerItem = nullptr; - } + picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) ); - return true; - } ); - - picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) - { - EE_COLLECTOR collector; - collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); - collector.Collect( m_frame->GetCurPart(), nonFields, (wxPoint) aPos ); - - EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - selectionTool->GuessSelectionCandidates( collector, aPos ); - - EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; - - if( m_pickerItem != item ) + picker->SetClickHandler( + [this] ( const VECTOR2D& aPosition ) -> bool { if( m_pickerItem ) + { + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); selectionTool->UnbrightenItem( m_pickerItem ); + selectionTool->AddItemToSel( m_pickerItem, true ); + m_toolMgr->RunAction( EE_ACTIONS::doDelete, true ); + m_pickerItem = nullptr; + } - m_pickerItem = item; + return true; + } ); + picker->SetMotionHandler( + [this] ( const VECTOR2D& aPos ) + { + EE_COLLECTOR collector; + collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); + collector.Collect( m_frame->GetCurPart(), nonFields, (wxPoint) aPos ); + + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + selectionTool->GuessSelectionCandidates( collector, aPos ); + + EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; + + if( m_pickerItem != item ) + { + 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 ) - selectionTool->BrightenItem( m_pickerItem ); - } - } ); + m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); + } ); - picker->SetFinalizeHandler( [this] ( const int& aFinalState ) - { - if( m_pickerItem ) - m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); - } ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - picker->Activate(); - Wait(); - - m_frame->PopTool( tool ); return 0; } diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index b62ef9f0eb..025222caf2 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -22,15 +22,14 @@ */ #include +#include #include #include #include -#include #include #include #include #include -#include #include #include #include @@ -39,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -942,73 +940,73 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { + std::string tool = aEvent.GetCommandStr().get(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); - - EE_PICKER_TOOL* picker = m_toolMgr->GetTool(); m_pickerItem = nullptr; - picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool - { - if( m_pickerItem ) - { - SCH_ITEM* sch_item = dynamic_cast( m_pickerItem ); + picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) ); - if( sch_item && sch_item->IsLocked() ) + picker->SetClickHandler( + [this] ( const VECTOR2D& aPosition ) -> bool + { + if( m_pickerItem ) { - STATUS_TEXT_POPUP statusPopup( m_frame ); - statusPopup.SetText( _( "Item locked." ) ); - statusPopup.PopupFor( 2000 ); - statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - return true; + SCH_ITEM* sch_item = dynamic_cast( m_pickerItem ); + + if( sch_item && sch_item->IsLocked() ) + { + STATUS_TEXT_POPUP statusPopup( m_frame ); + statusPopup.SetText( _( "Item locked." ) ); + statusPopup.PopupFor( 2000 ); + statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); + return true; + } + + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + selectionTool->UnbrightenItem( m_pickerItem ); + selectionTool->AddItemToSel( m_pickerItem, true ); + m_toolMgr->RunAction( EE_ACTIONS::doDelete, true ); + m_pickerItem = nullptr; } + return true; + } ); + + picker->SetMotionHandler( + [this] ( const VECTOR2D& aPos ) + { + EE_COLLECTOR collector; + collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); + collector.Collect( m_frame->GetScreen()->GetDrawItems(), deletableItems, (wxPoint) aPos ); + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - selectionTool->UnbrightenItem( m_pickerItem ); - selectionTool->AddItemToSel( m_pickerItem, true ); - m_toolMgr->RunAction( EE_ACTIONS::doDelete, true ); - m_pickerItem = nullptr; - } + selectionTool->GuessSelectionCandidates( collector, aPos ); - return true; - } ); + EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; - picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) - { - EE_COLLECTOR collector; - collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); - collector.Collect( m_frame->GetScreen()->GetDrawItems(), deletableItems, (wxPoint) aPos ); + if( m_pickerItem != item ) + { + if( m_pickerItem ) + selectionTool->UnbrightenItem( m_pickerItem ); - EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - selectionTool->GuessSelectionCandidates( collector, aPos ); + m_pickerItem = item; - EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; + if( m_pickerItem ) + selectionTool->BrightenItem( m_pickerItem ); + } + } ); - if( m_pickerItem != item ) + picker->SetFinalizeHandler( + [this] ( const int& aFinalState ) { if( m_pickerItem ) - selectionTool->UnbrightenItem( m_pickerItem ); + m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); + } ); - m_pickerItem = item; + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - if( m_pickerItem ) - selectionTool->BrightenItem( m_pickerItem ); - } - } ); - - picker->SetFinalizeHandler( [this] ( const int& aFinalState ) - { - if( m_pickerItem ) - m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); - } ); - - picker->Activate(); - Wait(); - - m_frame->PopTool( tool ); return 0; } diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 355e075cc9..c6eb4e0fcb 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -31,13 +31,11 @@ #include #include #include +#include #include -#include #include #include #include -#include -#include #include #include #include @@ -142,9 +140,8 @@ int SCH_EDITOR_CONTROL::UpdateFind( const TOOL_EVENT& aEvent ) { wxFindReplaceData* data = m_frame->GetFindReplaceData(); - if( aEvent.IsAction( &ACTIONS::find ) - || aEvent.IsAction( &ACTIONS::findAndReplace ) - || aEvent.IsAction( &ACTIONS::updateFind ) ) + if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace ) + || aEvent.IsAction( &ACTIONS::updateFind ) ) { m_selectionTool->ClearSelection(); @@ -298,12 +295,8 @@ int SCH_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent ) } else { - wxString msg; - - if( searchAllSheets ) - msg = _( "Reached end of schematic." ); - else - msg = _( "Reached end of sheet." ); + wxString msg = searchAllSheets ? _( "Reached end of schematic." ) + : _( "Reached end of sheet." ); m_frame->ShowFindReplaceStatus( msg + _( "\nFind again to wrap around to the start." ) ); wrapAroundTimer.StartOnce( 4000 ); @@ -352,8 +345,7 @@ int SCH_EDITOR_CONTROL::ReplaceAll( const TOOL_EVENT& aEvent ) for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() ) { - for( EDA_ITEM* item = nextMatch( screen, nullptr, data ); - item; + for( EDA_ITEM* item = nextMatch( screen, nullptr, data ); item; item = nextMatch( screen, item, data ) ) { item->Replace( *data, schematic.FindSheetForScreen( screen ) ); @@ -445,93 +437,83 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF #ifdef KICAD_SPICE -static bool probeSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition ) -{ - constexpr KICAD_T wiresAndComponents[] = { SCH_LINE_T, SCH_COMPONENT_T, SCH_SHEET_PIN_T, EOT }; - EE_SELECTION_TOOL* selTool = aFrame->GetToolManager()->GetTool(); - - EDA_ITEM* item = selTool->SelectPoint( aPosition, wiresAndComponents ); - - if( !item ) - return false; - - std::unique_ptr netlist( aFrame->BuildNetListBase() ); - - for( NETLIST_OBJECT* obj : *netlist ) - { - if( obj->m_Comp == item ) - { - auto simFrame = (SIM_PLOT_FRAME*) aFrame->Kiway().Player( FRAME_SIMULATOR, false ); - - if( simFrame ) - simFrame->AddVoltagePlot( obj->GetNetName() ); - - break; - } - } - - return true; -} - - int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) { - EE_PICKER_TOOL* picker = m_toolMgr->GetTool(); + constexpr KICAD_T wiresAndComponents[] = { SCH_LINE_T, SCH_COMPONENT_T, SCH_SHEET_PIN_T, EOT }; - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); - m_frame->GetCanvas()->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::PROBE ) ); + SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false ); + std::string tool = aEvent.GetCommandStr().get(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); - picker->SetClickHandler( std::bind( probeSimulation, m_frame, std::placeholders::_1 ) ); - picker->Activate(); - Wait(); + picker->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::PROBE ) ); + + picker->SetClickHandler( + [&]( const VECTOR2D& aPosition ) + { + EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + + EDA_ITEM* item = selTool->SelectPoint( aPosition, wiresAndComponents ); + + if( !item ) + return false; + + std::unique_ptr netlist( m_frame->BuildNetListBase() ); + + for( NETLIST_OBJECT* obj : *netlist ) + { + if( obj->m_Comp == item ) + { + if( simFrame ) + simFrame->AddVoltagePlot( obj->GetNetName() ); + + break; + } + } + + return true; + } ); + + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - m_frame->PopTool( tool ); return 0; } -static bool tuneSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition ) -{ - constexpr KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT }; - EE_SELECTION_TOOL* selTool = aFrame->GetToolManager()->GetTool(); - EDA_ITEM* item = selTool->SelectPoint( aPosition, fieldsAndComponents ); - - if( !item ) - return false; - - if( item->Type() != SCH_COMPONENT_T ) - { - item = item->GetParent(); - - if( item->Type() != SCH_COMPONENT_T ) - return false; - } - - auto simFrame = (SIM_PLOT_FRAME*) aFrame->Kiway().Player( FRAME_SIMULATOR, false ); - - if( simFrame ) - simFrame->AddTuner( static_cast( item ) ); - - return true; -} - - int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent ) { - EE_PICKER_TOOL* picker = m_toolMgr->GetTool(); + constexpr KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT }; - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); - m_frame->GetCanvas()->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::TUNE ) ); + std::string tool = aEvent.GetCommandStr().get(); + SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false ); + PICKER_TOOL* picker = m_toolMgr->GetTool(); - picker->SetClickHandler( std::bind( tuneSimulation, m_frame, std::placeholders::_1 ) ); - picker->Activate(); - Wait(); + picker->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::TUNE ) ); + + picker->SetClickHandler( + [&]( const VECTOR2D& aPosition ) + { + EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + EDA_ITEM* item = selTool->SelectPoint( aPosition, fieldsAndComponents ); + + if( !item ) + return false; + + if( item->Type() != SCH_COMPONENT_T ) + { + item = item->GetParent(); + + if( item->Type() != SCH_COMPONENT_T ) + return false; + } + + if( simFrame ) + simFrame->AddTuner( static_cast( item ) ); + + return true; + } ); + + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - m_frame->PopTool( tool ); return 0; } #endif /* KICAD_SPICE */ @@ -688,17 +670,19 @@ int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime ) m_frame->RecalculateConnections(); - EE_PICKER_TOOL* picker = m_toolMgr->GetTool(); + std::string tool = aEvent.GetCommandStr().get(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); + picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) ); - picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, std::placeholders::_1 ) ); - picker->Activate(); - Wait(); + picker->SetClickHandler( + [this]( const VECTOR2D& aPos ) + { + return highlightNet( m_toolMgr, aPos ); + } ); + + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - m_frame->PopTool( tool ); return 0; } @@ -1129,7 +1113,6 @@ int SCH_EDITOR_CONTROL::ToggleForceHV( const TOOL_EVENT& aEvent ) } - void SCH_EDITOR_CONTROL::setTransitions() { Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() ); @@ -1151,12 +1134,6 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::UpdateFind, ACTIONS::updateFind.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::UpdateFind, EVENTS::SelectedItemsModified ); - /* - Go( &SCH_EDITOR_CONTROL::ToggleLockSelected, EE_ACTIONS::toggleLock.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::LockSelected, EE_ACTIONS::lock.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::UnlockSelected, EE_ACTIONS::unlock.MakeEvent() ); - */ - Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::SelectedEvent ); Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::UnselectedEvent ); Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::ClearedEvent ); diff --git a/include/tool/actions.h b/include/tool/actions.h index ee7856fcf1..0b50833c8e 100644 --- a/include/tool/actions.h +++ b/include/tool/actions.h @@ -140,6 +140,7 @@ public: // Common Tools static TOOL_ACTION selectionTool; static TOOL_ACTION measureTool; + static TOOL_ACTION pickerTool; // Misc static TOOL_ACTION show3DViewer; diff --git a/pagelayout_editor/tools/pl_picker_tool.h b/include/tool/picker_tool.h similarity index 81% rename from pagelayout_editor/tools/pl_picker_tool.h rename to include/tool/picker_tool.h index 9a92b044b6..a4a64ddfb1 100644 --- a/pagelayout_editor/tools/pl_picker_tool.h +++ b/include/tool/picker_tool.h @@ -21,27 +21,27 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PL_PICKER_TOOL_H -#define PL_PICKER_TOOL_H +#ifndef PICKER_TOOL_H +#define PICKER_TOOL_H #include +#include #include -#include -class PL_EDITOR_FRAME; +class EDA_DRAW_FRAME; -class PL_PICKER_TOOL : public TOOL_INTERACTIVE +class PICKER_TOOL : public TOOL_INTERACTIVE { public: - PL_PICKER_TOOL(); - ~PL_PICKER_TOOL() {} + PICKER_TOOL(); + ~PICKER_TOOL() {} /// @copydoc TOOL_INTERACTIVE::Init() bool Init() override; /// @copydoc TOOL_INTERACTIVE::Reset() - void Reset( RESET_REASON aReason ) override; + void Reset( RESET_REASON aReason ) override { } ///> Event handler types. typedef std::function CLICK_HANDLER; @@ -61,6 +61,8 @@ public: ///> Main event loop. int Main( const TOOL_EVENT& aEvent ); + inline void SetCursor( const wxCursor& aCursor ) { m_cursor = aCursor; } + /** * Function SetClickHandler() * Sets a handler for mouse click event. Handler may decide to receive further click by @@ -68,7 +70,7 @@ public: */ inline void SetClickHandler( CLICK_HANDLER aHandler ) { - assert( !m_clickHandler ); + wxASSERT( !m_clickHandler ); m_clickHandler = aHandler; } @@ -88,7 +90,7 @@ public: */ inline void SetCancelHandler( CANCEL_HANDLER aHandler ) { - assert( !m_cancelHandler ); + wxASSERT( !m_cancelHandler ); m_cancelHandler = aHandler; } @@ -98,7 +100,7 @@ public: */ inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler ) { - assert( !m_finalizeHandler ); + wxASSERT( !m_finalizeHandler ); m_finalizeHandler = aHandler; } @@ -113,14 +115,15 @@ private: void setTransitions() override; private: - PL_EDITOR_FRAME* m_frame; + EDA_DRAW_FRAME* m_frame; + wxCursor m_cursor; - OPT m_clickHandler; - OPT m_motionHandler; - OPT m_cancelHandler; + OPT m_clickHandler; + OPT m_motionHandler; + OPT m_cancelHandler; OPT m_finalizeHandler; - OPT m_picked; + OPT m_picked; }; -#endif /* PL_PICKER_TOOL_H */ +#endif /* PICKER_TOOL_H */ diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt index 9ce9af1f4d..df6e57617e 100644 --- a/pagelayout_editor/CMakeLists.txt +++ b/pagelayout_editor/CMakeLists.txt @@ -35,7 +35,6 @@ set( PL_EDITOR_SRCS tools/pl_drawing_tools.cpp tools/pl_edit_tool.cpp tools/pl_editor_control.cpp - tools/pl_picker_tool.cpp tools/pl_point_editor.cpp ) diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 68c5267fe0..95d9d91f55 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -44,13 +44,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include @@ -212,7 +212,7 @@ void PL_EDITOR_FRAME::setupTools() m_toolManager->RegisterTool( new PL_DRAWING_TOOLS ); m_toolManager->RegisterTool( new PL_EDIT_TOOL ); m_toolManager->RegisterTool( new PL_POINT_EDITOR ); - m_toolManager->RegisterTool( new PL_PICKER_TOOL ); + m_toolManager->RegisterTool( new PICKER_TOOL ); m_toolManager->InitTools(); // Run the selection tool, it is supposed to be always active diff --git a/pagelayout_editor/tools/pl_actions.cpp b/pagelayout_editor/tools/pl_actions.cpp index b69affd57c..9344d45ac6 100644 --- a/pagelayout_editor/tools/pl_actions.cpp +++ b/pagelayout_editor/tools/pl_actions.cpp @@ -96,12 +96,6 @@ TOOL_ACTION PL_ACTIONS::previewSettings( "plEditor.EditorControl.PreviewSettings sheetset_xpm ); -// PL_PICKER_TOOL -// -TOOL_ACTION PL_ACTIONS::pickerTool( "plEditor.InteractivePicker", - AS_GLOBAL, 0, "", "", "", NULL, AF_ACTIVATE ); - - // PL_SELECTION_TOOL // TOOL_ACTION PL_ACTIONS::selectionActivate( "plEditor.InteractiveSelection", diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 039f2e85c6..7fb5f82918 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -22,20 +22,17 @@ */ #include +#include #include -#include #include #include -#include #include #include #include #include #include -#include #include #include -#include PL_EDIT_TOOL::PL_EDIT_TOOL() : @@ -341,68 +338,68 @@ int PL_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); + std::string tool = aEvent.GetCommandStr().get(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); - PL_PICKER_TOOL* picker = m_toolMgr->GetTool(); + picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) ); m_pickerItem = nullptr; - picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool - { - if( m_pickerItem ) + picker->SetClickHandler( + [this] ( const VECTOR2D& aPosition ) -> bool { - 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( m_pickerItem ) { - if( drawItem->HitTest( (wxPoint) aPos, threshold ) ) + 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() ) { - item = drawItem; - break; + if( drawItem->HitTest( (wxPoint) aPos, threshold ) ) + { + item = drawItem; + break; + } } } - } - if( m_pickerItem != item ) + 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 ) { - PL_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - if( m_pickerItem ) - selectionTool->UnbrightenItem( m_pickerItem ); + m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); + } ); - m_pickerItem = item; + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - if( m_pickerItem ) - selectionTool->BrightenItem( m_pickerItem ); - } - } ); - - picker->SetFinalizeHandler( [this] ( const int& aFinalState ) - { - if( m_pickerItem ) - m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); - } ); - - picker->Activate(); - Wait(); - - m_frame->PopTool( tool ); return 0; } diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 9b48ac8324..ec6a1d142f 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -20,19 +20,14 @@ */ #include - #include #include using namespace std::placeholders; - -#include "class_draw_panel_gal.h" #include "class_board.h" - #include #include #include #include -#include #include #include #include @@ -45,14 +40,11 @@ using namespace std::placeholders; #include #include #include -#include #include #include #include #include -#include #include -#include #include "router_tool.h" #include "pns_segment.h" @@ -1004,7 +996,7 @@ void ROUTER_TOOL::performDragging( int aMode ) highlightNet( true, m_startItem->Net() ); ctls->SetAutoPan( true ); - m_gridHelper->SetAuxAxes( true, m_startSnapPoint, true ); + m_gridHelper->SetAuxAxes( true, m_startSnapPoint ); frame()->UndoRedoBlock( true ); while( TOOL_EVENT* evt = Wait() ) @@ -1160,7 +1152,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) if( !dragStarted ) return 0; - m_gridHelper->SetAuxAxes( true, p, true ); + m_gridHelper->SetAuxAxes( true, p ); controls()->ShowCursor( true ); controls()->ForceCursorPosition( false ); controls()->SetAutoPan( true ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index c40a10e3c5..e768b9fbc0 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -25,7 +25,6 @@ */ #include - #include #include #include @@ -33,15 +32,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include -#include #include #include #include @@ -54,11 +50,9 @@ using namespace std::placeholders; #include "pcbnew_picker_tool.h" #include "grid_helper.h" #include "kicad_clipboard.h" -#include "pcbnew_control.h" #include #include #include -#include #include #include #include @@ -155,13 +149,11 @@ bool EDIT_TOOL::Init() menu.AddItem( PCB_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 ) || SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); - menu.AddItem( PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::positionRelative, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty ); - menu.AddSeparator(); menu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty ); @@ -250,8 +242,10 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can modify. If nothing was selected before, // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection) auto& selection = m_selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) - { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } ); + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) + { + EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); + } ); if( m_dragging || selection.Empty() ) return 0; @@ -1294,42 +1288,42 @@ int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent ) bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP ) { - STATUS_TEXT_POPUP statusPopup( frame() ); + std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint"; + STATUS_TEXT_POPUP statusPopup( frame() ); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - bool picking = true; - bool retVal = true; + bool retVal = true; - frame()->PushTool( "pcbnew.InteractiveEdit.selectReferencePoint" ); statusPopup.SetText( _( "Select reference point for the copy..." ) ); - picker->Activate(); - picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool - { - aP = aPoint; - statusPopup.SetText( _( "Selection copied." ) ); - statusPopup.Expire( 800 ); - picking = false; - return false; // we don't need any more points - } ); - picker->SetCancelHandler( [&]() - { - statusPopup.SetText( _( "Copy cancelled." ) ); - statusPopup.Expire( 800 ); - picking = false; - retVal = false; - } ); + picker->SetClickHandler( + [&]( const VECTOR2D& aPoint ) -> bool + { + aP = aPoint; + statusPopup.SetText( _( "Selection copied." ) ); + statusPopup.Expire( 800 ); + return false; // we don't need any more points + } ); + + picker->SetMotionHandler( + [&] ( const VECTOR2D& aPos ) + { + statusPopup.Move( aPos + wxPoint( 20, -50 ) ); + } ); + + picker->SetCancelHandler( + [&]() + { + statusPopup.SetText( _( "Copy cancelled." ) ); + statusPopup.Expire( 800 ); + retVal = false; + } ); statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); statusPopup.Popup(); - while( picking ) - { - statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); - Wait(); - } + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); statusPopup.Hide(); - // Picker calls PopTool() so that it gets done before activating tool's PushTool() return retVal; } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index a2ffd7cf6d..21fbd73a28 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -75,73 +75,61 @@ public: /** * Function Main() - * * Main loop in which events are handled. - * @param aEvent is the handled event. */ int Main( const TOOL_EVENT& aEvent ); /** * Function Drag() - * * Invoke the PNS router to drag tracks. */ int Drag( const TOOL_EVENT& aEvent ); /** - * Function Edit() - * + * Function Properties() * Displays properties window for the selected object. */ int Properties( const TOOL_EVENT& aEvent ); /** * Function Rotate() - * * Rotates currently selected items. */ int Rotate( const TOOL_EVENT& aEvent ); /** * Function Flip() - * * Rotates currently selected items. The rotation point is the current cursor position. */ int Flip( const TOOL_EVENT& aEvent ); /** * Function Mirror - * * Mirrors the current selection. The mirror axis passes through the current point. */ int Mirror( const TOOL_EVENT& aEvent ); /** * Function Remove() - * * Deletes currently selected items. The rotation point is the current cursor position. */ int Remove( const TOOL_EVENT& aEvent ); /** * Function Duplicate() - * * Duplicates the current selection and starts a move action. */ int Duplicate( const TOOL_EVENT& aEvent ); /** * Function MoveExact() - * * Invokes a dialog box to allow moving of the item by an exact amount. */ int MoveExact( const TOOL_EVENT& aEvent ); /** * Function CreateArray() - * - * Creates an array of the selected items, invoking the array editor dialog - * to set the array options + * Creates an array of the selected items, invoking the array editor dialog to set the options. */ int CreateArray( const TOOL_EVENT& aEvent ); @@ -150,17 +138,13 @@ public: /** * Function FootprintFilter() - * - * A selection filter which prunes the selection to contain only items - * of type PCB_MODULE_T + * A selection filter which prunes the selection to contain only items of type PCB_MODULE_T */ static void FootprintFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector ); /** * Function PadFilter() - * - * A selection filter which prunes the selection to contain only items - * of type PCB_PAD_T + * A selection filter which prunes the selection to contain only items of type PCB_PAD_T */ static void PadFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector ); @@ -171,7 +155,6 @@ public: * Function copyToClipboard() * Sends the current selection to the clipboard by formatting it as a fake pcb * see AppendBoardFromClipboard for importing - * @return True if it was sent succesfully */ int copyToClipboard( const TOOL_EVENT& aEvent ); @@ -179,28 +162,17 @@ public: * Function cutToClipboard() * Cuts the current selection to the clipboard by formatting it as a fake pcb * see AppendBoardFromClipboard for importing - * @return True if it was sent succesfully */ int cutToClipboard( const TOOL_EVENT& aEvent ); - BOARD_COMMIT* GetCurrentCommit() const - { - return m_commit.get(); - } + BOARD_COMMIT* GetCurrentCommit() const { return m_commit.get(); } private: - ///> Selection tool used for obtaining selected items - SELECTION_TOOL* m_selectionTool; - - ///> Flag determining if anything is being dragged right now - bool m_dragging; - - ///> Flag determining whether we are prompting for locked removal - bool m_lockedSelected; - - ///> Last cursor position (needed for getModificationPoint() to avoid changes - ///> of edit reference point). - VECTOR2I m_cursor; + SELECTION_TOOL* m_selectionTool; // Selection tool used for obtaining selected items + bool m_dragging; // Indicates objects are being dragged right now + bool m_lockedSelected; // Determines if we prompt before removing locked objects + VECTOR2I m_cursor; // Last cursor position (needed for getModificationPoint() + // to avoid changes of edit reference point). ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index 9de1686f0b..8d139e46c5 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -48,7 +48,6 @@ using namespace std::placeholders; GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) : m_frame( aFrame ) { - m_diagonalAuxAxesEnable = true; m_enableSnap = true; m_enableGrid = true; m_snapSize = 100; @@ -74,18 +73,6 @@ GRID_HELPER::~GRID_HELPER() } -void GRID_HELPER::SetGrid( int aSize ) -{ - assert( false ); -} - - -void GRID_HELPER::SetOrigin( const VECTOR2I& aOrigin ) -{ - assert( false ); -} - - VECTOR2I GRID_HELPER::GetGrid() const { PCB_SCREEN* screen = m_frame->GetScreen(); @@ -102,7 +89,7 @@ VECTOR2I GRID_HELPER::GetOrigin() const } -void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin, bool aEnableDiagonal ) +void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin ) { if( aEnable ) { @@ -115,8 +102,6 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin, bool aEnabl m_auxAxis = OPT(); m_frame->GetCanvas()->GetView()->SetVisible( &m_viewAxis, false ); } - - m_diagonalAuxAxesEnable = aEnable; } @@ -126,10 +111,10 @@ VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const return aPoint; const VECTOR2D gridOffset( GetOrigin() ); - const VECTOR2D gridSize( GetGrid() ); + const VECTOR2D grid( GetGrid() ); - VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x, - KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y ); + VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x, + KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y ); if( !m_auxAxis ) return nearest; @@ -320,7 +305,7 @@ BOARD_ITEM* GRID_HELPER::GetSnapped( void ) const } -void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, const bool aFrom ) +void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom ) { VECTOR2I origin; @@ -332,8 +317,8 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, co for( auto pad : mod->Pads() ) { - if(( aFrom || m_frame->Settings().m_MagneticPads == CAPTURE_ALWAYS ) && - pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) ) + if( ( aFrom || m_frame->Settings().m_MagneticPads == CAPTURE_ALWAYS ) + && pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) ) { addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad ); break; diff --git a/pcbnew/tools/grid_helper.h b/pcbnew/tools/grid_helper.h index f4946d3556..e36b85bf81 100644 --- a/pcbnew/tools/grid_helper.h +++ b/pcbnew/tools/grid_helper.h @@ -26,13 +26,10 @@ #define __GRID_HELPER_H #include - #include #include #include - #include - #include class PCB_BASE_FRAME; @@ -43,9 +40,6 @@ public: GRID_HELPER( PCB_BASE_FRAME* aFrame ); ~GRID_HELPER(); - void SetGrid( int aSize ); - void SetOrigin( const VECTOR2I& aOrigin ); - VECTOR2I GetGrid() const; VECTOR2I GetOrigin() const; @@ -58,7 +52,7 @@ public: */ BOARD_ITEM* GetSnapped() const; - void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ), bool aEnableDiagonal = false ); + void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) ); VECTOR2I Align( const VECTOR2I& aPoint ) const; @@ -67,7 +61,7 @@ public: VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers, - const std::vector aSkip = {} ); + const std::vector aSkip = {} ); void SetSnap( bool aSnap ) { @@ -89,8 +83,11 @@ private: struct ANCHOR { - ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ): - pos( aPos ), flags( aFlags ), item( aItem ) {} ; + ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ) : + pos( aPos ), + flags( aFlags ), + item( aItem ) + { }; VECTOR2I pos; int flags; @@ -105,11 +102,11 @@ private: std::vector m_anchors; std::set queryVisible( const BOX2I& aArea, - const std::vector aSkip ) const; + const std::vector aSkip ) const; - void addAnchor( const VECTOR2I& aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ) + void addAnchor( const VECTOR2I& aPos, int aFlags, BOARD_ITEM* aItem ) { - m_anchors.push_back( ANCHOR( aPos, aFlags, aItem ) ); + m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) ); } ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers ); @@ -122,7 +119,7 @@ private: * @param aRefPos The point for which to compute the anchors (if used by the component) * @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not */ - void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, const bool aFrom = false ); + void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false ); void clearAnchors() { @@ -132,7 +129,6 @@ private: PCB_BASE_FRAME* m_frame; OPT m_auxAxis; - bool m_diagonalAuxAxesEnable; ///< If true, use the aux axis for snapping as well bool m_enableSnap; ///< If true, allow snapping to other items on the layers bool m_enableGrid; ///< If true, allow snapping to grid int m_snapSize; ///< Sets the radius in screen units for snapping to items diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index 24c3c1a6f5..c8d72ceeb9 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -907,12 +907,6 @@ TOOL_ACTION PCB_ACTIONS::deleteTool( "pcbnew.Control.deleteTool", delete_xpm ); -// PCBNEW_PICKER_TOOL -// -TOOL_ACTION PCB_ACTIONS::pickerTool( "pcbnew.InteractivePicker", - AS_GLOBAL, 0, "", "", "", nullptr, AF_ACTIVATE ); - - // PLACEMENT_TOOL // TOOL_ACTION PCB_ACTIONS::alignTop( "pcbnew.AlignAndDistribute.alignTop", diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 9944598b75..ac3c4ae639 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -23,40 +23,33 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #include -#include #include #include "pcb_editor_control.h" #include "pcb_actions.h" #include #include -#include #include #include "edit_tool.h" #include "selection_tool.h" #include "drawing_tool.h" #include "pcbnew_picker_tool.h" - #include #include #include #include #include #include -#include #include #include #include #include -#include #include -#include #include #include #include #include #include #include -#include #include #include #include @@ -1120,24 +1113,19 @@ void PCB_EDITOR_CONTROL::DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* a int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) { - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); - + std::string tool = aEvent.GetCommandStr().get(); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - assert( picker ); - picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool + picker->SetClickHandler( + [this] ( const VECTOR2D& pt ) -> bool { m_frame->SaveCopyInUndoList( m_placeOrigin.get(), UR_DRILLORIGIN ); DoSetDrillOrigin( getView(), m_frame, m_placeOrigin.get(), pt ); return false; // drill origin is a one-shot; don't continue with tool } ); - picker->Activate(); - Wait(); + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - m_frame->PopTool( tool ); return 0; } @@ -1299,6 +1287,9 @@ int PCB_EDITOR_CONTROL::ClearHighlight( const TOOL_EVENT& aEvent ) int PCB_EDITOR_CONTROL::HighlightNetTool( const TOOL_EVENT& aEvent ) { + std::string tool = aEvent.GetCommandStr().get(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); + // If the keyboard hotkey was triggered and we are already in the highlight tool, behave // the same as a left-click. Otherwise highlight the net of the selected item(s), or if // there is no selection, then behave like a ctrl-left-click. @@ -1308,90 +1299,78 @@ int PCB_EDITOR_CONTROL::HighlightNetTool( const TOOL_EVENT& aEvent ) highlightNet( getViewControls()->GetMousePosition(), use_selection ); } - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); - - PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - - picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool + picker->SetClickHandler( + [this] ( const VECTOR2D& pt ) -> bool { highlightNet( pt, false ); return true; } ); picker->SetLayerSet( LSET::AllCuMask() ); - picker->Activate(); - Wait(); - m_frame->PopTool( tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + return 0; } -static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, bool aShow, const VECTOR2D& aPosition ) -{ - auto selectionTool = aToolMgr->GetTool(); - - aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::PadFilter ); - PCBNEW_SELECTION& selection = selectionTool->GetSelection(); - - if( selection.Empty() ) - { - aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::FootprintFilter ); - selection = selectionTool->GetSelection(); - } - - if( selection.Empty() ) - { - // Clear the previous local ratsnest if we click off all items - for( auto mod : aBoard->Modules() ) - { - for( auto pad : mod->Pads() ) - pad->SetLocalRatsnestVisible( aShow ); - } - } - else - { - for( auto item : selection ) - { - if( auto pad = dyn_cast(item) ) - { - pad->SetLocalRatsnestVisible( !pad->GetLocalRatsnestVisible() ); - } - else if( auto mod = dyn_cast(item) ) - { - bool enable = !( *( mod->Pads().begin() ) )->GetLocalRatsnestVisible(); - - for( auto modpad : mod->Pads() ) - modpad->SetLocalRatsnestVisible( enable ); - } - } - } - - aToolMgr->GetView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); - - return true; -} - - int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) { - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); + std::string tool = aEvent.GetCommandStr().get(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); + BOARD* board = getModel(); + PCB_DISPLAY_OPTIONS* opt = displayOptions(); - auto picker = m_toolMgr->GetTool(); - auto board = getModel(); - auto opt = displayOptions(); - wxASSERT( picker ); - wxASSERT( board ); + picker->SetClickHandler( + [&] ( const VECTOR2D& pt ) -> bool + { + SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - picker->SetClickHandler( std::bind( showLocalRatsnest, m_toolMgr, board, - opt->m_ShowGlobalRatsnest, _1 ) ); + m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::PadFilter ); + PCBNEW_SELECTION& selection = selectionTool->GetSelection(); - picker->SetFinalizeHandler( [ board, opt ]( int aCondition ) + if( selection.Empty() ) + { + m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, + EDIT_TOOL::FootprintFilter ); + selection = selectionTool->GetSelection(); + } + + if( selection.Empty() ) + { + // Clear the previous local ratsnest if we click off all items + for( auto mod : board->Modules() ) + { + for( auto pad : mod->Pads() ) + pad->SetLocalRatsnestVisible( opt->m_ShowGlobalRatsnest ); + } + } + else + { + for( auto item : selection ) + { + if( auto pad = dyn_cast(item) ) + { + pad->SetLocalRatsnestVisible( !pad->GetLocalRatsnestVisible() ); + } + else if( auto mod = dyn_cast(item) ) + { + bool enable = !( *( mod->Pads().begin() ) )->GetLocalRatsnestVisible(); + + for( auto modpad : mod->Pads() ) + modpad->SetLocalRatsnestVisible( enable ); + } + } + } + + m_toolMgr->GetView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); + + return true; + } ); + + picker->SetFinalizeHandler( + [ board, opt ]( int aCondition ) { if( aCondition != PCBNEW_PICKER_TOOL::END_ACTIVATE ) { @@ -1403,10 +1382,8 @@ int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) } } ); - picker->Activate(); - Wait(); + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - m_frame->PopTool( tool ); return 0; } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 9f427cf2cf..1c864d033b 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -412,7 +412,6 @@ int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent ) { m_frame->SetFastGrid1(); updateGrid(); - return 0; } @@ -421,7 +420,6 @@ int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent ) { m_frame->SetFastGrid2(); updateGrid(); - return 0; } @@ -444,29 +442,23 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) if( origin ) { // We can't undo the other grid dialog settings, so no sense undoing just the origin - DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), *origin ); delete origin; } else { - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); - + std::string tool = aEvent.GetCommandStr().get(); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool + picker->SetClickHandler( + [this] ( const VECTOR2D& pt ) -> bool { m_frame->SaveCopyInUndoList( m_gridOrigin.get(), UR_GRIDORIGIN ); DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), pt ); return false; // drill origin is a one-shot; don't continue with tool } ); - picker->Activate(); - Wait(); - - m_frame->PopTool( tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); } return 0; @@ -486,76 +478,76 @@ int PCBNEW_CONTROL::GridResetOrigin( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { + std::string tool = aEvent.GetCommandStr().get(); + PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); + + m_pickerItem = nullptr; m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); + picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) ); - PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - m_pickerItem = nullptr; - - picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool - { - if( m_pickerItem ) + picker->SetClickHandler( + [this] ( const VECTOR2D& aPosition ) -> bool { - if( m_pickerItem && m_pickerItem->IsLocked() ) + if( m_pickerItem ) { - STATUS_TEXT_POPUP statusPopup( m_frame ); - statusPopup.SetText( _( "Item locked." ) ); - statusPopup.PopupFor( 2000 ); - statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - return true; + if( m_pickerItem && m_pickerItem->IsLocked() ) + { + STATUS_TEXT_POPUP statusPopup( m_frame ); + statusPopup.SetText( _( "Item locked." ) ); + statusPopup.PopupFor( 2000 ); + statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); + return true; + } + + SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + selectionTool->UnbrightenItem( m_pickerItem ); + selectionTool->AddItemToSel( m_pickerItem, true ); + m_toolMgr->RunAction( ACTIONS::doDelete, true ); + m_pickerItem = nullptr; } - 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; + } ); - return true; - } ); - - picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) - { - BOARD* board = m_frame->GetBoard(); - GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); - GENERAL_COLLECTOR collector; - collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); - - if( m_editModules ) - collector.Collect( board, GENERAL_COLLECTOR::ModuleItems, (wxPoint) aPos, guide ); - else - collector.Collect( board, GENERAL_COLLECTOR::BoardLevelItems, (wxPoint) aPos, guide ); - - BOARD_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; - - if( m_pickerItem != item ) + picker->SetMotionHandler( + [this] ( const VECTOR2D& aPos ) { - SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + BOARD* board = m_frame->GetBoard(); + GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); + GENERAL_COLLECTOR collector; + collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); + if( m_editModules ) + collector.Collect( board, GENERAL_COLLECTOR::ModuleItems, (wxPoint) aPos, guide ); + else + collector.Collect( board, GENERAL_COLLECTOR::BoardLevelItems, (wxPoint) aPos, guide ); + + BOARD_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; + + if( m_pickerItem != item ) + { + 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( + [&]( const int& aFinalState ) + { if( m_pickerItem ) - selectionTool->UnbrightenItem( m_pickerItem ); + m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); + } ); - m_pickerItem = item; + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - if( m_pickerItem ) - selectionTool->BrightenItem( m_pickerItem ); - } - } ); - - picker->SetFinalizeHandler( [&]( const int& aFinalState ) - { - if( m_pickerItem ) - m_toolMgr->GetTool()->UnbrightenItem( m_pickerItem ); - } ); - - picker->Activate(); - Wait(); - - m_frame->PopTool( tool ); return 0; } @@ -667,7 +659,8 @@ template static void moveNoFlagToVector( std::deque& aList, std::vector& aTarget, bool aIsNew ) { std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ), - [](T aItem){ + [](T aItem) + { bool retval = ( aItem->GetFlags() & FLAG0 ) == 0; aItem->ClearFlags( FLAG0 ); return retval; @@ -857,6 +850,7 @@ int PCBNEW_CONTROL::Redo( const TOOL_EVENT& aEvent ) if( editFrame ) editFrame->RestoreCopyFromRedoList( dummy ); + return 0; } @@ -887,7 +881,6 @@ int PCBNEW_CONTROL::Show3DViewer( const TOOL_EVENT& aEvent ) void PCBNEW_CONTROL::updateGrid() { BASE_SCREEN* screen = m_frame->GetScreen(); - //GRID_TYPE grid = screen->GetGrid( idx ); getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); } diff --git a/pcbnew/tools/pcbnew_picker_tool.cpp b/pcbnew/tools/pcbnew_picker_tool.cpp index 958763a0fc..f2cf37c860 100644 --- a/pcbnew/tools/pcbnew_picker_tool.cpp +++ b/pcbnew/tools/pcbnew_picker_tool.cpp @@ -28,7 +28,6 @@ #include "grid_helper.h" #include #include -#include "tool_event_utils.h" #include "selection_tool.h" @@ -45,11 +44,13 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) GRID_HELPER grid( frame() ); int finalize_state = WAIT_CANCEL; + Activate(); setControls(); while( TOOL_EVENT* evt = Wait() ) { - frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE ); + frame()->GetCanvas()->SetCursor( m_cursor ); + grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); controls->SetSnapping( !evt->Modifier( MD_ALT ) ); @@ -153,13 +154,14 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) void PCBNEW_PICKER_TOOL::setTransitions() { - Go( &PCBNEW_PICKER_TOOL::Main, PCB_ACTIONS::pickerTool.MakeEvent() ); + Go( &PCBNEW_PICKER_TOOL::Main, ACTIONS::pickerTool.MakeEvent() ); } void PCBNEW_PICKER_TOOL::reset() { m_layerMask = LSET::AllLayersMask(); + m_cursor = wxStockCursor( wxCURSOR_ARROW ); m_picked = NULLOPT; m_clickHandler = NULLOPT; diff --git a/pcbnew/tools/pcbnew_picker_tool.h b/pcbnew/tools/pcbnew_picker_tool.h index 06639ed719..b30f66a767 100644 --- a/pcbnew/tools/pcbnew_picker_tool.h +++ b/pcbnew/tools/pcbnew_picker_tool.h @@ -35,7 +35,7 @@ class PCBNEW_PICKER_TOOL : public PCB_TOOL_BASE { public: PCBNEW_PICKER_TOOL(); - ~PCBNEW_PICKER_TOOL() {} + ~PCBNEW_PICKER_TOOL() override { } ///> Event handler types. typedef std::function CLICK_HANDLER; @@ -64,6 +64,8 @@ public: */ inline void SetLayerSet( LSET aLayerSet ) { m_layerMask = aLayerSet; } + inline void SetCursor( const wxCursor& aCursor ) { m_cursor = aCursor; } + /** * Function SetClickHandler() * Sets a handler for mouse click event. Handler may decide to receive further click by @@ -105,25 +107,27 @@ public: m_finalizeHandler = aHandler; } +private: ///> @copydoc TOOL_INTERACTIVE::setTransitions(); void setTransitions() override; -private: - ///> The layer set to use for optional snapping - LSET m_layerMask; - - OPT m_clickHandler; - OPT m_motionHandler; - OPT m_cancelHandler; - OPT m_finalizeHandler; - - OPT m_picked; - ///> Reinitializes tool to its initial state. void reset(); ///> Applies the requested VIEW_CONTROLS settings. void setControls(); + +private: + ///> The layer set to use for optional snapping + LSET m_layerMask; + wxCursor m_cursor; + + OPT m_clickHandler; + OPT m_motionHandler; + OPT m_cancelHandler; + OPT m_finalizeHandler; + + OPT m_picked; }; #endif /* PICKER_TOOL_H */ diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index c7a836b510..d55330919c 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -24,13 +24,11 @@ #include using namespace std::placeholders; - #include #include #include #include #include - #include "pcb_actions.h" #include "selection_tool.h" #include "point_editor.h" @@ -38,18 +36,13 @@ using namespace std::placeholders; #include #include #include - #include #include #include #include -#include -#include #include #include -#include "zone_filler.h" - // Few constants to avoid using bare numbers for point indices enum SEG_POINTS { @@ -354,7 +347,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) m_original = *m_editedPoint; // Save the original position controls->SetAutoPan( true ); inDrag = true; - grid.SetAuxAxes( true, m_original.GetPosition(), true ); + grid.SetAuxAxes( true, m_original.GetPosition() ); } //TODO: unify the constraints to solve simultaneously instead of sequentially diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index 41fa5c75ad..9a97730614 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -122,56 +122,55 @@ int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint aPosAnchor, wxPoi int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent ) { - Activate(); - + std::string tool = "pcbnew.PositionRelative.selectReferenceItem"; PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - STATUS_TEXT_POPUP statusPopup( frame() ); - bool picking = true; + STATUS_TEXT_POPUP statusPopup( frame() ); - frame()->PushTool( "pcbnew.PositionRelative.selectReferenceItem" ); statusPopup.SetText( _( "Select reference item..." ) ); - picker->Activate(); - picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool - { - m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - const PCBNEW_SELECTION& sel = m_selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) - { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } ); + picker->SetClickHandler( + [&]( const VECTOR2D& aPoint ) -> bool + { + m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + const PCBNEW_SELECTION& sel = m_selectionTool->RequestSelection( + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) + { + EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); + } ); - if( sel.Empty() ) - return true; // still looking for an item + if( sel.Empty() ) + return true; // still looking for an item - m_anchor_item = sel.Front(); - statusPopup.Hide(); + m_anchor_item = sel.Front(); + statusPopup.Hide(); - if( m_dialog ) - m_dialog->UpdateAnchor( sel.Front() ); + if( m_dialog ) + m_dialog->UpdateAnchor( sel.Front() ); - picking = false; - return false; // got our item; don't need any more - } ); + return false; // got our item; don't need any more + } ); - picker->SetCancelHandler( [&]() - { - statusPopup.Hide(); + picker->SetMotionHandler( + [&] ( const VECTOR2D& aPos ) + { + statusPopup.Move( aPos + wxPoint( 20, -50 ) ); + } ); - if( m_dialog ) - m_dialog->UpdateAnchor( m_anchor_item ); + picker->SetCancelHandler( + [&]() + { + statusPopup.Hide(); - picking = false; - } ); + if( m_dialog ) + m_dialog->UpdateAnchor( m_anchor_item ); + } ); statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); statusPopup.Popup(); - while( picking ) - { - statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); - Wait(); - } + m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - frame()->PopTool( "pcbnew.PositionRelative.selectReferenceItem" ); + statusPopup.Hide(); return 0; }