diff --git a/common/tool/tool_interactive.cpp b/common/tool/tool_interactive.cpp index a994f17a4b..efaecb9b19 100644 --- a/common/tool/tool_interactive.cpp +++ b/common/tool/tool_interactive.cpp @@ -54,7 +54,7 @@ void TOOL_INTERACTIVE::Activate() } -OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait( const TOOL_EVENT_LIST& aEventList ) +TOOL_EVENT* TOOL_INTERACTIVE::Wait( const TOOL_EVENT_LIST& aEventList ) { return m_toolMgr->ScheduleWait( this, aEventList ); } diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index d16160370a..6f71fe2cd8 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -470,9 +470,9 @@ int TOOL_MANAGER::GetPriority( int aToolId ) const { int priority = 0; - for( auto it = m_activeTools.begin(), itEnd = m_activeTools.end(); it != itEnd; ++it ) + for( TOOL_ID tool : m_activeTools ) { - if( *it == aToolId ) + if( tool == aToolId ) return priority; ++priority; @@ -505,7 +505,7 @@ void TOOL_MANAGER::RunMainStack( TOOL_BASE* aTool, std::function aFunc ) } -OPT TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_LIST& aConditions ) +TOOL_EVENT* TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_LIST& aConditions ) { TOOL_STATE* st = m_toolState[aTool]; @@ -519,7 +519,7 @@ OPT TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_L // switch context back to event dispatcher loop st->cofunc->KiYield(); - return st->wakeupEvent; + return &st->wakeupEvent; } @@ -557,7 +557,7 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) } // If the tool did not request the event be passed to other tools, we're done - if( !aEvent.PassEvent() ) + if( !st->wakeupEvent.PassEvent() ) break; } } diff --git a/common/tool/tool_menu.cpp b/common/tool/tool_menu.cpp index 120a26ec57..487b0d56f7 100644 --- a/common/tool/tool_menu.cpp +++ b/common/tool/tool_menu.cpp @@ -72,7 +72,3 @@ void TOOL_MENU::ShowContextMenu() } -void TOOL_MENU::CloseContextMenu( OPT_TOOL_EVENT& evt ) -{ -} - diff --git a/cvpcb/tools/cvpcb_selection_tool.cpp b/cvpcb/tools/cvpcb_selection_tool.cpp index 164e589f3c..bd6d9b2a62 100644 --- a/cvpcb/tools/cvpcb_selection_tool.cpp +++ b/cvpcb/tools/cvpcb_selection_tool.cpp @@ -54,7 +54,7 @@ void CVPCB_SELECTION_TOOL::Reset( RESET_REASON aReason ) int CVPCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This is kind of hacky: activate RMB drag on any event. // There doesn't seem to be any other good way to tell when another tool @@ -88,11 +88,6 @@ int CVPCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) clearSelection(); } - else if( evt->Action() == TA_CHOICE_MENU_CLOSED ) - { - m_menu.CloseContextMenu( evt ); - } - else evt->SetPassEvent(); } diff --git a/eeschema/tools/ee_picker_tool.cpp b/eeschema/tools/ee_picker_tool.cpp index 2645f6805c..81d6a3a649 100644 --- a/eeschema/tools/ee_picker_tool.cpp +++ b/eeschema/tools/ee_picker_tool.cpp @@ -42,7 +42,7 @@ int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) setControls(); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { VECTOR2I cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) ); @@ -75,7 +75,7 @@ int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) setControls(); } - else if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( m_cancelHandler ) { diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index 800fd46503..658455e291 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -271,9 +271,9 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) bool modified = false; // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { - if( !m_editPoints || TOOL_EVT_UTILS::IsSelectionEvent( evt.get() ) ) + if( !m_editPoints || TOOL_EVT_UTILS::IsSelectionEvent( *evt ) ) break; if ( !inDrag ) @@ -295,7 +295,7 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) updatePoints(); } - else if( evt->IsMouseUp( BUT_LEFT ) ) + else if( inDrag && evt->IsMouseUp( BUT_LEFT ) ) { controls->SetAutoPan( false ); inDrag = false; diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index e999d79863..0037be063a 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -292,7 +292,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) }; // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // Should selected items be added to the current selection or // become the new selection (discarding previously selected items) @@ -417,11 +417,6 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) ClearSelection(); } - else if( evt->Action() == TA_CHOICE_MENU_CLOSED ) - { - m_menu.CloseContextMenu( evt ); - } - else evt->SetPassEvent(); } @@ -656,7 +651,7 @@ bool EE_SELECTION_TOOL::selectMultiple() KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsActivate() || evt->IsCancel() ) { @@ -987,7 +982,7 @@ bool EE_SELECTION_TOOL::doSelectionMenu( EE_COLLECTOR* aCollector ) menu.DisplayTitle( true ); SetContextMenu( &menu, CMENU_NOW ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->Action() == TA_CHOICE_MENU_UPDATE ) { @@ -1004,7 +999,7 @@ bool EE_SELECTION_TOOL::doSelectionMenu( EE_COLLECTOR* aCollector ) } else { - current = NULL; + current = nullptr; } } else if( evt->Action() == TA_CHOICE_MENU_CHOICE ) @@ -1018,7 +1013,7 @@ bool EE_SELECTION_TOOL::doSelectionMenu( EE_COLLECTOR* aCollector ) if( id && ( *id > 0 ) ) current = ( *aCollector )[*id - 1]; else - current = NULL; + current = nullptr; break; } diff --git a/eeschema/tools/lib_drawing_tools.cpp b/eeschema/tools/lib_drawing_tools.cpp index 8439296404..12542e261a 100644 --- a/eeschema/tools/lib_drawing_tools.cpp +++ b/eeschema/tools/lib_drawing_tools.cpp @@ -118,11 +118,11 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode ) m_toolMgr->RunAction( ACTIONS::cursorClick ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( item ) { @@ -282,7 +282,7 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) { VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_view->ClearPreview(); @@ -396,9 +396,9 @@ int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent ) Activate(); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { break; } diff --git a/eeschema/tools/lib_move_tool.cpp b/eeschema/tools/lib_move_tool.cpp index 613117b868..015ee92b6f 100644 --- a/eeschema/tools/lib_move_tool.cpp +++ b/eeschema/tools/lib_move_tool.cpp @@ -89,10 +89,10 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) controls->ShowCursor( true ); controls->SetAutoPan( true ); - bool restore_state = false; - bool chain_commands = false; - OPT_TOOL_EVENT evt = aEvent; - VECTOR2I prevPos; + bool restore_state = false; + bool chain_commands = false; + TOOL_EVENT* evt = const_cast( &aEvent ); + VECTOR2I prevPos; if( !selection.Front()->IsNew() ) saveCopyInUndoList( m_frame->GetCurPart(), UR_LIBEDIT ); @@ -193,7 +193,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) //------------------------------------------------------------------------ // Handle cancel // - else if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( m_moveInProgress ) restore_state = true; @@ -254,7 +254,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) break; // Finish } - } while( ( evt = Wait() ) ); //Should be assignment not equality test + } while( ( evt = Wait() ) ); // Assignment intentional; not equality test controls->ForceCursorPosition( false ); controls->ShowCursor( false ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 2c506d74c4..8bd55c435b 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -117,11 +117,11 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::cursorClick ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( component ) { @@ -254,11 +254,11 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( ACTIONS::cursorClick ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( image ) { @@ -408,11 +408,11 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( ACTIONS::cursorClick ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( !evt->IsActivate() && !immediateMode ) m_frame->PopTool(); @@ -508,11 +508,11 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( ACTIONS::cursorClick ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( item ) { @@ -621,7 +621,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); } - else if( item && TOOL_EVT_UTILS::IsSelectionEvent( evt.get() ) ) + else if( item && TOOL_EVT_UTILS::IsSelectionEvent( *evt ) ) { // This happens if our text was replaced out from under us by ConvertTextType() EE_SELECTION& selection = m_selectionTool->GetSelection(); @@ -644,8 +644,8 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } // Enable autopanning and cursor capture only when there is a module to be placed - getViewControls()->SetAutoPan( !!item ); - getViewControls()->CaptureCursor( !!item ); + getViewControls()->SetAutoPan( item != nullptr ); + getViewControls()->CaptureCursor( item != nullptr ); } if( immediateMode ) @@ -675,11 +675,11 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( ACTIONS::cursorClick ); // Main loop: keep receiving events - while( auto evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_view->ClearPreview(); diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index c544d9e0c0..904f534875 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -313,7 +313,7 @@ int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent ) SetContextMenu( &unfoldMenu, CMENU_NOW ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->Action() == TA_CHOICE_MENU_CHOICE ) { @@ -495,14 +495,14 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment, bool m_toolMgr->RunAction( ACTIONS::cursorClick ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); //------------------------------------------------------------------------ // Handle cancel: // - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( aSegment || m_busUnfold.in_progress ) { diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index d859ecc879..9bf3a3c488 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -150,10 +150,10 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) Activate(); controls->ShowCursor( true ); - bool restore_state = false; - bool chain_commands = false; - OPT_TOOL_EVENT evt = aEvent; - VECTOR2I prevPos; + bool restore_state = false; + bool chain_commands = false; + TOOL_EVENT* evt = const_cast( &aEvent ); + VECTOR2I prevPos; m_cursor = controls->GetCursorPosition(); @@ -334,7 +334,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) //------------------------------------------------------------------------ // Handle cancel // - else if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( m_moveInProgress ) restore_state = true; diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index 8e5877c7cd..24ff8b9492 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -181,7 +181,7 @@ void GERBVIEW_SELECTION_TOOL::Reset( RESET_REASON aReason ) int GERBVIEW_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This is kind of hacky: activate RMB drag on any event. // There doesn't seem to be any other good way to tell when another tool @@ -224,11 +224,6 @@ int GERBVIEW_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) clearSelection(); } - else if( evt->Action() == TA_CHOICE_MENU_CLOSED ) - { - m_menu.CloseContextMenu( evt ); - } - else evt->SetPassEvent(); } @@ -355,7 +350,7 @@ bool GERBVIEW_SELECTION_TOOL::selectMultiple() KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->IsCancel() ) { @@ -605,7 +600,7 @@ EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollec menu.DisplayTitle( true ); SetContextMenu( &menu, CMENU_NOW ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->Action() == TA_CHOICE_MENU_UPDATE ) { diff --git a/include/tool/tool_interactive.h b/include/tool/tool_interactive.h index c943a26005..44747d9f92 100644 --- a/include/tool/tool_interactive.h +++ b/include/tool/tool_interactive.h @@ -90,7 +90,7 @@ public: * Suspends execution of the tool until an event specified in aEventList arrives. * No parameters means waiting for any event. */ - OPT_TOOL_EVENT Wait( const TOOL_EVENT_LIST& aEventList = TOOL_EVENT( TC_ANY, TA_ANY ) ); + TOOL_EVENT* Wait( const TOOL_EVENT_LIST& aEventList = TOOL_EVENT( TC_ANY, TA_ANY ) ); /** functions below are not yet implemented - their interface may change */ /*template diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 1d248db7b0..4cdfa64ead 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -318,8 +318,7 @@ public: * The pause/resume operation is done through COROUTINE object. * Called only from coroutines. */ - OPT ScheduleWait( TOOL_BASE* aTool, - const TOOL_EVENT_LIST& aConditions ); + TOOL_EVENT* ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_LIST& aConditions ); /** * Sets behaviour of the tool's context popup menu. @@ -331,8 +330,7 @@ public: * CMENU_OFF: menu is disabled. * May be called from a coroutine context. */ - void ScheduleContextMenu( TOOL_BASE* aTool, ACTION_MENU* aMenu, - CONTEXT_MENU_TRIGGER aTrigger ); + void ScheduleContextMenu( TOOL_BASE* aTool, ACTION_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger ); /** * Stores an information to the system clipboard. diff --git a/include/tool/tool_menu.h b/include/tool/tool_menu.h index 94b449b1e3..670eaf16e6 100644 --- a/include/tool/tool_menu.h +++ b/include/tool/tool_menu.h @@ -110,14 +110,6 @@ public: */ void ShowContextMenu(); - /** - * Function CloseContextMenu - * - * Helper function to close a menu previously opened with - * ShowContextMenu(), if a suitable event is received - */ - void CloseContextMenu( OPT_TOOL_EVENT& evt ); - private: /** * The conditional menu displayed by the tool diff --git a/pagelayout_editor/tools/pl_drawing_tools.cpp b/pagelayout_editor/tools/pl_drawing_tools.cpp index b9f73ac17a..0f069223ca 100644 --- a/pagelayout_editor/tools/pl_drawing_tools.cpp +++ b/pagelayout_editor/tools/pl_drawing_tools.cpp @@ -108,11 +108,11 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) Activate(); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( item ) { @@ -230,11 +230,11 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) WS_DRAW_ITEM_BASE* item = nullptr; // Main loop: keep receiving events - while( auto evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 53f3a94673..decace4f08 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -107,10 +107,10 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) controls->ShowCursor( true ); controls->SetAutoPan( true ); - bool restore_state = false; - bool chain_commands = false; - OPT_TOOL_EVENT evt = aEvent; - VECTOR2I prevPos; + bool restore_state = false; + bool chain_commands = false; + TOOL_EVENT* evt = const_cast( &aEvent ); + VECTOR2I prevPos; if( !selection.Front()->IsNew() ) m_frame->SaveCopyInUndoList(); @@ -184,7 +184,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) //------------------------------------------------------------------------ // Handle cancel // - else if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( m_moveInProgress ) restore_state = true; diff --git a/pagelayout_editor/tools/pl_picker_tool.cpp b/pagelayout_editor/tools/pl_picker_tool.cpp index ff7d28484a..f706e3d213 100644 --- a/pagelayout_editor/tools/pl_picker_tool.cpp +++ b/pagelayout_editor/tools/pl_picker_tool.cpp @@ -70,7 +70,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) setControls(); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { VECTOR2I cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) ); @@ -103,7 +103,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) setControls(); } - else if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { if( m_cancelHandler ) { diff --git a/pagelayout_editor/tools/pl_point_editor.cpp b/pagelayout_editor/tools/pl_point_editor.cpp index 22753ff51f..d16a0c0c79 100644 --- a/pagelayout_editor/tools/pl_point_editor.cpp +++ b/pagelayout_editor/tools/pl_point_editor.cpp @@ -178,9 +178,9 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) bool modified = false; // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { - if( !m_editPoints || TOOL_EVT_UTILS::IsSelectionEvent( evt.get() ) ) + if( !m_editPoints || TOOL_EVT_UTILS::IsSelectionEvent( *evt ) ) break; if ( !inDrag ) @@ -203,7 +203,7 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) updatePoints(); } - else if( evt->IsMouseUp( BUT_LEFT ) ) + else if( inDrag && evt->IsMouseUp( BUT_LEFT ) ) { controls->SetAutoPan( false ); m_frame->PopTool(); diff --git a/pagelayout_editor/tools/pl_selection_tool.cpp b/pagelayout_editor/tools/pl_selection_tool.cpp index 6fc9bc15d1..0c44a165cc 100644 --- a/pagelayout_editor/tools/pl_selection_tool.cpp +++ b/pagelayout_editor/tools/pl_selection_tool.cpp @@ -109,7 +109,7 @@ int PL_SELECTION_TOOL::UpdateMenu( const TOOL_EVENT& aEvent ) int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // Should selected items be added to the current selection or // become the new selection (discarding previously selected items) @@ -187,11 +187,6 @@ int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) ClearSelection(); } - else if( evt->Action() == TA_CHOICE_MENU_CLOSED ) - { - m_menu.CloseContextMenu( evt ); - } - else evt->SetPassEvent(); } @@ -308,9 +303,9 @@ bool PL_SELECTION_TOOL::selectMultiple() KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { - if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsActivate() || evt->IsCancel() ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { cancelled = true; break; @@ -525,7 +520,7 @@ bool PL_SELECTION_TOOL::doSelectionMenu( COLLECTOR* aCollector ) menu.DisplayTitle( true ); SetContextMenu( &menu, CMENU_NOW ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->Action() == TA_CHOICE_MENU_UPDATE ) { diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index fa18fc6f25..d4f0095c8c 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -187,7 +187,7 @@ void LENGTH_TUNER_TOOL::performTuning() m_router->Move( end, NULL ); updateStatusPopup( statusPopup ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) break; @@ -293,7 +293,7 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) SetContextMenu( ctxMenu.get() ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index bd69731d45..6e586e8ae3 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -757,7 +757,7 @@ void ROUTER_TOOL::performRouting() if( !prepareInteractive() ) return; - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // Don't crash if we missed an operation that cancelled routing. wxCHECK2( m_router->RoutingInProgress(), break ); @@ -914,7 +914,7 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) SetContextMenu( ctxMenu.get() ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { @@ -1000,7 +1000,7 @@ void ROUTER_TOOL::performDragging( int aMode ) m_gridHelper->SetAuxAxes( true, m_startSnapPoint, true ); frame()->UndoRedoBlock( true ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { ctls->ForceCursorPosition( false ); @@ -1153,7 +1153,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) controls()->SetAutoPan( true ); frame()->UndoRedoBlock( true ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->IsCancel() ) { diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 7f1d4c9bdf..92393ea86f 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -285,7 +285,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) bool reselect = false; // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); @@ -480,7 +480,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) int step = SET_ORIGIN; // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); @@ -770,7 +770,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) Activate(); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { cursorPos = m_controls->GetCursorPosition(); @@ -848,7 +848,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) m_controls->SetAutoPan( true ); m_controls->CaptureCursor( false ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); @@ -928,7 +928,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPTModifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); @@ -1142,7 +1142,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) bool firstPoint = false; // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { PCB_LAYER_ID layer = getDrawingLayer(); aGraphic->SetLayer( layer ); @@ -1329,7 +1329,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) status.SetTextColor( wxColour( 255, 0, 0 ) ); status.SetText( _( "Self-intersecting polygons are not allowed" ) ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 3b8afb036f..0ab129d590 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -291,11 +291,11 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) } } - bool restore_state = false; - VECTOR2I totalMovement; + bool restore_state = false; + VECTOR2I totalMovement; GRID_HELPER grid( editFrame ); - OPT_TOOL_EVENT evt = aEvent; - VECTOR2I prevPos; + TOOL_EVENT* evt = const_cast( &aEvent ); + VECTOR2I prevPos; // Main loop: keep receiving events do @@ -310,8 +310,8 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) { if( m_dragging && evt->Category() == TC_MOUSE ) { - m_cursor = grid.BestSnapAnchor( controls->GetMousePosition(), - item_layers, sel_items ); + m_cursor = grid.BestSnapAnchor( controls->GetMousePosition(), item_layers, + sel_items ); controls->ForceCursorPosition(true, m_cursor ); VECTOR2I movement( m_cursor - prevPos ); selection.SetReferencePoint( m_cursor ); diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 63c68807d1..0d5e8076e3 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -367,7 +367,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) statusPopup.Popup(); statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) { diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index cb0b14c350..4465cc23c1 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -533,7 +533,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) bool reselect = false; // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); @@ -713,7 +713,7 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) m_frame->SetToolID( ID_PCB_TARGET_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) ); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 8b668999cd..d8cb326f64 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -71,7 +71,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer } // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { VECTOR2I cursorPos = controls()->GetCursorPosition(); aPlacer->m_modifiers = evt->Modifier(); diff --git a/pcbnew/tools/pcbnew_picker_tool.cpp b/pcbnew/tools/pcbnew_picker_tool.cpp index 2ea9a8ab5c..074543d0c8 100644 --- a/pcbnew/tools/pcbnew_picker_tool.cpp +++ b/pcbnew/tools/pcbnew_picker_tool.cpp @@ -46,7 +46,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) setControls(); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index de570025bd..daad403b8d 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -318,7 +318,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) view->Add( m_editPoints.get() ); setEditedPoint( nullptr ); m_refill = false; - bool modified = false; + bool inDrag = false; BOARD_COMMIT commit( editFrame ); LSET snapLayers = item->GetLayerSet(); @@ -327,34 +327,34 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) snapLayers = LSET::AllLayersMask(); // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); controls->SetSnapping( !evt->Modifier( MD_ALT ) ); - if( !m_editPoints || TOOL_EVT_UTILS::IsSelectionEvent( evt.get() ) ) + if( !m_editPoints || TOOL_EVT_UTILS::IsSelectionEvent( *evt ) ) break; - if ( !modified ) + if ( !inDrag ) updateEditedPoint( *evt ); if( evt->IsDrag( BUT_LEFT ) && m_editedPoint ) { - if( !modified ) + if( !inDrag ) { commit.StageItems( selection, CHT_MODIFY ); controls->ForceCursorPosition( false ); m_original = *m_editedPoint; // Save the original position controls->SetAutoPan( true ); - modified = true; + inDrag = true; grid.SetAuxAxes( true, m_original.GetPosition(), true ); } //TODO: unify the constraints to solve simultaneously instead of sequentially m_editedPoint->SetPosition( grid.BestSnapAnchor( evt->Position(), - snapLayers, { item } ) ); + snapLayers, { item } ) ); bool enableAltConstraint = !!evt->Modifier( MD_CTRL ); if( enableAltConstraint != (bool) m_altConstraint ) // alternative constraint @@ -366,28 +366,25 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) m_editedPoint->ApplyConstraint(); m_editedPoint->SetPosition( grid.BestSnapAnchor( m_editedPoint->GetPosition(), - snapLayers, { item } ) ); + snapLayers, { item } ) ); updateItem(); updatePoints(); } - else if( evt->IsMouseUp( BUT_LEFT ) ) + else if( inDrag && evt->IsMouseUp( BUT_LEFT ) ) { controls->SetAutoPan( false ); setAltConstraint( false ); - if( modified ) - { - commit.Push( _( "Drag a corner" ) ); - modified = false; - m_refill = true; - } + commit.Push( _( "Drag a corner" ) ); + inDrag = false; + m_refill = true; } else if( evt->IsCancel() ) { - if( modified ) // Restore the last change + if( inDrag ) // Restore the last change commit.Revert(); // ESC should clear selection along with edit points diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index e4bc09051d..9eedd38a8e 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -188,7 +188,7 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { // Should selected items be added to the current selection or // become the new selection (discarding previously selected items) @@ -293,11 +293,6 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::clearHighlight, true ); } - else if( evt->Action() == TA_CHOICE_MENU_CLOSED ) - { - m_menu.CloseContextMenu( evt ); - } - else evt->SetPassEvent(); } @@ -528,7 +523,7 @@ bool SELECTION_TOOL::selectMultiple() KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { @@ -1358,7 +1353,7 @@ bool SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector, const wxStr menu.DisplayTitle( true ); SetContextMenu( &menu, CMENU_NOW ); - while( OPT_TOOL_EVENT evt = Wait() ) + while( TOOL_EVENT* evt = Wait() ) { if( evt->Action() == TA_CHOICE_MENU_UPDATE ) {