Push Eeschema & PLEditor PICKER_TOOLs down into common.

Also implements a more robust push/pop tool strategy for pickers.
This commit is contained in:
Jeff Young 2019-07-16 00:44:01 +01:00
parent 16f672a9bd
commit e816a0c29d
30 changed files with 530 additions and 939 deletions

View File

@ -379,6 +379,7 @@ set( COMMON_SRCS
tool/edit_constraints.cpp
tool/edit_points.cpp
tool/grid_menu.cpp
tool/picker_tool.cpp
tool/selection_conditions.cpp
tool/tool_action.cpp
tool/tool_base.cpp

View File

@ -481,6 +481,9 @@ TOOL_ACTION ACTIONS::measureTool( "common.InteractiveEdit.measureTool",
_( "Measure Tool" ), _( "Interactively measure distance between points" ),
measurement_xpm, AF_ACTIVATE );
TOOL_ACTION ACTIONS::pickerTool( "common.InteractivePicker.pickerTool",
AS_GLOBAL, 0, "", "", "", NULL, AF_ACTIVATE );
TOOL_ACTION ACTIONS::show3DViewer( "common.Control.show3DViewer",
AS_GLOBAL,
MD_ALT + '3', LEGACY_HK_NAME( "3D Viewer" ),

View File

@ -21,25 +21,22 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <tool/tool_manager.h>
#include <tool/selection_conditions.h>
#include <tools/pl_picker_tool.h>
#include <tools/pl_actions.h>
#include <tool/actions.h>
#include <tool/picker_tool.h>
#include <view/view_controls.h>
#include <pl_editor_frame.h>
#include <eda_draw_frame.h>
PL_PICKER_TOOL::PL_PICKER_TOOL() :
TOOL_INTERACTIVE( "plEditor.InteractivePicker" ),
m_frame( nullptr )
PICKER_TOOL::PICKER_TOOL()
: TOOL_INTERACTIVE( "common.InteractivePicker" )
{
resetPicker();
}
bool PL_PICKER_TOOL::Init()
bool PICKER_TOOL::Init()
{
m_frame = getEditFrame<PL_EDITOR_FRAME>();
m_frame = getEditFrame<EDA_DRAW_FRAME>();
auto& ctxMenu = m_menu.GetMenu();
@ -54,22 +51,24 @@ bool PL_PICKER_TOOL::Init()
}
void PL_PICKER_TOOL::Reset( RESET_REASON aReason )
{
}
int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW_CONTROLS* controls = getViewControls();
int finalize_state = WAIT_CANCEL;
std::string tool = *aEvent.Parameter<std::string*>();
m_frame->PushTool( tool );
Activate();
// To many things are off-grid in LibEdit; turn snapping off.
bool snap = !m_frame->IsType( FRAME_SCH_LIB_EDITOR );
setControls();
while( TOOL_EVENT* evt = Wait() )
{
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
VECTOR2I cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) );
m_frame->GetCanvas()->SetCursor( m_cursor );
VECTOR2D cursorPos = controls->GetCursorPosition( snap && !evt->Modifier( MD_ALT ) );
if( evt->IsClick( BUT_LEFT ) )
{
@ -85,7 +84,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
catch( std::exception& e )
{
std::cerr << "PL_PICKER_TOOL click handler error: " << e.what() << std::endl;
std::cerr << "PICKER_TOOL click handler error: " << e.what() << std::endl;
finalize_state = EXCEPTION_CANCEL;
break;
}
@ -110,7 +109,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
catch( std::exception& e )
{
std::cerr << "PL_PICKER_TOOL motion handler error: " << e.what() << std::endl;
std::cerr << "PICKER_TOOL motion handler error: " << e.what() << std::endl;
}
}
}
@ -125,11 +124,12 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
catch( std::exception& e )
{
std::cerr << "PL_PICKER_TOOL cancel handler error: " << e.what() << std::endl;
std::cerr << "PICKER_TOOL cancel handler error: " << e.what() << std::endl;
}
}
// Activating a new tool may have alternate finalization from canceling the current tool
// Activating a new tool may have alternate finalization from canceling the current
// tool
if( evt->IsActivate() )
finalize_state = END_ACTIVATE;
else
@ -153,33 +153,36 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
catch( std::exception& e )
{
std::cerr << "PL_PICKER_TOOL finalize handler error: " << e.what() << std::endl;
std::cerr << "PICKER_TOOL finalize handler error: " << e.what() << std::endl;
}
}
resetPicker();
controls->ForceCursorPosition( false );
m_frame->PopTool( tool );
return 0;
}
void PL_PICKER_TOOL::setTransitions()
void PICKER_TOOL::setTransitions()
{
Go( &PL_PICKER_TOOL::Main, PL_ACTIONS::pickerTool.MakeEvent() );
Go( &PICKER_TOOL::Main, ACTIONS::pickerTool.MakeEvent() );
}
void PL_PICKER_TOOL::resetPicker()
void PICKER_TOOL::resetPicker()
{
m_cursor = wxStockCursor( wxCURSOR_ARROW );
m_picked = NULLOPT;
m_motionHandler = NULLOPT;
m_clickHandler = NULLOPT;
m_motionHandler = NULLOPT;
m_cancelHandler = NULLOPT;
m_finalizeHandler = NULLOPT;
}
void PL_PICKER_TOOL::setControls()
void PICKER_TOOL::setControls()
{
KIGFX::VIEW_CONTROLS* controls = getViewControls();

View File

@ -220,7 +220,6 @@ set( EESCHEMA_SRCS
tools/backanno.cpp
tools/ee_actions.cpp
tools/ee_inspection_tool.cpp
tools/ee_picker_tool.cpp
tools/ee_point_editor.cpp
tools/ee_selection.cpp
tools/ee_selection_tool.cpp

View File

@ -45,11 +45,11 @@
#include <tool/tool_dispatcher.h>
#include <tool/action_toolbar.h>
#include <tool/common_control.h>
#include <tool/picker_tool.h>
#include <tool/common_tools.h>
#include <tool/zoom_tool.h>
#include <tools/ee_actions.h>
#include <tools/ee_selection_tool.h>
#include <tools/ee_picker_tool.h>
#include <tools/ee_inspection_tool.h>
#include <tools/lib_pin_tool.h>
#include <tools/lib_edit_tool.h>
@ -218,7 +218,7 @@ void LIB_EDIT_FRAME::setupTools()
m_toolManager->RegisterTool( new COMMON_TOOLS );
m_toolManager->RegisterTool( new ZOOM_TOOL );
m_toolManager->RegisterTool( new EE_SELECTION_TOOL );
m_toolManager->RegisterTool( new EE_PICKER_TOOL );
m_toolManager->RegisterTool( new PICKER_TOOL );
m_toolManager->RegisterTool( new EE_INSPECTION_TOOL );
m_toolManager->RegisterTool( new LIB_PIN_TOOL );
m_toolManager->RegisterTool( new LIB_DRAWING_TOOLS );

View File

@ -54,10 +54,10 @@
#include <tool/action_toolbar.h>
#include <tool/common_control.h>
#include <tool/common_tools.h>
#include <tool/picker_tool.h>
#include <tool/zoom_tool.h>
#include <tools/ee_actions.h>
#include <tools/ee_selection_tool.h>
#include <tools/ee_picker_tool.h>
#include <tools/ee_point_editor.h>
#include <tools/sch_drawing_tools.h>
#include <tools/sch_line_wire_bus_tool.h>
@ -336,7 +336,7 @@ void SCH_EDIT_FRAME::setupTools()
m_toolManager->RegisterTool( new COMMON_TOOLS );
m_toolManager->RegisterTool( new ZOOM_TOOL );
m_toolManager->RegisterTool( new EE_SELECTION_TOOL );
m_toolManager->RegisterTool( new EE_PICKER_TOOL );
m_toolManager->RegisterTool( new PICKER_TOOL );
m_toolManager->RegisterTool( new SCH_DRAWING_TOOLS );
m_toolManager->RegisterTool( new SCH_LINE_WIRE_BUS_TOOL );
m_toolManager->RegisterTool( new SCH_MOVE_TOOL );

View File

@ -60,12 +60,6 @@ TOOL_ACTION EE_ACTIONS::showMarkerInfo( "eeschema.InspectionTool.showMarkerInfo"
info_xpm );
// EE_PICKER
//
TOOL_ACTION EE_ACTIONS::pickerTool( "eeschema.InteractivePicker",
AS_GLOBAL, 0, "", "", "", NULL, AF_ACTIVATE );
// EE_POINT_EDITOR
//
TOOL_ACTION EE_ACTIONS::pointEditorAddCorner( "eeschema.PointEditor.addCorner",

View File

@ -1,163 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <ee_picker_tool.h>
#include <ee_actions.h>
#include <view/view_controls.h>
#include <sch_base_frame.h>
EE_PICKER_TOOL::EE_PICKER_TOOL()
: EE_TOOL_BASE<SCH_BASE_FRAME>( "eeschema.InteractivePicker" )
{
resetPicker();
}
int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW_CONTROLS* controls = getViewControls();
int finalize_state = WAIT_CANCEL;
// To many things are off-grid in LibEdit; turn snapping off.
bool snap = !m_isLibEdit;
setControls();
while( TOOL_EVENT* evt = Wait() )
{
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
VECTOR2D cursorPos = controls->GetCursorPosition( snap && !evt->Modifier( MD_ALT ) );
if( evt->IsClick( BUT_LEFT ) )
{
bool getNext = false;
if( m_clickHandler )
{
try
{
getNext = (*m_clickHandler)( cursorPos );
}
catch( std::exception& e )
{
std::cerr << "EE_PICKER_TOOL click handler error: " << e.what() << std::endl;
finalize_state = EXCEPTION_CANCEL;
break;
}
}
if( !getNext )
{
finalize_state = CLICK_CANCEL;
break;
}
else
setControls();
}
else if( evt->IsMotion() )
{
if( m_motionHandler )
{
try
{
(*m_motionHandler)( cursorPos );
}
catch( std::exception& e )
{
std::cerr << "EE_PICKER_TOOL motion handler error: " << e.what() << std::endl;
}
}
}
else if( evt->IsCancelInteractive() || evt->IsActivate() )
{
if( m_cancelHandler )
{
try
{
(*m_cancelHandler)();
}
catch( std::exception& e )
{
std::cerr << "EE_PICKER_TOOL cancel handler error: " << e.what() << std::endl;
}
}
// Activating a new tool may have alternate finalization from canceling the current tool
if( evt->IsActivate() )
finalize_state = END_ACTIVATE;
else
finalize_state = EVT_CANCEL;
break;
}
else if( evt->IsClick( BUT_RIGHT ) )
{
m_menu.ShowContextMenu();
}
else
evt->SetPassEvent();
}
if( m_finalizeHandler )
{
try
{
(*m_finalizeHandler)( finalize_state );
}
catch( std::exception& e )
{
std::cerr << "EE_PICKER_TOOL finalize handler error: " << e.what() << std::endl;
}
}
resetPicker();
controls->ForceCursorPosition( false );
return 0;
}
void EE_PICKER_TOOL::setTransitions()
{
Go( &EE_PICKER_TOOL::Main, EE_ACTIONS::pickerTool.MakeEvent() );
}
void EE_PICKER_TOOL::resetPicker()
{
m_clickHandler = NULLOPT;
m_motionHandler = NULLOPT;
m_cancelHandler = NULLOPT;
m_finalizeHandler = NULLOPT;
}
void EE_PICKER_TOOL::setControls()
{
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->CaptureCursor( false );
controls->SetAutoPan( false );
}

View File

@ -1,116 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef EE_PICKER_TOOL_H
#define EE_PICKER_TOOL_H
#include <boost/optional/optional.hpp>
#include <tools/ee_tool_base.h>
class SCH_BASE_FRAME;
class EE_PICKER_TOOL : public EE_TOOL_BASE<SCH_BASE_FRAME>
{
public:
EE_PICKER_TOOL();
~EE_PICKER_TOOL() {}
///> Event handler types.
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
typedef std::function<void(void)> CANCEL_HANDLER;
typedef std::function<void(const int&)> FINALIZE_HANDLER;
enum pickerEndState
{
WAIT_CANCEL,
CLICK_CANCEL,
END_ACTIVATE,
EVT_CANCEL,
EXCEPTION_CANCEL
};
///> Main event loop.
int Main( const TOOL_EVENT& aEvent );
/**
* Function SetClickHandler()
* Sets a handler for mouse click event. Handler may decide to receive further click by
* returning true.
*/
inline void SetClickHandler( CLICK_HANDLER aHandler )
{
wxASSERT( !m_clickHandler );
m_clickHandler = aHandler;
}
/**
* Function SetMotionHandler()
* Sets a handler for mouse motion. Used for roll-over highlighting.
*/
inline void SetMotionHandler( MOTION_HANDLER aHandler )
{
wxASSERT( !m_motionHandler );
m_motionHandler = aHandler;
}
/**
* Function SetCancelHandler()
* Sets a handler for cancel events (ESC or context-menu Cancel).
*/
inline void SetCancelHandler( CANCEL_HANDLER aHandler )
{
wxASSERT( !m_cancelHandler );
m_cancelHandler = aHandler;
}
/**
* Function SetFinalizeHandler()
* Sets a handler for the finalize event. Takes the state of the exit from the Main loop
*/
inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
{
wxASSERT( !m_finalizeHandler );
m_finalizeHandler = aHandler;
}
private:
///> Reinitializes tool to its initial state.
void resetPicker();
///> Applies the requested VIEW_CONTROLS settings.
void setControls();
///> @copydoc TOOL_INTERACTIVE::setTransitions();
void setTransitions() override;
private:
OPT<CLICK_HANDLER> m_clickHandler;
OPT<MOTION_HANDLER> m_motionHandler;
OPT<CANCEL_HANDLER> m_cancelHandler;
OPT<FINALIZE_HANDLER> m_finalizeHandler;
};
#endif /* EE_PICKER_TOOL_H */

View File

@ -22,8 +22,8 @@
*/
#include <tool/tool_manager.h>
#include <tool/picker_tool.h>
#include <tools/ee_selection_tool.h>
#include <tools/ee_picker_tool.h>
#include <tools/lib_pin_tool.h>
#include <tools/lib_drawing_tools.h>
#include <tools/lib_move_tool.h>
@ -280,16 +280,16 @@ int LIB_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_pickerItem = nullptr;
picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool
picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) );
picker->SetClickHandler(
[this] ( const VECTOR2D& aPosition ) -> bool
{
if( m_pickerItem )
{
@ -303,7 +303,8 @@ int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
return true;
} );
picker->SetMotionHandler( [this] ( const VECTOR2D& aPos )
picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos )
{
EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
@ -326,16 +327,15 @@ int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
}
} );
picker->SetFinalizeHandler( [this] ( const int& aFinalState )
picker->SetFinalizeHandler(
[this] ( const int& aFinalState )
{
if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
} );
picker->Activate();
Wait();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
m_frame->PopTool( tool );
return 0;
}

