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
|
2019-05-04 13:02:05 +00:00
|
|
|
* 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 <tool/tool_manager.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>
|
|
|
|
#include <base_struct.h>
|
2019-05-10 19:57:24 +00:00
|
|
|
#include <sch_item.h>
|
2019-05-04 13:02:05 +00:00
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_view.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#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 ),
|
2019-07-18 01:21:36 +00:00
|
|
|
m_isDragOperation( 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
|
|
|
|
|
|
|
auto moveCondition = [] ( const SELECTION& aSel ) {
|
|
|
|
if( aSel.Empty() )
|
|
|
|
return false;
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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 );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-20 18:51:24 +00:00
|
|
|
/* TODO - Tom/Jeff
|
|
|
|
- add preferences option "Move origin: always cursor / item origin"
|
|
|
|
- add preferences option "Default drag action: drag items / move"
|
|
|
|
- add preferences option "Drag always selects"
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
const KICAD_T movableItems[] =
|
|
|
|
{
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_BITMAP_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
controls->SetSnapping( true );
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
m_anchorPos.reset();
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::move ) )
|
|
|
|
m_isDragOperation = false;
|
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::drag ) )
|
|
|
|
m_isDragOperation = true;
|
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::moveActivate ) )
|
|
|
|
m_isDragOperation = !m_frame->GetDragActionIsMove();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( m_moveInProgress )
|
|
|
|
{
|
2019-07-18 01:21:36 +00:00
|
|
|
auto sel = m_selectionTool->GetSelection().Front();
|
|
|
|
|
|
|
|
if( sel && !sel->IsNew() )
|
2019-05-31 18:23:49 +00:00
|
|
|
{
|
|
|
|
// User must have switched from move to drag or vice-versa. Reset the selected
|
|
|
|
// items so we can start again with the current m_isDragOperation.
|
|
|
|
m_frame->RollbackSchematicFromUndo();
|
|
|
|
m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
|
2019-06-11 14:17:24 +00:00
|
|
|
m_anchorPos = m_cursor - m_moveOffset;
|
2019-05-31 18:23:49 +00:00
|
|
|
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.
|
2019-06-11 14:17:24 +00:00
|
|
|
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).
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( movableItems );
|
|
|
|
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
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
|
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;
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-09-11 23:59:16 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
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
|
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
2019-05-04 13:02:05 +00:00
|
|
|
controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
|
|
|
|
2019-06-11 14:17:24 +00:00
|
|
|
if( evt->IsAction( &EE_ACTIONS::moveActivate ) || evt->IsAction( &EE_ACTIONS::restartMove )
|
2019-05-20 18:51:24 +00:00
|
|
|
|| evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag )
|
2019-05-04 13:02:05 +00:00
|
|
|
|| 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();
|
2019-07-18 01:21:36 +00:00
|
|
|
bool appendUndo = sch_item && sch_item->IsNew();
|
2020-01-10 17:22:23 +00:00
|
|
|
bool 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();
|
2019-10-19 03:15:29 +00:00
|
|
|
internalPoints.clear();
|
2019-08-31 19:20:44 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
for( auto 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
|
|
|
}
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
if( m_isDragOperation )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-05-31 18:23:49 +00:00
|
|
|
// Add connections to the selection for a drag.
|
|
|
|
//
|
2019-05-04 13:02:05 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
if( static_cast<SCH_ITEM*>( item )->IsConnectable() )
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> connections;
|
2019-06-11 20:17:05 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
static_cast<SCH_LINE*>( item )->GetSelectedPoints( connections );
|
|
|
|
else
|
|
|
|
static_cast<SCH_ITEM*>( item )->GetConnectionPoints( connections );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
for( wxPoint point : connections )
|
2019-05-18 12:52:03 +00:00
|
|
|
getConnectedDragItems( (SCH_ITEM*) item, point, m_dragAdditions );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 12:52:03 +00:00
|
|
|
m_selectionTool->AddItemsToSel( &m_dragAdditions, 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 )
|
|
|
|
{
|
2019-05-07 19:06:46 +00:00
|
|
|
if( item->IsNew() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-12-24 22:12:16 +00:00
|
|
|
if( item->HasFlag( TEMP_SELECTED ) && m_isDragOperation )
|
2019-05-07 19:06:46 +00:00
|
|
|
{
|
|
|
|
// Item was added in getConnectedDragItems
|
|
|
|
saveCopyInUndoList( (SCH_ITEM*) item, UR_NEW, appendUndo );
|
|
|
|
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
|
|
|
|
{
|
2019-05-04 17:17:56 +00:00
|
|
|
saveCopyInUndoList( (SCH_ITEM*) item, UR_CHANGED, appendUndo );
|
|
|
|
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 ) )
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_anchorPos, "Should be already set from previous cmd" );
|
|
|
|
}
|
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);
|
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;
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
moveItem( item, delta, m_isDragOperation );
|
2019-05-04 13:02:05 +00:00
|
|
|
updateView( item );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// hierarchical sheets or components can have the anchor outside the view)
|
2019-06-11 20:17:05 +00:00
|
|
|
else if( selection.Size() == 1 && sch_item->IsMovableFromAnchorPoint()
|
|
|
|
&& m_frame->GetMoveWarpsCursor() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-08-27 12:12:34 +00:00
|
|
|
if( sch_item->Type() == SCH_LINE_T && !sch_item->HasFlag( STARTPOINT ) )
|
2019-06-11 20:17:05 +00:00
|
|
|
m_anchorPos = static_cast<SCH_LINE*>( sch_item )->GetEndPoint();
|
|
|
|
else
|
|
|
|
m_anchorPos = sch_item->GetPosition();
|
|
|
|
|
2019-08-04 01:02:15 +00:00
|
|
|
getViewControls()->WarpCursor( *m_anchorPos, true, true );
|
2019-06-11 14:17:24 +00:00
|
|
|
m_cursor = *m_anchorPos;
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2019-06-11 14:17:24 +00:00
|
|
|
// ...otherwise modify items with regard to the grid-snapped cursor position
|
2019-05-04 13:02:05 +00:00
|
|
|
else
|
|
|
|
{
|
2019-06-11 14:17:24 +00:00
|
|
|
m_cursor = getViewControls()->GetCursorPosition( true );
|
|
|
|
m_anchorPos = m_cursor;
|
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
|
|
|
|
//
|
|
|
|
m_cursor = controls->GetCursorPosition();
|
|
|
|
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;
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
moveItem( item, delta, m_isDragOperation );
|
2019-05-04 13:02:05 +00:00
|
|
|
updateView( item );
|
|
|
|
}
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
2019-05-04 13:02:05 +00:00
|
|
|
m_frame->UpdateMsgPanel();
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel
|
|
|
|
//
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
if( m_moveInProgress )
|
|
|
|
restore_state = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle TOOL_ACTION special cases
|
|
|
|
//
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
|
|
|
unselect = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2019-07-31 12:48:00 +00:00
|
|
|
if( evt->IsAction( &ACTIONS::doDelete ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
// Exit on a remove operation; there is no further processing for removed items.
|
|
|
|
break;
|
|
|
|
}
|
2019-05-27 10:40:52 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
if( selection.Front()->IsNew() )
|
|
|
|
{
|
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
|
|
|
// objects so Duplicate() is going to ignore this and we'll just carry on.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move original back and exit. The duplicate will run in its own loop.
|
|
|
|
restore_state = true;
|
|
|
|
unselect = false;
|
|
|
|
chain_commands = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-06-15 00:29:42 +00:00
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = dynamic_cast<SCH_COMPONENT*>( selection.Front() );
|
|
|
|
int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
|
|
|
|
|
|
|
|
if( component )
|
|
|
|
{
|
|
|
|
m_frame->SelectUnit( component, unit );
|
2019-07-04 20:56:21 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
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
|
|
|
|
//
|
|
|
|
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
break; // Finish
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
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->SetSnapping( 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
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Moving items changes the RTree box bounds.
|
|
|
|
for( auto item : selection )
|
2020-01-25 17:23:28 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
// Moving sheet pins does not change the BBox.
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Moving fields should update the associated component
|
|
|
|
case SCH_FIELD_T:
|
|
|
|
if( item->GetParent() )
|
|
|
|
m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( item->GetParent() ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( item ) );
|
|
|
|
}
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
|
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.
|
|
|
|
for( auto it : internalPoints )
|
|
|
|
{
|
|
|
|
if( m_frame->GetScreen()->IsJunctionNeeded( it.GetPosition(), true ) )
|
|
|
|
m_frame->AddJunction( it.GetPosition(), true, false );
|
|
|
|
}
|
|
|
|
|
2019-06-19 03:10:21 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &selection );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
|
2019-10-19 03:15:29 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
m_frame->SchematicCleanUp();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 11:00:24 +00:00
|
|
|
void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aOriginalItem, wxPoint aPoint,
|
|
|
|
EDA_ITEMS& aList )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto test : m_frame->GetScreen()->Items() )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-05-07 11:00:24 +00:00
|
|
|
if( test->IsSelected() || !test->IsConnectable() || !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:
|
|
|
|
{
|
2019-05-07 19:06:46 +00:00
|
|
|
// Select the connected end of wires/bus connections.
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_LINE* testLine = static_cast<SCH_LINE*>( test );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-05-07 11:00:24 +00:00
|
|
|
if( testLine->GetStartPoint() == aPoint )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-08-31 19:20:44 +00:00
|
|
|
if( !testLine->HasFlag( TEMP_SELECTED ) )
|
2019-05-07 11:00:24 +00:00
|
|
|
aList.push_back( testLine );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-08-31 19:20:44 +00:00
|
|
|
testLine->SetFlags( STARTPOINT | TEMP_SELECTED );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2019-05-07 11:00:24 +00:00
|
|
|
else if( testLine->GetEndPoint() == aPoint )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-08-31 19:20:44 +00:00
|
|
|
if( !testLine->HasFlag( TEMP_SELECTED ) )
|
2019-05-07 11:00:24 +00:00
|
|
|
aList.push_back( testLine );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-08-31 19:20:44 +00:00
|
|
|
testLine->SetFlags( ENDPOINT | TEMP_SELECTED );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
// Dragging a sheet just because it's connected to something else feels a bit like
|
|
|
|
// the tail wagging the dog, but this could be moved down to the next case.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_COMPONENT_T:
|
2019-05-07 11:00:24 +00:00
|
|
|
if( test->IsConnected( aPoint ) )
|
|
|
|
{
|
2019-05-31 20:52:07 +00:00
|
|
|
// Add a new wire between the component and the selected item so the selected
|
|
|
|
// item can be dragged.
|
|
|
|
SCH_LINE* newWire = new SCH_LINE( aPoint, LAYER_WIRE );
|
|
|
|
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:
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
// Select no-connects and junctions 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:
|
|
|
|
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;
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
// Select labels and bus entries that are connected to a wire being moved.
|
2019-08-31 19:20:44 +00:00
|
|
|
if( aOriginalItem->Type() == SCH_LINE_T )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
std::vector<wxPoint> connections;
|
|
|
|
test->GetConnectionPoints( connections );
|
|
|
|
|
|
|
|
for( wxPoint& point : connections )
|
|
|
|
{
|
2019-05-07 11:00:24 +00:00
|
|
|
if( aOriginalItem->HitTest( point ) )
|
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
|
|
|
|
if( testType == SCH_BUS_WIRE_ENTRY_T || testType == SCH_BUS_BUS_ENTRY_T )
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> ends;
|
|
|
|
wxPoint otherEnd;
|
|
|
|
|
|
|
|
test->GetConnectionPoints( ends );
|
|
|
|
|
|
|
|
if( ends[0] == point )
|
|
|
|
otherEnd = ends[1];
|
|
|
|
else
|
|
|
|
otherEnd = ends[0];
|
|
|
|
|
|
|
|
getConnectedDragItems( (SCH_ITEM*) test, otherEnd, m_dragAdditions );
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-06 15:30:29 +00:00
|
|
|
void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta, bool isDrag )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
2019-08-27 12:12:34 +00:00
|
|
|
if( aItem->HasFlag( STARTPOINT ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
static_cast<SCH_LINE*>( aItem )->MoveStart( (wxPoint) aDelta );
|
|
|
|
|
2019-08-27 12:12:34 +00:00
|
|
|
if( aItem->HasFlag( ENDPOINT ) )
|
2019-05-04 13:02:05 +00:00
|
|
|
static_cast<SCH_LINE*>( aItem )->MoveEnd( (wxPoint) aDelta );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_PIN_T:
|
|
|
|
case SCH_FIELD_T:
|
2019-05-06 15:58:53 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aItem->GetParent();
|
|
|
|
TRANSFORM transform = component->GetTransform().InverseTransform();
|
|
|
|
wxPoint transformedDelta = transform.TransformCoordinate( (wxPoint) aDelta );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2019-05-06 15:58:53 +00:00
|
|
|
static_cast<SCH_ITEM*>( aItem )->Move( transformedDelta );
|
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
|
|
|
|
if( aItem->Type() == SCH_FIELD_T && !component->IsSelected() )
|
|
|
|
component->ClearFieldsAutoplaced();
|
|
|
|
|
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;
|
|
|
|
}
|
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 );
|
2019-05-04 13:02:05 +00:00
|
|
|
aItem->SetFlags( IS_MOVED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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() );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|