2019-05-20 10:23:32 +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-03-06 12:12:11 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-20 10:23:32 +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
|
|
|
|
*/
|
|
|
|
|
2023-03-29 16:53:28 +00:00
|
|
|
#include <wx/log.h>
|
2023-03-06 12:12:11 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-07-15 23:44:01 +00:00
|
|
|
#include <tool/picker_tool.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <confirm.h>
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2023-09-09 04:10:57 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-13 05:04:31 +00:00
|
|
|
#include <view/view.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2020-10-13 05:04:31 +00:00
|
|
|
#include "tools/pl_selection_tool.h"
|
|
|
|
#include "tools/pl_actions.h"
|
|
|
|
#include "tools/pl_edit_tool.h"
|
|
|
|
#include "pl_draw_panel_gal.h"
|
|
|
|
#include "pl_editor_frame.h"
|
|
|
|
#include "pl_editor_id.h"
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
PL_EDIT_TOOL::PL_EDIT_TOOL() :
|
|
|
|
TOOL_INTERACTIVE( "plEditor.InteractiveEdit" ),
|
|
|
|
m_frame( nullptr ),
|
2020-01-11 16:56:25 +00:00
|
|
|
m_selectionTool( nullptr ),
|
|
|
|
m_moveInProgress( false ),
|
|
|
|
m_moveOffset( 0, 0 ),
|
|
|
|
m_cursor( 0, 0 ),
|
|
|
|
m_pickerItem( nullptr )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PL_EDIT_TOOL::Init()
|
|
|
|
{
|
|
|
|
m_frame = getEditFrame<PL_EDITOR_FRAME>();
|
|
|
|
m_selectionTool = m_toolMgr->GetTool<PL_SELECTION_TOOL>();
|
|
|
|
|
|
|
|
wxASSERT_MSG( m_selectionTool, "plEditor.InteractiveSelection tool is not available" );
|
|
|
|
|
|
|
|
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
|
|
|
// cancel current tool goes in main context menu at the top if present
|
|
|
|
ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 );
|
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 200 );
|
2019-07-31 12:48:00 +00:00
|
|
|
ctxMenu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 200 );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
// Finally, add the standard zoom/grid items
|
2019-06-11 14:38:21 +00:00
|
|
|
m_frame->AddStandardSubMenus( m_menu );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Add editing actions to the selection tool menu
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
|
|
|
|
2021-01-17 18:19:02 +00:00
|
|
|
selToolMenu.AddItem( PL_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty, 250 );
|
|
|
|
|
|
|
|
selToolMenu.AddSeparator( 250 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 250 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty, 250 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::paste, SELECTION_CONDITIONS::ShowAlways, 250 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 250 );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_EDIT_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
if( aReason == MODEL_RELOAD )
|
|
|
|
m_frame = getEditFrame<PL_EDITOR_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
|
|
|
|
VECTOR2I originalCursorPos = controls->GetCursorPosition();
|
|
|
|
|
|
|
|
// 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
|
|
|
PL_SELECTION& selection = m_selectionTool->RequestSelection();
|
|
|
|
bool unselect = selection.IsHover();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-09-04 23:03:19 +00:00
|
|
|
if( selection.Empty() || m_moveInProgress )
|
2019-05-20 10:23:32 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
std::set<DS_DATA_ITEM*> unique_peers;
|
2021-01-04 14:40:12 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_BASE* drawItem = static_cast<DS_DRAW_ITEM_BASE*>( item );
|
2021-01-04 14:40:12 +00:00
|
|
|
unique_peers.insert( drawItem->GetPeer() );
|
|
|
|
}
|
|
|
|
|
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-20 10:23:32 +00:00
|
|
|
controls->ShowCursor( true );
|
|
|
|
controls->SetAutoPan( true );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
bool restore_state = false;
|
|
|
|
bool chain_commands = 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;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( !selection.Front()->IsNew() )
|
2023-03-06 12:12:11 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_frame->SaveCopyInUndoList();
|
|
|
|
}
|
2023-07-15 17:49:47 +00:00
|
|
|
catch( const fmt::v10::format_error& exc )
|
2023-03-06 12:12:11 +00:00
|
|
|
{
|
|
|
|
wxLogWarning( wxS( "Exception \"%s\" serializing string ocurred." ),
|
|
|
|
exc.what() );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
do
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( evt->IsAction( &PL_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
|
2019-07-04 20:56:21 +00:00
|
|
|
|| evt->IsAction( &ACTIONS::refreshPreview ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Start a move operation
|
|
|
|
//
|
|
|
|
if( !m_moveInProgress )
|
|
|
|
{
|
|
|
|
// Apply any initial offset in case we're coming from a previous command.
|
|
|
|
//
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* item : unique_peers )
|
2019-05-20 10:23:32 +00:00
|
|
|
moveItem( item, m_moveOffset );
|
|
|
|
|
|
|
|
// Set up the starting position and move/drag offset
|
|
|
|
//
|
|
|
|
m_cursor = controls->GetCursorPosition();
|
|
|
|
|
|
|
|
if( selection.HasReferencePoint() )
|
|
|
|
{
|
|
|
|
VECTOR2I delta = m_cursor - selection.GetReferencePoint();
|
|
|
|
|
|
|
|
// Drag items to the current cursor position
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* item : unique_peers )
|
2019-05-20 10:23:32 +00:00
|
|
|
moveItem( item, delta );
|
|
|
|
|
|
|
|
selection.SetReferencePoint( m_cursor );
|
|
|
|
}
|
|
|
|
else if( selection.Size() == 1 )
|
|
|
|
{
|
|
|
|
// Set the current cursor position to the first dragged item origin,
|
|
|
|
// so the movement vector can be computed later
|
|
|
|
updateModificationPoint( selection );
|
|
|
|
m_cursor = originalCursorPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
updateModificationPoint( selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
controls->SetCursorPosition( m_cursor, false );
|
|
|
|
|
|
|
|
prevPos = m_cursor;
|
|
|
|
controls->SetAutoPan( true );
|
|
|
|
m_moveInProgress = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Follow the mouse
|
|
|
|
//
|
|
|
|
m_cursor = controls->GetCursorPosition();
|
|
|
|
VECTOR2I delta( m_cursor - prevPos );
|
|
|
|
selection.SetReferencePoint( m_cursor );
|
|
|
|
|
|
|
|
m_moveOffset += delta;
|
|
|
|
prevPos = m_cursor;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* item : unique_peers )
|
2019-05-20 10:23:32 +00:00
|
|
|
moveItem( item, delta );
|
|
|
|
|
2021-09-29 19:59:04 +00:00
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel
|
|
|
|
//
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
if( m_moveInProgress )
|
2020-08-25 11:53:39 +00:00
|
|
|
{
|
2021-09-29 19:59:04 +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.
|
|
|
|
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel move." ) );
|
|
|
|
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-08-25 11:53:39 +00:00
|
|
|
evt->SetPassEvent( false );
|
2019-05-20 10:23:32 +00:00
|
|
|
restore_state = true;
|
2020-08-25 11:53:39 +00:00
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle TOOL_ACTION special cases
|
|
|
|
//
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
|
|
|
unselect = true;
|
|
|
|
break;
|
|
|
|
}
|
2021-09-29 19:59:04 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::doDelete ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2021-09-29 19:59:04 +00:00
|
|
|
evt->SetPassEvent();
|
|
|
|
// Exit on a delete; there will no longer be anything to drag.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate ) )
|
|
|
|
{
|
|
|
|
if( selection.Front()->IsNew() )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2021-09-29 19:59:04 +00:00
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
|
|
|
// objects so we ignore the duplicate and just carry on.
|
|
|
|
continue;
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
2021-09-29 19:59:04 +00:00
|
|
|
|
|
|
|
// Move original back and exit. The duplicate will run in its own loop.
|
|
|
|
restore_state = true;
|
|
|
|
unselect = false;
|
|
|
|
chain_commands = true;
|
|
|
|
break;
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle context menu
|
|
|
|
//
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle drop
|
|
|
|
//
|
|
|
|
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
break; // Finish
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2021-09-29 19:59:04 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2021-09-29 19:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
controls->SetAutoPan( m_moveInProgress );
|
2019-05-20 10:23:32 +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 };
|
|
|
|
|
|
|
|
selection.ClearReferencePoint();
|
|
|
|
|
2021-07-07 18:00:00 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2019-05-20 10:23:32 +00:00
|
|
|
item->ClearEditFlags();
|
|
|
|
|
|
|
|
if( restore_state )
|
|
|
|
m_frame->RollbackFromUndo();
|
|
|
|
else
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
2021-09-29 19:59:04 +00:00
|
|
|
if( unselect )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PL_ACTIONS::clearSelection );
|
2021-09-29 19:59:04 +00:00
|
|
|
else
|
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
m_moveInProgress = false;
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-05-20 10:23:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void PL_EDIT_TOOL::moveItem( DS_DATA_ITEM* aItem, const VECTOR2I& aDelta )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2023-09-30 20:00:11 +00:00
|
|
|
aItem->MoveToIU( aItem->GetStartPosIU() + aDelta );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item : aItem->GetDrawItems() )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-05-26 18:35:20 +00:00
|
|
|
getView()->Update( item );
|
2021-05-30 21:04:07 +00:00
|
|
|
item->SetFlags( IS_MOVING );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
bool PL_EDIT_TOOL::updateModificationPoint( PL_SELECTION& aSelection )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
if( m_moveInProgress && aSelection.HasReferencePoint() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// When there is only one item selected, the reference point is its position...
|
|
|
|
if( aSelection.Size() == 1 )
|
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
aSelection.SetReferencePoint( aSelection.Front()->GetPosition() );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
2019-05-26 18:35:20 +00:00
|
|
|
// ...otherwise modify items with regard to the grid-snapped cursor position
|
2019-05-20 10:23:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cursor = getViewControls()->GetCursorPosition( true );
|
|
|
|
aSelection.SetReferencePoint( m_cursor );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
int PL_EDIT_TOOL::ImportDrawingSheetContent( const TOOL_EVENT& aEvent )
|
2019-05-24 13:37:55 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2019-05-24 13:37:55 +00:00
|
|
|
wxCommandEvent evt( wxEVT_NULL, ID_APPEND_DESCR_FILE );
|
|
|
|
m_frame->Files_io( evt );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
int PL_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
PL_SELECTION& selection = m_selectionTool->RequestSelection();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( selection.Size() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2022-10-22 16:30:30 +00:00
|
|
|
|
|
|
|
// Do not delete an item if it is currently a new item being created to avoid a crash
|
|
|
|
// In this case the selection contains only one item.
|
|
|
|
DS_DRAW_ITEM_BASE* currItem = static_cast<DS_DRAW_ITEM_BASE*>( selection.Front() );
|
|
|
|
|
|
|
|
if( currItem->GetFlags() & ( IS_NEW ) )
|
|
|
|
return 0;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
m_frame->SaveCopyInUndoList();
|
|
|
|
|
|
|
|
while( selection.Front() )
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_BASE* drawItem = static_cast<DS_DRAW_ITEM_BASE*>( selection.Front() );
|
|
|
|
DS_DATA_ITEM* dataItem = drawItem->GetPeer();
|
|
|
|
DS_DATA_MODEL::GetTheInstance().Remove( dataItem );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
// Note: repeat items won't be selected but must be removed & deleted
|
|
|
|
|
|
|
|
if( item->IsSelected() )
|
|
|
|
m_selectionTool->RemoveItemFromSel( item );
|
|
|
|
|
|
|
|
getView()->Remove( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete dataItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 14:12:40 +00:00
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2023-10-10 14:43:45 +00:00
|
|
|
int PL_EDIT_TOOL::InteractiveDelete( const TOOL_EVENT& aEvent )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-07-19 20:47:33 +00:00
|
|
|
// Deactivate other tools; particularly important if another PICKER is currently running
|
|
|
|
Activate();
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
picker->SetCursor( KICURSOR::REMOVE );
|
2019-06-25 14:12:40 +00:00
|
|
|
m_pickerItem = nullptr;
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetClickHandler(
|
|
|
|
[this] ( const VECTOR2D& aPosition ) -> bool
|
2019-06-25 14:12:40 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
{
|
|
|
|
PL_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PL_SELECTION_TOOL>();
|
|
|
|
selectionTool->UnbrightenItem( m_pickerItem );
|
2019-09-08 18:43:54 +00:00
|
|
|
selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::doDelete );
|
2019-07-15 23:44:01 +00:00
|
|
|
m_pickerItem = nullptr;
|
|
|
|
}
|
2019-06-25 14:12:40 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
return true;
|
|
|
|
} );
|
2019-06-25 14:12:40 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetMotionHandler(
|
|
|
|
[this] ( const VECTOR2D& aPos )
|
2019-06-25 14:12:40 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
|
|
|
EDA_ITEM* item = nullptr;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* dataItem : DS_DATA_MODEL::GetTheInstance().GetItems() )
|
2019-06-25 14:12:40 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() )
|
2019-06-25 14:12:40 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
if( drawItem->HitTest( aPos, threshold ) )
|
2019-07-15 23:44:01 +00:00
|
|
|
{
|
|
|
|
item = drawItem;
|
|
|
|
break;
|
|
|
|
}
|
2019-06-25 14:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
if( m_pickerItem != item )
|
|
|
|
{
|
|
|
|
PL_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PL_SELECTION_TOOL>();
|
2019-06-25 14:12:40 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->UnbrightenItem( m_pickerItem );
|
2019-06-25 14:12:40 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
m_pickerItem = item;
|
2019-06-25 14:12:40 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->BrightenItem( m_pickerItem );
|
|
|
|
}
|
|
|
|
} );
|
2019-06-25 14:12:40 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetFinalizeHandler(
|
|
|
|
[this] ( const int& aFinalState )
|
|
|
|
{
|
|
|
|
if( m_pickerItem )
|
|
|
|
m_toolMgr->GetTool<PL_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
|
2020-10-11 17:12:13 +00:00
|
|
|
|
|
|
|
// Wake the selection tool after exiting to ensure the cursor gets updated
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( PL_ACTIONS::selectionActivate );
|
2019-07-15 23:44:01 +00:00
|
|
|
} );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
|
2019-07-15 12:15:58 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDIT_TOOL::Undo( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->GetLayoutFromUndoList();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDIT_TOOL::Redo( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->GetLayoutFromRedoList();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
int PL_EDIT_TOOL::Cut( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
int retVal = Copy( aEvent );
|
|
|
|
|
|
|
|
if( retVal == 0 )
|
|
|
|
retVal = DoDelete( aEvent );
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
PL_SELECTION& selection = m_selectionTool->RequestSelection();
|
2021-02-22 23:47:17 +00:00
|
|
|
std::vector<DS_DATA_ITEM*> items;
|
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2019-05-26 18:35:20 +00:00
|
|
|
wxString sexpr;
|
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection.GetItems() )
|
2021-02-22 23:47:17 +00:00
|
|
|
items.push_back( static_cast<DS_DRAW_ITEM_BASE*>( item )->GetPeer() );
|
2019-05-26 18:35:20 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-06-09 09:47:14 +00:00
|
|
|
model.SaveInString( items, &sexpr );
|
2019-05-26 18:35:20 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxMessageBox( ioe.What(), _( "Error writing objects to clipboard" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_toolMgr->SaveClipboard( TO_UTF8( sexpr ) ) )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
PL_SELECTION& selection = m_selectionTool->GetSelection();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2020-11-21 09:59:25 +00:00
|
|
|
std::string sexpr = m_toolMgr->GetClipboardUTF8();
|
2019-05-26 18:35:20 +00:00
|
|
|
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
|
|
|
model.SetPageLayout( sexpr.c_str(), true, wxT( "clipboard" ) );
|
|
|
|
|
|
|
|
// Build out draw items and select the first of each data item
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* dataItem : model.GetItems() )
|
2019-05-26 18:35:20 +00:00
|
|
|
{
|
|
|
|
if( dataItem->GetDrawItems().empty() )
|
|
|
|
{
|
|
|
|
dataItem->SyncDrawItems( nullptr, getView() );
|
|
|
|
dataItem->GetDrawItems().front()->SetSelected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_selectionTool->RebuildSelection();
|
|
|
|
|
|
|
|
if( !selection.Empty() )
|
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
selection.SetReferencePoint( selection.GetTopLeftItem()->GetPosition() );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( PL_ACTIONS::move );
|
2019-05-26 18:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
void PL_EDIT_TOOL::setTransitions()
|
|
|
|
{
|
2021-05-30 22:56:24 +00:00
|
|
|
Go( &PL_EDIT_TOOL::Main, PL_ACTIONS::move.MakeEvent() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
Go( &PL_EDIT_TOOL::ImportDrawingSheetContent, PL_ACTIONS::appendImportedDrawingSheet.MakeEvent() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
Go( &PL_EDIT_TOOL::Undo, ACTIONS::undo.MakeEvent() );
|
|
|
|
Go( &PL_EDIT_TOOL::Redo, ACTIONS::redo.MakeEvent() );
|
2019-05-26 18:35:20 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
Go( &PL_EDIT_TOOL::Cut, ACTIONS::cut.MakeEvent() );
|
|
|
|
Go( &PL_EDIT_TOOL::Copy, ACTIONS::copy.MakeEvent() );
|
|
|
|
Go( &PL_EDIT_TOOL::Paste, ACTIONS::paste.MakeEvent() );
|
|
|
|
Go( &PL_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() );
|
2019-07-31 12:10:13 +00:00
|
|
|
|
2023-10-10 14:43:45 +00:00
|
|
|
Go( &PL_EDIT_TOOL::InteractiveDelete, ACTIONS::deleteTool.MakeEvent() );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|