View File

@ -22,15 +22,14 @@
*/
#include <tool/tool_manager.h>
#include <tool/picker_tool.h>
#include <tools/sch_edit_tool.h>
#include <tools/ee_selection_tool.h>
#include <tools/sch_line_wire_bus_tool.h>
#include <tools/ee_picker_tool.h>
#include <tools/sch_move_tool.h>
#include <ee_actions.h>
#include <bitmaps.h>
#include <confirm.h>
#include <eda_doc.h>
#include <base_struct.h>
#include <sch_item.h>
#include <sch_component.h>
@ -39,7 +38,6 @@
#include <sch_bitmap.h>
#include <sch_view.h>
#include <sch_line.h>
#include <sch_item.h>
#include <sch_bus_entry.h>
#include <sch_edit_frame.h>
#include <eeschema_id.h>
@ -942,16 +940,16 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_pickerItem = nullptr;
picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool
picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) );
picker->SetClickHandler(
[this] ( const VECTOR2D& aPosition ) -> bool
{
if( m_pickerItem )
{
@ -976,7 +974,8 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
return true;
} );
picker->SetMotionHandler( [this] ( const VECTOR2D& aPos )
picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos )
{
EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
@ -999,16 +998,15 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
}
} );
picker->SetFinalizeHandler( [this] ( const int& aFinalState )
picker->SetFinalizeHandler(
[this] ( const int& aFinalState )
{
if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
} );
picker->Activate();
Wait();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
m_frame->PopTool( tool );
return 0;
}

