Special-case synthetic click after tool selection.

Fixes https://gitlab.com/kicad/code/kicad/issues/11057

(cherry picked from commit 1f745b000d)
(cherry picked from commit dd55ffb75c)
This commit is contained in:
Jeff Young 2022-03-07 12:45:24 +00:00 committed by Seth Hillbrand
parent 02b1f552fd
commit 8ccc5bd8f2
2 changed files with 80 additions and 31 deletions

View File

@ -22,9 +22,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "sch_drawing_tools.h"
#include "ee_selection_tool.h"
#include "ee_grid_helper.h"
#include <tools/sch_drawing_tools.h>
#include <tools/ee_selection_tool.h>
#include <tools/ee_grid_helper.h>
#include <ee_actions.h>
#include <sch_edit_frame.h>
#include <project.h>
@ -987,6 +987,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
SCH_ITEM* item = nullptr;
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
bool ignorePrimePosition = false;
if( m_inTwoClickPlace )
return 0;
@ -1048,10 +1049,17 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
setCursor();
// Prime the pump if the tool isn't being re-activated
if( aEvent.HasPosition() || ( !aEvent.IsReactivate()
&& ( isText || isGlobalLabel || isHierLabel || isNetLabel ) ) )
if( aEvent.HasPosition() )
{
m_toolMgr->RunAction( ACTIONS::cursorClick );
m_toolMgr->PrimeTool( aEvent.Position() );
}
else if( !aEvent.IsReactivate() && ( isText
|| isGlobalLabel
|| isHierLabel
|| isNetLabel ) )
{
m_toolMgr->PrimeTool( { 0, 0 } );
ignorePrimePosition = true;
}
// Main loop: keep receiving events
@ -1170,11 +1178,17 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
}
}
// Restore cursor after dialog
controls->WarpCursor( controls->GetCursorPosition(), true );
// If we started with a click on a tool button or menu then continue with the
// current mouse position. Otherwise warp back to the original click position.
if( evt->IsPrime() && ignorePrimePosition )
cursorPos = grid.Align( controls->GetMousePosition() );
else
controls->WarpCursor( cursorPos, true );
if( item )
{
item->SetPosition( (wxPoint) cursorPos );
item->SetFlags( IS_NEW | IS_MOVING );
item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
updatePreview();

View File

@ -26,6 +26,7 @@
#include <symbol_edit_frame.h>
#include <tools/symbol_editor_drawing_tools.h>
#include <tools/symbol_editor_pin_tool.h>
#include <tools/ee_grid_helper.h>
#include <bitmaps.h>
#include <lib_text.h>
#include <dialogs/dialog_lib_text_properties.h>
@ -67,12 +68,16 @@ bool SYMBOL_EDITOR_DRAWING_TOOLS::Init()
int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
{
KICAD_T type = aEvent.Parameter<KICAD_T>();
auto* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
auto* pinTool = type == LIB_PIN_T ? m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() : nullptr;
VECTOR2I cursorPos;
EDA_ITEM* item = nullptr;
bool isText = aEvent.IsAction( &EE_ACTIONS::placeSymbolText );
KICAD_T type = aEvent.Parameter<KICAD_T>();
auto* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
auto* pinTool = type == LIB_PIN_T ? m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() : nullptr;
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
VECTOR2I cursorPos;
bool ignorePrimePosition = false;
LIB_ITEM* item = nullptr;
bool isText = aEvent.IsAction( &EE_ACTIONS::placeSymbolText );
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
@ -92,20 +97,30 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
controls->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( aEvent.HasPosition() || ( isText && !aEvent.IsReactivate() ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
if( aEvent.HasPosition() )
{
m_toolMgr->PrimeTool( aEvent.Position() );
}
else if( !aEvent.IsReactivate() && isText )
{
m_toolMgr->PrimeTool( { 0, 0 } );
ignorePrimePosition = true;
}
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
cursorPos = grid.Align( controls->GetMousePosition() );
controls->ForceCursorPosition( true, cursorPos );
auto cleanup =
[&] ()
@ -132,12 +147,26 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
}
else if( evt->IsActivate() )
{
if( item )
cleanup();
if( evt->IsMoveTool() )
if( item && evt->IsMoveTool() )
{
// we're already moving our own item; ignore the move tool
evt->SetPassEvent( false );
continue;
}
if( item )
{
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel item creation." ) );
evt->SetPassEvent( false );
continue;
}
if( evt->IsPointEditor() )
{
// don't exit (the point editor runs in the background)
}
else if( evt->IsMoveTool() )
{
// leave ourselves on the stack so we come back after the move
break;
}
else
@ -188,11 +217,17 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
wxFAIL_MSG( wxT( "TwoClickPlace(): unknown type" ) );
}
// Restore cursor after dialog
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
// If we started with a click on a tool button or menu then continue with the
// current mouse position. Otherwise warp back to the original click position.
if( evt->IsPrime() && ignorePrimePosition )
cursorPos = grid.Align( controls->GetMousePosition() );
else
controls->WarpCursor( cursorPos, true );
if( item )
{
item->SetPosition( wxPoint( cursorPos.x, -cursorPos.y ) );
item->SetFlags( IS_NEW | IS_MOVING );
m_view->ClearPreview();
m_view->AddToPreview( item->Clone() );
@ -202,7 +237,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
setCursor();
}
getViewControls()->SetCursorPosition( cursorPos, false );
controls->SetCursorPosition( cursorPos, false );
}
// ... and second click places:
else
@ -239,7 +274,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
}
else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
{
static_cast<LIB_ITEM*>( item )->SetPosition( wxPoint( cursorPos.x, -cursorPos.y ) );
item->SetPosition( wxPoint( cursorPos.x, -cursorPos.y ) );
m_view->ClearPreview();
m_view->AddToPreview( item->Clone() );
}
@ -249,12 +284,12 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
}
// Enable autopanning and cursor capture only when there is an item to be placed
getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr );
controls->SetAutoPan( item != nullptr );
controls->CaptureCursor( item != nullptr );
}
getViewControls()->SetAutoPan( false );
getViewControls()->CaptureCursor( false );
controls->SetAutoPan( false );
controls->CaptureCursor( false );
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
return 0;
}