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
|
2019-05-20 10:23:32 +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-07-15 23:44:01 +00:00
|
|
|
#include <tool/picker_tool.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <tools/pl_selection_tool.h>
|
|
|
|
#include <tools/pl_actions.h>
|
|
|
|
#include <tools/pl_edit_tool.h>
|
2019-05-25 11:05:39 +00:00
|
|
|
#include <ws_data_model.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <ws_draw_item.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <pl_editor_frame.h>
|
|
|
|
#include <pl_editor_id.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
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();
|
|
|
|
|
2019-07-31 12:48:30 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 200 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty, 200 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::paste, SELECTION_CONDITIONS::ShowAlways, 200 );
|
2019-06-04 12:20:05 +00:00
|
|
|
selToolMenu.AddItem( PL_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty, 200 );
|
2019-07-31 12:48:00 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 200 );
|
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;
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-05-20 10:23:32 +00:00
|
|
|
Activate();
|
2019-06-18 17:56:40 +00:00
|
|
|
|
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;
|
|
|
|
TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
|
|
|
|
VECTOR2I prevPos;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( !selection.Front()->IsNew() )
|
|
|
|
m_frame->SaveCopyInUndoList();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
do
|
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
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.
|
|
|
|
//
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
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
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
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;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
moveItem( item, delta );
|
|
|
|
|
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel
|
|
|
|
//
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
if( m_moveInProgress )
|
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;
|
|
|
|
}
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2019-07-31 12:48:00 +00:00
|
|
|
if( evt->IsAction( &ACTIONS::doDelete ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
// Exit on a remove operation; there is no further processing for removed items.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// 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
|
|
|
|
evt->SetPassEvent();
|
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();
|
|
|
|
|
|
|
|
for( auto item : selection )
|
|
|
|
item->ClearEditFlags();
|
|
|
|
|
|
|
|
if( unselect )
|
|
|
|
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
|
|
|
|
|
|
|
|
if( restore_state )
|
|
|
|
m_frame->RollbackFromUndo();
|
|
|
|
else
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
m_moveInProgress = false;
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-05-20 10:23:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_EDIT_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta )
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_BASE* drawItem = static_cast<WS_DRAW_ITEM_BASE*>( aItem );
|
2019-05-25 11:05:39 +00:00
|
|
|
WS_DATA_ITEM* dataItem = drawItem->GetPeer();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
dataItem->MoveToUi( dataItem->GetStartPosUi() + (wxPoint) aDelta );
|
|
|
|
|
|
|
|
for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
|
|
|
|
{
|
2019-05-26 18:35:20 +00:00
|
|
|
getView()->Update( item );
|
2019-05-20 10:23:32 +00:00
|
|
|
item->SetFlags( IS_MOVED );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-24 13:37:55 +00:00
|
|
|
int PL_EDIT_TOOL::ImportWorksheetContent( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-27 11:47:24 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive, true );
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
m_frame->SaveCopyInUndoList();
|
|
|
|
|
|
|
|
while( selection.Front() )
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_BASE* drawItem = static_cast<WS_DRAW_ITEM_BASE*>( selection.Front() );
|
2019-05-25 11:05:39 +00:00
|
|
|
WS_DATA_ITEM* dataItem = drawItem->GetPeer();
|
|
|
|
WS_DATA_MODEL::GetTheInstance().Remove( dataItem );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
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();
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) );
|
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*/ );
|
2019-07-15 23:44:01 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::doDelete, true );
|
|
|
|
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;
|
|
|
|
|
|
|
|
for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
|
2019-06-25 14:12:40 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
for( WS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() )
|
2019-06-25 14:12:40 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
if( drawItem->HitTest( (wxPoint) aPos, threshold ) )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
} );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
|
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();
|
2019-05-26 18:35:20 +00:00
|
|
|
std::vector<WS_DATA_ITEM*> items;
|
|
|
|
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
|
|
|
|
wxString sexpr;
|
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection.GetItems() )
|
|
|
|
items.push_back( static_cast<WS_DRAW_ITEM_BASE*>( item )->GetPeer() );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
model.SaveInString( items, sexpr );
|
|
|
|
}
|
|
|
|
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();
|
2019-05-26 18:35:20 +00:00
|
|
|
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
|
|
|
|
std::string sexpr = m_toolMgr->GetClipboard();
|
|
|
|
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
|
|
|
model.SetPageLayout( sexpr.c_str(), true, wxT( "clipboard" ) );
|
|
|
|
|
|
|
|
// Build out draw items and select the first of each data item
|
|
|
|
for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
|
|
|
|
{
|
|
|
|
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() );
|
2019-05-26 18:35:20 +00:00
|
|
|
m_toolMgr->RunAction( PL_ACTIONS::move, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
void PL_EDIT_TOOL::setTransitions()
|
|
|
|
{
|
2019-05-24 13:37:55 +00:00
|
|
|
Go( &PL_EDIT_TOOL::Main, PL_ACTIONS::move.MakeEvent() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-05-24 13:37:55 +00:00
|
|
|
Go( &PL_EDIT_TOOL::ImportWorksheetContent, PL_ACTIONS::appendImportedWorksheet.MakeEvent() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-05-24 13:37:55 +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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Go( &PL_EDIT_TOOL::DeleteItemCursor, ACTIONS::deleteTool.MakeEvent() );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|