2013-12-09 10:01:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-08-24 14:31:23 +00:00
|
|
|
* Copyright (C) 2013-2017 CERN
|
2013-12-09 10:01:05 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2015-03-03 10:55:23 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2019-06-24 15:27:05 +00:00
|
|
|
* Copyright (C) 2017-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-12-09 10:01: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
|
|
|
|
*/
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
#include <limits>
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
2014-07-09 12:22:29 +00:00
|
|
|
#include <class_edge_mod.h>
|
2016-05-04 16:35:20 +00:00
|
|
|
#include <collectors.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2015-02-18 00:10:20 +00:00
|
|
|
#include <kiway.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <footprint_edit_frame.h>
|
2016-04-02 12:52:29 +00:00
|
|
|
#include <array_creator.h>
|
2017-03-09 09:09:13 +00:00
|
|
|
#include <pcbnew_id.h>
|
2018-08-22 18:05:40 +00:00
|
|
|
#include <status_popup.h>
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-08-13 12:29:18 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/selection_tool.h>
|
|
|
|
#include <tools/edit_tool.h>
|
|
|
|
#include <tools/pcbnew_picker_tool.h>
|
|
|
|
#include <tools/tool_event_utils.h>
|
|
|
|
#include <tools/grid_helper.h>
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <view/view_controls.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <confirm.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <bitmaps.h>
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <cassert>
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2017-09-17 17:49:06 +00:00
|
|
|
#include "kicad_clipboard.h"
|
2015-07-02 14:10:07 +00:00
|
|
|
#include <router/router_tool.h>
|
2015-02-12 03:22:24 +00:00
|
|
|
#include <dialogs/dialog_move_exact.h>
|
2015-07-09 11:35:51 +00:00
|
|
|
#include <dialogs/dialog_track_via_properties.h>
|
2017-03-09 09:09:13 +00:00
|
|
|
#include <preview_items/ruler_item.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
|
|
|
|
2018-04-25 22:32:05 +00:00
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags )
|
2018-03-09 06:25:06 +00:00
|
|
|
{
|
|
|
|
// Iterate from the back so we don't have to worry about removals.
|
|
|
|
for( int i = aCollector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = aCollector[ i ];
|
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
if( ( aFlags & EXCLUDE_LOCKED ) && item->IsLocked() )
|
|
|
|
{
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
|
|
|
else if( item->Type() == PCB_PAD_T )
|
2018-03-09 06:25:06 +00:00
|
|
|
{
|
|
|
|
MODULE* mod = static_cast<MODULE*>( item->GetParent() );
|
|
|
|
|
2018-09-26 20:55:43 +00:00
|
|
|
// case 1: handle locking
|
|
|
|
if( ( aFlags & EXCLUDE_LOCKED ) && mod && mod->IsLocked() )
|
2018-03-09 06:25:06 +00:00
|
|
|
{
|
|
|
|
aCollector.Remove( item );
|
2018-09-26 20:55:43 +00:00
|
|
|
}
|
|
|
|
else if( ( aFlags & EXCLUDE_LOCKED_PADS ) && mod && mod->PadsLocked() )
|
|
|
|
{
|
|
|
|
// Pad locking is considerably "softer" than item locking
|
|
|
|
aCollector.Remove( item );
|
2018-03-09 06:25:06 +00:00
|
|
|
|
|
|
|
if( !mod->IsLocked() && !aCollector.HasItem( mod ) )
|
|
|
|
aCollector.Append( mod );
|
|
|
|
}
|
|
|
|
|
|
|
|
// case 2: selection contains both the module and its pads - remove the pads
|
|
|
|
if( mod && aCollector.HasItem( mod ) )
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
2018-09-25 14:23:38 +00:00
|
|
|
else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T )
|
2018-03-09 06:25:06 +00:00
|
|
|
{
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
EDIT_TOOL::EDIT_TOOL() :
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
|
|
|
|
m_selectionTool( NULL ),
|
|
|
|
m_dragging( false ),
|
|
|
|
m_lockedSelected( false )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-08 12:09:20 +00:00
|
|
|
void EDIT_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
m_dragging = false;
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
if( aReason != RUN )
|
|
|
|
m_commit.reset( new BOARD_COMMIT( this ) );
|
2014-09-08 12:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
bool EDIT_TOOL::Init()
|
|
|
|
{
|
|
|
|
// Find the selection tool, so they can cooperate
|
2014-07-09 11:50:27 +00:00
|
|
|
m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
|
2019-06-05 19:15:57 +00:00
|
|
|
wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) {
|
|
|
|
return m_editModules;
|
|
|
|
};
|
|
|
|
|
2017-01-31 08:03:07 +00:00
|
|
|
auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
|
|
|
|
&& SELECTION_CONDITIONS::Count( 1 );
|
|
|
|
|
2018-02-11 01:15:16 +00:00
|
|
|
auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
|
2019-06-24 15:27:05 +00:00
|
|
|
return frame()->ToolStackIsEmpty();
|
2018-02-11 01:15:16 +00:00
|
|
|
};
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Add context menu entries that are displayed when selection tool is active
|
2017-01-12 10:07:52 +00:00
|
|
|
CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu();
|
2017-08-03 15:53:07 +00:00
|
|
|
|
|
|
|
menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty );
|
2018-12-14 03:43:51 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::inlineBreakTrack, SELECTION_CONDITIONS::Count( 1 )
|
|
|
|
&& SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
|
2017-08-03 15:53:07 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
|
|
|
|
menu.AddItem( PCB_ACTIONS::dragFreeAngle, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::NotEmpty );
|
2017-03-30 11:49:47 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
|
2019-07-04 19:56:52 +00:00
|
|
|
menu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 )
|
2016-05-04 16:35:20 +00:00
|
|
|
|| SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
|
2017-08-03 15:53:07 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
|
2017-05-10 13:55:03 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::positionRelative, SELECTION_CONDITIONS::NotEmpty );
|
2019-07-04 19:56:52 +00:00
|
|
|
menu.AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
|
2019-08-24 16:08:33 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator();
|
2019-05-14 19:21:10 +00:00
|
|
|
menu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
menu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty );
|
2018-02-11 01:15:16 +00:00
|
|
|
// Selection tool handles the context menu for some other tools, such as the Picker.
|
|
|
|
// Don't add things like Paste when another tool is active.
|
2019-05-14 19:21:10 +00:00
|
|
|
menu.AddItem( ACTIONS::paste, noActiveToolCondition );
|
2017-09-17 17:49:06 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
// Footprint actions
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator();
|
2018-01-12 19:36:15 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::editFootprintInFpEditor, singleModuleCondition );
|
2019-06-03 13:49:17 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::updateFootprint, singleModuleCondition );
|
|
|
|
menu.AddItem( PCB_ACTIONS::changeFootprint, singleModuleCondition );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2019-06-02 10:12:11 +00:00
|
|
|
// Populate the context menu displayed during the edit tool (primarily the measure tool)
|
|
|
|
auto activeToolCondition = [ this ] ( const SELECTION& aSel ) {
|
2019-06-24 15:27:05 +00:00
|
|
|
return frame()->ToolStackIsEmpty();
|
2019-06-02 10:12:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
|
|
|
auto& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
|
|
|
// "Cancel" goes at the top of the context menu when a tool is active
|
2019-06-02 15:37:24 +00:00
|
|
|
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 1 );
|
2019-06-02 10:12:11 +00:00
|
|
|
|
|
|
|
if( frame )
|
2019-06-11 14:38:21 +00:00
|
|
|
frame->AddStandardSubMenus( m_menu );
|
2019-06-02 10:12:11 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-13 12:29:18 +00:00
|
|
|
int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
MODULE* module = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
|
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, (void*) module );
|
|
|
|
|
|
|
|
selectionTool->GetSelection().SetReferencePoint( module->GetPosition() );
|
2019-08-15 00:12:00 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::move, false );
|
2019-08-13 12:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2019-08-13 12:29:18 +00:00
|
|
|
ROUTER_TOOL* theRouter = m_toolMgr->GetTool<ROUTER_TOOL>();
|
2017-08-29 23:15:23 +00:00
|
|
|
|
|
|
|
if( !theRouter )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// make sure we don't accidentally invoke inline routing mode while the router is already active!
|
2018-01-05 23:44:37 +00:00
|
|
|
if( theRouter->IsToolActive() )
|
2017-08-29 23:15:23 +00:00
|
|
|
return false;
|
|
|
|
|
2018-01-05 23:44:37 +00:00
|
|
|
if( theRouter->CanInlineDrag() )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::routerInlineDrag, true, aDragMode );
|
2015-02-18 00:10:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2017-08-24 14:31:23 +00:00
|
|
|
|
2017-08-22 14:44:47 +00:00
|
|
|
bool EDIT_TOOL::isInteractiveDragEnabled() const
|
|
|
|
{
|
|
|
|
auto theRouter = static_cast<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
|
|
|
|
|
2017-08-24 14:31:23 +00:00
|
|
|
return theRouter ? theRouter->Router()->Settings().InlineDragEnabled() : false;
|
2017-08-22 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 14:31:23 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
int mode = PNS::DM_ANY;
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::dragFreeAngle ) )
|
|
|
|
mode |= PNS::DM_FREE_ANGLE;
|
|
|
|
|
|
|
|
invokeInlineRouter( mode );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-03-03 10:50:50 +00:00
|
|
|
|
2019-08-10 10:56:15 +00:00
|
|
|
int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2015-07-15 12:08:51 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
VECTOR2I originalCursorPos = controls->GetCursorPosition();
|
2019-06-12 12:24:00 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
// Be sure that there is at least one item that we can modify. If nothing was selected before,
|
2015-02-18 16:53:46 +00:00
|
|
|
// try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
|
2019-08-10 10:56:15 +00:00
|
|
|
PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection(
|
2019-07-15 23:44:01 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
|
|
|
{
|
|
|
|
EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS );
|
|
|
|
} );
|
2017-03-03 12:42:28 +00:00
|
|
|
|
2018-10-04 05:45:10 +00:00
|
|
|
if( m_dragging || selection.Empty() )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
2014-04-01 12:35:09 +00:00
|
|
|
|
2019-08-21 04:31:11 +00:00
|
|
|
LSET item_layers = selection.GetSelectionLayers();
|
2018-10-04 05:45:10 +00:00
|
|
|
bool unselect = selection.IsHover(); //N.B. This must be saved before the re-selection below
|
|
|
|
|
2019-08-10 10:56:15 +00:00
|
|
|
// Now filter out locked pads. We cannot do this in the first RequestSelection() as we need
|
|
|
|
// the item_layers when a pad is the selection front (ie: will become curr_tiem).
|
2018-10-04 05:45:10 +00:00
|
|
|
selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2019-08-10 10:56:15 +00:00
|
|
|
{
|
|
|
|
EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS );
|
|
|
|
} );
|
2017-03-03 12:42:28 +00:00
|
|
|
|
2018-10-04 05:45:10 +00:00
|
|
|
if( selection.Empty() )
|
2017-11-28 09:42:36 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
editFrame->PushTool( tool );
|
2014-04-01 12:35:09 +00:00
|
|
|
Activate();
|
2013-12-09 10:01:05 +00:00
|
|
|
controls->ShowCursor( true );
|
2017-03-02 14:21:28 +00:00
|
|
|
controls->SetAutoPan( true );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2018-11-16 18:01:54 +00:00
|
|
|
std::vector<BOARD_ITEM*> sel_items;
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2018-11-16 18:01:54 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
|
|
|
|
MODULE* module = dynamic_cast<MODULE*>( item );
|
2019-02-03 03:20:53 +00:00
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
if( boardItem )
|
|
|
|
sel_items.push_back( boardItem );
|
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad : module->Pads() )
|
|
|
|
sel_items.push_back( pad );
|
2019-02-03 03:20:53 +00:00
|
|
|
}
|
2018-11-16 18:01:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
bool restore_state = false;
|
|
|
|
VECTOR2I totalMovement;
|
2015-07-07 16:36:32 +00:00
|
|
|
GRID_HELPER grid( editFrame );
|
2019-06-17 13:43:22 +00:00
|
|
|
TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
|
|
|
|
VECTOR2I prevPos;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2019-07-05 01:57:39 +00:00
|
|
|
// Prime the pump
|
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Main loop: keep receiving events
|
2015-07-07 16:36:50 +00:00
|
|
|
do
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
2018-10-04 00:15:54 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2018-10-05 04:08:15 +00:00
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
2018-10-04 00:15:54 +00:00
|
|
|
|
2019-08-19 20:09:17 +00:00
|
|
|
if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() ||
|
|
|
|
evt->IsAction( &PCB_ACTIONS::drag ) || evt->IsDrag( BUT_LEFT ) ||
|
2019-07-04 20:56:21 +00:00
|
|
|
evt->IsAction( &ACTIONS::refreshPreview ) )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2015-07-15 12:08:52 +00:00
|
|
|
if( m_dragging && evt->Category() == TC_MOUSE )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2019-09-03 16:16:27 +00:00
|
|
|
VECTOR2I mousePos( controls->GetMousePosition() );
|
2019-12-15 14:29:22 +00:00
|
|
|
|
2019-09-03 16:16:27 +00:00
|
|
|
m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items );
|
2019-12-15 14:29:22 +00:00
|
|
|
|
|
|
|
if( controls->GetSettings().m_lastKeyboardCursorPositionValid )
|
|
|
|
{
|
|
|
|
long action = controls->GetSettings().m_lastKeyboardCursorCommand;
|
|
|
|
|
|
|
|
// The arrow keys are by definition SINGLE AXIS. Do not allow the other
|
|
|
|
// axis to be snapped to the grid.
|
|
|
|
if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
|
|
|
|
m_cursor.y = prevPos.y;
|
|
|
|
else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
|
|
|
|
m_cursor.x = prevPos.x;
|
|
|
|
}
|
|
|
|
|
2019-08-20 18:40:26 +00:00
|
|
|
controls->ForceCursorPosition( true, m_cursor );
|
2018-06-18 21:02:16 +00:00
|
|
|
selection.SetReferencePoint( m_cursor );
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2019-09-03 16:16:27 +00:00
|
|
|
VECTOR2I movement( m_cursor - prevPos );
|
2017-09-22 15:17:38 +00:00
|
|
|
prevPos = m_cursor;
|
2019-09-03 16:16:27 +00:00
|
|
|
totalMovement += movement;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Drag items to the current cursor position
|
2019-09-03 15:50:19 +00:00
|
|
|
for( EDA_ITEM* item : sel_items )
|
2017-12-18 17:24:25 +00:00
|
|
|
{
|
2018-06-18 21:02:16 +00:00
|
|
|
// Don't double move footprint pads, fields, etc.
|
2019-11-01 02:57:13 +00:00
|
|
|
if( !item->GetParent() || !item->GetParent()->IsSelected() )
|
|
|
|
static_cast<BOARD_ITEM*>( item )->Move( movement );
|
2017-12-18 17:24:25 +00:00
|
|
|
}
|
2018-04-12 16:33:18 +00:00
|
|
|
|
|
|
|
frame()->UpdateMsgPanel();
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
2015-07-15 12:08:52 +00:00
|
|
|
else if( !m_dragging ) // Prepare to start dragging
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2017-08-22 14:44:47 +00:00
|
|
|
if ( !evt->IsAction( &PCB_ACTIONS::move ) && isInteractiveDragEnabled() )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2019-04-08 03:57:10 +00:00
|
|
|
if( invokeInlineRouter( PNS::DM_ANY ) )
|
2015-07-02 14:09:56 +00:00
|
|
|
break;
|
2019-04-08 03:57:10 +00:00
|
|
|
}
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
// deal with locked items (override lock or abort the operation)
|
|
|
|
SELECTION_LOCK_FLAGS lockFlags = m_selectionTool->CheckLock();
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
if( lockFlags == SELECTION_LOCKED )
|
|
|
|
break;
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2019-07-05 01:57:39 +00:00
|
|
|
m_dragging = true;
|
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
// When editing modules, all items have the same parent
|
|
|
|
if( EditingModules() )
|
|
|
|
{
|
|
|
|
m_commit->Modify( selection.Front() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Save items, so changes can be undone
|
2019-09-03 16:16:27 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2017-09-22 15:17:38 +00:00
|
|
|
{
|
2019-04-08 03:57:10 +00:00
|
|
|
// Don't double move footprint pads, fields, etc.
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
}
|
|
|
|
}
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
editFrame->UndoRedoBlock( true );
|
|
|
|
m_cursor = controls->GetCursorPosition();
|
2018-06-18 21:02:16 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
if ( selection.HasReferencePoint() )
|
|
|
|
{
|
|
|
|
// start moving with the reference point attached to the cursor
|
|
|
|
grid.SetAuxAxes( false );
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
auto delta = m_cursor - selection.GetReferencePoint();
|
|
|
|
|
|
|
|
// Drag items to the current cursor position
|
2019-09-03 16:16:27 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2015-07-28 08:28:59 +00:00
|
|
|
{
|
2019-04-08 03:57:10 +00:00
|
|
|
// Don't double move footprint pads, fields, etc.
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Move( delta );
|
|
|
|
}
|
2015-07-15 15:32:30 +00:00
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
selection.SetReferencePoint( m_cursor );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
2019-08-21 04:31:11 +00:00
|
|
|
else
|
2019-04-08 03:57:10 +00:00
|
|
|
{
|
2019-08-21 04:31:11 +00:00
|
|
|
std::vector<BOARD_ITEM*> items;
|
|
|
|
|
2019-09-03 16:16:27 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2019-08-21 04:31:11 +00:00
|
|
|
items.push_back( static_cast<BOARD_ITEM*>( item ) );
|
|
|
|
|
2019-04-08 03:57:10 +00:00
|
|
|
// Set the current cursor position to the first dragged item origin, so the
|
|
|
|
// movement vector could be computed later
|
2019-08-21 04:31:11 +00:00
|
|
|
m_cursor = grid.BestDragOrigin( originalCursorPos, items );
|
|
|
|
selection.SetReferencePoint( m_cursor );
|
2019-04-08 03:57:10 +00:00
|
|
|
grid.SetAuxAxes( true, m_cursor );
|
|
|
|
}
|
|
|
|
|
|
|
|
controls->SetCursorPosition( m_cursor, false );
|
|
|
|
|
|
|
|
prevPos = m_cursor;
|
|
|
|
controls->SetAutoPan( true );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 15:50:19 +00:00
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
2019-01-01 21:54:10 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::updateLocalRatsnest, false );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2017-01-30 13:05:26 +00:00
|
|
|
{
|
2018-10-04 05:45:10 +00:00
|
|
|
restore_state = true; // Canceling the tool means that items have to be restored
|
2019-05-11 10:06:28 +00:00
|
|
|
break; // Finish
|
2017-01-30 13:05:26 +00:00
|
|
|
}
|
|
|
|
|
2019-12-15 21:33:58 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::undo ) )
|
2017-01-30 13:05:26 +00:00
|
|
|
{
|
2019-12-15 21:33:58 +00:00
|
|
|
restore_state = true; // Perform undo locally
|
|
|
|
break; // Finish
|
2017-01-30 13:05:26 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:50 +00:00
|
|
|
// Dispatch TOOL_ACTIONs
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2019-07-04 19:56:52 +00:00
|
|
|
if( evt->IsAction( &ACTIONS::doDelete ) )
|
2015-07-07 16:36:50 +00:00
|
|
|
{
|
2019-09-03 16:16:27 +00:00
|
|
|
break; // finish -- there is no further processing for removed items
|
2015-07-07 16:36:50 +00:00
|
|
|
}
|
2019-07-04 19:56:52 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate ) )
|
2015-07-07 16:36:50 +00:00
|
|
|
{
|
2019-09-03 16:16:27 +00:00
|
|
|
break; // finish -- Duplicate tool will start a new Move with the dup'ed items
|
2015-07-07 16:36:50 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
|
2015-07-07 16:36:50 +00:00
|
|
|
{
|
2019-09-03 16:16:27 +00:00
|
|
|
// Reset positions so the Move Exactly is from the start.
|
|
|
|
for( EDA_ITEM* item : selection )
|
2015-07-07 16:36:50 +00:00
|
|
|
{
|
2017-02-28 03:04:44 +00:00
|
|
|
BOARD_ITEM* i = static_cast<BOARD_ITEM*>( item );
|
2019-08-30 22:31:41 +00:00
|
|
|
i->Move( -totalMovement );
|
2015-07-07 16:36:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 16:16:27 +00:00
|
|
|
break; // finish -- we moved exactly, so we are finished
|
2015-07-07 16:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2019-09-03 16:16:27 +00:00
|
|
|
break; // finish
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
2018-12-13 01:22:27 +00:00
|
|
|
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2019-11-01 02:57:13 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2019-11-01 02:57:13 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
|
2019-09-03 16:16:27 +00:00
|
|
|
} while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2018-12-13 01:22:27 +00:00
|
|
|
m_lockedSelected = false;
|
2017-03-14 09:54:22 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
controls->ShowCursor( false );
|
|
|
|
controls->SetSnapping( false );
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
m_dragging = false;
|
2018-09-23 13:02:01 +00:00
|
|
|
editFrame->UndoRedoBlock( false );
|
|
|
|
|
2017-11-20 16:14:41 +00:00
|
|
|
// Discard reference point when selection is "dropped" onto the board (ie: not dragging anymore)
|
|
|
|
selection.ClearReferencePoint();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
if( unselect )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2019-06-03 03:22:57 +00:00
|
|
|
// If canceled, we need to remove the dynamic ratsnest from the screen
|
2018-10-04 05:45:10 +00:00
|
|
|
if( restore_state )
|
2019-06-03 03:22:57 +00:00
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::hideDynamicRatsnest, true );
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Revert();
|
2019-06-03 03:22:57 +00:00
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
else
|
2019-06-03 03:22:57 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Push( _( "Drag" ) );
|
2019-06-03 03:22:57 +00:00
|
|
|
}
|
2014-01-07 16:23:17 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
editFrame->PopTool( tool );
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-31 00:00:07 +00:00
|
|
|
int EDIT_TOOL::ChangeTrackWidth( const TOOL_EVENT& aEvent )
|
2017-08-03 15:53:07 +00:00
|
|
|
{
|
2019-10-31 00:00:07 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
|
2017-08-03 15:53:07 +00:00
|
|
|
|
2019-10-31 00:00:07 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
if( auto via = dyn_cast<VIA*>( item ) )
|
|
|
|
{
|
2019-10-31 00:00:07 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
|
2019-07-17 20:45:43 +00:00
|
|
|
int new_width;
|
|
|
|
int new_drill;
|
2017-08-03 15:53:07 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( via->GetViaType() == VIATYPE::MICROVIA )
|
2017-08-03 15:53:07 +00:00
|
|
|
{
|
|
|
|
auto net = via->GetNet();
|
|
|
|
|
|
|
|
new_width = net->GetMicroViaSize();
|
|
|
|
new_drill = net->GetMicroViaDrillSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_width = board()->GetDesignSettings().GetCurrentViaSize();
|
|
|
|
new_drill = board()->GetDesignSettings().GetCurrentViaDrill();
|
|
|
|
}
|
|
|
|
|
|
|
|
via->SetDrill( new_drill );
|
|
|
|
via->SetWidth( new_width );
|
|
|
|
}
|
|
|
|
else if ( auto track = dyn_cast<TRACK*>( item ) )
|
|
|
|
{
|
2019-10-31 00:00:07 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
|
|
|
|
track->SetWidth( new_width );
|
|
|
|
}
|
2019-10-31 00:00:07 +00:00
|
|
|
}
|
2017-08-03 15:53:07 +00:00
|
|
|
|
2019-10-31 00:00:07 +00:00
|
|
|
m_commit->Push( _("Edit track width/via size") );
|
|
|
|
|
|
|
|
if( selection.IsHover() )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
// Notify other tools of the changes -- This updates the visual ratsnest
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2017-08-03 15:53:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 00:00:07 +00:00
|
|
|
return 0;
|
2017-08-03 15:53:07 +00:00
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2019-10-31 00:00:07 +00:00
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2019-06-12 12:24:00 +00:00
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2015-07-09 11:35:51 +00:00
|
|
|
// Tracks & vias are treated in a special way:
|
2016-05-04 16:35:20 +00:00
|
|
|
if( ( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) )( selection ) )
|
2015-07-09 11:35:51 +00:00
|
|
|
{
|
2018-02-03 09:09:53 +00:00
|
|
|
DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
|
2018-08-19 16:11:58 +00:00
|
|
|
dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
|
2015-07-09 11:35:51 +00:00
|
|
|
}
|
|
|
|
else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
|
|
|
// Display properties dialog
|
2017-02-28 03:04:44 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
|
2014-02-05 08:05:27 +00:00
|
|
|
|
2019-05-31 23:24:38 +00:00
|
|
|
// Do not handle undo buffer, it is done by the properties dialogs
|
2019-05-28 23:23:58 +00:00
|
|
|
editFrame->OnEditItemRequest( item );
|
2014-05-22 10:06:45 +00:00
|
|
|
|
2018-09-17 13:14:23 +00:00
|
|
|
// Notify other tools of the changes
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.IsHover() )
|
2018-09-17 13:14:23 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2015-07-09 11:35:51 +00:00
|
|
|
|
2018-09-17 13:14:23 +00:00
|
|
|
// Notify other tools of the changes -- This updates the visual ratsnest
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2018-09-17 13:14:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2019-06-12 12:24:00 +00:00
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2019-01-16 16:00:38 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
|
2017-03-03 12:42:28 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
updateModificationPoint( selection );
|
2019-02-23 22:33:43 +00:00
|
|
|
auto refPt = selection.GetReferencePoint();
|
2017-02-04 05:09:50 +00:00
|
|
|
const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2018-07-31 04:52:21 +00:00
|
|
|
// When editing modules, all items have the same parent
|
|
|
|
if( EditingModules() )
|
|
|
|
m_commit->Modify( selection.Front() );
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : selection )
|
2013-12-18 13:33:34 +00:00
|
|
|
{
|
2018-07-31 04:52:21 +00:00
|
|
|
if( !item->IsNew() && !EditingModules() )
|
2018-06-11 23:41:24 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
|
2019-02-23 22:33:43 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Rotate( refPt, rotateAngle );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:36:00 +00:00
|
|
|
if( !m_dragging )
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Push( _( "Rotate" ) );
|
2014-01-29 09:17:14 +00:00
|
|
|
|
2017-08-07 08:02:07 +00:00
|
|
|
if( selection.IsHover() && !m_dragging )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2014-02-28 15:53:28 +00:00
|
|
|
|
2019-01-01 21:54:10 +00:00
|
|
|
if( m_dragging )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::updateLocalRatsnest, false );
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
/*!
|
|
|
|
* Mirror a point about the vertical axis passing through another point
|
|
|
|
*/
|
|
|
|
static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint )
|
|
|
|
{
|
|
|
|
wxPoint mirrored = aPoint;
|
|
|
|
|
|
|
|
mirrored.x -= aMirrorPoint.x;
|
|
|
|
mirrored.x = -mirrored.x;
|
|
|
|
mirrored.x += aMirrorPoint.x;
|
|
|
|
|
|
|
|
return mirrored;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror a pad in the vertical axis passing through a point
|
|
|
|
*/
|
|
|
|
static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
|
|
|
|
{
|
|
|
|
wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
|
|
|
|
|
2019-01-17 04:55:40 +00:00
|
|
|
if( aPad.GetShape() == PAD_SHAPE_CUSTOM )
|
|
|
|
aPad.MirrorXPrimitives( tmpPt.x );
|
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
aPad.SetPosition( tmpPt );
|
|
|
|
|
|
|
|
aPad.SetX0( aPad.GetPosition().x );
|
|
|
|
|
|
|
|
tmpPt = aPad.GetOffset();
|
|
|
|
tmpPt.x = -tmpPt.x;
|
|
|
|
aPad.SetOffset( tmpPt );
|
|
|
|
|
|
|
|
auto tmpz = aPad.GetDelta();
|
|
|
|
tmpz.x = -tmpz.x;
|
|
|
|
aPad.SetDelta( tmpz );
|
|
|
|
|
|
|
|
aPad.SetOrientation( -aPad.GetOrientation() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-09-25 14:23:38 +00:00
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2019-03-07 16:43:21 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
|
2017-01-23 06:47:39 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.Empty() )
|
2017-01-23 06:47:39 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
updateModificationPoint( selection );
|
|
|
|
auto refPoint = selection.GetReferencePoint();
|
|
|
|
wxPoint mirrorPoint( refPoint.x, refPoint.y );
|
2017-01-23 06:47:39 +00:00
|
|
|
|
2018-07-31 04:52:21 +00:00
|
|
|
// When editing modules, all items have the same parent
|
|
|
|
if( EditingModules() )
|
|
|
|
m_commit->Modify( selection.Front() );
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2017-01-23 06:47:39 +00:00
|
|
|
{
|
|
|
|
// only modify items we can mirror
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_PAD_T:
|
2018-06-11 23:41:24 +00:00
|
|
|
// Only create undo entry for items on the board
|
2018-07-31 04:52:21 +00:00
|
|
|
if( !item->IsNew() && !EditingModules() )
|
2018-06-11 23:41:24 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// modify each object as necessary
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
auto& edge = static_cast<EDGE_MODULE&>( *item );
|
|
|
|
edge.Mirror( mirrorPoint, false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
{
|
|
|
|
auto& modText = static_cast<TEXTE_MODULE&>( *item );
|
|
|
|
modText.Mirror( mirrorPoint, false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
auto& pad = static_cast<D_PAD&>( *item );
|
|
|
|
mirrorPadX( pad, mirrorPoint );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
// it's likely the commit object is wrong if you get here
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_dragging )
|
|
|
|
m_commit->Push( _( "Mirror" ) );
|
|
|
|
|
2017-08-07 08:02:07 +00:00
|
|
|
if( selection.IsHover() && !m_dragging )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2017-01-23 06:47:39 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2017-01-23 06:47:39 +00:00
|
|
|
|
2019-01-01 21:54:10 +00:00
|
|
|
if( m_dragging )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::updateLocalRatsnest, false );
|
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2018-09-25 14:23:38 +00:00
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2019-08-02 22:07:01 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); },
|
|
|
|
nullptr, ! m_dragging );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.Empty() )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
updateModificationPoint( selection );
|
2019-09-17 08:06:39 +00:00
|
|
|
|
2019-10-01 10:01:40 +00:00
|
|
|
// Flip around the anchor for footprints, and the bounding box center for board items
|
|
|
|
VECTOR2I modPoint = EditingModules() ? VECTOR2I( 0, 0 ) : selection.GetCenter();
|
2019-09-17 08:06:39 +00:00
|
|
|
|
|
|
|
// If only one item selected, flip around the item anchor point, instead
|
|
|
|
// of the bounding box center, to avoid moving the item anchor
|
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
modPoint = static_cast<BOARD_ITEM*>( selection.GetItem( 0 ) )->GetPosition();
|
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
bool leftRight = frame()->Settings().m_FlipLeftRight;
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2018-07-31 04:52:21 +00:00
|
|
|
// When editing modules, all items have the same parent
|
|
|
|
if( EditingModules() )
|
|
|
|
m_commit->Modify( selection.Front() );
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2013-12-18 13:33:34 +00:00
|
|
|
{
|
2018-07-31 04:52:21 +00:00
|
|
|
if( !item->IsNew() && !EditingModules() )
|
2018-06-11 23:41:24 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Flip( modPoint, leftRight );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:36:00 +00:00
|
|
|
if( !m_dragging )
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Push( _( "Flip" ) );
|
2014-01-29 09:17:14 +00:00
|
|
|
|
2017-08-07 08:02:07 +00:00
|
|
|
if( selection.IsHover() && !m_dragging )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2014-02-28 15:53:28 +00:00
|
|
|
|
2019-01-01 21:54:10 +00:00
|
|
|
if( m_dragging )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::updateLocalRatsnest, false );
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2018-04-24 17:44:28 +00:00
|
|
|
ROUTER_TOOL* routerTool = static_cast<ROUTER_TOOL*>
|
|
|
|
( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
|
|
|
|
|
|
|
|
// Do not delete items while actively routing.
|
|
|
|
if( routerTool && routerTool->Router() && routerTool->Router()->RoutingInProgress() )
|
2019-01-18 03:33:47 +00:00
|
|
|
return 1;
|
2018-04-24 17:44:28 +00:00
|
|
|
|
2018-12-13 01:22:27 +00:00
|
|
|
std::vector<BOARD_ITEM*> lockedItems;
|
2019-08-04 04:16:35 +00:00
|
|
|
Activate();
|
2018-12-13 01:22:27 +00:00
|
|
|
|
2018-06-12 07:36:35 +00:00
|
|
|
// get a copy instead of reference (as we're going to clear the selection before removing items)
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_SELECTION selectionCopy;
|
2019-06-17 22:02:30 +00:00
|
|
|
bool isCut = aEvent.Parameter<PCB_ACTIONS::REMOVE_FLAGS>() == PCB_ACTIONS::REMOVE_FLAGS::CUT;
|
|
|
|
bool isAlt = aEvent.Parameter<PCB_ACTIONS::REMOVE_FLAGS>() == PCB_ACTIONS::REMOVE_FLAGS::ALT;
|
2019-01-12 01:27:29 +00:00
|
|
|
|
|
|
|
// If we are in a "Cut" operation, then the copied selection exists already
|
|
|
|
if( isCut )
|
2019-05-05 10:33:34 +00:00
|
|
|
{
|
2019-01-12 01:27:29 +00:00
|
|
|
selectionCopy = m_selectionTool->GetSelection();
|
2019-05-05 10:33:34 +00:00
|
|
|
}
|
2019-01-12 01:27:29 +00:00
|
|
|
else
|
2019-05-05 10:33:34 +00:00
|
|
|
{
|
2019-01-12 01:27:29 +00:00
|
|
|
selectionCopy = m_selectionTool->RequestSelection(
|
2018-09-25 14:23:38 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2018-12-13 01:22:27 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
2019-05-05 10:33:34 +00:00
|
|
|
}
|
2017-03-03 12:42:28 +00:00
|
|
|
|
2018-12-13 01:22:27 +00:00
|
|
|
bool isHover = selectionCopy.IsHover();
|
2017-02-04 06:45:52 +00:00
|
|
|
|
2018-02-12 09:17:35 +00:00
|
|
|
// in "alternative" mode, deletion is not just a simple list of selected items,
|
|
|
|
// it removes whole tracks, not just segments
|
2018-12-13 01:22:27 +00:00
|
|
|
if( isAlt && isHover
|
2018-09-30 10:36:18 +00:00
|
|
|
&& ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
|
2017-02-04 06:45:52 +00:00
|
|
|
{
|
2019-11-22 19:29:07 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectConnection, true );
|
2017-02-04 06:45:52 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 10:36:18 +00:00
|
|
|
if( selectionCopy.Empty() )
|
2018-02-12 09:17:35 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-01-12 01:27:29 +00:00
|
|
|
// N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
|
|
|
|
// were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
|
|
|
|
// in the copyToClipboard() routine
|
|
|
|
if( !m_lockedSelected && !isCut )
|
2018-12-13 01:22:27 +00:00
|
|
|
{
|
|
|
|
// Second RequestSelection removes locked items but keeps a copy of their pointers
|
|
|
|
selectionCopy = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED ); }, &lockedItems );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-09 10:07:30 +00:00
|
|
|
// As we are about to remove items, they have to be removed from the selection first
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* item : selectionCopy )
|
2018-09-15 23:30:10 +00:00
|
|
|
{
|
|
|
|
if( m_editModules )
|
|
|
|
{
|
|
|
|
m_commit->Remove( item );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
{
|
|
|
|
auto text = static_cast<TEXTE_MODULE*>( item );
|
|
|
|
auto parent = static_cast<MODULE*>( item->GetParent() );
|
|
|
|
|
|
|
|
if( text->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
|
|
|
|
{
|
|
|
|
m_commit->Modify( text );
|
|
|
|
getView()->Remove( text );
|
|
|
|
parent->Remove( text );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-12-17 12:56:17 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
auto pad = static_cast<D_PAD*>( item );
|
|
|
|
auto parent = static_cast<MODULE*>( item->GetParent() );
|
|
|
|
|
|
|
|
m_commit->Modify( parent );
|
|
|
|
getView()->Remove( pad );
|
|
|
|
parent->Remove( pad );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-09-15 23:30:10 +00:00
|
|
|
default:
|
|
|
|
m_commit->Remove( item );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2019-01-12 01:27:29 +00:00
|
|
|
if( isCut )
|
|
|
|
m_commit->Push( _( "Cut" ) );
|
|
|
|
else
|
|
|
|
m_commit->Push( _( "Delete" ) );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2019-07-17 20:45:43 +00:00
|
|
|
if( !m_lockedSelected && !lockedItems.empty() )
|
2018-12-13 01:22:27 +00:00
|
|
|
{
|
|
|
|
///> Popup nag for deleting locked items
|
|
|
|
STATUS_TEXT_POPUP statusPopup( frame() );
|
|
|
|
|
|
|
|
m_lockedSelected = true;
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &lockedItems );
|
|
|
|
statusPopup.SetText( _( "Delete again to remove locked items" ) );
|
2019-05-19 21:04:04 +00:00
|
|
|
statusPopup.PopupFor( 2000 );
|
2018-12-13 01:22:27 +00:00
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
while( m_lockedSelected && statusPopup.IsShown() )
|
|
|
|
{
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lockedSelected = false;
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
return 0;
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 19:27:00 +00:00
|
|
|
int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2018-09-25 14:23:38 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.Empty() )
|
2015-02-12 03:22:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
|
2018-06-12 07:36:35 +00:00
|
|
|
wxPoint translation;
|
|
|
|
double rotation;
|
|
|
|
ROTATION_ANCHOR rotationAnchor = selection.Size() > 1 ? ROTATE_AROUND_SEL_CENTER
|
|
|
|
: ROTATE_AROUND_ITEM_ANCHOR;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-06-20 13:28:51 +00:00
|
|
|
// TODO: Implement a visible bounding border at the edge
|
|
|
|
auto sel_box = selection.GetBoundingBox();
|
|
|
|
|
|
|
|
DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation, rotationAnchor, sel_box );
|
2015-02-12 03:22:24 +00:00
|
|
|
int ret = dialog.ShowModal();
|
|
|
|
|
2015-02-22 14:43:44 +00:00
|
|
|
if( ret == wxID_OK )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2015-02-20 10:40:36 +00:00
|
|
|
VECTOR2I rp = selection.GetCenter();
|
2018-06-12 07:36:35 +00:00
|
|
|
wxPoint selCenter( rp.x, rp.y );
|
2017-04-22 20:07:29 +00:00
|
|
|
|
|
|
|
// Make sure the rotation is from the right reference point
|
2018-06-12 07:36:35 +00:00
|
|
|
selCenter += translation;
|
2017-04-22 20:07:29 +00:00
|
|
|
|
2018-07-31 04:52:21 +00:00
|
|
|
// When editing modules, all items have the same parent
|
|
|
|
if( EditingModules() )
|
|
|
|
m_commit->Modify( selection.Front() );
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* selItem : selection )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2019-03-07 16:43:21 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selItem );
|
2018-06-12 07:36:35 +00:00
|
|
|
|
2018-07-31 04:52:21 +00:00
|
|
|
if( !item->IsNew() && !EditingModules() )
|
2018-06-11 23:41:24 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
|
2018-06-12 07:36:35 +00:00
|
|
|
item->Move( translation );
|
|
|
|
|
|
|
|
switch( rotationAnchor )
|
|
|
|
{
|
|
|
|
case ROTATE_AROUND_ITEM_ANCHOR:
|
|
|
|
item->Rotate( item->GetPosition(), rotation );
|
|
|
|
break;
|
|
|
|
case ROTATE_AROUND_SEL_CENTER:
|
|
|
|
item->Rotate( selCenter, rotation );
|
|
|
|
break;
|
|
|
|
case ROTATE_AROUND_USER_ORIGIN:
|
2019-06-13 13:34:38 +00:00
|
|
|
item->Rotate( (wxPoint) editFrame->GetScreen()->m_LocalOrigin, rotation );
|
2018-06-12 07:36:35 +00:00
|
|
|
break;
|
|
|
|
case ROTATE_AROUND_AUX_ORIGIN:
|
|
|
|
item->Rotate( editFrame->GetAuxOrigin(), rotation );
|
|
|
|
break;
|
|
|
|
}
|
2017-04-22 20:07:29 +00:00
|
|
|
|
|
|
|
if( !m_dragging )
|
|
|
|
getView()->Update( item );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:36:00 +00:00
|
|
|
m_commit->Push( _( "Move exact" ) );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.IsHover() )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2019-01-01 21:54:10 +00:00
|
|
|
|
|
|
|
if( m_dragging )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::updateLocalRatsnest, false );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 19:27:00 +00:00
|
|
|
int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
// Be sure that there is at least one item that we can modify
|
2018-09-25 14:23:38 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
2017-03-03 12:42:28 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
2015-02-12 03:22:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// we have a selection to work on now, so start the tool process
|
2016-05-25 09:52:43 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-11-01 02:57:13 +00:00
|
|
|
// If the selection was given a hover, we do not keep the selection after completion
|
|
|
|
bool is_hover = selection.IsHover();
|
|
|
|
|
2017-06-12 09:16:30 +00:00
|
|
|
std::vector<BOARD_ITEM*> new_items;
|
|
|
|
new_items.reserve( selection.Size() );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-06-12 09:16:30 +00:00
|
|
|
BOARD_ITEM* orig_item = nullptr;
|
|
|
|
BOARD_ITEM* dupe_item = nullptr;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-06-12 09:16:30 +00:00
|
|
|
// Each selected item is duplicated and pushed to new_items list
|
|
|
|
// Old selection is cleared, and new items are then selected.
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-06-12 09:16:30 +00:00
|
|
|
orig_item = static_cast<BOARD_ITEM*>( item );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-02-18 19:29:52 +00:00
|
|
|
if( m_editModules )
|
2019-05-31 00:15:57 +00:00
|
|
|
dupe_item = editFrame->GetBoard()->GetFirstModule()->Duplicate( orig_item, increment );
|
2015-02-18 19:29:52 +00:00
|
|
|
else
|
2017-06-12 09:16:30 +00:00
|
|
|
dupe_item = editFrame->GetBoard()->Duplicate( orig_item );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-06-12 09:16:30 +00:00
|
|
|
if( dupe_item )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-06-12 09:16:30 +00:00
|
|
|
// Clear the selection flag here, otherwise the SELECTION_TOOL
|
|
|
|
// will not properly select it later on
|
|
|
|
dupe_item->ClearSelected();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-06-12 09:16:30 +00:00
|
|
|
new_items.push_back( dupe_item );
|
|
|
|
m_commit->Add( dupe_item );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 09:16:30 +00:00
|
|
|
// Clear the old selection first
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
// Select the new items
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
// record the new items as added
|
2016-06-08 09:24:46 +00:00
|
|
|
if( !selection.Empty() )
|
2016-03-18 11:15:50 +00:00
|
|
|
{
|
|
|
|
editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
|
2019-05-05 10:33:34 +00:00
|
|
|
(int) new_items.size() ) );
|
2018-03-05 13:52:09 +00:00
|
|
|
|
2016-03-18 11:15:50 +00:00
|
|
|
// If items were duplicated, pick them up
|
2016-06-21 15:06:28 +00:00
|
|
|
// this works well for "dropping" copies around and pushes the commit
|
2018-03-05 13:52:09 +00:00
|
|
|
TOOL_EVENT evt = PCB_ACTIONS::move.MakeEvent();
|
2019-08-10 10:56:15 +00:00
|
|
|
Move( evt );
|
2019-11-01 02:57:13 +00:00
|
|
|
|
|
|
|
// After moving the new items, we need to refresh the group and view flags
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
if( !is_hover )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
|
2016-03-18 11:15:50 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-04-19 12:15:11 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-09-25 14:23:38 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.Empty() )
|
2016-05-11 09:18:27 +00:00
|
|
|
return 0;
|
2016-03-07 07:13:06 +00:00
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
// we have a selection to work on now, so start the tool process
|
|
|
|
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
|
2019-06-01 11:11:05 +00:00
|
|
|
ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection );
|
2016-04-02 12:52:29 +00:00
|
|
|
array_creator.Invoke();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-09 01:17:49 +00:00
|
|
|
void EDIT_TOOL::PadFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector )
|
|
|
|
{
|
|
|
|
for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
|
|
|
|
|
|
|
|
if( item->Type() != PCB_PAD_T )
|
|
|
|
aCollector.Remove( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-05 23:44:37 +00:00
|
|
|
void EDIT_TOOL::FootprintFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector )
|
|
|
|
{
|
|
|
|
for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
|
|
|
|
|
|
|
|
if( item->Type() != PCB_MODULE_T )
|
|
|
|
aCollector.Remove( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-09 09:09:13 +00:00
|
|
|
int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-06-12 23:48:59 +00:00
|
|
|
if( EditingModules() && !frame()->GetModel())
|
|
|
|
return 0;
|
|
|
|
|
2017-03-09 09:09:13 +00:00
|
|
|
auto& view = *getView();
|
|
|
|
auto& controls = *getViewControls();
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
frame()->PushTool( tool );
|
2017-03-09 09:09:13 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS units = frame()->GetUserUnits();
|
2017-03-16 14:37:39 +00:00
|
|
|
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
|
2018-10-10 09:48:16 +00:00
|
|
|
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
|
2017-03-16 14:37:39 +00:00
|
|
|
|
2017-03-09 09:09:13 +00:00
|
|
|
view.Add( &ruler );
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
|
2018-10-05 04:19:12 +00:00
|
|
|
GRID_HELPER grid( frame() );
|
|
|
|
|
2017-03-09 09:09:13 +00:00
|
|
|
bool originSet = false;
|
|
|
|
|
|
|
|
controls.ShowCursor( true );
|
2018-02-14 14:40:18 +00:00
|
|
|
controls.SetAutoPan( false );
|
2018-12-06 03:58:07 +00:00
|
|
|
controls.CaptureCursor( false );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
while( auto evt = Wait() )
|
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
2018-10-05 04:19:12 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
controls.SetSnapping( !evt->Modifier( MD_ALT ) );
|
|
|
|
const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
|
2018-11-03 18:05:11 +00:00
|
|
|
controls.ForceCursorPosition(true, cursorPos );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto clearRuler = [&] () {
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
originSet = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2017-03-09 09:09:13 +00:00
|
|
|
{
|
2019-06-24 15:27:05 +00:00
|
|
|
if( originSet )
|
2019-07-01 21:01:33 +00:00
|
|
|
clearRuler();
|
|
|
|
else
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
frame()->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( originSet )
|
|
|
|
clearRuler();
|
|
|
|
|
|
|
|
if( evt->IsMoveTool() )
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2019-06-24 15:27:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
frame()->PopTool( tool );
|
2019-06-24 15:27:05 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2017-03-09 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// click or drag starts
|
2018-09-14 09:59:38 +00:00
|
|
|
else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
|
2017-03-09 09:09:13 +00:00
|
|
|
{
|
2018-09-14 09:59:38 +00:00
|
|
|
twoPtMgr.SetOrigin( cursorPos );
|
|
|
|
twoPtMgr.SetEnd( cursorPos );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
controls.CaptureCursor( true );
|
|
|
|
controls.SetAutoPan( true );
|
|
|
|
|
|
|
|
originSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// second click or mouse up after drag ends
|
2018-09-14 09:59:38 +00:00
|
|
|
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
|
2017-03-09 09:09:13 +00:00
|
|
|
{
|
|
|
|
originSet = false;
|
|
|
|
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// move or drag when origin set updates rules
|
2018-09-14 09:59:38 +00:00
|
|
|
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
2017-03-09 09:09:13 +00:00
|
|
|
{
|
2017-03-16 14:37:39 +00:00
|
|
|
twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
|
|
|
|
twoPtMgr.SetEnd( cursorPos );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
view.SetVisible( &ruler, true );
|
|
|
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
|
|
}
|
2018-01-12 03:12:46 +00:00
|
|
|
|
2019-05-14 10:51:24 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::toggleUnits )
|
2018-10-10 09:48:16 +00:00
|
|
|
|| evt->IsAction( &PCB_ACTIONS::updateUnits ) )
|
2018-07-22 23:53:05 +00:00
|
|
|
{
|
2018-10-10 09:48:16 +00:00
|
|
|
if( frame()->GetUserUnits() != units )
|
|
|
|
{
|
|
|
|
units = frame()->GetUserUnits();
|
|
|
|
ruler.SwitchUnits();
|
|
|
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
|
|
}
|
2018-07-22 23:53:05 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 03:12:46 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-06-02 10:12:11 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2018-01-12 03:12:46 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2017-03-09 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
view.Remove( &ruler );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
bool EDIT_TOOL::updateModificationPoint( PCBNEW_SELECTION& aSelection )
|
2014-02-04 16:27:00 +00:00
|
|
|
{
|
2018-04-19 14:55:40 +00:00
|
|
|
if( m_dragging && aSelection.HasReferencePoint() )
|
2017-09-28 16:38:54 +00:00
|
|
|
return false;
|
|
|
|
|
2018-04-19 14:55:40 +00:00
|
|
|
// When there is only one item selected, the reference point is its position...
|
2014-02-04 16:27:00 +00:00
|
|
|
if( aSelection.Size() == 1 )
|
|
|
|
{
|
2017-09-22 15:17:38 +00:00
|
|
|
auto item = static_cast<BOARD_ITEM*>( aSelection.Front() );
|
|
|
|
auto pos = item->GetPosition();
|
2017-09-28 16:38:54 +00:00
|
|
|
aSelection.SetReferencePoint( VECTOR2I( pos.x, pos.y ) );
|
2014-02-04 16:27:00 +00:00
|
|
|
}
|
2019-02-23 22:33:43 +00:00
|
|
|
// ...otherwise modify items with regard to the grid-snapped cursor position
|
2014-02-04 16:27:00 +00:00
|
|
|
else
|
|
|
|
{
|
2019-02-23 22:33:43 +00:00
|
|
|
m_cursor = getViewControls()->GetCursorPosition( true );
|
2017-09-28 16:38:54 +00:00
|
|
|
aSelection.SetReferencePoint( m_cursor );
|
2014-02-04 16:27:00 +00:00
|
|
|
}
|
2017-09-28 16:38:54 +00:00
|
|
|
|
|
|
|
return true;
|
2014-02-04 16:27:00 +00:00
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2019-06-03 13:49:17 +00:00
|
|
|
int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2018-03-09 06:25:06 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection( FootprintFilter );
|
2017-03-03 12:42:28 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
2015-06-16 13:27:59 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
MODULE* mod = selection.FirstOfKind<MODULE>();
|
2015-03-03 10:50:50 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
if( !mod )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2015-03-03 10:50:50 +00:00
|
|
|
|
2019-05-28 23:23:58 +00:00
|
|
|
if( mod->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2019-05-28 23:23:58 +00:00
|
|
|
mod->SetTimeStamp( GetNewTimeStamp() );
|
2015-02-18 00:10:20 +00:00
|
|
|
editFrame->OnModify();
|
|
|
|
}
|
|
|
|
|
2019-09-05 22:00:47 +00:00
|
|
|
auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2019-05-28 23:23:58 +00:00
|
|
|
editor->Load_Module_From_BOARD( mod );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
editor->Show( true );
|
|
|
|
editor->Raise(); // Iconize( false );
|
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.IsHover() )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2015-06-16 13:27:59 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-03-03 12:42:28 +00:00
|
|
|
|
2017-10-02 06:49:25 +00:00
|
|
|
|
2019-07-17 20:19:23 +00:00
|
|
|
bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aReferencePoint )
|
2017-09-22 15:17:38 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
|
|
|
|
STATUS_TEXT_POPUP statusPopup( frame() );
|
2019-05-20 10:23:32 +00:00
|
|
|
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
|
2019-07-17 20:19:23 +00:00
|
|
|
OPT<VECTOR2I> pickedPoint;
|
|
|
|
bool done = false;
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
statusPopup.SetText( _( "Select reference point for the copy..." ) );
|
2019-07-09 14:01:43 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetClickHandler(
|
|
|
|
[&]( const VECTOR2D& aPoint ) -> bool
|
|
|
|
{
|
2019-07-17 20:19:23 +00:00
|
|
|
pickedPoint = aPoint;
|
2019-07-15 23:44:01 +00:00
|
|
|
statusPopup.SetText( _( "Selection copied." ) );
|
|
|
|
statusPopup.Expire( 800 );
|
|
|
|
return false; // we don't need any more points
|
|
|
|
} );
|
|
|
|
|
|
|
|
picker->SetMotionHandler(
|
|
|
|
[&] ( const VECTOR2D& aPos )
|
|
|
|
{
|
2019-07-17 20:19:23 +00:00
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
|
2019-07-15 23:44:01 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
picker->SetCancelHandler(
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
statusPopup.SetText( _( "Copy cancelled." ) );
|
|
|
|
statusPopup.Expire( 800 );
|
2019-07-17 20:19:23 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
picker->SetFinalizeHandler(
|
|
|
|
[&]( const int& aFinalState )
|
|
|
|
{
|
|
|
|
done = true;
|
2019-07-15 23:44:01 +00:00
|
|
|
} );
|
2018-08-22 18:05:40 +00:00
|
|
|
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
|
|
|
|
statusPopup.Popup();
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2019-07-17 20:19:23 +00:00
|
|
|
while( !done )
|
|
|
|
Wait();
|
|
|
|
|
|
|
|
if( pickedPoint.is_initialized() )
|
|
|
|
aReferencePoint = pickedPoint.get();
|
|
|
|
|
|
|
|
return pickedPoint.is_initialized();
|
2017-09-22 15:17:38 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 06:49:25 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
|
2017-09-17 17:49:06 +00:00
|
|
|
{
|
|
|
|
CLIPBOARD_IO io;
|
2017-09-22 15:17:38 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection(
|
2018-09-25 14:23:38 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2017-09-29 08:58:05 +00:00
|
|
|
if( selection.Empty() )
|
2018-04-04 22:03:34 +00:00
|
|
|
return 1;
|
2017-09-29 08:58:05 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
VECTOR2I refPoint;
|
|
|
|
bool rv = pickCopyReferencePoint( refPoint );
|
|
|
|
frame()->SetMsgPanel( board() );
|
2017-09-29 08:58:05 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
if( !rv )
|
|
|
|
return 1;
|
2018-08-22 18:05:40 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
selection.SetReferencePoint( refPoint );
|
2017-09-17 17:49:06 +00:00
|
|
|
|
2017-09-29 08:58:05 +00:00
|
|
|
io.SetBoard( board() );
|
2017-09-17 17:49:06 +00:00
|
|
|
io.SaveSelection( selection );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-02 06:49:25 +00:00
|
|
|
|
2017-09-17 17:49:06 +00:00
|
|
|
int EDIT_TOOL::cutToClipboard( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-04-04 22:03:34 +00:00
|
|
|
if( !copyToClipboard( aEvent ) )
|
2019-01-12 01:27:29 +00:00
|
|
|
{
|
|
|
|
// N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
|
|
|
|
// were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
|
|
|
|
// in the copyToClipboard() routine
|
2019-01-22 15:35:36 +00:00
|
|
|
TOOL_EVENT evt( aEvent.Category(), aEvent.Action(), TOOL_ACTION_SCOPE::AS_GLOBAL );
|
2019-01-12 01:27:29 +00:00
|
|
|
evt.SetParameter( PCB_ACTIONS::REMOVE_FLAGS::CUT );
|
|
|
|
Remove( evt );
|
|
|
|
}
|
2018-04-04 22:03:34 +00:00
|
|
|
|
2017-09-17 17:49:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
void EDIT_TOOL::setTransitions()
|
|
|
|
{
|
2019-08-13 12:29:18 +00:00
|
|
|
Go( &EDIT_TOOL::GetAndPlace, PCB_ACTIONS::getAndPlace.MakeEvent() );
|
2019-08-10 10:56:15 +00:00
|
|
|
Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() );
|
2019-08-19 20:09:17 +00:00
|
|
|
Go( &EDIT_TOOL::Move, PCB_ACTIONS::drag.MakeEvent() );
|
2019-06-03 13:49:17 +00:00
|
|
|
Go( &EDIT_TOOL::Drag, PCB_ACTIONS::drag45Degree.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Drag, PCB_ACTIONS::dragFreeAngle.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCcw.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
|
2019-07-04 19:56:52 +00:00
|
|
|
Go( &EDIT_TOOL::Remove, ACTIONS::doDelete.MakeEvent() );
|
2019-06-09 21:57:23 +00:00
|
|
|
Go( &EDIT_TOOL::Remove, PCB_ACTIONS::deleteFull.MakeEvent() );
|
2019-06-03 13:49:17 +00:00
|
|
|
Go( &EDIT_TOOL::Properties, PCB_ACTIONS::properties.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::MoveExact, PCB_ACTIONS::moveExact.MakeEvent() );
|
2019-07-04 19:56:52 +00:00
|
|
|
Go( &EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
|
2019-06-03 13:49:17 +00:00
|
|
|
Go( &EDIT_TOOL::Duplicate, PCB_ACTIONS::duplicateIncrement.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::CreateArray, PCB_ACTIONS::createArray.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
|
2019-10-31 00:00:07 +00:00
|
|
|
Go( &EDIT_TOOL::ChangeTrackWidth, PCB_ACTIONS::changeTrackWidth.MakeEvent() );
|
2019-06-03 13:49:17 +00:00
|
|
|
|
|
|
|
Go( &EDIT_TOOL::EditFpInFpEditor, PCB_ACTIONS::editFootprintInFpEditor.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::MeasureTool, ACTIONS::measureTool.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
|
2019-05-14 19:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|