View File

@ -31,13 +31,11 @@
#include <eeschema_id.h>
#include <netlist_object.h>
#include <tool/tool_manager.h>
#include <tool/picker_tool.h>
#include <tools/ee_actions.h>
#include <tools/ee_picker_tool.h>
#include <tools/sch_editor_control.h>
#include <tools/ee_selection.h>
#include <tools/ee_selection_tool.h>
#include <tools/sch_drawing_tools.h>
#include <tools/sch_line_wire_bus_tool.h>
#include <advanced_config.h>
#include <simulation_cursors.h>
#include <sim/sim_plot_frame.h>
@ -142,8 +140,7 @@ int SCH_EDITOR_CONTROL::UpdateFind( const TOOL_EVENT& aEvent )
{
wxFindReplaceData* data = m_frame->GetFindReplaceData();
if( aEvent.IsAction( &ACTIONS::find )
|| aEvent.IsAction( &ACTIONS::findAndReplace )
if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
|| aEvent.IsAction( &ACTIONS::updateFind ) )
{
m_selectionTool->ClearSelection();
@ -298,12 +295,8 @@ int SCH_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent )
}
else
{
wxString msg;
if( searchAllSheets )
msg = _( "Reached end of schematic." );
else
msg = _( "Reached end of sheet." );
wxString msg = searchAllSheets ? _( "Reached end of schematic." )
: _( "Reached end of sheet." );
m_frame->ShowFindReplaceStatus( msg + _( "\nFind again to wrap around to the start." ) );
wrapAroundTimer.StartOnce( 4000 );
@ -352,8 +345,7 @@ int SCH_EDITOR_CONTROL::ReplaceAll( const TOOL_EVENT& aEvent )
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
{
for( EDA_ITEM* item = nextMatch( screen, nullptr, data );
item;
for( EDA_ITEM* item = nextMatch( screen, nullptr, data ); item;
item = nextMatch( screen, item, data ) )
{
item->Replace( *data, schematic.FindSheetForScreen( screen ) );
@ -445,24 +437,32 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF
#ifdef KICAD_SPICE
static bool probeSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition )
int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
{
constexpr KICAD_T wiresAndComponents[] = { SCH_LINE_T, SCH_COMPONENT_T, SCH_SHEET_PIN_T, EOT };
EE_SELECTION_TOOL* selTool = aFrame->GetToolManager()->GetTool<EE_SELECTION_TOOL>();
SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false );
std::string tool = aEvent.GetCommandStr().get();
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
picker->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::PROBE ) );
picker->SetClickHandler(
[&]( const VECTOR2D& aPosition )
{
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item = selTool->SelectPoint( aPosition, wiresAndComponents );
if( !item )
return false;
std::unique_ptr<NETLIST_OBJECT_LIST> netlist( aFrame->BuildNetListBase() );
std::unique_ptr<NETLIST_OBJECT_LIST> netlist( m_frame->BuildNetListBase() );
for( NETLIST_OBJECT* obj : *netlist )
{
if( obj->m_Comp == item )
{
auto simFrame = (SIM_PLOT_FRAME*) aFrame->Kiway().Player( FRAME_SIMULATOR, false );
if( simFrame )
simFrame->AddVoltagePlot( obj->GetNetName() );
@ -471,31 +471,28 @@ static bool probeSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition )
}
return true;
}
} );
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
{
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
m_frame->GetCanvas()->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::PROBE ) );
picker->SetClickHandler( std::bind( probeSimulation, m_frame, std::placeholders::_1 ) );
picker->Activate();
Wait();
m_frame->PopTool( tool );
return 0;
}
static bool tuneSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition )
int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
{
constexpr KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT };
EE_SELECTION_TOOL* selTool = aFrame->GetToolManager()->GetTool<EE_SELECTION_TOOL>();
std::string tool = aEvent.GetCommandStr().get();
SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false );
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
picker->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::TUNE ) );
picker->SetClickHandler(
[&]( const VECTOR2D& aPosition )
{
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item = selTool->SelectPoint( aPosition, fieldsAndComponents );
if( !item )
@ -509,29 +506,14 @@ static bool tuneSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition )
return false;
}
auto simFrame = (SIM_PLOT_FRAME*) aFrame->Kiway().Player( FRAME_SIMULATOR, false );
if( simFrame )
simFrame->AddTuner( static_cast<SCH_COMPONENT*>( item ) );
return true;
}
} );
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
{
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
m_frame->GetCanvas()->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::TUNE ) );
picker->SetClickHandler( std::bind( tuneSimulation, m_frame, std::placeholders::_1 ) );
picker->Activate();
Wait();
m_frame->PopTool( tool );
return 0;
}
#endif /* KICAD_SPICE */
@ -688,17 +670,19 @@ int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent )
if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
m_frame->RecalculateConnections();
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, std::placeholders::_1 ) );
picker->Activate();
Wait();
picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) );
picker->SetClickHandler(
[this]( const VECTOR2D& aPos )
{
return highlightNet( m_toolMgr, aPos );
} );
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
m_frame->PopTool( tool );
return 0;
}
@ -1129,7 +1113,6 @@ int SCH_EDITOR_CONTROL::ToggleForceHV( const TOOL_EVENT& aEvent )
}
void SCH_EDITOR_CONTROL::setTransitions()
{
Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
@ -1151,12 +1134,6 @@ void SCH_EDITOR_CONTROL::setTransitions()
Go( &SCH_EDITOR_CONTROL::UpdateFind, ACTIONS::updateFind.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::UpdateFind, EVENTS::SelectedItemsModified );
/*
Go( &SCH_EDITOR_CONTROL::ToggleLockSelected, EE_ACTIONS::toggleLock.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::LockSelected, EE_ACTIONS::lock.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::UnlockSelected, EE_ACTIONS::unlock.MakeEvent() );
*/
Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::SelectedEvent );
Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::UnselectedEvent );
Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::ClearedEvent );

