Formatting and organisation.

This commit is contained in:
Jeff Young 2021-04-07 14:50:18 +01:00
parent 21d4197eab
commit e50b450092
1 changed files with 65 additions and 68 deletions

View File

@ -426,39 +426,8 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
BOARD_ITEM* text = NULL;
const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
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 some text
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Prime the pump
if( !aEvent.IsReactivate() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
auto setCursor =
[&]()
{
if( text )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
else
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::TEXT );
};
// Set initial cursor
setCursor();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
VECTOR2I cursorPos = m_controls->GetCursorPosition();
auto cleanup =
[&]()
{
@ -471,10 +440,42 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
text = NULL;
};
auto setCursor =
[&]()
{
if( text )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
else
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::TEXT );
};
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();
// 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() )
{
setCursor();
VECTOR2I cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancelInteractive() )
{
if( text )
{
cleanup();
}
else
{
m_frame->PopTool( tool );
@ -648,27 +649,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
if( m_isFootprintEditor && !m_frame->GetModel() )
return 0;
TOOL_EVENT originalEvent = aEvent;
DIMENSION_BASE* dimension = nullptr;
BOARD_COMMIT commit( m_frame );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
// Add a VIEW_GROUP that serves as a preview for the new item
PCB_SELECTION preview;
m_view->Add( &preview );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
enum DIMENSION_STEPS
{
SET_ORIGIN = 0,
@ -676,13 +656,31 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
SET_HEIGHT,
FINISHED
};
TOOL_EVENT originalEvent = aEvent;
DIMENSION_BASE* dimension = nullptr;
BOARD_COMMIT commit( m_frame );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
PCB_SELECTION preview; // A VIEW_GROUP that serves as a preview for the new item(s)
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
int step = SET_ORIGIN;
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
m_view->Add( &preview );
if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( aEvent.Position() );
auto cleanup =
[&]()
{
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
preview.Clear();
m_view->Update( &preview );
delete dimension;
dimension = nullptr;
step = SET_ORIGIN;
};
auto setCursor =
[&]()
@ -690,6 +688,19 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE );
};
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aEvent.HasPosition() )
m_toolMgr->PrimeTool( aEvent.Position() );
// Set initial cursor
setCursor();
@ -709,20 +720,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
cursorPos = grid.BestSnapAnchor( cursorPos, nullptr );
m_controls->ForceCursorPosition( true, cursorPos );
auto cleanup =
[&]()
{
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
preview.Clear();
m_view->Update( &preview );
delete dimension;
dimension = nullptr;
step = SET_ORIGIN;
};
if( evt->IsCancelInteractive() )
{
m_controls->SetAutoPan( false );