Don't push view control settings to the previous active tool.

See further comments in bug report.

Fixes https://gitlab.com/kicad/code/kicad/issues/9147
This commit is contained in:
Jeff Young 2021-09-13 13:23:10 +01:00
parent efc9279a19
commit fdfecf5932
20 changed files with 285 additions and 279 deletions

View File

@ -131,11 +131,8 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
wxFAIL_MSG( "PlaceSymbol(): unexpected request" );
}
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
auto addSymbol =
[&]( SCH_SYMBOL* aSymbol )
@ -169,6 +166,12 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
symbol = nullptr;
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( symbol )
{
@ -180,9 +183,6 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::cursorClick );
}
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -378,7 +378,6 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inPlaceImage );
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
// Add all the drawable symbols to preview
if( image )
@ -390,8 +389,6 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
auto setCursor =
[&]()
{
@ -410,15 +407,18 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
image = nullptr;
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( image )
m_toolMgr->RunAction( ACTIONS::refreshPreview );
else if( !aEvent.IsReactivate() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -659,7 +659,6 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
}
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
cursorPos = static_cast<wxPoint>( aEvent.HasPosition() ?
aEvent.Position() :
@ -667,7 +666,18 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
m_view->ClearPreview();
m_view->AddToPreview( previewItem->Clone() );
@ -678,15 +688,6 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
else
m_toolMgr->RunAction( ACTIONS::refreshPreview );
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
};
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -992,12 +993,9 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
int snapLayer = isText ? LAYER_GRAPHICS : LAYER_CONNECTABLE;
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
auto setCursor =
[&]()
{
@ -1035,17 +1033,19 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
item = nullptr;
};
// Prime the pump
// If the tool isn't being re-activated
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump if the tool isn't being re-activated
if( aEvent.HasPosition() || ( !aEvent.IsReactivate()
&& ( isText || isGlobalLabel || isHierLabel || isNetLabel ) ) )
{
m_toolMgr->RunAction( ACTIONS::cursorClick );
}
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -1248,11 +1248,9 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inDrawSheet );
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
auto setCursor =
[&]()
@ -1269,13 +1267,16 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
sheet = nullptr;
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{

View File

@ -514,9 +514,11 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType,
m_view->ShowPreview( false );
};
controls->ShowCursor( true );
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
// Set initial cursor
setCursor();
// Add the new label to the selection so the rotate command operates on it
if( m_busUnfold.label )
@ -526,9 +528,6 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType,
if( !m_wires.empty() )
segment = m_wires.back();
// Set initial cursor
setCursor();
wxPoint contextMenuPos;
// Main loop: keep receiving events

View File

@ -134,6 +134,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
std::vector<DANGLING_END_ITEM> internalPoints;
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();

View File