View File

@ -140,6 +140,7 @@ public:
// Common Tools
static TOOL_ACTION selectionTool;
static TOOL_ACTION measureTool;
static TOOL_ACTION pickerTool;
// Misc
static TOOL_ACTION show3DViewer;

View File

@ -21,27 +21,27 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef PL_PICKER_TOOL_H
#define PL_PICKER_TOOL_H
#ifndef PICKER_TOOL_H
#define PICKER_TOOL_H
#include <boost/optional/optional.hpp>
#include <math/vector2d.h>
#include <tool/tool_interactive.h>
#include <tool/tool_menu.h>
class PL_EDITOR_FRAME;
class EDA_DRAW_FRAME;
class PL_PICKER_TOOL : public TOOL_INTERACTIVE
class PICKER_TOOL : public TOOL_INTERACTIVE
{
public:
PL_PICKER_TOOL();
~PL_PICKER_TOOL() {}
PICKER_TOOL();
~PICKER_TOOL() {}
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;
/// @copydoc TOOL_INTERACTIVE::Reset()
void Reset( RESET_REASON aReason ) override;
void Reset( RESET_REASON aReason ) override { }
///> Event handler types.
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
@ -61,6 +61,8 @@ public:
///> Main event loop.
int Main( const TOOL_EVENT& aEvent );
inline void SetCursor( const wxCursor& aCursor ) { m_cursor = aCursor; }
/**
* Function SetClickHandler()
* Sets a handler for mouse click event. Handler may decide to receive further click by
@ -68,7 +70,7 @@ public:
*/
inline void SetClickHandler( CLICK_HANDLER aHandler )
{
assert( !m_clickHandler );
wxASSERT( !m_clickHandler );
m_clickHandler = aHandler;
}
@ -88,7 +90,7 @@ public:
*/
inline void SetCancelHandler( CANCEL_HANDLER aHandler )
{
assert( !m_cancelHandler );
wxASSERT( !m_cancelHandler );
m_cancelHandler = aHandler;
}
@ -98,7 +100,7 @@ public:
*/
inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
{
assert( !m_finalizeHandler );
wxASSERT( !m_finalizeHandler );
m_finalizeHandler = aHandler;
}
@ -113,7 +115,8 @@ private:
void setTransitions() override;
private:
PL_EDITOR_FRAME* m_frame;
EDA_DRAW_FRAME* m_frame;
wxCursor m_cursor;
OPT<CLICK_HANDLER> m_clickHandler;
OPT<MOTION_HANDLER> m_motionHandler;
@ -123,4 +126,4 @@ private:
OPT<VECTOR2D> m_picked;
};
#endif /* PL_PICKER_TOOL_H */
#endif /* PICKER_TOOL_H */

View File

@ -35,7 +35,6 @@ set( PL_EDITOR_SRCS
tools/pl_drawing_tools.cpp
tools/pl_edit_tool.cpp
tools/pl_editor_control.cpp
tools/pl_picker_tool.cpp
tools/pl_point_editor.cpp
)

View File

@ -44,13 +44,13 @@
#include <tool/tool_manager.h>
#include <tool/common_control.h>
#include <tool/common_tools.h>
#include <tool/picker_tool.h>
#include <tool/zoom_tool.h>
#include <tools/pl_actions.h>
#include <tools/pl_selection_tool.h>
#include <tools/pl_drawing_tools.h>
#include <tools/pl_edit_tool.h>
#include <tools/pl_point_editor.h>
#include <tools/pl_picker_tool.h>
#include <invoke_pl_editor_dialog.h>
#include <tools/pl_editor_control.h>
@ -212,7 +212,7 @@ void PL_EDITOR_FRAME::setupTools()
m_toolManager->RegisterTool( new PL_DRAWING_TOOLS );
m_toolManager->RegisterTool( new PL_EDIT_TOOL );
m_toolManager->RegisterTool( new PL_POINT_EDITOR );
m_toolManager->RegisterTool( new PL_PICKER_TOOL );
m_toolManager->RegisterTool( new PICKER_TOOL );
m_toolManager->InitTools();
// Run the selection tool, it is supposed to be always active

View File

