Make LibEdit respect the Move-warps-cursor setting.

This commit is contained in:
Jeff Young 2019-08-09 23:45:44 +01:00
parent b15f039444
commit 039bd92ea5
2 changed files with 36 additions and 26 deletions

View File

@ -24,11 +24,9 @@
#include <tool/tool_manager.h>
#include <tools/ee_selection_tool.h>
#include <ee_actions.h>
#include <view/view.h>
#include <bitmaps.h>
#include <base_struct.h>
#include <lib_edit_frame.h>
#include <eeschema_id.h>
#include "lib_move_tool.h"
#include "lib_pin_tool.h"
@ -71,9 +69,9 @@ void LIB_MOVE_TOOL::Reset( RESET_REASON aReason )
int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetSnapping( true );
VECTOR2I originalCursorPos = controls->GetCursorPosition();
m_anchorPos = { 0, 0 };
// Be sure that there is at least one item that we can move. If there's no selection try
// looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
@ -98,6 +96,8 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
if( !selection.Front()->IsNew() )
saveCopyInUndoList( m_frame->GetCurPart(), UR_LIBEDIT );
m_cursor = controls->GetCursorPosition();
// Main loop: keep receiving events
do
{
@ -109,15 +109,17 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{
if( !m_moveInProgress ) // Prepare to start moving/dragging
{
LIB_ITEM* lib_item = (LIB_ITEM*) selection.Front();
// Pick up any synchronized pins
//
// Careful when pasting. The pasted pin will be at the same location as it
// was copied from, leading us to believe it's a synchronized pin. It's not.
if( selection.GetSize() == 1 && selection.Front()->Type() == LIB_PIN_T
if( selection.GetSize() == 1 && lib_item->Type() == LIB_PIN_T
&& m_frame->SynchronizePins()
&& ( selection.Front()->GetEditFlags() & IS_PASTED ) == 0 )
&& ( lib_item->GetEditFlags() & IS_PASTED ) == 0 )
{
LIB_PIN* cur_pin = (LIB_PIN*) selection.Front();
LIB_PIN* cur_pin = (LIB_PIN*) lib_item;
LIB_PART* part = m_frame->GetCurPart();
for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
@ -140,36 +142,34 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
//
m_cursor = controls->GetCursorPosition();
if( selection.HasReferencePoint() )
if( ( lib_item->GetFlags() & IS_NEW ) != 0 )
{
VECTOR2I delta = m_cursor - mapCoords( selection.GetReferencePoint() );
m_anchorPos = selection.GetReferencePoint();
VECTOR2I delta = m_cursor - mapCoords( m_anchorPos );
// Drag items to the current cursor position
for( EDA_ITEM* item : selection )
{
// Don't double move pins, fields, etc.
if( item->GetParent() && item->GetParent()->IsSelected() )
continue;
moveItem( item, delta );
updateView( item );
}
selection.SetReferencePoint( m_cursor );
m_anchorPos = m_cursor;
}
else if( selection.Size() == 1 )
else if( selection.Size() == 1 && m_frame->GetMoveWarpsCursor() )
{
// Set the current cursor position to the first dragged item origin,
// so the movement vector can be computed later
updateModificationPoint( selection );
m_cursor = originalCursorPos;
m_anchorPos = lib_item->GetPosition();
getViewControls()->WarpCursor( m_anchorPos, true, true );
m_cursor = m_anchorPos;
}
else
{
updateModificationPoint( selection );
m_cursor = getViewControls()->GetCursorPosition( true );
m_anchorPos = m_cursor;
}
controls->SetCursorPosition( m_cursor, false );
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
prevPos = m_cursor;
controls->SetAutoPan( true );
@ -181,7 +181,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
//
m_cursor = controls->GetCursorPosition();
VECTOR2I delta( m_cursor - prevPos );
selection.SetReferencePoint( m_cursor );
m_anchorPos = m_cursor;
m_moveOffset += delta;
prevPos = m_cursor;
@ -271,18 +271,27 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
if( !chain_commands )
m_moveOffset = { 0, 0 };
m_anchorPos = { 0, 0 };
for( auto item : selection )
item->ClearEditFlags();
if( unselect )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
else
selection.ClearReferencePoint();
if( restore_state )
{
m_frame->RollbackPartFromUndo();
if( unselect )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
else
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
}
else
{
if( unselect )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_frame->OnModify();
}
m_moveInProgress = false;
m_frame->PopTool( tool );

View File

@ -70,6 +70,7 @@ private:
///> Last cursor position (needed for getModificationPoint() to avoid changes
///> of edit reference point).
VECTOR2I m_cursor;
VECTOR2I m_anchorPos;
};
#endif //KICAD_LIB_MOVE_TOOL_H