@ -31,7 +31,7 @@ using namespace std::placeholders;
# include "picker_tool.h"
# include <dialogs/dialog_position_relative.h>
# include <status_popup.h>
# include <board_commit.h>
# include <hotkeys.h>
# include <bitmaps.h>
@ -54,7 +54,7 @@ TOOL_ACTION PCB_ACTIONS::selectpositionRelativeItem(
POSITION_RELATIVE_TOOL : : POSITION_RELATIVE_TOOL ( ) :
PCB_TOOL ( " pcbnew.PositionRelative " ) ,
m_position_relative_ dialog ( NULL ) ,
m_dialog ( NULL ) ,
m_selectionTool ( NULL ) ,
m_anchor_item ( NULL )
{
@ -71,16 +71,9 @@ void POSITION_RELATIVE_TOOL::Reset( RESET_REASON aReason )
bool POSITION_RELATIVE_TOOL : : Init ( )
{
// Find the selection tool, so they can cooperate
m_selectionTool =
static_cast < SELECTION_TOOL * > ( m_toolMgr - > FindTool ( " pcbnew.InteractiveSelection " ) ) ;
if ( ! m_selectionTool )
{
DisplayError ( NULL , wxT ( " pcbnew.InteractiveSelection tool is not available " ) ) ;
return false ;
}
m_selectionTool = m_toolMgr - > GetTool < SELECTION_TOOL > ( ) ;
return true ;
return m_selectionTool ! = nullptr ;
}
@ -95,55 +88,28 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
const auto & selection = m_selectionTool - > RequestSelection ( filter ) ;
if ( m_selectionTool - > CheckLock ( ) = = SELECTION_LOCKED )
if ( m_selectionTool - > CheckLock ( ) = = SELECTION_LOCKED | | selection . Empty ( ) )
return 0 ;
if ( selection . Empty ( ) )
return 0 ;
m_position_relative_selection = selection ;
m_selection = selection ;
if ( ! m_position_relative_dialog )
m_position_relative_dialog = new DIALOG_POSITION_RELATIVE ( editFrame ,
m_toolMgr ,
m_position_relative_translation ,
m_anchor_position ) ;
if ( ! m_dialog )
m_dialog = new DIALOG_POSITION_RELATIVE ( editFrame , m_translation , m_anchor ) ;
m_position_relative_ dialog - > Show ( true ) ;
m_dialog - > Show ( true ) ;
return 0 ;
}
static bool selectPRitem ( TOOL_MANAGER * aToolMgr , const VECTOR2D & aPosition )
{
SELECTION_TOOL * selectionTool = aToolMgr - > GetTool < SELECTION_TOOL > ( ) ;
POSITION_RELATIVE_TOOL * positionRelativeTool = aToolMgr - > GetTool < POSITION_RELATIVE_TOOL > ( ) ;
wxCHECK ( selectionTool , false ) ;
wxCHECK ( positionRelativeTool , false ) ;
aToolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
const SELECTION & selection = selectionTool - > RequestSelection ( EnsureEditableFilter ) ;
if ( selection . Empty ( ) )
return true ;
positionRelativeTool - > UpdateAnchor ( static_cast < BOARD_ITEM * > ( selection . Front ( ) ) ) ;
return true ;
}
int POSITION_RELATIVE_TOOL : : RelativeItemSelectionMove ( wxPoint anchorPosition ,
wxPoint relativePosition ,
double rotation )
int POSITION_RELATIVE_TOOL : : RelativeItemSelectionMove ( wxPoint anchor , wxPoint relativePosition ,
double rotation )
{
VECTOR2I rp = m_position_relative_ selection . GetCenter ( ) ;
VECTOR2I rp = m_selection . GetCenter ( ) ;
wxPoint rotPoint ( rp . x , rp . y ) ;
wxPoint translation = anchorPosition + relativePosition - rotPoint ;
wxPoint translation = anchor + relativePosition - rotPoint ;
for ( auto item : m_position_relative_ selection )
for ( auto item : m_selection )
{
m_commit - > Modify ( item ) ;
@ -153,7 +119,7 @@ int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint anchorPosition,
m_commit - > Push ( _ ( " Position Relative " ) ) ;
if ( m_position_relative_ selection . IsHover ( ) )
if ( m_selection . IsHover ( ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionModified , true ) ;
@ -166,23 +132,51 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent
Activate ( ) ;
PICKER_TOOL * picker = m_toolMgr - > GetTool < PICKER_TOOL > ( ) ;
assert ( picker ) ;
STATUS_TEXT_POPUP statusPopup ( frame ( ) ) ;
bool picking = true ;
statusPopup . SetText ( _ ( " Select reference item... " ) ) ;
picker - > SetSnapping ( false ) ;
picker - > SetClickHandler ( std : : bind ( selectPRitem , m_toolMgr , _1 ) ) ;
picker - > Activate ( ) ;
Wait ( ) ;
return 0 ;
}
picker - > SetClickHandler ( [ & ] ( const VECTOR2D & aPoint ) - > bool
{
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
const SELECTION & sel = m_selectionTool - > RequestSelection ( EnsureEditableFilter ) ;
if ( sel . Empty ( ) )
return true ; // still looking for an item
void POSITION_RELATIVE_TOOL : : UpdateAnchor ( BOARD_ITEM * aItem )
{
m_anchor_item = aItem ;
m_anchor_item = sel . Front ( ) ;
statusPopup . Hide ( ) ;
if ( m_dialog )
m_dialog - > UpdateAnchor ( sel . Front ( ) ) ;
picking = false ;
return false ; // got our item; don't need any more
} ) ;
picker - > SetCancelHandler ( [ & ] ( )
{
statusPopup . Hide ( ) ;
if ( m_position_relative_dialog )
m_position_relative_dialog - > UpdateAnchor ( aItem ) ;
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 ( ) ;
}
return 0 ;
}