@ -96,12 +96,6 @@ TOOL_ACTION PL_ACTIONS::previewSettings( "plEditor.EditorControl.PreviewSettings
sheetset_xpm );
// PL_PICKER_TOOL
//
TOOL_ACTION PL_ACTIONS::pickerTool( "plEditor.InteractivePicker",
AS_GLOBAL, 0, "", "", "", NULL, AF_ACTIVATE );
// PL_SELECTION_TOOL
//
TOOL_ACTION PL_ACTIONS::selectionActivate( "plEditor.InteractiveSelection",

View File

@ -22,20 +22,17 @@
*/
#include <tool/tool_manager.h>
#include <tool/picker_tool.h>
#include <tools/pl_selection_tool.h>
#include <tools/pl_drawing_tools.h>
#include <tools/pl_actions.h>
#include <tools/pl_edit_tool.h>
#include <tools/pl_picker_tool.h>
#include <ws_data_model.h>
#include <ws_draw_item.h>
#include <bitmaps.h>
#include <confirm.h>
#include <base_struct.h>
#include <view/view.h>
#include <pl_editor_frame.h>
#include <pl_editor_id.h>
#include <wildcards_and_files_ext.h>
PL_EDIT_TOOL::PL_EDIT_TOOL() :
@ -342,13 +339,13 @@ int PL_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
{
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
PL_PICKER_TOOL* picker = m_toolMgr->GetTool<PL_PICKER_TOOL>();
picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) );
m_pickerItem = nullptr;
picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool
picker->SetClickHandler(
[this] ( const VECTOR2D& aPosition ) -> bool
{
if( m_pickerItem )
{
@ -362,7 +359,8 @@ int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
return true;
} );
picker->SetMotionHandler( [this] ( const VECTOR2D& aPos )
picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos )
{
int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
EDA_ITEM* item = nullptr;
@ -393,16 +391,15 @@ int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
}
} );
picker->SetFinalizeHandler( [this] ( const int& aFinalState )
picker->SetFinalizeHandler(
[this] ( const int& aFinalState )
{
if( m_pickerItem )
m_toolMgr->GetTool<PL_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
} );
picker->Activate();
Wait();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
m_frame->PopTool( tool );
return 0;
}

View File

@ -20,19 +20,14 @@
*/
#include <wx/numdlg.h>
#include <core/optional.h>
#include <functional>
using namespace std::placeholders;
#include "class_draw_panel_gal.h"
#include "class_board.h"
#include <pcb_edit_frame.h>
#include <id.h>
#include <macros.h>
#include <pcbnew_id.h>
#include <view/view.h>
#include <view/view_controls.h>
#include <pcb_layer_widget.h>
#include <pcb_painter.h>
@ -45,14 +40,11 @@ using namespace std::placeholders;
#include <collectors.h>
#include <tool/action_menu.h>
#include <tool/tool_manager.h>
#include <tool/tool_settings.h>
#include <tool/grid_menu.h>
#include <tool/zoom_menu.h>
#include <tools/pcb_actions.h>
#include <tools/selection_tool.h>
#include <tools/edit_tool.h>
#include <tools/grid_helper.h>
#include <tools/tool_event_utils.h>
#include "router_tool.h"
#include "pns_segment.h"
@ -1004,7 +996,7 @@ void ROUTER_TOOL::performDragging( int aMode )
highlightNet( true, m_startItem->Net() );
ctls->SetAutoPan( true );
m_gridHelper->SetAuxAxes( true, m_startSnapPoint, true );
m_gridHelper->SetAuxAxes( true, m_startSnapPoint );
frame()->UndoRedoBlock( true );
while( TOOL_EVENT* evt = Wait() )
@ -1160,7 +1152,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
if( !dragStarted )
return 0;
m_gridHelper->SetAuxAxes( true, p, true );
m_gridHelper->SetAuxAxes( true, p );
controls()->ShowCursor( true );
controls()->ForceCursorPosition( false );
controls()->SetAutoPan( true );

View File

@ -25,7 +25,6 @@
*/
#include <limits>
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
@ -33,15 +32,12 @@
#include <collectors.h>
#include <pcb_edit_frame.h>
#include <kiway.h>
#include <class_draw_panel_gal.h>
#include <footprint_edit_frame.h>
#include <array_creator.h>
#include <pcbnew_id.h>
#include <status_popup.h>
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <view/view.h>
#include <gal/graphics_abstraction_layer.h>
#include <connectivity/connectivity_data.h>
#include <confirm.h>
#include <bitmaps.h>
@ -54,11 +50,9 @@ using namespace std::placeholders;
#include "pcbnew_picker_tool.h"
#include "grid_helper.h"
#include "kicad_clipboard.h"
#include "pcbnew_control.h"
#include <router/router_tool.h>
#include <dialogs/dialog_move_exact.h>
#include <dialogs/dialog_track_via_properties.h>
#include <dialogs/dialog_exchange_footprints.h>
#include <tools/tool_event_utils.h>
#include <preview_items/ruler_item.h>
#include <board_commit.h>
@ -155,13 +149,11 @@ bool EDIT_TOOL::Init()
menu.AddItem( PCB_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 )
|| SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
menu.AddItem( PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::positionRelative, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
menu.AddSeparator();
menu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty );
@ -251,7 +243,9 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
// try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
{ EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
{
EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS );
} );
if( m_dragging || selection.Empty() )
return 0;
@ -1294,42 +1288,42 @@ int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP )
{
std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
STATUS_TEXT_POPUP statusPopup( frame() );
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
bool picking = true;
bool retVal = true;
frame()->PushTool( "pcbnew.InteractiveEdit.selectReferencePoint" );
statusPopup.SetText( _( "Select reference point for the copy..." ) );
picker->Activate();
picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool
picker->SetClickHandler(
[&]( const VECTOR2D& aPoint ) -> bool
{
aP = aPoint;
statusPopup.SetText( _( "Selection copied." ) );
statusPopup.Expire( 800 );
picking = false;
return false; // we don't need any more points
} );
picker->SetCancelHandler( [&]()
picker->SetMotionHandler(
[&] ( const VECTOR2D& aPos )
{
statusPopup.Move( aPos + wxPoint( 20, -50 ) );
} );
picker->SetCancelHandler(
[&]()
{
statusPopup.SetText( _( "Copy cancelled." ) );
statusPopup.Expire( 800 );
picking = false;
retVal = false;
} );
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup.Popup();
while( picking )
{
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
Wait();
}
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
statusPopup.Hide();
// Picker calls PopTool() so that it gets done before activating tool's PushTool()
return retVal;
}

View File

@ -75,73 +75,61 @@ public:
/**
* Function Main()
*
* Main loop in which events are handled.
* @param aEvent is the handled event.
*/
int Main( const TOOL_EVENT& aEvent );
/**
* Function Drag()
*
* Invoke the PNS router to drag tracks.
*/
int Drag( const TOOL_EVENT& aEvent );
/**
* Function Edit()
*
* Function Properties()
* Displays properties window for the selected object.
*/
int Properties( const TOOL_EVENT& aEvent );
/**
* Function Rotate()
*
* Rotates currently selected items.
*/
int Rotate( const TOOL_EVENT& aEvent );
/**
* Function Flip()
*
* Rotates currently selected items. The rotation point is the current cursor position.
*/
int Flip( const TOOL_EVENT& aEvent );
/**
* Function Mirror
*
* Mirrors the current selection. The mirror axis passes through the current point.
*/
int Mirror( const TOOL_EVENT& aEvent );
/**
* Function Remove()
*
* Deletes currently selected items. The rotation point is the current cursor position.
*/
int Remove( const TOOL_EVENT& aEvent );
/**
* Function Duplicate()
*
* Duplicates the current selection and starts a move action.
*/
int Duplicate( const TOOL_EVENT& aEvent );
/**
* Function MoveExact()
*
* Invokes a dialog box to allow moving of the item by an exact amount.
*/
int MoveExact( const TOOL_EVENT& aEvent );
/**
* Function CreateArray()
*
* Creates an array of the selected items, invoking the array editor dialog
* to set the array options
* Creates an array of the selected items, invoking the array editor dialog to set the options.
*/
int CreateArray( const TOOL_EVENT& aEvent );
@ -150,17 +138,13 @@ public:
/**
* Function FootprintFilter()
*
* A selection filter which prunes the selection to contain only items
* of type PCB_MODULE_T
* A selection filter which prunes the selection to contain only items of type PCB_MODULE_T
*/
static void FootprintFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector );
/**
* Function PadFilter()
*
* A selection filter which prunes the selection to contain only items
* of type PCB_PAD_T
* A selection filter which prunes the selection to contain only items of type PCB_PAD_T
*/
static void PadFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector );
@ -171,7 +155,6 @@ public:
* Function copyToClipboard()
* Sends the current selection to the clipboard by formatting it as a fake pcb
* see AppendBoardFromClipboard for importing
* @return True if it was sent succesfully
*/
int copyToClipboard( const TOOL_EVENT& aEvent );
@ -179,28 +162,17 @@ public:
* Function cutToClipboard()
* Cuts the current selection to the clipboard by formatting it as a fake pcb
* see AppendBoardFromClipboard for importing
* @return True if it was sent succesfully
*/
int cutToClipboard( const TOOL_EVENT& aEvent );
BOARD_COMMIT* GetCurrentCommit() const
{
return m_commit.get();
}
BOARD_COMMIT* GetCurrentCommit() const { return m_commit.get(); }
private:
///> Selection tool used for obtaining selected items
SELECTION_TOOL* m_selectionTool;
///> Flag determining if anything is being dragged right now
bool m_dragging;
///> Flag determining whether we are prompting for locked removal
bool m_lockedSelected;
///> Last cursor position (needed for getModificationPoint() to avoid changes
///> of edit reference point).
VECTOR2I m_cursor;
SELECTION_TOOL* m_selectionTool; // Selection tool used for obtaining selected items
bool m_dragging; // Indicates objects are being dragged right now
bool m_lockedSelected; // Determines if we prompt before removing locked objects
VECTOR2I m_cursor; // Last cursor position (needed for getModificationPoint()
// to avoid changes of edit reference point).
///> Returns the right modification point (e.g. for rotation), depending on the number of
///> selected items.