@ -78,15 +78,9 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
bool isText = aEvent.IsAction( &EE_ACTIONS::placeSymbolText );
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Prime the pump
if( aEvent.HasPosition() || ( isText && !aEvent.IsReactivate() ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor =
[&]()
@ -99,9 +93,16 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( aEvent.HasPosition() || ( isText && !aEvent.IsReactivate() ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -262,26 +263,20 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
{
SYMBOL_EDITOR_SETTINGS* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
SYMBOL_EDITOR_SETTINGS* settings = settingsMgr.GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
KICAD_T type = aEvent.Parameter<KICAD_T>();
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
LIB_ITEM* item = nullptr;
// We might be running as the same shape in another co-routine. Make sure that one
// gets whacked.
m_toolMgr->DeactivateTool();
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
LIB_ITEM* item = nullptr;
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor =
[&]()
@ -289,9 +284,25 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
};
auto cleanup =
[&] ()
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_view->ClearPreview();
delete item;
item = nullptr;
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -299,15 +310,6 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
auto cleanup =
[&] ()
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_view->ClearPreview();
delete item;
item = nullptr;
};
if( evt->IsCancelInteractive() )
{
if( item )
@ -425,11 +427,8 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
int SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
{
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
auto setCursor =
[&]()
@ -437,6 +436,9 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();

View File

@ -108,8 +108,9 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
controls->SetAutoPan( true );

View File

@ -196,27 +196,19 @@ int GERBVIEW_INSPECTION_TOOL::ShowSource( const TOOL_EVENT& aEvent )
}
using KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER;
int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW& view = *getView();
KIGFX::VIEW_CONTROLS& controls = *getViewControls();
KIGFX::VC_SETTINGS previous_settings = controls.GetSettings();
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
KIGFX::VIEW_CONTROLS& controls = *getViewControls();
bool originSet = false;
TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
EDA_UNITS units = m_frame->GetUserUnits();
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
view.Add( &ruler );
view.SetVisible( &ruler, false );
bool originSet = false;
controls.ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
auto setCursor =
[&]()
@ -224,28 +216,34 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE );
};
auto cleanup =
[&] ()
{
getView()->SetVisible( &ruler, false );
controls.SetAutoPan( false );
controls.CaptureCursor( false );
originSet = false;
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls.ShowCursor( true );
// Set initial cursor
setCursor();
getView()->Add( &ruler );
getView()->SetVisible( &ruler, false );
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
const VECTOR2I cursorPos = controls.GetCursorPosition();
auto clearRuler =
[&] ()
{
view.SetVisible( &ruler, false );
controls.SetAutoPan( false );
controls.CaptureCursor( false );
originSet = false;
};
if( evt->IsCancelInteractive() )
{
if( originSet )
{
clearRuler();
cleanup();
}
else
{
@ -256,7 +254,7 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
else if( evt->IsActivate() )
{
if( originSet )
clearRuler();
cleanup();
if( evt->IsMoveTool() )
{
@ -294,8 +292,8 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
twoPtMgr.SetAngleSnap( evt->Modifier( MD_SHIFT ) );
twoPtMgr.SetEnd( cursorPos );
view.SetVisible( &ruler, true );
view.Update( &ruler, KIGFX::GEOMETRY );
getView()->SetVisible( &ruler, true );
getView()->Update( &ruler, KIGFX::GEOMETRY );
}
else if( evt->IsAction( &ACTIONS::updateUnits ) )
{
@ -303,7 +301,7 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
{
units = m_frame->GetUserUnits();
ruler.SwitchUnits( units );
view.Update( &ruler, KIGFX::GEOMETRY );
getView()->Update( &ruler, KIGFX::GEOMETRY );
}
evt->SetPassEvent();
}
@ -317,10 +315,9 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
}
}
view.SetVisible( &ruler, false );
view.Remove( &ruler );
getView()->SetVisible( &ruler, false );
getView()->Remove( &ruler );
controls.ApplySettings( previous_settings );
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
return 0;
}

View File

@ -81,15 +81,9 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
bool isText = aEvent.IsAction( &PL_ACTIONS::placeText );
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Prime the pump
if( aEvent.HasPosition() || ( !aEvent.IsReactivate() && isText ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor =
[&]()
@ -100,8 +94,17 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( isText ? KICURSOR::TEXT : KICURSOR::PENCIL );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( aEvent.HasPosition() || ( !aEvent.IsReactivate() && isText ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -229,15 +232,9 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_toolMgr->DeactivateTool();
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor =
[&]()
@ -245,9 +242,16 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{

View File

@ -119,8 +119,9 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
controls->SetAutoPan( true );

View File

@ -156,24 +156,20 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
{
static KICAD_T pointTypes[] = { WSG_LINE_T, WSG_RECT_T, EOT };
if( !m_selectionTool )
return 0;
const PL_SELECTION& selection = m_selectionTool->GetSelection();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
const PL_SELECTION& selection = m_selectionTool->GetSelection();
if( selection.Size() != 1 || !selection.Front()->IsType( pointTypes ) )
return 0;
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
// Wait till drawing tool is done
if( selection.Front()->IsNew() )
if( item->IsNew() )
return 0;
Activate();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
KIGFX::VIEW* view = getView();
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
m_editPoints = EDIT_POINTS_FACTORY::Make( item );
@ -181,7 +177,7 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
if( !m_editPoints )
return 0;
view->Add( m_editPoints.get() );
getView()->Add( m_editPoints.get() );
setEditedPoint( nullptr );
updateEditedPoint( aEvent );
bool inDrag = false;
@ -245,7 +241,7 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
if( m_editPoints )
{
view->Remove( m_editPoints.get() );
getView()->Remove( m_editPoints.get() );
if( modified )
m_frame->OnModify();

View File

@ -116,23 +116,6 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
frame.PushTool( tool );
Activate();
TWO_POINT_GEOMETRY_MANAGER tpGeomMgr;
CENTRELINE_RECT_ITEM previewRect( tpGeomMgr, inductorAreaAspect );
previewRect.SetFillColor( inductorAreaFill );
previewRect.SetStrokeColor( inductorAreaStroke );
previewRect.SetLineWidth( inductorAreaStrokeWidth );
bool originSet = false;
controls.ShowCursor( true );
controls.CaptureCursor( false );
controls.SetAutoPan( false );
view.Add( &previewRect );
auto setCursor =
[&]()
@ -140,9 +123,23 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
frame.GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls.ShowCursor( true );
controls.CaptureCursor( false );
controls.SetAutoPan( false );
// Set initial cursor
setCursor();
bool originSet = false;
TWO_POINT_GEOMETRY_MANAGER tpGeomMgr;
CENTRELINE_RECT_ITEM previewRect( tpGeomMgr, inductorAreaAspect );
previewRect.SetFillColor( inductorAreaFill );
previewRect.SetStrokeColor( inductorAreaStroke );
previewRect.SetLineWidth( inductorAreaStrokeWidth );
view.Add( &previewRect );
while( auto evt = Wait() )
{
setCursor();

View File

@ -270,19 +270,19 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
frame()->PushTool( tool );
Activate();
m_lastTuneMode = aEvent.Parameter<PNS::ROUTER_MODE>();
m_router->SetMode( m_lastTuneMode );
controls()->ShowCursor( true );
auto setCursor =
[&]()
{
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls()->ShowCursor( true );
// Set initial cursor
setCursor();

View File

@ -1253,6 +1253,7 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
{
PNS::ROUTER_MODE mode = aEvent.Parameter<PNS::ROUTER_MODE>();
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
VIEW_CONTROLS* controls = getViewControls();
if( m_router->RoutingInProgress() )
{
@ -1267,18 +1268,6 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
frame->PushTool( tool );
Activate();
m_router->SetMode( mode );
VIEW_CONTROLS* ctls = getViewControls();
ctls->ShowCursor( true );
ctls->ForceCursorPosition( false );
m_cancelled = false;
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( ctls->GetCursorPosition( false ) );
auto setCursor =
[&]()
@ -1286,9 +1275,20 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
controls->ForceCursorPosition( false );
// Set initial cursor
setCursor();
m_router->SetMode( mode );
m_cancelled = false;
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( controls->GetCursorPosition( false ) );
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{

View File

@ -940,11 +940,21 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent )
BOARD* board = getModel<BOARD>();
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
// Set initial cursor
setCursor();
VECTOR2I cursorPos = controls->GetCursorPosition();
bool reselect = false;
@ -960,15 +970,6 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent )
else if( !aEvent.IsReactivate() )
m_toolMgr->RunAction( PCB_ACTIONS::cursorClick );
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
};
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{

View File

@ -533,14 +533,16 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
BOARD_COMMIT commit( m_frame );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
// do not capture or auto-pan until we start placing the table
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Must be done after Activate() so that it gets set into the correct context
m_controls->ShowCursor( true );
// Prime the pump
if( aEvent.HasPosition() )

View File

@ -484,20 +484,21 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
};
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
// do not capture or auto-pan until we start placing some text
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Must be done after Activate() so that it gets set into the correct context
m_controls->ShowCursor( true );
// do not capture or auto-pan until we start placing some text
// Set initial cursor
setCursor();
// Prime the pump
if( !aEvent.IsReactivate() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -738,11 +739,15 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
};
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Must be done after Activate() so that it gets set into the correct context
m_controls->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
@ -750,9 +755,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( aEvent.Position() );
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -1209,8 +1211,21 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &selectedItems );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
m_controls->ShowCursor( true );
m_controls->ForceCursorPosition( false );
// Set initial cursor
setCursor();
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
@ -1223,19 +1238,6 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
m_view->Update( &preview );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
};
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -1305,14 +1307,10 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
m_controls->SetAutoPan( true );
m_controls->CaptureCursor( false );
auto setCursor =
[&]()
@ -1320,6 +1318,11 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
m_controls->ShowCursor( true );
m_controls->SetAutoPan( true );
m_controls->CaptureCursor( false );
// Set initial cursor
setCursor();
@ -1422,8 +1425,6 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
m_view->Add( &preview );
m_view->Add( &twoPointAsst );
m_controls->ShowCursor( true );
bool started = false;
bool cancelled = false;
bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
@ -1447,15 +1448,16 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
};
m_controls->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aStartingPoint )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -1743,12 +1745,6 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool
m_view->Add( &arcAsst );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_controls->ShowCursor( true );
bool firstPoint = false;
bool cancelled = false;
// Set initial cursor
auto setCursor =
[&]()
{
@ -1763,14 +1759,19 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool
*aGraphic = nullptr;
};
m_controls->ShowCursor( true );
// Set initial cursor
setCursor();
bool firstPoint = false;
bool cancelled = false;
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aImmediateMode )
m_toolMgr->RunAction( ACTIONS::cursorClick );
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
@ -2044,24 +2045,20 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
else
params.m_layer = m_frame->GetActiveLayer();
ZONE_CREATE_HELPER zoneTool( *this, params );
// the geometry manager which handles the zone geometry, and
// hands the calculated points over to the zone creator tool
ZONE_CREATE_HELPER zoneTool( *this, params );
// the geometry manager which handles the zone geometry, and hands the calculated points
// over to the zone creator tool
POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
bool constrainAngle = false;
bool constrainAngle = false;
bool started = false;
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
STATUS_TEXT_POPUP status( m_frame );
status.SetTextColor( wxColour( 255, 0, 0 ) );
status.SetText( _( "Self-intersecting polygons are not allowed" ) );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate(); // register for events
m_controls->ShowCursor( true );
bool started = false;
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
STATUS_TEXT_POPUP status( m_frame );
status.SetTextColor( wxColour( 255, 0, 0 ) );
status.SetText( _( "Self-intersecting polygons are not allowed" ) );
auto setCursor =
[&]()
@ -2079,13 +2076,16 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
m_controls->CaptureCursor( false );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
m_controls->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( aEvent.Position() );
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{

View File

@ -332,8 +332,6 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
if( selection.Size() != 1 || selection.Front()->Type() != PCB_ARC_T )
return 0;
Activate();
PCB_ARC* theArc = static_cast<PCB_ARC*>( selection.Front() );
double arcAngleDegrees = std::abs( theArc->GetAngle() ) / 10.0;
@ -347,10 +345,12 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
KIGFX::VIEW_CONTROLS* controls = getViewControls();
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
controls->SetAutoPan( true );
bool restore_state = false;
bool restore_state = false;
VECTOR2I arcCenter = theArc->GetCenter();
SEG tanStart = SEG( arcCenter, theArc->GetStart() ).PerpendicularSeg( theArc->GetStart() );
SEG tanEnd = SEG( arcCenter, theArc->GetEnd() ).PerpendicularSeg( theArc->GetEnd() );
@ -802,7 +802,9 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
std::string tool = aEvent.GetCommandStr().get();
editFrame->PushTool( tool );
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true );
controls->SetAutoPan( true );

View File

@ -270,15 +270,6 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
if( !board()->GetFirstFootprint() || board()->GetFirstFootprint()->Pads().empty() )
return 0;
DIALOG_ENUM_PADS settingsDlg( frame() );
if( settingsDlg.ShowModal() != wxID_OK )
return 0;
std::string tool = aEvent.GetCommandStr().get();
frame()->PushTool( tool );
Activate();
GENERAL_COLLECTOR collector;
const KICAD_T types[] = { PCB_PAD_T, EOT };
@ -289,25 +280,25 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
guide.SetIgnoreModulesVals( true );
guide.SetIgnoreModulesRefs( true );
int seqPadNum = settingsDlg.GetStartNumber();
wxString padPrefix = settingsDlg.GetPrefix();
DIALOG_ENUM_PADS settingsDlg( frame() );
if( settingsDlg.ShowModal() != wxID_OK )
return 0;
int seqPadNum = settingsDlg.GetStartNumber();
wxString padPrefix = settingsDlg.GetPrefix();
std::deque<int> storedPadNumbers;
std::map<wxString, std::pair<int, wxString>> oldNumbers;
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
getViewControls()->ShowCursor( true );
KIGFX::VIEW* view = m_toolMgr->GetView();
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
std::string tool = aEvent.GetCommandStr().get();
frame()->PushTool( tool );
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
std::list<PAD*> selectedPads;
BOARD_COMMIT commit( frame() );
std::map<wxString, std::pair<int, wxString>> oldNumbers;
bool isFirstPoint = true; // used to be sure oldCursorPos will be initialized at least once.
STATUS_TEXT_POPUP statusPopup( frame() );
wxString msg = _( "Click on pad %s%d\nPress <esc> to cancel or double-click to commit" );
statusPopup.SetText( wxString::Format( msg, padPrefix, seqPadNum ) );
statusPopup.Popup();
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
BOARD_COMMIT commit( frame() );
bool isFirstPoint = true; // make sure oldCursorPos is initialized at least once
auto setCursor =
[&]()
@ -315,9 +306,18 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
// Set initial cursor
setCursor();
STATUS_TEXT_POPUP statusPopup( frame() );
wxString msg = _( "Click on pad %s%d\nPress <esc> to cancel or double-click to commit" );
statusPopup.SetText( wxString::Format( msg, padPrefix, seqPadNum ) );
statusPopup.Popup();
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
@ -452,7 +452,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
for( PAD* p : board()->GetFirstFootprint()->Pads() )
{
p->ClearSelected();
view->Update( p );
getView()->Update( p );
}
statusPopup.Hide();

View File

@ -416,6 +416,7 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
return 0;
Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true );
PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );

View File

@ -42,14 +42,15 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool,
std::unique_ptr<BOARD_ITEM> newItem;
frame()->PushTool( aTool );
Activate();
BOARD_COMMIT commit( frame() );
GetManager()->RunAction( PCB_ACTIONS::selectionClear, true );
// do not capture or auto-pan until we start placing an item
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls()->ShowCursor( true );
// do not capture or auto-pan until we start placing an item
PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );

View File

@ -194,6 +194,9 @@ int PCB_VIEWER_TOOLS::TextOutlines( const TOOL_EVENT& aEvent )
}
using KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER;
int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
{
if( IsFootprintFrame() && !frame()->GetModel() )
@ -207,30 +210,36 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get();
frame()->PushTool( tool );
Activate();
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
bool originSet = false;
EDA_UNITS units = frame()->GetUserUnits();
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
view.Add( &ruler );
view.SetVisible( &ruler, false );
PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
bool originSet = false;
controls.ShowCursor( true );
controls.SetAutoPan( false );
controls.CaptureCursor( false );
auto setCursor =
[&]()
{
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE );
};
auto cleanup =
[&] ()
{
view.SetVisible( &ruler, false );
controls.SetAutoPan( false );
controls.CaptureCursor( false );
originSet = false;
};
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls.ShowCursor( true );
controls.SetAutoPan( false );
controls.CaptureCursor( false );
// Set initial cursor
setCursor();
@ -242,20 +251,11 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
controls.ForceCursorPosition(true, cursorPos );
auto clearRuler =
[&] ()
{
view.SetVisible( &ruler, false );
controls.SetAutoPan( false );
controls.CaptureCursor( false );
originSet = false;
};
if( evt->IsCancelInteractive() )
{
if( originSet )
{
clearRuler();
cleanup();
}
else
{
@ -266,7 +266,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
else if( evt->IsActivate() )
{
if( originSet )
clearRuler();
cleanup();
if( evt->IsMoveTool() )
{