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" ); wxFAIL_MSG( "PlaceSymbol(): unexpected request" );
} }
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
auto addSymbol = auto addSymbol =
[&]( SCH_SYMBOL* aSymbol ) [&]( SCH_SYMBOL* aSymbol )
@ -169,6 +166,12 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
symbol = nullptr; 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 // Prime the pump
if( symbol ) if( symbol )
{ {
@ -180,9 +183,6 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::cursorClick ); m_toolMgr->RunAction( EE_ACTIONS::cursorClick );
} }
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
@ -378,7 +378,6 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inPlaceImage ); REENTRANCY_GUARD guard( &m_inPlaceImage );
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
// Add all the drawable symbols to preview // Add all the drawable symbols to preview
if( image ) if( image )
@ -390,8 +389,6 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
auto setCursor = auto setCursor =
[&]() [&]()
{ {
@ -410,15 +407,18 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
image = nullptr; 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 // Prime the pump
if( image ) if( image )
m_toolMgr->RunAction( ACTIONS::refreshPreview ); m_toolMgr->RunAction( ACTIONS::refreshPreview );
else if( !aEvent.IsReactivate() ) else if( !aEvent.IsReactivate() )
m_toolMgr->RunAction( ACTIONS::cursorClick ); m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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 ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
cursorPos = static_cast<wxPoint>( aEvent.HasPosition() ? cursorPos = static_cast<wxPoint>( aEvent.HasPosition() ?
aEvent.Position() : aEvent.Position() :
@ -667,7 +666,18 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
};
Activate(); 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->ClearPreview();
m_view->AddToPreview( previewItem->Clone() ); m_view->AddToPreview( previewItem->Clone() );
@ -678,15 +688,6 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
else else
m_toolMgr->RunAction( ACTIONS::refreshPreview ); m_toolMgr->RunAction( ACTIONS::refreshPreview );
auto setCursor =
[&]()
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
};
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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; int snapLayer = isText ? LAYER_GRAPHICS : LAYER_CONNECTABLE;
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
auto setCursor = auto setCursor =
[&]() [&]()
{ {
@ -1035,17 +1033,19 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
item = nullptr; item = nullptr;
}; };
// Prime the pump Activate();
// If the tool isn't being re-activated // 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() if( aEvent.HasPosition() || ( !aEvent.IsReactivate()
&& ( isText || isGlobalLabel || isHierLabel || isNetLabel ) ) ) && ( isText || isGlobalLabel || isHierLabel || isNetLabel ) ) )
{ {
m_toolMgr->RunAction( ACTIONS::cursorClick ); m_toolMgr->RunAction( ACTIONS::cursorClick );
} }
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
@ -1248,11 +1248,9 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inDrawSheet ); REENTRANCY_GUARD guard( &m_inDrawSheet );
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
auto setCursor = auto setCursor =
[&]() [&]()
@ -1269,13 +1267,16 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
sheet = nullptr; 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 // Prime the pump
if( aEvent.HasPosition() ) if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick ); m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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 ); m_view->ShowPreview( false );
}; };
controls->ShowCursor( true );
Activate(); 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 // Add the new label to the selection so the rotate command operates on it
if( m_busUnfold.label ) 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() ) if( !m_wires.empty() )
segment = m_wires.back(); segment = m_wires.back();
// Set initial cursor
setCursor();
wxPoint contextMenuPos; wxPoint contextMenuPos;
// Main loop: keep receiving events // 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; std::vector<DANGLING_END_ITEM> internalPoints;
Activate(); Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true ); controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); 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 ); bool isText = aEvent.IsAction( &EE_ACTIONS::placeSymbolText );
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
// Prime the pump
if( aEvent.HasPosition() || ( isText && !aEvent.IsReactivate() ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor = auto setCursor =
[&]() [&]()
@ -99,9 +93,16 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL ); 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 // Set initial cursor
setCursor(); setCursor();
// Prime the pump
if( aEvent.HasPosition() || ( isText && !aEvent.IsReactivate() ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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 ) 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>(); 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 // We might be running as the same shape in another co-routine. Make sure that one
// gets whacked. // gets whacked.
m_toolMgr->DeactivateTool(); m_toolMgr->DeactivateTool();
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); 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 = auto setCursor =
[&]() [&]()
@ -289,9 +284,25 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL ); 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 // Set initial cursor
setCursor(); setCursor();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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() ); 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( evt->IsCancelInteractive() )
{ {
if( item ) 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 ) int SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
{ {
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
auto setCursor = auto setCursor =
[&]() [&]()
@ -437,6 +436,9 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE ); 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 // Set initial cursor
setCursor(); setCursor();

View File

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

View File

@ -81,15 +81,9 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
bool isText = aEvent.IsAction( &PL_ACTIONS::placeText ); bool isText = aEvent.IsAction( &PL_ACTIONS::placeText );
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
// Prime the pump
if( aEvent.HasPosition() || ( !aEvent.IsReactivate() && isText ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor = auto setCursor =
[&]() [&]()
@ -100,8 +94,17 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( isText ? KICURSOR::TEXT : KICURSOR::PENCIL ); 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(); setCursor();
// Prime the pump
if( aEvent.HasPosition() || ( !aEvent.IsReactivate() && isText ) )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
@ -229,15 +232,9 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_toolMgr->DeactivateTool(); m_toolMgr->DeactivateTool();
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor = auto setCursor =
[&]() [&]()
@ -245,9 +242,16 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL ); 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 // Set initial cursor
setCursor(); setCursor();
// Prime the pump
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate();
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true ); controls->ShowCursor( true );
controls->SetAutoPan( 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 }; static KICAD_T pointTypes[] = { WSG_LINE_T, WSG_RECT_T, EOT };
if( !m_selectionTool ) KIGFX::VIEW_CONTROLS* controls = getViewControls();
return 0; const PL_SELECTION& selection = m_selectionTool->GetSelection();
const PL_SELECTION& selection = m_selectionTool->GetSelection();
if( selection.Size() != 1 || !selection.Front()->IsType( pointTypes ) ) if( selection.Size() != 1 || !selection.Front()->IsType( pointTypes ) )
return 0; return 0;
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
// Wait till drawing tool is done // Wait till drawing tool is done
if( selection.Front()->IsNew() ) if( item->IsNew() )
return 0; return 0;
Activate(); Activate();
// Must be done after Activate() so that it gets set into the correct context
KIGFX::VIEW_CONTROLS* controls = getViewControls();
KIGFX::VIEW* view = getView();
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
controls->ShowCursor( true ); controls->ShowCursor( true );
m_editPoints = EDIT_POINTS_FACTORY::Make( item ); m_editPoints = EDIT_POINTS_FACTORY::Make( item );
@ -181,7 +177,7 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
if( !m_editPoints ) if( !m_editPoints )
return 0; return 0;
view->Add( m_editPoints.get() ); getView()->Add( m_editPoints.get() );
setEditedPoint( nullptr ); setEditedPoint( nullptr );
updateEditedPoint( aEvent ); updateEditedPoint( aEvent );
bool inDrag = false; bool inDrag = false;
@ -245,7 +241,7 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
if( m_editPoints ) if( m_editPoints )
{ {
view->Remove( m_editPoints.get() ); getView()->Remove( m_editPoints.get() );
if( modified ) if( modified )
m_frame->OnModify(); m_frame->OnModify();

View File

@ -116,23 +116,6 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
frame.PushTool( tool ); 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 = auto setCursor =
[&]() [&]()
@ -140,9 +123,23 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
frame.GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL ); 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 // Set initial cursor
setCursor(); 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() ) while( auto evt = Wait() )
{ {
setCursor(); setCursor();

View File

@ -270,19 +270,19 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
frame()->PushTool( tool ); frame()->PushTool( tool );
Activate();
m_lastTuneMode = aEvent.Parameter<PNS::ROUTER_MODE>(); m_lastTuneMode = aEvent.Parameter<PNS::ROUTER_MODE>();
m_router->SetMode( m_lastTuneMode ); m_router->SetMode( m_lastTuneMode );
controls()->ShowCursor( true );
auto setCursor = auto setCursor =
[&]() [&]()
{ {
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); 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 // Set initial cursor
setCursor(); setCursor();

View File

@ -1253,6 +1253,7 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
{ {
PNS::ROUTER_MODE mode = aEvent.Parameter<PNS::ROUTER_MODE>(); PNS::ROUTER_MODE mode = aEvent.Parameter<PNS::ROUTER_MODE>();
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>(); PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
VIEW_CONTROLS* controls = getViewControls();
if( m_router->RoutingInProgress() ) if( m_router->RoutingInProgress() )
{ {
@ -1267,18 +1268,6 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
frame->PushTool( tool ); 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 = auto setCursor =
[&]() [&]()
@ -1286,9 +1275,20 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL ); 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 // Set initial cursor
setCursor(); 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 // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {

View File

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

View File

@ -533,14 +533,16 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
// do not capture or auto-pan until we start placing the table // do not capture or auto-pan until we start placing the table
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate(); Activate();
// Must be done after Activate() so that it gets set into the correct context
m_controls->ShowCursor( true );
// Prime the pump // Prime the pump
if( aEvent.HasPosition() ) 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_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(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate(); 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 // Prime the pump
if( !aEvent.IsReactivate() ) if( !aEvent.IsReactivate() )
m_toolMgr->RunAction( ACTIONS::cursorClick ); m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate(); 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 // Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview ); m_toolMgr->RunAction( ACTIONS::refreshPreview );
@ -750,9 +755,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
if( aEvent.HasPosition() ) if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( aEvent.Position() ); m_toolMgr->PrimeTool( aEvent.Position() );
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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::selectionClear, true );
m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &selectedItems ); 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->ShowCursor( true );
m_controls->ForceCursorPosition( false ); m_controls->ForceCursorPosition( false );
// Set initial cursor
setCursor();
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
@ -1223,19 +1238,6 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
m_view->Update( &preview ); 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 // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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 ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); 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 = auto setCursor =
[&]() [&]()
@ -1320,6 +1318,11 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE ); 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 // Set initial cursor
setCursor(); setCursor();
@ -1422,8 +1425,6 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
m_view->Add( &preview ); m_view->Add( &preview );
m_view->Add( &twoPointAsst ); m_view->Add( &twoPointAsst );
m_controls->ShowCursor( true );
bool started = false; bool started = false;
bool cancelled = false; bool cancelled = false;
bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) ); 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_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
}; };
m_controls->ShowCursor( true );
// Set initial cursor
setCursor();
// Prime the pump // Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview ); m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aStartingPoint ) if( aStartingPoint )
m_toolMgr->RunAction( ACTIONS::cursorClick ); m_toolMgr->RunAction( ACTIONS::cursorClick );
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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 ); m_view->Add( &arcAsst );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_controls->ShowCursor( true );
bool firstPoint = false;
bool cancelled = false;
// Set initial cursor
auto setCursor = auto setCursor =
[&]() [&]()
{ {
@ -1763,14 +1759,19 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool
*aGraphic = nullptr; *aGraphic = nullptr;
}; };
m_controls->ShowCursor( true );
// Set initial cursor
setCursor();
bool firstPoint = false;
bool cancelled = false;
// Prime the pump // Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview ); m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aImmediateMode ) if( aImmediateMode )
m_toolMgr->RunAction( ACTIONS::cursorClick ); m_toolMgr->RunAction( ACTIONS::cursorClick );
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
@ -2044,24 +2045,20 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
else else
params.m_layer = m_frame->GetActiveLayer(); params.m_layer = m_frame->GetActiveLayer();
ZONE_CREATE_HELPER zoneTool( *this, params ); ZONE_CREATE_HELPER zoneTool( *this, params );
// the geometry manager which handles the zone geometry, and hands the calculated points
// the geometry manager which handles the zone geometry, and // over to the zone creator tool
// hands the calculated points over to the zone creator tool
POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool ); 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(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); 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 = auto setCursor =
[&]() [&]()
@ -2079,13 +2076,16 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
m_controls->CaptureCursor( false ); 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 // Prime the pump
if( aEvent.HasPosition() ) if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( aEvent.Position() ); m_toolMgr->PrimeTool( aEvent.Position() );
// Set initial cursor
setCursor();
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) 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 ) if( selection.Size() != 1 || selection.Front()->Type() != PCB_ARC_T )
return 0; return 0;
Activate();
PCB_ARC* theArc = static_cast<PCB_ARC*>( selection.Front() ); PCB_ARC* theArc = static_cast<PCB_ARC*>( selection.Front() );
double arcAngleDegrees = std::abs( theArc->GetAngle() ) / 10.0; 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(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true ); controls->ShowCursor( true );
controls->SetAutoPan( true ); controls->SetAutoPan( true );
bool restore_state = false;
bool restore_state = false;
VECTOR2I arcCenter = theArc->GetCenter(); VECTOR2I arcCenter = theArc->GetCenter();
SEG tanStart = SEG( arcCenter, theArc->GetStart() ).PerpendicularSeg( theArc->GetStart() ); SEG tanStart = SEG( arcCenter, theArc->GetStart() ).PerpendicularSeg( theArc->GetStart() );
SEG tanEnd = SEG( arcCenter, theArc->GetEnd() ).PerpendicularSeg( theArc->GetEnd() ); 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(); std::string tool = aEvent.GetCommandStr().get();
editFrame->PushTool( tool ); editFrame->PushTool( tool );
Activate(); Activate();
// Must be done after Activate() so that it gets set into the correct context
controls->ShowCursor( true ); controls->ShowCursor( true );
controls->SetAutoPan( 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() ) if( !board()->GetFirstFootprint() || board()->GetFirstFootprint()->Pads().empty() )
return 0; 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; GENERAL_COLLECTOR collector;
const KICAD_T types[] = { PCB_PAD_T, EOT }; const KICAD_T types[] = { PCB_PAD_T, EOT };
@ -289,25 +280,25 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
guide.SetIgnoreModulesVals( true ); guide.SetIgnoreModulesVals( true );
guide.SetIgnoreModulesRefs( true ); guide.SetIgnoreModulesRefs( true );
int seqPadNum = settingsDlg.GetStartNumber(); DIALOG_ENUM_PADS settingsDlg( frame() );
wxString padPrefix = settingsDlg.GetPrefix();
if( settingsDlg.ShowModal() != wxID_OK )
return 0;
int seqPadNum = settingsDlg.GetStartNumber();
wxString padPrefix = settingsDlg.GetPrefix();
std::deque<int> storedPadNumbers; std::deque<int> storedPadNumbers;
std::map<wxString, std::pair<int, wxString>> oldNumbers;
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
getViewControls()->ShowCursor( true );
KIGFX::VIEW* view = m_toolMgr->GetView(); std::string tool = aEvent.GetCommandStr().get();
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag frame()->PushTool( tool );
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
std::list<PAD*> selectedPads; std::list<PAD*> selectedPads;
BOARD_COMMIT commit( frame() ); BOARD_COMMIT commit( frame() );
std::map<wxString, std::pair<int, wxString>> oldNumbers; bool isFirstPoint = true; // make sure oldCursorPos is initialized at least once
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 ) );
auto setCursor = auto setCursor =
[&]() [&]()
@ -315,9 +306,18 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE ); 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 // Set initial cursor
setCursor(); 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() ) while( TOOL_EVENT* evt = Wait() )
{ {
setCursor(); setCursor();
@ -452,7 +452,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
for( PAD* p : board()->GetFirstFootprint()->Pads() ) for( PAD* p : board()->GetFirstFootprint()->Pads() )
{ {
p->ClearSelected(); p->ClearSelected();
view->Update( p ); getView()->Update( p );
} }
statusPopup.Hide(); statusPopup.Hide();

View File

@ -416,6 +416,7 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
return 0; return 0;
Activate(); Activate();
// Must be done after Activate() so that it gets set into the correct context
getViewControls()->ShowCursor( true ); getViewControls()->ShowCursor( true );
PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() ); 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; std::unique_ptr<BOARD_ITEM> newItem;
frame()->PushTool( aTool ); frame()->PushTool( aTool );
Activate();
BOARD_COMMIT commit( frame() ); BOARD_COMMIT commit( frame() );
GetManager()->RunAction( PCB_ACTIONS::selectionClear, true ); 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 ); controls()->ShowCursor( true );
// do not capture or auto-pan until we start placing an item
PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() ); 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 ) int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
{ {
if( IsFootprintFrame() && !frame()->GetModel() ) if( IsFootprintFrame() && !frame()->GetModel() )
@ -207,30 +210,36 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
frame()->PushTool( tool ); 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(); EDA_UNITS units = frame()->GetUserUnits();
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units ); KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
view.Add( &ruler ); view.Add( &ruler );
view.SetVisible( &ruler, false ); 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 = auto setCursor =
[&]() [&]()
{ {
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE ); 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 // Set initial cursor
setCursor(); setCursor();
@ -242,20 +251,11 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr ); const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
controls.ForceCursorPosition(true, cursorPos ); controls.ForceCursorPosition(true, cursorPos );
auto clearRuler =
[&] ()
{
view.SetVisible( &ruler, false );
controls.SetAutoPan( false );
controls.CaptureCursor( false );
originSet = false;
};
if( evt->IsCancelInteractive() ) if( evt->IsCancelInteractive() )
{ {
if( originSet ) if( originSet )
{ {
clearRuler(); cleanup();
} }
else else
{ {
@ -266,7 +266,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
else if( evt->IsActivate() ) else if( evt->IsActivate() )
{ {
if( originSet ) if( originSet )
clearRuler(); cleanup();
if( evt->IsMoveTool() ) if( evt->IsMoveTool() )
{ {