View File

@ -48,7 +48,6 @@ using namespace std::placeholders;
GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) :
m_frame( aFrame )
{
m_diagonalAuxAxesEnable = true;
m_enableSnap = true;
m_enableGrid = true;
m_snapSize = 100;
@ -74,18 +73,6 @@ GRID_HELPER::~GRID_HELPER()
}
void GRID_HELPER::SetGrid( int aSize )
{
assert( false );
}
void GRID_HELPER::SetOrigin( const VECTOR2I& aOrigin )
{
assert( false );
}
VECTOR2I GRID_HELPER::GetGrid() const
{
PCB_SCREEN* screen = m_frame->GetScreen();
@ -102,7 +89,7 @@ VECTOR2I GRID_HELPER::GetOrigin() const
}
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin, bool aEnableDiagonal )
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin )
{
if( aEnable )
{
@ -115,8 +102,6 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin, bool aEnabl
m_auxAxis = OPT<VECTOR2I>();
m_frame->GetCanvas()->GetView()->SetVisible( &m_viewAxis, false );
}
m_diagonalAuxAxesEnable = aEnable;
}
@ -126,10 +111,10 @@ VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
return aPoint;
const VECTOR2D gridOffset( GetOrigin() );
const VECTOR2D gridSize( GetGrid() );
const VECTOR2D grid( GetGrid() );
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
if( !m_auxAxis )
return nearest;
@ -320,7 +305,7 @@ BOARD_ITEM* GRID_HELPER::GetSnapped( void ) const
}
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, const bool aFrom )
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom )
{
VECTOR2I origin;
@ -332,8 +317,8 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, co
for( auto pad : mod->Pads() )
{
if(( aFrom || m_frame->Settings().m_MagneticPads == CAPTURE_ALWAYS ) &&
pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) )
if( ( aFrom || m_frame->Settings().m_MagneticPads == CAPTURE_ALWAYS )
&& pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) )
{
addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
break;

View File

@ -26,13 +26,10 @@
#define __GRID_HELPER_H
#include <vector>
#include <math/vector2d.h>
#include <core/optional.h>
#include <origin_viewitem.h>
#include <layers_id_colors_and_visibility.h>
#include <geometry/seg.h>
class PCB_BASE_FRAME;
@ -43,9 +40,6 @@ public:
GRID_HELPER( PCB_BASE_FRAME* aFrame );
~GRID_HELPER();
void SetGrid( int aSize );
void SetOrigin( const VECTOR2I& aOrigin );
VECTOR2I GetGrid() const;
VECTOR2I GetOrigin() const;
@ -58,7 +52,7 @@ public:
*/
BOARD_ITEM* GetSnapped() const;
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ), bool aEnableDiagonal = false );
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );
VECTOR2I Align( const VECTOR2I& aPoint ) const;
@ -89,8 +83,11 @@ private:
struct ANCHOR
{
ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ):
pos( aPos ), flags( aFlags ), item( aItem ) {} ;
ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ) :
pos( aPos ),
flags( aFlags ),
item( aItem )
{ };
VECTOR2I pos;
int flags;
@ -107,9 +104,9 @@ private:
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea,
const std::vector<BOARD_ITEM*> aSkip ) const;
void addAnchor( const VECTOR2I& aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL )
void addAnchor( const VECTOR2I& aPos, int aFlags, BOARD_ITEM* aItem )
{
m_anchors.push_back( ANCHOR( aPos, aFlags, aItem ) );
m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
}
ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers );
@ -122,7 +119,7 @@ private:
* @param aRefPos The point for which to compute the anchors (if used by the component)
* @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not
*/
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, const bool aFrom = false );
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false );
void clearAnchors()
{
@ -132,7 +129,6 @@ private:
PCB_BASE_FRAME* m_frame;
OPT<VECTOR2I> m_auxAxis;
bool m_diagonalAuxAxesEnable; ///< If true, use the aux axis for snapping as well
bool m_enableSnap; ///< If true, allow snapping to other items on the layers
bool m_enableGrid; ///< If true, allow snapping to grid
int m_snapSize; ///< Sets the radius in screen units for snapping to items

View File

@ -907,12 +907,6 @@ TOOL_ACTION PCB_ACTIONS::deleteTool( "pcbnew.Control.deleteTool",
delete_xpm );
// PCBNEW_PICKER_TOOL
//
TOOL_ACTION PCB_ACTIONS::pickerTool( "pcbnew.InteractivePicker",
AS_GLOBAL, 0, "", "", "", nullptr, AF_ACTIVATE );
// PLACEMENT_TOOL
//
TOOL_ACTION PCB_ACTIONS::alignTop( "pcbnew.AlignAndDistribute.alignTop",

View File

@ -23,40 +23,33 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <cstdint>
#include <thread>
#include <functional>
#include "pcb_editor_control.h"
#include "pcb_actions.h"
#include <tool/tool_manager.h>
#include <tools/tool_event_utils.h>
#include <wx/progdlg.h>
#include <ws_proxy_undo_item.h>
#include "edit_tool.h"
#include "selection_tool.h"
#include "drawing_tool.h"
#include "pcbnew_picker_tool.h"
#include <painter.h>
#include <project.h>
#include <pcbnew_id.h>
#include <pcb_edit_frame.h>
#include <class_board.h>
#include <class_zone.h>
#include <pcb_draw_panel_gal.h>
#include <class_module.h>
#include <class_pcb_target.h>
#include <connectivity/connectivity_data.h>
#include <collectors.h>
#include <zones_functions_for_undo_redo.h>
#include <board_commit.h>
#include <confirm.h>
#include <bitmaps.h>
#include <view/view_group.h>
#include <view/view_controls.h>
#include <origin_viewitem.h>
#include <profile.h>
#include <widgets/progress_reporter.h>
#include <dialogs/dialog_find.h>
#include <dialogs/dialog_page_settings.h>
#include <pcb_netlist.h>
#include <dialogs/dialog_update_pcb.h>
@ -1121,23 +1114,18 @@ void PCB_EDITOR_CONTROL::DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* a
int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent )
{
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
assert( picker );
picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool
picker->SetClickHandler(
[this] ( const VECTOR2D& pt ) -> bool
{
m_frame->SaveCopyInUndoList( m_placeOrigin.get(), UR_DRILLORIGIN );
DoSetDrillOrigin( getView(), m_frame, m_placeOrigin.get(), pt );
return false; // drill origin is a one-shot; don't continue with tool
} );
picker->Activate();
Wait();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
m_frame->PopTool( tool );
return 0;
}
@ -1299,6 +1287,9 @@ int PCB_EDITOR_CONTROL::ClearHighlight( const TOOL_EVENT& aEvent )
int PCB_EDITOR_CONTROL::HighlightNetTool( const TOOL_EVENT& aEvent )
{
std::string tool = aEvent.GetCommandStr().get();
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
// If the keyboard hotkey was triggered and we are already in the highlight tool, behave
// the same as a left-click. Otherwise highlight the net of the selected item(s), or if
// there is no selection, then behave like a ctrl-left-click.
@ -1308,48 +1299,51 @@ int PCB_EDITOR_CONTROL::HighlightNetTool( const TOOL_EVENT& aEvent )
highlightNet( getViewControls()->GetMousePosition(), use_selection );
}
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool
picker->SetClickHandler(
[this] ( const VECTOR2D& pt ) -> bool
{
highlightNet( pt, false );
return true;
} );
picker->SetLayerSet( LSET::AllCuMask() );
picker->Activate();
Wait();
m_frame->PopTool( tool );
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
return 0;
}
static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, bool aShow, const VECTOR2D& aPosition )
int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent )
{
auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
std::string tool = aEvent.GetCommandStr().get();
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
BOARD* board = getModel<BOARD>();
PCB_DISPLAY_OPTIONS* opt = displayOptions();
aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::PadFilter );
picker->SetClickHandler(
[&] ( const VECTOR2D& pt ) -> bool
{
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::PadFilter );
PCBNEW_SELECTION& selection = selectionTool->GetSelection();
if( selection.Empty() )
{
aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::FootprintFilter );
m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true,
EDIT_TOOL::FootprintFilter );
selection = selectionTool->GetSelection();
}
if( selection.Empty() )
{
// Clear the previous local ratsnest if we click off all items
for( auto mod : aBoard->Modules() )
for( auto mod : board->Modules() )
{
for( auto pad : mod->Pads() )
pad->SetLocalRatsnestVisible( aShow );
pad->SetLocalRatsnestVisible( opt->m_ShowGlobalRatsnest );
}
}
else
@ -1370,28 +1364,13 @@ static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, bool aShow
}
}
aToolMgr->GetView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY );
m_toolMgr->GetView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY );
return true;
}
} );
int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent )
{
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
auto picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
auto board = getModel<BOARD>();
auto opt = displayOptions();
wxASSERT( picker );
wxASSERT( board );
picker->SetClickHandler( std::bind( showLocalRatsnest, m_toolMgr, board,
opt->m_ShowGlobalRatsnest, _1 ) );
picker->SetFinalizeHandler( [ board, opt ]( int aCondition )
picker->SetFinalizeHandler(
[ board, opt ]( int aCondition )
{
if( aCondition != PCBNEW_PICKER_TOOL::END_ACTIVATE )
{
@ -1403,10 +1382,8 @@ int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent )
}
} );
picker->Activate();
Wait();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
m_frame->PopTool( tool );
return 0;
}

