2019-05-04 13:02:05 +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
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-04 13:02:05 +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>
|
2020-09-09 17:08:24 +00:00
|
|
|
#include <tools/ee_grid_helper.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
2019-06-16 13:42:40 +00:00
|
|
|
#include <tools/sch_line_wire_bus_tool.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_actions.h>
|
2019-05-04 13:02:05 +00:00
|
|
|
#include <bitmaps.h>
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2019-05-10 19:57:24 +00:00
|
|
|
#include <sch_item.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-05-04 13:02:05 +00:00
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2019-05-04 13:02:05 +00:00
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <eeschema_id.h>
|
2020-04-12 23:09:17 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2019-05-04 13:02:05 +00:00
|
|
|
#include "sch_move_tool.h"
|
|
|
|
|
|
|
|
|
|
|
|
// For adding to or removing from selections
|
|
|
|
#define QUIET_MODE true
|
|
|
|
|
|
|
|
|
|
|
|
SCH_MOVE_TOOL::SCH_MOVE_TOOL() :
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveMove" ),
|
2019-05-04 13:02:05 +00:00
|
|
|
m_moveInProgress( false ),
|
2021-03-22 12:51:32 +00:00
|
|
|
m_isDrag( false ),
|
2019-05-04 13:02:05 +00:00
|
|
|
m_moveOffset( 0, 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_MOVE_TOOL::Init()
|
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2020-12-27 12:36:11 +00:00
|
|
|
auto moveCondition =
|
|
|
|
[]( const SELECTION& aSel )
|
|
|
|
{
|
2021-02-19 14:51:18 +00:00
|
|
|
if( aSel.Empty() || SELECTION_CONDITIONS::OnlyType( SCH_MARKER_T )( aSel ) )
|
2020-12-27 12:36:11 +00:00
|
|
|
return false;
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2020-12-27 12:36:11 +00:00
|
|
|
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
|
|
|
|
return false;
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2020-12-27 12:36:11 +00:00
|
|
|
return true;
|
|
|
|
};
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
// Add move actions to the selection tool menu
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::move, moveCondition, 150 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::drag, moveCondition, 150 );
|
2020-09-17 19:26:54 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::alignToGrid, moveCondition, 150 );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-12-02 23:17:56 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
2019-05-04 13:02:05 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2020-12-02 23:17:56 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2021-03-22 12:51:32 +00:00
|
|
|
bool wasDragging = m_moveInProgress && m_isDrag;
|
2022-02-18 15:29:22 +00:00
|
|
|
SCH_MOVE_TOOL_PARAMS* params = aEvent.Parameter<SCH_MOVE_TOOL_PARAMS*>();
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
m_anchorPos.reset();
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::move ) )
|
2021-03-22 12:51:32 +00:00
|
|
|
m_isDrag = false;
|
2019-05-31 18:23:49 +00:00
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::drag ) )
|
2021-03-22 12:51:32 +00:00
|
|
|
m_isDrag = true;
|
2019-05-31 18:23:49 +00:00
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::moveActivate ) )
|
2021-03-22 12:51:32 +00:00
|
|
|
m_isDrag = !cfg->m_Input.drag_is_move;
|
2019-05-31 18:23:49 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( m_moveInProgress )
|
|
|
|
{
|
2021-03-22 12:51:32 +00:00
|
|
|
if( m_isDrag != wasDragging )
|
2019-05-31 18:23:49 +00:00
|
|
|
{
|
2021-04-07 09:48:51 +00:00
|
|
|
EDA_ITEM* sel = m_selectionTool->GetSelection().Front();
|
2021-03-22 12:51:32 +00:00
|
|
|
|
|
|
|
if( sel && !sel->IsNew() )
|
|
|
|
{
|
|
|
|
// Reset the selected items so we can start again with the current m_isDrag
|
|
|
|
// state.
|
|
|
|
m_frame->RollbackSchematicFromUndo();
|
|
|
|
m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
|
|
|
|
m_anchorPos = m_cursor - m_moveOffset;
|
|
|
|
m_moveInProgress = false;
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
|
|
|
|
// And give it a kick so it doesn't have to wait for the first mouse movement
|
|
|
|
// to refresh.
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::restartMove );
|
|
|
|
}
|
2019-05-31 18:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-20 15:42:49 +00:00
|
|
|
|
2019-05-04 13:02:05 +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-13 01:15:45 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::MovableItems );
|
2019-06-08 21:48:22 +00:00
|
|
|
bool unselect = selection.IsHover();
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-10-19 03:15:29 +00:00
|
|
|
// Keep an original copy of the starting points for cleanup after the move
|
|
|
|
std::vector<DANGLING_END_ITEM> internalPoints;
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
Activate();
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
2019-05-04 13:02:05 +00:00
|
|
|
controls->ShowCursor( true );
|
|
|
|
|
2020-10-18 10:29:08 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
{
|
|
|
|
// Note that it's important to go through push/pop even when the selection is empty.
|
|
|
|
// This keeps other tools from having to special-case an empty move.
|
|
|
|
m_frame->PopTool( tool );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
bool restore_state = false;
|
|
|
|
bool chain_commands = false;
|
|
|
|
TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
|
|
|
|
VECTOR2I prevPos;
|
2020-12-03 15:10:23 +00:00
|
|
|
int snapLayer = UNDEFINED_LAYER;
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-05-20 15:42:49 +00:00
|
|
|
m_cursor = controls->GetCursorPosition();
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
// Main loop: keep receiving events
|
|
|
|
do
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
2020-12-02 23:17:56 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2020-12-02 23:17:56 +00:00
|
|
|
|
|
|
|
if( evt->IsAction( &EE_ACTIONS::moveActivate )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::restartMove )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::move )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::drag )
|
|
|
|
|| evt->IsMotion()
|
|
|
|
|| evt->IsDrag( BUT_LEFT )
|
2019-07-04 20:56:21 +00:00
|
|
|
|| evt->IsAction( &ACTIONS::refreshPreview ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
if( !m_moveInProgress ) // Prepare to start moving/dragging
|
|
|
|
{
|
2019-06-11 20:17:05 +00:00
|
|
|
SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
|
2022-02-18 15:29:22 +00:00
|
|
|
bool appendUndo =
|
|
|
|
params ? params->appendToLastUndo : ( sch_item && sch_item->IsNew() );
|
|
|
|
bool placingNewItems =
|
|
|
|
params ? params->placingNewItems : ( sch_item && sch_item->IsNew() );
|
|
|
|
|
2019-05-18 12:52:03 +00:00
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Setup a drag or a move
|
|
|
|
//
|
2019-08-31 19:20:44 +00:00
|
|
|
m_dragAdditions.clear();
|
2020-05-06 10:53:56 +00:00
|
|
|
m_specialCaseLabels.clear();
|
2019-10-19 03:15:29 +00:00
|
|
|
internalPoints.clear();
|
2019-08-31 19:20:44 +00:00
|
|
|
|
2020-10-12 09:32:51 +00:00
|
|
|
for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
it->ClearFlags( TEMP_SELECTED );
|
2019-08-29 21:00:38 +00:00
|
|
|
|
2019-06-11 20:17:05 +00:00
|
|
|
if( !it->IsSelected() )
|
2019-08-29 21:00:38 +00:00
|
|
|
it->ClearFlags( STARTPOINT | ENDPOINT );
|
2019-06-13 18:57:11 +00:00
|
|
|
|
|
|
|
if( !selection.IsHover() && it->IsSelected() )
|
|
|
|
it->SetFlags( STARTPOINT | ENDPOINT );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 12:51:32 +00:00
|
|
|
if( m_isDrag )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-03-22 12:51:32 +00:00
|
|
|
EDA_ITEMS connectedDragItems;
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
// Add connections to the selection for a drag.
|
|
|
|
//
|
2020-10-12 09:32:51 +00:00
|
|
|
for( EDA_ITEM* edaItem : selection )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2020-10-12 09:32:51 +00:00
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
|
2020-09-11 16:31:38 +00:00
|
|
|
std::vector<wxPoint> connections;
|
2019-06-11 20:17:05 +00:00
|
|
|
|
2020-09-11 16:31:38 +00:00
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
static_cast<SCH_LINE*>( item )->GetSelectedPoints( connections );
|
|
|
|
else
|
2020-10-12 09:32:51 +00:00
|
|
|
connections = item->GetConnectionPoints();
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2020-09-11 16:31:38 +00:00
|
|
|
for( wxPoint point : connections )
|
2021-03-22 12:51:32 +00:00
|
|
|
getConnectedDragItems( item, point, connectedDragItems );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 12:51:32 +00:00
|
|
|
for( EDA_ITEM* item : connectedDragItems )
|
|
|
|
{
|
|
|
|
m_dragAdditions.push_back( item->m_Uuid );
|
|
|
|
m_selectionTool->AddItemToSel( item, QUIET_MODE );
|
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2019-05-31 18:23:49 +00:00
|
|
|
else
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-05-31 18:23:49 +00:00
|
|
|
// Mark the edges of the block with dangling flags for a move.
|
2019-05-04 13:02:05 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
static_cast<SCH_ITEM*>( item )->GetEndPoints( internalPoints );
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
static_cast<SCH_ITEM*>( item )->UpdateDanglingState( internalPoints );
|
|
|
|
}
|
|
|
|
// Generic setup
|
|
|
|
//
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2020-12-03 15:10:23 +00:00
|
|
|
if( static_cast<SCH_ITEM*>( item )->IsConnectable() )
|
|
|
|
{
|
|
|
|
if( snapLayer == LAYER_GRAPHICS )
|
|
|
|
snapLayer = LAYER_ANY;
|
|
|
|
else
|
|
|
|
snapLayer = LAYER_CONNECTABLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( snapLayer == LAYER_CONNECTABLE )
|
|
|
|
snapLayer = LAYER_ANY;
|
|
|
|
else
|
|
|
|
snapLayer = LAYER_GRAPHICS;
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:06:46 +00:00
|
|
|
if( item->IsNew() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-03-22 12:51:32 +00:00
|
|
|
if( item->HasFlag( TEMP_SELECTED ) && m_isDrag )
|
2019-05-07 19:06:46 +00:00
|
|
|
{
|
|
|
|
// Item was added in getConnectedDragItems
|
2020-08-26 18:04:32 +00:00
|
|
|
saveCopyInUndoList( (SCH_ITEM*) item, UNDO_REDO::NEWITEM, appendUndo );
|
2019-05-07 19:06:46 +00:00
|
|
|
appendUndo = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Item was added in a previous command (and saved to undo by
|
|
|
|
// that command)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
{
|
|
|
|
// Item will be (or has been) saved to undo by parent
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
saveCopyInUndoList( (SCH_ITEM*) item, UNDO_REDO::CHANGED, appendUndo );
|
2019-05-04 17:17:56 +00:00
|
|
|
appendUndo = true;
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
SCH_ITEM* schItem = (SCH_ITEM*) item;
|
|
|
|
schItem->SetStoredPos( schItem->GetPosition() );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the starting position and move/drag offset
|
|
|
|
//
|
|
|
|
m_cursor = controls->GetCursorPosition();
|
|
|
|
|
2019-06-11 14:17:24 +00:00
|
|
|
if( evt->IsAction( &EE_ACTIONS::restartMove ) )
|
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
wxASSERT_MSG( m_anchorPos, wxT( "Should be already set from previous cmd" ) );
|
2019-06-11 14:17:24 +00:00
|
|
|
}
|
2019-12-28 00:29:41 +00:00
|
|
|
else if( placingNewItems )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-05-31 18:23:49 +00:00
|
|
|
m_anchorPos = selection.GetReferencePoint();
|
2019-05-20 15:42:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
if( m_anchorPos )
|
2019-05-20 15:42:49 +00:00
|
|
|
{
|
2019-05-31 18:23:49 +00:00
|
|
|
VECTOR2I delta = m_cursor - (*m_anchorPos);
|
2021-11-06 16:03:41 +00:00
|
|
|
bool isPasted = false;
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
// Drag items to the current cursor position
|
2019-05-06 15:30:29 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
// Don't double move pins, fields, etc.
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2020-04-19 16:04:14 +00:00
|
|
|
moveItem( item, delta );
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( item, false );
|
2021-11-06 16:03:41 +00:00
|
|
|
|
2022-01-01 19:40:27 +00:00
|
|
|
isPasted |= ( item->GetFlags() & IS_PASTED ) != 0;
|
2021-11-06 16:03:41 +00:00
|
|
|
item->ClearFlags( IS_PASTED );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-06 16:03:41 +00:00
|
|
|
// The first time pasted items are moved we need to store
|
|
|
|
// the position of the cursor so that rotate while moving
|
|
|
|
// works as expected (instead of around the original anchor
|
|
|
|
// point
|
|
|
|
if( isPasted )
|
|
|
|
selection.SetReferencePoint( m_cursor );
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
m_anchorPos = m_cursor;
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2019-06-11 14:17:24 +00:00
|
|
|
// For some items, moving the cursor to anchor is not good (for instance large
|
2021-03-29 10:46:05 +00:00
|
|
|
// hierarchical sheets or symbols can have the anchor outside the view)
|
2020-09-09 17:08:24 +00:00
|
|
|
else if( selection.Size() == 1 && !sch_item->IsMovableFromAnchorPoint() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2020-09-09 17:08:24 +00:00
|
|
|
m_cursor = getViewControls()->GetCursorPosition( true );
|
|
|
|
m_anchorPos = m_cursor;
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-18 00:16:08 +00:00
|
|
|
if( m_frame->GetMoveWarpsCursor() )
|
|
|
|
{
|
|
|
|
// User wants to warp the mouse
|
2020-12-03 15:10:23 +00:00
|
|
|
m_cursor = grid.BestDragOrigin( m_cursor, snapLayer, selection );
|
2021-10-18 12:24:06 +00:00
|
|
|
selection.SetReferencePoint( m_cursor );
|
2020-09-18 00:16:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User does not want to warp the mouse
|
|
|
|
m_cursor = getViewControls()->GetCursorPosition( true );
|
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
controls->SetCursorPosition( m_cursor, false );
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
prevPos = m_cursor;
|
|
|
|
controls->SetAutoPan( true );
|
|
|
|
m_moveInProgress = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Follow the mouse
|
|
|
|
//
|
2020-12-02 23:17:56 +00:00
|
|
|
m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ),
|
2020-12-03 15:10:23 +00:00
|
|
|
snapLayer, selection );
|
2020-12-02 23:17:56 +00:00
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
VECTOR2I delta( m_cursor - prevPos );
|
2019-05-31 18:23:49 +00:00
|
|
|
m_anchorPos = m_cursor;
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
m_moveOffset += delta;
|
|
|
|
prevPos = m_cursor;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
// Don't double move pins, fields, etc.
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2020-04-19 16:04:14 +00:00
|
|
|
moveItem( item, delta );
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( item, false );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 12:24:06 +00:00
|
|
|
if( selection.HasReferencePoint() )
|
|
|
|
selection.SetReferencePoint( selection.GetReferencePoint() + delta );
|
|
|
|
|
2020-08-15 18:38:01 +00:00
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel
|
|
|
|
//
|
2021-01-25 17:39:37 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-01-25 17:39:37 +00:00
|
|
|
if( m_moveInProgress )
|
2021-05-08 19:49:09 +00:00
|
|
|
{
|
|
|
|
if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
// Allowing other tools to activate during a move runs the risk of race
|
|
|
|
// conditions in which we try to spool up both event loops at once.
|
|
|
|
|
|
|
|
if( m_isDrag )
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel drag." ) );
|
|
|
|
else
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel move." ) );
|
|
|
|
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->SetPassEvent( false );
|
2019-05-04 13:02:05 +00:00
|
|
|
restore_state = true;
|
2021-05-08 19:49:09 +00:00
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle TOOL_ACTION special cases
|
|
|
|
//
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
|
|
|
unselect = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-09-18 15:44:01 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::doDelete ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-03-15 14:23:17 +00:00
|
|
|
evt->SetPassEvent();
|
|
|
|
// Exit on a delete; there will no longer be anything to drag.
|
2020-09-18 15:44:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate ) )
|
|
|
|
{
|
|
|
|
if( selection.Front()->IsNew() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2020-09-18 15:44:01 +00:00
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
2021-05-08 19:49:09 +00:00
|
|
|
// objects so we ignore the duplicate and just carry on.
|
2020-09-18 15:44:01 +00:00
|
|
|
continue;
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 15:44:01 +00:00
|
|
|
// Move original back and exit. The duplicate will run in its own loop.
|
|
|
|
restore_state = true;
|
|
|
|
unselect = false;
|
|
|
|
chain_commands = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
|
|
|
|
{
|
|
|
|
if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
2021-06-10 14:10:55 +00:00
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_SYM_MAX )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
|
2020-09-18 15:44:01 +00:00
|
|
|
int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2021-03-29 10:46:05 +00:00
|
|
|
if( symbol )
|
2020-09-18 15:44:01 +00:00
|
|
|
{
|
2021-03-29 10:46:05 +00:00
|
|
|
m_frame->SelectUnit( symbol, unit );
|
2020-09-18 15:44:01 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-21 12:25:22 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::highlightNet )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::explicitCrossProbe ) )
|
|
|
|
{
|
|
|
|
// These don't make any sense during a move. Eat them.
|
|
|
|
}
|
2019-05-04 13:02:05 +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-04 13:02:05 +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-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
break; // Finish
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2021-03-15 14:23:17 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2021-03-15 14:23:17 +00:00
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-05-31 17:45:43 +00:00
|
|
|
controls->SetAutoPan( m_moveInProgress );
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
} while( ( evt = Wait() ) ); //Should be assignment not equality test
|
|
|
|
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
controls->ShowCursor( false );
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
|
|
|
|
if( !chain_commands )
|
|
|
|
m_moveOffset = { 0, 0 };
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
m_anchorPos.reset();
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-05-16 21:27:03 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2019-05-11 10:06:28 +00:00
|
|
|
item->ClearEditFlags();
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
if( restore_state )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
|
2019-05-04 13:02:05 +00:00
|
|
|
m_frame->RollbackSchematicFromUndo();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-30 15:15:20 +00:00
|
|
|
// One last update after exiting loop (for slower stuff, such as updating SCREEN's RTree).
|
2020-12-27 12:36:11 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( item, true );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-12-27 13:16:16 +00:00
|
|
|
EE_SELECTION selectionCopy( selection );
|
|
|
|
m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
|
|
|
|
|
2019-10-19 03:15:29 +00:00
|
|
|
// If we move items away from a junction, we _may_ want to add a junction there
|
|
|
|
// to denote the state.
|
2020-12-27 12:36:11 +00:00
|
|
|
for( const DANGLING_END_ITEM& it : internalPoints )
|
2019-10-19 03:15:29 +00:00
|
|
|
{
|
2021-11-04 12:38:15 +00:00
|
|
|
if( m_frame->GetScreen()->IsExplicitJunctionNeeded( it.GetPosition()) )
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddJunction( m_frame->GetScreen(), it.GetPosition(), true, false );
|
2019-10-19 03:15:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 00:49:26 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::trimOverlappingWires, true, &selectionCopy );
|
2020-12-27 13:16:16 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &selectionCopy );
|
2019-10-19 03:15:29 +00:00
|
|
|
|
2021-03-09 21:24:03 +00:00
|
|
|
m_frame->RecalculateConnections( LOCAL_CLEANUP );
|
2019-05-04 13:02:05 +00:00
|
|
|
m_frame->TestDanglingEnds();
|
2019-05-16 21:27:03 +00:00
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
|
2019-08-29 21:00:38 +00:00
|
|
|
if( unselect )
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
else
|
2019-08-31 19:20:44 +00:00
|
|
|
m_selectionTool->RebuildSelection(); // Schematic cleanup might have merged lines, etc.
|
2019-08-29 21:00:38 +00:00
|
|
|
|
2019-05-18 12:52:03 +00:00
|
|
|
m_dragAdditions.clear();
|
2019-06-15 00:29:42 +00:00
|
|
|
m_moveInProgress = false;
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-05-04 13:02:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aOriginalItem, const wxPoint& aPoint,
|
2019-05-07 11:00:24 +00:00
|
|
|
EDA_ITEMS& aList )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2020-10-12 09:32:51 +00:00
|
|
|
EE_RTREE& items = m_frame->GetScreen()->Items();
|
|
|
|
EE_RTREE::EE_TYPE itemsOverlapping = items.Overlapping( aOriginalItem->GetBoundingBox() );
|
2020-10-13 12:52:15 +00:00
|
|
|
bool ptHasUnselectedJunction = false;
|
2020-10-12 09:32:51 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : itemsOverlapping )
|
|
|
|
{
|
2020-10-13 12:52:15 +00:00
|
|
|
if( item->Type() == SCH_JUNCTION_T && item->IsConnected( aPoint ) && !item->IsSelected() )
|
2020-10-12 09:32:51 +00:00
|
|
|
{
|
2020-10-13 12:52:15 +00:00
|
|
|
ptHasUnselectedJunction = true;
|
2020-10-12 09:32:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-09-11 16:31:38 +00:00
|
|
|
|
2021-04-07 09:48:51 +00:00
|
|
|
for( SCH_ITEM* test : itemsOverlapping )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2020-09-17 19:26:54 +00:00
|
|
|
if( test == aOriginalItem || test->IsSelected() || !test->CanConnect( aOriginalItem ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
continue;
|
|
|
|
|
2019-11-17 18:55:27 +00:00
|
|
|
KICAD_T testType = test->Type();
|
|
|
|
|
|
|
|
switch( testType )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
|
|
|
{
|
2020-10-13 12:52:15 +00:00
|
|
|
// Select the connected end of wires/bus connections that don't have an unselected
|
|
|
|
// junction isolating them from the drag
|
|
|
|
if( ptHasUnselectedJunction )
|
2020-10-12 09:32:51 +00:00
|
|
|
break;
|
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( test );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
if( line->GetStartPoint() == aPoint )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-04-07 13:37:58 +00:00
|
|
|
if( !line->HasFlag(TEMP_SELECTED ) )
|
|
|
|
aList.push_back( line );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
line->SetFlags(STARTPOINT | TEMP_SELECTED );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2021-04-07 13:37:58 +00:00
|
|
|
else if( line->GetEndPoint() == aPoint )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-04-07 13:37:58 +00:00
|
|
|
if( !line->HasFlag(TEMP_SELECTED ) )
|
|
|
|
aList.push_back( line );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
line->SetFlags(ENDPOINT | TEMP_SELECTED );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2020-05-06 19:35:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2020-05-06 10:53:56 +00:00
|
|
|
|
|
|
|
// Since only one end is going to move, the movement vector of any labels attached
|
|
|
|
// to it is scaled by the proportion of the line length the label is from the moving
|
|
|
|
// end.
|
2020-10-12 09:32:51 +00:00
|
|
|
for( SCH_ITEM* item : itemsOverlapping )
|
2020-05-06 10:53:56 +00:00
|
|
|
{
|
2020-10-12 09:32:51 +00:00
|
|
|
if( item->Type() == SCH_LABEL_T )
|
2020-05-06 10:53:56 +00:00
|
|
|
{
|
|
|
|
SCH_TEXT* label = static_cast<SCH_TEXT*>( item );
|
|
|
|
|
2020-10-12 09:32:51 +00:00
|
|
|
if( label->IsSelected() )
|
|
|
|
continue; // These will be moved on their own because they're selected
|
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
if( label->HasFlag( TEMP_SELECTED ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( label->CanConnect( line ) && line->HitTest( label->GetPosition(), 1 ) )
|
2020-10-12 09:32:51 +00:00
|
|
|
{
|
2021-04-07 13:37:58 +00:00
|
|
|
label->SetFlags( TEMP_SELECTED );
|
|
|
|
aList.push_back( label );
|
2020-05-06 10:53:56 +00:00
|
|
|
|
2020-10-12 09:32:51 +00:00
|
|
|
SPECIAL_CASE_LABEL_INFO info;
|
2021-04-07 13:37:58 +00:00
|
|
|
info.attachedLine = line;
|
2020-10-12 09:32:51 +00:00
|
|
|
info.originalLabelPos = label->GetPosition();
|
|
|
|
m_specialCaseLabels[label] = info;
|
|
|
|
}
|
2020-05-06 10:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_SHEET_T:
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2020-10-12 09:32:51 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2019-05-07 11:00:24 +00:00
|
|
|
if( test->IsConnected( aPoint ) )
|
|
|
|
{
|
2021-03-29 10:46:05 +00:00
|
|
|
// Add a new wire between the symbol or junction and the selected item so
|
2020-10-12 09:32:51 +00:00
|
|
|
// the selected item can be dragged.
|
2021-01-23 16:45:36 +00:00
|
|
|
SCH_LINE* newWire = nullptr;
|
|
|
|
|
2021-06-04 02:29:04 +00:00
|
|
|
if( test->GetLayer() == LAYER_BUS_JUNCTION ||
|
|
|
|
aOriginalItem->GetLayer() == LAYER_BUS )
|
|
|
|
{
|
2021-01-23 16:45:36 +00:00
|
|
|
newWire = new SCH_LINE( aPoint, LAYER_BUS );
|
2021-06-04 02:29:04 +00:00
|
|
|
}
|
2021-01-23 16:45:36 +00:00
|
|
|
else
|
|
|
|
newWire = new SCH_LINE( aPoint, LAYER_WIRE );
|
|
|
|
|
2019-05-31 20:52:07 +00:00
|
|
|
newWire->SetFlags( IS_NEW );
|
|
|
|
m_frame->AddToScreen( newWire, m_frame->GetScreen() );
|
|
|
|
|
2019-08-31 19:20:44 +00:00
|
|
|
newWire->SetFlags( TEMP_SELECTED | STARTPOINT );
|
2019-05-31 20:52:07 +00:00
|
|
|
aList.push_back( newWire );
|
|
|
|
}
|
|
|
|
break;
|
2019-05-07 19:06:46 +00:00
|
|
|
|
2019-05-31 20:52:07 +00:00
|
|
|
case SCH_NO_CONNECT_T:
|
2020-10-12 09:32:51 +00:00
|
|
|
// Select no-connects that are connected to items being moved.
|
2019-08-31 19:20:44 +00:00
|
|
|
if( !test->HasFlag( TEMP_SELECTED ) && test->IsConnected( aPoint ) )
|
2019-08-29 21:00:38 +00:00
|
|
|
{
|
2019-05-31 20:52:07 +00:00
|
|
|
aList.push_back( test );
|
2019-08-31 19:20:44 +00:00
|
|
|
test->SetFlags( TEMP_SELECTED );
|
2019-08-29 21:00:38 +00:00
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
2021-04-07 13:37:58 +00:00
|
|
|
// Performance optimization:
|
|
|
|
if( test->HasFlag( TEMP_SELECTED ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Select labels that are connected to a wire (or bus) being moved.
|
|
|
|
if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
|
|
|
|
{
|
|
|
|
SCH_TEXT* label = static_cast<SCH_TEXT*>( test );
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
|
|
|
|
bool oneEndFixed = !line->HasFlag( STARTPOINT ) || !line->HasFlag( ENDPOINT );
|
|
|
|
|
|
|
|
if( line->HitTest( label->GetTextPos(), 1 ) )
|
|
|
|
{
|
|
|
|
label->SetFlags( TEMP_SELECTED );
|
|
|
|
aList.push_back( label );
|
|
|
|
|
|
|
|
if( oneEndFixed )
|
|
|
|
{
|
|
|
|
SPECIAL_CASE_LABEL_INFO info;
|
|
|
|
info.attachedLine = line;
|
|
|
|
info.originalLabelPos = label->GetPosition();
|
|
|
|
m_specialCaseLabels[ label ] = info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
2019-08-31 19:20:44 +00:00
|
|
|
// Performance optimization:
|
|
|
|
if( test->HasFlag( TEMP_SELECTED ) )
|
|
|
|
break;
|
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
// Select bus entries that are connected to a bus being moved.
|
|
|
|
if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-04-07 13:37:58 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
|
|
|
|
bool oneEndFixed = !line->HasFlag( STARTPOINT ) || !line->HasFlag( ENDPOINT );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
if( oneEndFixed )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2021-04-07 13:37:58 +00:00
|
|
|
// This is only going to end in tears, so don't go there
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( wxPoint& point : test->GetConnectionPoints() )
|
|
|
|
{
|
|
|
|
if( line->HitTest( point, 1 ) )
|
2019-08-29 21:00:38 +00:00
|
|
|
{
|
2019-08-31 19:20:44 +00:00
|
|
|
test->SetFlags( TEMP_SELECTED );
|
2019-05-04 13:02:05 +00:00
|
|
|
aList.push_back( test );
|
2019-11-17 18:55:27 +00:00
|
|
|
|
|
|
|
// A bus entry needs its wire & label as well
|
2021-04-07 13:37:58 +00:00
|
|
|
std::vector<wxPoint> ends = test->GetConnectionPoints();
|
|
|
|
wxPoint otherEnd;
|
2019-11-17 18:55:27 +00:00
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
if( ends[0] == point )
|
|
|
|
otherEnd = ends[1];
|
|
|
|
else
|
|
|
|
otherEnd = ends[0];
|
2019-11-17 18:55:27 +00:00
|
|
|
|
2021-04-07 13:37:58 +00:00
|
|
|
getConnectedDragItems( test, otherEnd, aList );
|
|
|
|
|
|
|
|
// No need to test the other end of the bus entry
|
2019-08-29 21:00:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-17 18:55:27 +00:00
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
break;
|
2019-05-07 11:00:24 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-19 16:04:14 +00:00
|
|
|
void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
2020-04-19 16:04:14 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
|
|
|
|
|
2019-08-27 12:12:34 +00:00
|
|
|
if( aItem->HasFlag( STARTPOINT ) )
|
2020-04-19 16:04:14 +00:00
|
|
|
line->MoveStart( (wxPoint) aDelta );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-08-27 12:12:34 +00:00
|
|
|
if( aItem->HasFlag( ENDPOINT ) )
|
2020-04-19 16:04:14 +00:00
|
|
|
line->MoveEnd( (wxPoint) aDelta );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2020-04-19 16:04:14 +00:00
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_PIN_T:
|
|
|
|
case SCH_FIELD_T:
|
2019-05-06 15:58:53 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
SCH_ITEM* parent = (SCH_ITEM*) aItem->GetParent();
|
|
|
|
wxPoint delta( aDelta );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( parent && parent->Type() == SCH_SYMBOL_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem->GetParent();
|
|
|
|
TRANSFORM transform = symbol->GetTransform().InverseTransform();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
delta = transform.TransformCoordinate( delta );
|
|
|
|
}
|
|
|
|
|
|
|
|
static_cast<SCH_ITEM*>( aItem )->Move( delta );
|
2019-10-01 14:31:25 +00:00
|
|
|
|
|
|
|
// If we're moving a field with respect to its parent then it's no longer auto-placed
|
2020-04-01 07:34:44 +00:00
|
|
|
if( aItem->Type() == SCH_FIELD_T && parent && !parent->IsSelected() )
|
2020-03-06 20:02:58 +00:00
|
|
|
parent->ClearFieldsAutoplaced();
|
2019-10-01 14:31:25 +00:00
|
|
|
|
2019-05-06 15:58:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-05-16 21:27:03 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
{
|
|
|
|
SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) aItem;
|
2019-05-17 16:45:27 +00:00
|
|
|
pin->SetStoredPos( pin->GetStoredPos() + (wxPoint) aDelta );
|
|
|
|
pin->ConstrainOnEdge( pin->GetStoredPos() );
|
2019-05-16 21:27:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-06 10:53:56 +00:00
|
|
|
case SCH_LABEL_T:
|
|
|
|
{
|
|
|
|
SCH_TEXT* label = static_cast<SCH_TEXT*>( aItem );
|
|
|
|
|
|
|
|
if( m_specialCaseLabels.count( label ) )
|
2020-05-07 17:59:06 +00:00
|
|
|
{
|
|
|
|
SPECIAL_CASE_LABEL_INFO info = m_specialCaseLabels[ label ];
|
|
|
|
SEG currentLine( info.attachedLine->GetStartPoint(), info.attachedLine->GetEndPoint() );
|
|
|
|
label->SetPosition( (wxPoint) currentLine.NearestPoint( info.originalLabelPos ) );
|
|
|
|
}
|
2020-05-06 10:53:56 +00:00
|
|
|
else
|
2020-12-27 12:36:11 +00:00
|
|
|
{
|
2020-05-06 10:53:56 +00:00
|
|
|
label->Move( (wxPoint) aDelta );
|
2020-12-27 12:36:11 +00:00
|
|
|
}
|
2020-05-06 10:53:56 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
default:
|
2019-05-06 15:30:29 +00:00
|
|
|
static_cast<SCH_ITEM*>( aItem )->Move( (wxPoint) aDelta );
|
2019-05-04 13:02:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-29 22:55:25 +00:00
|
|
|
getView()->Hide( aItem, false );
|
2021-05-30 21:04:07 +00:00
|
|
|
aItem->SetFlags( IS_MOVING );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-17 19:26:54 +00:00
|
|
|
int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr);
|
2021-02-13 01:15:45 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::MovableItems );
|
2020-09-17 19:26:54 +00:00
|
|
|
bool append_undo = false;
|
|
|
|
|
2020-11-06 12:20:52 +00:00
|
|
|
for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
|
|
|
|
{
|
|
|
|
if( !it->IsSelected() )
|
|
|
|
it->ClearFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
|
|
|
if( !selection.IsHover() && it->IsSelected() )
|
|
|
|
it->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
|
|
|
it->SetStoredPos( it->GetPosition() );
|
|
|
|
|
|
|
|
if( it->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( it )->GetPins() )
|
|
|
|
pin->SetStoredPos( pin->GetPosition() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-17 19:26:54 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
|
|
|
std::vector<int> flags{ STARTPOINT, ENDPOINT };
|
|
|
|
std::vector<wxPoint> pts{ line->GetStartPoint(), line->GetEndPoint() };
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 2; ++ii )
|
|
|
|
{
|
|
|
|
EDA_ITEMS drag_items{ item };
|
|
|
|
line->ClearFlags();
|
2021-12-01 00:29:27 +00:00
|
|
|
line->SetFlags( SELECTED );
|
2020-09-17 19:26:54 +00:00
|
|
|
line->SetFlags( flags[ii] );
|
|
|
|
getConnectedDragItems( line, pts[ii], drag_items );
|
|
|
|
std::set<EDA_ITEM*> unique_items( drag_items.begin(), drag_items.end() );
|
|
|
|
|
|
|
|
VECTOR2I gridpt = grid.AlignGrid( pts[ii] ) - pts[ii];
|
|
|
|
|
|
|
|
if( gridpt != VECTOR2I( 0, 0 ) )
|
|
|
|
{
|
2021-01-03 22:39:24 +00:00
|
|
|
for( EDA_ITEM* dragItem : unique_items )
|
2020-09-17 19:26:54 +00:00
|
|
|
{
|
2021-01-03 22:39:24 +00:00
|
|
|
if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
|
2020-09-17 19:26:54 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-03 22:39:24 +00:00
|
|
|
saveCopyInUndoList( dragItem, UNDO_REDO::CHANGED, append_undo );
|
2020-09-17 19:26:54 +00:00
|
|
|
append_undo = true;
|
|
|
|
|
2021-01-03 22:39:24 +00:00
|
|
|
moveItem( dragItem, gridpt );
|
2021-05-30 21:04:07 +00:00
|
|
|
dragItem->ClearFlags( IS_MOVING );
|
2021-01-03 22:39:24 +00:00
|
|
|
updateItem( dragItem, true );
|
2020-09-17 19:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-03 22:39:24 +00:00
|
|
|
else if( item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
VECTOR2I gridpt = grid.AlignGrid( item->GetPosition() ) - item->GetPosition();
|
|
|
|
|
|
|
|
if( gridpt != VECTOR2I( 0, 0 ) )
|
|
|
|
{
|
|
|
|
saveCopyInUndoList( item, UNDO_REDO::CHANGED, append_undo );
|
|
|
|
append_undo = true;
|
|
|
|
|
|
|
|
moveItem( item, gridpt );
|
|
|
|
updateItem( item, true );
|
2021-05-30 21:04:07 +00:00
|
|
|
item->ClearFlags( IS_MOVING );
|
2021-01-03 22:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-17 19:26:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> connections;
|
|
|
|
EDA_ITEMS drag_items{ item };
|
|
|
|
connections = static_cast<SCH_ITEM*>( item )->GetConnectionPoints();
|
|
|
|
|
2020-11-06 12:20:52 +00:00
|
|
|
for( const wxPoint& point : connections )
|
2020-09-17 19:26:54 +00:00
|
|
|
getConnectedDragItems( static_cast<SCH_ITEM*>( item ), point, drag_items );
|
|
|
|
|
|
|
|
std::map<VECTOR2I, int> shifts;
|
|
|
|
VECTOR2I most_common( 0, 0 );
|
|
|
|
int max_count = 0;
|
|
|
|
|
2020-11-06 12:20:52 +00:00
|
|
|
for( const wxPoint& conn : connections )
|
2020-09-17 19:26:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I gridpt = grid.AlignGrid( conn ) - conn;
|
|
|
|
|
|
|
|
shifts[gridpt]++;
|
|
|
|
|
|
|
|
if( shifts[gridpt] > max_count )
|
|
|
|
{
|
|
|
|
most_common = gridpt;
|
|
|
|
max_count = shifts[most_common];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( most_common != VECTOR2I( 0, 0 ) )
|
|
|
|
{
|
2021-01-03 22:39:24 +00:00
|
|
|
for( EDA_ITEM* dragItem : drag_items )
|
2020-09-17 19:26:54 +00:00
|
|
|
{
|
2021-01-03 22:39:24 +00:00
|
|
|
if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
|
2020-09-17 19:26:54 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-03 22:39:24 +00:00
|
|
|
saveCopyInUndoList( dragItem, UNDO_REDO::CHANGED, append_undo );
|
2020-09-17 19:26:54 +00:00
|
|
|
append_undo = true;
|
|
|
|
|
2021-01-03 22:39:24 +00:00
|
|
|
moveItem( dragItem, most_common );
|
2021-05-30 21:04:07 +00:00
|
|
|
dragItem->ClearFlags( IS_MOVING );
|
2021-01-03 22:39:24 +00:00
|
|
|
updateItem( dragItem, true );
|
2020-09-17 19:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );
|
2022-02-20 00:49:26 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::trimOverlappingWires, true, &selection );
|
2020-09-17 19:26:54 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &selection );
|
|
|
|
|
2021-03-09 21:24:03 +00:00
|
|
|
m_frame->RecalculateConnections( LOCAL_CLEANUP );
|
2020-09-17 19:26:54 +00:00
|
|
|
m_frame->TestDanglingEnds();
|
|
|
|
|
|
|
|
m_frame->OnModify();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
void SCH_MOVE_TOOL::setTransitions()
|
|
|
|
{
|
2019-05-15 11:02:30 +00:00
|
|
|
Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::moveActivate.MakeEvent() );
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::move.MakeEvent() );
|
|
|
|
Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::drag.MakeEvent() );
|
2020-09-17 19:26:54 +00:00
|
|
|
Go( &SCH_MOVE_TOOL::AlignElements, EE_ACTIONS::alignToGrid.MakeEvent() );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|