2019-05-08 18:56:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2023-07-01 21:35:39 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-08 18:56:03 +00:00
|
|
|
*
|
|
|
|
* 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 <tool/tool_manager.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
|
|
|
#include <ee_actions.h>
|
2023-08-22 14:09:04 +00:00
|
|
|
#include <ee_grid_helper.h>
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2023-08-30 14:45:07 +00:00
|
|
|
#include <lib_shape.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include "symbol_editor_move_tool.h"
|
|
|
|
#include "symbol_editor_pin_tool.h"
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_MOVE_TOOL::SYMBOL_EDITOR_MOVE_TOOL() :
|
2019-06-09 22:21:53 +00:00
|
|
|
EE_TOOL_BASE( "eeschema.SymbolMoveTool" ),
|
2023-07-01 21:35:39 +00:00
|
|
|
m_moveInProgress( false )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
bool SYMBOL_EDITOR_MOVE_TOOL::Init()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-12 17:19:20 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
2019-08-15 18:32:19 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
//
|
|
|
|
// Add move actions to the selection tool menu
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
|
|
|
|
2021-02-10 22:56:26 +00:00
|
|
|
auto canMove =
|
2021-01-08 23:24:12 +00:00
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
|
|
|
wxCHECK( editor, false );
|
|
|
|
|
2021-02-10 22:56:26 +00:00
|
|
|
if( !editor->IsSymbolEditable() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( editor->IsSymbolAlias() )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : sel )
|
|
|
|
{
|
|
|
|
if( item->Type() != LIB_FIELD_T )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-01-08 23:24:12 +00:00
|
|
|
};
|
|
|
|
|
2023-08-30 14:45:07 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::move, canMove && EE_CONDITIONS::IdleSelection, 150 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::alignToGrid, canMove && EE_CONDITIONS::IdleSelection, 150 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
void SYMBOL_EDITOR_MOVE_TOOL::Reset( RESET_REASON aReason )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Reset( aReason );
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
if( aReason == MODEL_RELOAD )
|
|
|
|
m_moveInProgress = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2023-07-01 21:35:39 +00:00
|
|
|
if( SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() ) )
|
|
|
|
{
|
|
|
|
wxCHECK( aEvent.SynchronousState(), 0 );
|
|
|
|
aEvent.SynchronousState()->store( STS_RUNNING );
|
|
|
|
|
|
|
|
if( doMoveSelection( aEvent, commit ) )
|
|
|
|
aEvent.SynchronousState()->store( STS_FINISHED );
|
|
|
|
else
|
|
|
|
aEvent.SynchronousState()->store( STS_CANCELLED );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_COMMIT localCommit( m_toolMgr );
|
|
|
|
|
|
|
|
if( doMoveSelection( aEvent, &localCommit ) )
|
|
|
|
localCommit.Push( _( "Move" ) );
|
|
|
|
else
|
|
|
|
localCommit.Revert();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2023-06-09 21:41:33 +00:00
|
|
|
|
2023-07-01 21:35:39 +00:00
|
|
|
|
|
|
|
bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2023-08-22 14:09:04 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2019-08-09 22:45:44 +00:00
|
|
|
|
|
|
|
m_anchorPos = { 0, 0 };
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
// 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).
|
2021-02-10 22:56:26 +00:00
|
|
|
EE_SELECTION& selection = m_frame->IsSymbolAlias()
|
2022-08-20 09:27:35 +00:00
|
|
|
? m_selectionTool->RequestSelection( { LIB_FIELD_T } )
|
|
|
|
: m_selectionTool->RequestSelection();
|
2019-06-08 21:48:22 +00:00
|
|
|
bool unselect = selection.IsHover();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
if( !m_frame->IsSymbolEditable() || selection.Empty() )
|
2023-07-01 21:35:39 +00:00
|
|
|
return false;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
if( m_moveInProgress )
|
|
|
|
{
|
|
|
|
// The tool hotkey is interpreted as a click when already moving
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
2023-07-01 21:35:39 +00:00
|
|
|
return true;
|
2022-06-09 15:53:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-06-18 17:56:40 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
2019-05-08 18:56:03 +00:00
|
|
|
controls->ShowCursor( true );
|
|
|
|
controls->SetAutoPan( true );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
bool restore_state = false;
|
2022-09-14 17:31:56 +00:00
|
|
|
TOOL_EVENT copy = aEvent;
|
|
|
|
TOOL_EVENT* evt = ©
|
2019-06-17 13:43:22 +00:00
|
|
|
VECTOR2I prevPos;
|
2023-07-01 21:35:39 +00:00
|
|
|
VECTOR2I moveOffset;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( !selection.Front()->IsNew() )
|
2023-07-01 21:35:39 +00:00
|
|
|
aCommit->Modify( m_frame->GetCurSymbol(), m_frame->GetScreen() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2022-02-20 16:10:25 +00:00
|
|
|
m_cursor = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2019-08-09 22:45:44 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// Main loop: keep receiving events
|
|
|
|
do
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
2023-08-22 14:09:04 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-12-14 22:03:17 +00:00
|
|
|
if( evt->IsAction( &EE_ACTIONS::move )
|
|
|
|
|| evt->IsMotion()
|
|
|
|
|| evt->IsDrag( BUT_LEFT )
|
2023-07-15 22:11:24 +00:00
|
|
|
|| evt->IsAction( &ACTIONS::refreshPreview ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( !m_moveInProgress ) // Prepare to start moving/dragging
|
|
|
|
{
|
2020-12-18 23:26:37 +00:00
|
|
|
LIB_ITEM* lib_item = static_cast<LIB_ITEM*>( selection.Front() );
|
2019-08-09 22:45:44 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// Pick up any synchronized pins
|
|
|
|
//
|
2019-06-26 23:24:09 +00:00
|
|
|
// 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.
|
2020-12-18 23:26:37 +00:00
|
|
|
if( m_frame->SynchronizePins()
|
2019-08-09 22:45:44 +00:00
|
|
|
&& ( lib_item->GetEditFlags() & IS_PASTED ) == 0 )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-12-18 23:26:37 +00:00
|
|
|
std::set<LIB_PIN*> sync_pins;
|
2020-12-18 23:16:30 +00:00
|
|
|
|
2020-12-18 23:26:37 +00:00
|
|
|
for( EDA_ITEM* sel_item : selection )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-12-18 23:26:37 +00:00
|
|
|
lib_item = static_cast<LIB_ITEM*>( sel_item );
|
|
|
|
|
|
|
|
if( lib_item->Type() == LIB_PIN_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-12-18 23:26:37 +00:00
|
|
|
LIB_PIN* cur_pin = static_cast<LIB_PIN*>( lib_item );
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2021-10-30 12:52:13 +00:00
|
|
|
std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
|
2020-12-18 23:26:37 +00:00
|
|
|
|
|
|
|
got_unit[cur_pin->GetUnit()] = true;
|
|
|
|
|
2023-01-20 22:12:15 +00:00
|
|
|
std::vector<LIB_PIN*> pins = symbol->GetAllLibPins();
|
|
|
|
|
|
|
|
for( LIB_PIN* pin : pins )
|
2020-12-18 23:26:37 +00:00
|
|
|
{
|
|
|
|
if( !got_unit[pin->GetUnit()]
|
2023-07-15 22:11:24 +00:00
|
|
|
&& pin->GetPosition() == cur_pin->GetPosition()
|
|
|
|
&& pin->GetOrientation() == cur_pin->GetOrientation()
|
2024-01-26 16:16:13 +00:00
|
|
|
&& pin->GetBodyStyle() == cur_pin->GetBodyStyle()
|
2023-07-15 22:11:24 +00:00
|
|
|
&& pin->GetType() == cur_pin->GetType()
|
|
|
|
&& pin->GetName() == cur_pin->GetName() )
|
2020-12-18 23:26:37 +00:00
|
|
|
{
|
|
|
|
if( sync_pins.insert( pin ).second )
|
|
|
|
got_unit[pin->GetUnit()] = true;
|
|
|
|
}
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-18 23:26:37 +00:00
|
|
|
|
|
|
|
for( LIB_PIN* pin : sync_pins )
|
|
|
|
m_selectionTool->AddItemToSel( pin, true /*quiet mode*/ );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply any initial offset in case we're coming from a previous command.
|
|
|
|
//
|
|
|
|
for( EDA_ITEM* item : selection )
|
2023-07-01 21:35:39 +00:00
|
|
|
moveItem( item, moveOffset );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
// Set up the starting position and move/drag offset
|
|
|
|
//
|
2022-02-20 16:10:25 +00:00
|
|
|
m_cursor = controls->GetCursorPosition( !evt->DisableGridSnapping() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-08-27 12:12:34 +00:00
|
|
|
if( lib_item->IsNew() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-08-09 22:45:44 +00:00
|
|
|
m_anchorPos = selection.GetReferencePoint();
|
|
|
|
VECTOR2I delta = m_cursor - mapCoords( m_anchorPos );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
// Drag items to the current cursor position
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
moveItem( item, delta );
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( item, false );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 22:45:44 +00:00
|
|
|
m_anchorPos = m_cursor;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2022-04-12 17:13:15 +00:00
|
|
|
else if( m_frame->GetMoveWarpsCursor() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-04-12 17:13:15 +00:00
|
|
|
VECTOR2I itemPos = selection.GetTopLeftItem()->GetPosition();
|
2023-08-29 11:15:50 +00:00
|
|
|
m_anchorPos = VECTOR2I( itemPos.x, -itemPos.y );
|
2019-08-15 18:32:19 +00:00
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
getViewControls()->WarpMouseCursor( m_anchorPos, true, true );
|
2019-08-09 22:45:44 +00:00
|
|
|
m_cursor = m_anchorPos;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-20 16:10:25 +00:00
|
|
|
m_cursor = controls->GetCursorPosition( !evt->DisableGridSnapping() );
|
2019-08-09 22:45:44 +00:00
|
|
|
m_anchorPos = m_cursor;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
controls->SetCursorPosition( m_cursor, false );
|
|
|
|
|
|
|
|
prevPos = m_cursor;
|
|
|
|
controls->SetAutoPan( true );
|
|
|
|
m_moveInProgress = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Follow the mouse
|
|
|
|
//
|
2023-08-22 14:09:04 +00:00
|
|
|
m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ),
|
|
|
|
grid.GetSelectionGrid( selection ), selection );
|
2019-05-08 18:56:03 +00:00
|
|
|
VECTOR2I delta( m_cursor - prevPos );
|
2019-08-09 22:45:44 +00:00
|
|
|
m_anchorPos = m_cursor;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-07-01 21:35:39 +00:00
|
|
|
moveOffset += delta;
|
2019-05-08 18:56:03 +00:00
|
|
|
prevPos = m_cursor;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
moveItem( item, delta );
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( item, false );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 18:40:49 +00:00
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel
|
|
|
|
//
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( m_moveInProgress )
|
2020-08-25 11:53:39 +00:00
|
|
|
{
|
|
|
|
evt->SetPassEvent( false );
|
2019-05-08 18:56:03 +00:00
|
|
|
restore_state = true;
|
2020-08-25 11:53:39 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle TOOL_ACTION special cases
|
|
|
|
//
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
|
|
|
unselect = true;
|
|
|
|
break;
|
|
|
|
}
|
2023-07-01 21:35:39 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::doDelete ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2023-07-01 21:35:39 +00:00
|
|
|
// Exit on a remove operation; there is no further processing for removed items.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate ) )
|
|
|
|
{
|
|
|
|
wxBell();
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle context menu
|
|
|
|
//
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle drop
|
|
|
|
//
|
2020-12-14 22:03:17 +00:00
|
|
|
else if( evt->IsMouseUp( BUT_LEFT )
|
|
|
|
|| evt->IsClick( BUT_LEFT )
|
|
|
|
|| evt->IsDblClick( BUT_LEFT ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( selection.GetSize() == 1 && selection.Front()->Type() == LIB_PIN_T )
|
|
|
|
{
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-01-13 16:23:09 +00:00
|
|
|
try
|
|
|
|
{
|
2023-04-06 09:08:01 +00:00
|
|
|
LIB_PIN* curr_pin = (LIB_PIN*) selection.Front();
|
2023-12-22 14:59:40 +00:00
|
|
|
|
|
|
|
if( pinTool->PlacePin( curr_pin ) )
|
|
|
|
{
|
|
|
|
// PlacePin() clears the current selection, which we don't want. Not only
|
|
|
|
// is it a poor user experience, but it also prevents us from doing the
|
|
|
|
// proper cleanup at the end of this routine (ie: clearing the edit flags).
|
|
|
|
m_selectionTool->AddItemToSel( curr_pin, true /*quiet mode*/ );
|
|
|
|
}
|
2023-04-06 09:08:01 +00:00
|
|
|
else
|
2023-12-22 14:59:40 +00:00
|
|
|
{
|
|
|
|
restore_state = true;
|
|
|
|
}
|
2021-01-13 16:23:09 +00:00
|
|
|
}
|
|
|
|
catch( const boost::bad_pointer& e )
|
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
restore_state = true;
|
2021-01-13 16:23:09 +00:00
|
|
|
wxLogError( "Boost pointer exception occurred: \"%s\"", e.what() );
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break; // Finish
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-15 17:42:51 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-15 17:42:51 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
} while( ( evt = Wait() ) ); // Assignment intentional; not equality test
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
controls->ShowCursor( false );
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
|
2019-08-09 22:45:44 +00:00
|
|
|
m_anchorPos = { 0, 0 };
|
|
|
|
|
2021-07-07 18:00:00 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2019-05-11 10:06:28 +00:00
|
|
|
item->ClearEditFlags();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-07-01 21:35:39 +00:00
|
|
|
if( unselect )
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
m_moveInProgress = false;
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2023-07-01 21:35:39 +00:00
|
|
|
|
|
|
|
return !restore_state;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-30 14:45:07 +00:00
|
|
|
int SYMBOL_EDITOR_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr);
|
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection();
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
|
|
|
|
auto doMoveItem =
|
|
|
|
[&]( EDA_ITEM* item, const VECTOR2I& delta )
|
|
|
|
{
|
|
|
|
commit.Modify( item, m_frame->GetScreen() );
|
2024-06-07 16:58:19 +00:00
|
|
|
static_cast<LIB_ITEM*>( item )->Offset( delta );
|
2023-08-30 14:45:07 +00:00
|
|
|
updateItem( item, true );
|
|
|
|
};
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
if( LIB_SHAPE* shape = dynamic_cast<LIB_SHAPE*>( item ) )
|
|
|
|
{
|
|
|
|
VECTOR2I newStart = grid.AlignGrid( shape->GetStart(), grid.GetItemGrid( shape ) );
|
|
|
|
VECTOR2I newEnd = grid.AlignGrid( shape->GetEnd(), grid.GetItemGrid( shape ) );
|
|
|
|
|
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::SEGMENT:
|
|
|
|
case SHAPE_T::RECTANGLE:
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
if( newStart == newEnd )
|
|
|
|
{
|
|
|
|
// Don't collapse shape; just snap its position
|
|
|
|
if( newStart != shape->GetStart() )
|
|
|
|
doMoveItem( shape, newStart - shape->GetStart() );
|
|
|
|
}
|
|
|
|
else if( newStart != shape->GetStart() || newEnd != shape->GetEnd() )
|
|
|
|
{
|
|
|
|
// Snap both ends
|
|
|
|
commit.Modify( shape, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
shape->SetStart( newStart );
|
|
|
|
shape->SetEnd( newEnd );
|
|
|
|
|
|
|
|
updateItem( item, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
if( shape->GetPointCount() > 0 )
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2I> newPts;
|
|
|
|
|
|
|
|
for( const VECTOR2I& pt : shape->GetPolyShape().Outline( 0 ).CPoints() )
|
|
|
|
newPts.push_back( grid.AlignGrid( pt, grid.GetItemGrid( shape ) ) );
|
|
|
|
|
|
|
|
bool collapsed = false;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < (int) newPts.size() - 1; ++ii )
|
|
|
|
{
|
|
|
|
if( newPts[ii] == newPts[ii + 1] )
|
|
|
|
collapsed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( collapsed )
|
|
|
|
{
|
|
|
|
// Don't collapse shape; just snap its position
|
|
|
|
if( newStart != shape->GetStart() )
|
|
|
|
doMoveItem( shape, newStart - shape->GetStart() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commit.Modify( shape, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < (int) newPts.size(); ++ii )
|
|
|
|
shape->GetPolyShape().Outline( 0 ).SetPoint( ii, newPts[ii] );
|
|
|
|
|
|
|
|
updateItem( item, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
// Snapping bezier control points is unlikely to be useful. Just snap its
|
|
|
|
// position.
|
|
|
|
if( newStart != shape->GetStart() )
|
|
|
|
doMoveItem( shape, newStart - shape->GetStart() );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VECTOR2I newPos = grid.AlignGrid( item->GetPosition(), grid.GetItemGrid( item ) );
|
|
|
|
VECTOR2I delta = newPos - item->GetPosition();
|
|
|
|
|
|
|
|
if( delta != VECTOR2I( 0, 0 ) )
|
|
|
|
doMoveItem( item, delta );
|
|
|
|
|
|
|
|
if( LIB_PIN* pin = dynamic_cast<LIB_PIN*>( item ) )
|
|
|
|
{
|
|
|
|
int length = pin->GetLength();
|
|
|
|
int pinGrid;
|
|
|
|
|
|
|
|
if( pin->GetOrientation() == PIN_ORIENTATION::PIN_LEFT
|
|
|
|
|| pin->GetOrientation() == PIN_ORIENTATION::PIN_RIGHT )
|
|
|
|
{
|
|
|
|
pinGrid = KiROUND( grid.GetGridSize( grid.GetItemGrid( item ) ).x );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pinGrid = KiROUND( grid.GetGridSize( grid.GetItemGrid( item ) ).y );
|
|
|
|
}
|
|
|
|
|
|
|
|
int newLength = KiROUND( (double) length / pinGrid ) * pinGrid;
|
|
|
|
|
|
|
|
if( newLength > 0 )
|
|
|
|
pin->SetLength( newLength );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );
|
|
|
|
|
|
|
|
commit.Push( _( "Align" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-01 21:35:39 +00:00
|
|
|
void SYMBOL_EDITOR_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
static_cast<LIB_ITEM*>( aItem )->Offset( mapCoords( aDelta ) );
|
2021-05-30 21:04:07 +00:00
|
|
|
aItem->SetFlags( IS_MOVING );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
void SYMBOL_EDITOR_MOVE_TOOL::setTransitions()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-12-12 03:13:52 +00:00
|
|
|
Go( &SYMBOL_EDITOR_MOVE_TOOL::Main, EE_ACTIONS::move.MakeEvent() );
|
2023-08-30 14:45:07 +00:00
|
|
|
Go( &SYMBOL_EDITOR_MOVE_TOOL::AlignElements, EE_ACTIONS::alignToGrid.MakeEvent() );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|