View File

@ -412,7 +412,6 @@ int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent )
{
m_frame->SetFastGrid1();
updateGrid();
return 0;
}
@ -421,7 +420,6 @@ int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent )
{
m_frame->SetFastGrid2();
updateGrid();
return 0;
}
@ -444,29 +442,23 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
if( origin )
{
// We can't undo the other grid dialog settings, so no sense undoing just the origin
DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), *origin );
delete origin;
}
else
{
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool
picker->SetClickHandler(
[this] ( const VECTOR2D& pt ) -> bool
{
m_frame->SaveCopyInUndoList( m_gridOrigin.get(), UR_GRIDORIGIN );
DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), pt );
return false; // drill origin is a one-shot; don't continue with tool
} );
picker->Activate();
Wait();
m_frame->PopTool( tool );
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
}
return 0;
@ -486,16 +478,16 @@ int PCBNEW_CONTROL::GridResetOrigin( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
{
std::string tool = aEvent.GetCommandStr().get();
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
m_pickerItem = nullptr;
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
Activate();
picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) );
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
m_pickerItem = nullptr;
picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool
picker->SetClickHandler(
[this] ( const VECTOR2D& aPosition ) -> bool
{
if( m_pickerItem )
{
@ -518,7 +510,8 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
return true;
} );
picker->SetMotionHandler( [this] ( const VECTOR2D& aPos )
picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos )
{
BOARD* board = m_frame->GetBoard();
GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
@ -546,16 +539,15 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
}
} );
picker->SetFinalizeHandler( [&]( const int& aFinalState )
picker->SetFinalizeHandler(
[&]( const int& aFinalState )
{
if( m_pickerItem )
m_toolMgr->GetTool<SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
} );
picker->Activate();
Wait();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
m_frame->PopTool( tool );
return 0;
}
@ -667,7 +659,8 @@ template<typename T>
static void moveNoFlagToVector( std::deque<T>& aList, std::vector<BOARD_ITEM*>& aTarget, bool aIsNew )
{
std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
[](T aItem){
[](T aItem)
{
bool retval = ( aItem->GetFlags() & FLAG0 ) == 0;
aItem->ClearFlags( FLAG0 );
return retval;
@ -857,6 +850,7 @@ int PCBNEW_CONTROL::Redo( const TOOL_EVENT& aEvent )
if( editFrame )
editFrame->RestoreCopyFromRedoList( dummy );
return 0;
}
@ -887,7 +881,6 @@ int PCBNEW_CONTROL::Show3DViewer( const TOOL_EVENT& aEvent )
void PCBNEW_CONTROL::updateGrid()
{
BASE_SCREEN* screen = m_frame->GetScreen();
//GRID_TYPE grid = screen->GetGrid( idx );
getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) );
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}

View File

@ -28,7 +28,6 @@
#include "grid_helper.h"
#include <view/view_controls.h>
#include <tool/tool_manager.h>
#include "tool_event_utils.h"
#include "selection_tool.h"
@ -45,11 +44,13 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
GRID_HELPER grid( frame() );
int finalize_state = WAIT_CANCEL;
Activate();
setControls();
while( TOOL_EVENT* evt = Wait() )
{
frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
frame()->GetCanvas()->SetCursor( m_cursor );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
controls->SetSnapping( !evt->Modifier( MD_ALT ) );
@ -153,13 +154,14 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
void PCBNEW_PICKER_TOOL::setTransitions()
{
Go( &PCBNEW_PICKER_TOOL::Main, PCB_ACTIONS::pickerTool.MakeEvent() );
Go( &PCBNEW_PICKER_TOOL::Main, ACTIONS::pickerTool.MakeEvent() );
}
void PCBNEW_PICKER_TOOL::reset()
{
m_layerMask = LSET::AllLayersMask();
m_cursor = wxStockCursor( wxCURSOR_ARROW );
m_picked = NULLOPT;
m_clickHandler = NULLOPT;

View File

@ -35,7 +35,7 @@ class PCBNEW_PICKER_TOOL : public PCB_TOOL_BASE
{
public:
PCBNEW_PICKER_TOOL();
~PCBNEW_PICKER_TOOL() {}
~PCBNEW_PICKER_TOOL() override { }
///> Event handler types.
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
@ -64,6 +64,8 @@ public:
*/
inline void SetLayerSet( LSET aLayerSet ) { m_layerMask = aLayerSet; }
inline void SetCursor( const wxCursor& aCursor ) { m_cursor = aCursor; }
/**
* Function SetClickHandler()
* Sets a handler for mouse click event. Handler may decide to receive further click by
@ -105,12 +107,20 @@ public:
m_finalizeHandler = aHandler;
}
private:
///> @copydoc TOOL_INTERACTIVE::setTransitions();
void setTransitions() override;
///> Reinitializes tool to its initial state.
void reset();
///> Applies the requested VIEW_CONTROLS settings.
void setControls();
private:
///> The layer set to use for optional snapping
LSET m_layerMask;
wxCursor m_cursor;
OPT<CLICK_HANDLER> m_clickHandler;
OPT<MOTION_HANDLER> m_motionHandler;
@ -118,12 +128,6 @@ private:
OPT<FINALIZE_HANDLER> m_finalizeHandler;
OPT<VECTOR2D> m_picked;
///> Reinitializes tool to its initial state.
void reset();
///> Applies the requested VIEW_CONTROLS settings.
void setControls();
};
#endif /* PICKER_TOOL_H */

View File

@ -24,13 +24,11 @@
#include <functional>
using namespace std::placeholders;
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <geometry/seg.h>
#include <confirm.h>
#include "pcb_actions.h"
#include "selection_tool.h"
#include "point_editor.h"
@ -38,18 +36,13 @@ using namespace std::placeholders;
#include <board_commit.h>
#include <bitmaps.h>
#include <status_popup.h>
#include <pcb_edit_frame.h>
#include <class_edge_mod.h>
#include <class_dimension.h>
#include <class_zone.h>
#include <class_board.h>
#include <class_module.h>
#include <connectivity/connectivity_data.h>
#include <widgets/progress_reporter.h>
#include "zone_filler.h"
// Few constants to avoid using bare numbers for point indices
enum SEG_POINTS
{
@ -354,7 +347,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
m_original = *m_editedPoint; // Save the original position
controls->SetAutoPan( true );
inDrag = true;
grid.SetAuxAxes( true, m_original.GetPosition(), true );
grid.SetAuxAxes( true, m_original.GetPosition() );
}
//TODO: unify the constraints to solve simultaneously instead of sequentially

View File

@ -122,22 +122,21 @@ int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint aPosAnchor, wxPoi
int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent )
{
Activate();
std::string tool = "pcbnew.PositionRelative.selectReferenceItem";
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
STATUS_TEXT_POPUP statusPopup( frame() );
bool picking = true;
frame()->PushTool( "pcbnew.PositionRelative.selectReferenceItem" );
statusPopup.SetText( _( "Select reference item..." ) );
picker->Activate();
picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool
picker->SetClickHandler(
[&]( const VECTOR2D& aPoint ) -> bool
{
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
const PCBNEW_SELECTION& sel = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
{ EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
{
EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS );
} );
if( sel.Empty() )
return true; // still looking for an item
@ -148,30 +147,30 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent
if( m_dialog )
m_dialog->UpdateAnchor( sel.Front() );
picking = false;
return false; // got our item; don't need any more
} );
picker->SetCancelHandler( [&]()
picker->SetMotionHandler(
[&] ( const VECTOR2D& aPos )
{
statusPopup.Move( aPos + wxPoint( 20, -50 ) );
} );
picker->SetCancelHandler(
[&]()
{
statusPopup.Hide();
if( m_dialog )
m_dialog->UpdateAnchor( m_anchor_item );
picking = false;
} );
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup.Popup();
while( picking )
{
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
Wait();
}
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
frame()->PopTool( "pcbnew.PositionRelative.selectReferenceItem" );
statusPopup.Hide();
return 0;
}