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>
|
2020-02-20 12:11:04 +00:00
|
|
|
* Copyright (C) 2017-2020 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_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>
|
2020-05-02 23:06:43 +00:00
|
|
|
#include <ws_proxy_view_item.h>
|
2015-02-18 00:10:20 +00:00
|
|
|
#include <kiway.h>
|
2016-04-02 12:52:29 +00:00
|
|
|
#include <array_creator.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcbnew_settings.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>
|
2020-06-27 11:57:40 +00:00
|
|
|
#include <tools/pad_tool.h>
|
2020-05-03 07:59:05 +00:00
|
|
|
#include <pad_naming.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>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2020-04-14 16:57:18 +00:00
|
|
|
#include <zone_filler.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
|
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 );
|
|
|
|
}
|
2020-06-14 14:29:44 +00:00
|
|
|
else if( item->Type() == PCB_MODULE_ZONE_AREA_T )
|
|
|
|
{
|
|
|
|
MODULE* mod = static_cast<MODULE*>( item->GetParent() );
|
|
|
|
|
|
|
|
// case 1: handle locking
|
|
|
|
if( ( aFlags & EXCLUDE_LOCKED ) && mod && mod->IsLocked() )
|
|
|
|
{
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
// case 2: selection contains both the module and its pads - remove the pads
|
|
|
|
if( !( aFlags & INCLUDE_PADS_AND_MODULES ) && mod && aCollector.HasItem( mod ) )
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
2018-09-25 14:23:38 +00:00
|
|
|
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
|
2020-03-02 20:55:06 +00:00
|
|
|
if( !( aFlags & INCLUDE_PADS_AND_MODULES ) && mod && aCollector.HasItem( mod ) )
|
2018-03-09 06:25:06 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-16 14:09:00 +00:00
|
|
|
class SPECIAL_TOOLS_CONTEXT_MENU : public ACTION_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SPECIAL_TOOLS_CONTEXT_MENU() :
|
|
|
|
ACTION_MENU( true )
|
|
|
|
{
|
|
|
|
SetIcon( options_board_xpm );
|
|
|
|
SetTitle( _( "Special Tools..." ) );
|
|
|
|
|
|
|
|
Add( PCB_ACTIONS::moveExact );
|
2020-07-09 15:56:37 +00:00
|
|
|
Add( PCB_ACTIONS::moveWithReference );
|
2020-05-16 14:09:00 +00:00
|
|
|
Add( PCB_ACTIONS::positionRelative );
|
|
|
|
Add( PCB_ACTIONS::createArray );
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTION_MENU* create() const override
|
|
|
|
{
|
|
|
|
return new SPECIAL_TOOLS_CONTEXT_MENU();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-04-20 23:24:29 +00:00
|
|
|
auto editingModuleCondition =
|
|
|
|
[ this ] ( const SELECTION& aSelection )
|
|
|
|
{
|
|
|
|
return m_editModules;
|
|
|
|
};
|
2017-01-23 06:47:39 +00:00
|
|
|
|
2017-01-31 08:03:07 +00:00
|
|
|
auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
|
|
|
|
&& SELECTION_CONDITIONS::Count( 1 );
|
|
|
|
|
2020-04-20 23:24:29 +00:00
|
|
|
auto noActiveToolCondition =
|
|
|
|
[ this ] ( const SELECTION& aSelection )
|
|
|
|
{
|
|
|
|
return frame()->ToolStackIsEmpty();
|
|
|
|
};
|
2018-02-11 01:15:16 +00:00
|
|
|
|
2020-07-16 01:22:29 +00:00
|
|
|
auto notMovingCondition =
|
|
|
|
[ this ] ( const SELECTION& aSelection )
|
|
|
|
{
|
|
|
|
return !frame()->IsCurrentTool( PCB_ACTIONS::move )
|
|
|
|
&& !frame()->IsCurrentTool( PCB_ACTIONS::moveWithReference );
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2020-07-16 01:22:29 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
|
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 );
|
2020-05-16 14:09:00 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
|
2019-07-04 19:56:52 +00:00
|
|
|
menu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty );
|
2020-05-16 14:09:00 +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
|
|
|
|
2019-07-04 19:56:52 +00:00
|
|
|
menu.AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
|
2020-05-16 14:09:00 +00:00
|
|
|
|
|
|
|
// Add the submenu for create array and special move
|
|
|
|
auto specialToolsSubMenu = std::make_shared<SPECIAL_TOOLS_CONTEXT_MENU>();
|
|
|
|
specialToolsSubMenu->SetTool( this );
|
|
|
|
menu.AddSeparator();
|
|
|
|
m_selectionTool->GetToolMenu().AddSubMenu( specialToolsSubMenu );
|
|
|
|
menu.AddMenu( specialToolsSubMenu.get(), 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();
|
2020-06-27 11:57:40 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::editFpInFpEditor, 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
|
|
|
|
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;
|
|
|
|
|
2020-08-04 13:31:31 +00:00
|
|
|
// don't allow switch from moving to dragging
|
|
|
|
if( m_dragging )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-29 23:15:23 +00:00
|
|
|
// 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
|
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
ROUTER_TOOL* router = m_toolMgr->GetTool<ROUTER_TOOL>();
|
2017-08-22 14:44:47 +00:00
|
|
|
|
2020-08-05 15:01:10 +00:00
|
|
|
return router && router->Router()->Settings().InlineDragEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDIT_TOOL::isRouterActive() const
|
|
|
|
{
|
|
|
|
ROUTER_TOOL* router = m_toolMgr->GetTool<ROUTER_TOOL>();
|
|
|
|
|
|
|
|
return router && router->IsToolActive();
|
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
|
|
|
|
2020-07-05 21:36:12 +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
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
return doMoveSelection( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::MoveWithReference( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
return doMoveSelection( aEvent, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, bool aPickReference )
|
|
|
|
{
|
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2015-07-15 12:08:51 +00:00
|
|
|
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(
|
2020-07-05 21:36:12 +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();
|
2020-07-05 21:36:12 +00:00
|
|
|
bool unselect = selection.IsHover(); // N.B. This must be saved before the re-selection below
|
2018-10-04 05:45:10 +00:00
|
|
|
|
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(
|
2020-07-05 21:36:12 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
|
|
|
{
|
|
|
|
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 );
|
2020-07-05 21:36:12 +00:00
|
|
|
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;
|
2020-06-13 12:33:29 +00:00
|
|
|
GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
|
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
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion()
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::drag ) || evt->IsDrag( BUT_LEFT )
|
|
|
|
|| evt->IsAction( &ACTIONS::refreshPreview )
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::moveWithReference ) )
|
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
|
|
|
}
|
2020-07-05 21:36:12 +00:00
|
|
|
else if( !m_dragging ) // Prepare to start dragging
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2020-07-05 21:36:12 +00:00
|
|
|
if( !( evt->IsAction( &PCB_ACTIONS::move )
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::moveWithReference ) )
|
|
|
|
&& 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
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
if( selection.HasReferencePoint() )
|
2019-04-08 03:57:10 +00:00
|
|
|
{
|
|
|
|
// 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 ) );
|
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
m_cursor = grid.BestDragOrigin( originalCursorPos, items );
|
|
|
|
|
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
|
2020-07-05 21:36:12 +00:00
|
|
|
if( aPickReference )
|
|
|
|
{
|
|
|
|
VECTOR2I ref;
|
|
|
|
|
|
|
|
if( pickReferencePoint( _( "Select reference point for move..." ),
|
|
|
|
"", "", ref ) )
|
|
|
|
{
|
|
|
|
selection.SetReferencePoint( ref );
|
|
|
|
controls->ForceCursorPosition( true, ref );
|
|
|
|
m_cursor = ref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Cancel before move started
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selection.SetReferencePoint( m_cursor );
|
|
|
|
grid.SetAuxAxes( true, m_cursor );
|
|
|
|
}
|
2019-04-08 03:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-07-05 21:36:12 +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
|
|
|
{
|
2020-07-05 21:36:12 +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
|
|
|
}
|
|
|
|
|
2020-07-05 21:36:12 +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
|
|
|
{
|
2020-07-05 21:36:12 +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-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
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
if( unselect )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
editFrame->PopTool( tool );
|
2020-07-05 21:36:12 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
|
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(
|
2020-07-05 21:36:12 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) {
|
2020-02-05 12:49:12 +00:00
|
|
|
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
|
|
|
{
|
2020-05-02 23:06:43 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
const PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection(
|
2018-09-25 14:23:38 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2020-02-05 12:49:12 +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
|
|
|
}
|
2020-04-20 23:24:29 +00:00
|
|
|
else if( selection.Size() == 1 )
|
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
|
|
|
}
|
2020-05-02 23:06:43 +00:00
|
|
|
else if( selection.Size() == 0 && getView()->IsLayerVisible( LAYER_WORKSHEET ) )
|
|
|
|
{
|
|
|
|
KIGFX::WS_PROXY_VIEW_ITEM* worksheet = editFrame->GetCanvas()->GetWorksheet();
|
|
|
|
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
|
|
|
|
|
|
|
|
if( worksheet && worksheet->HitTestWorksheetItems( getView(), (wxPoint) cursorPos ) )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::pageSettings );
|
|
|
|
}
|
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
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 )
|
2020-02-05 12:49:12 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-07-25 15:41:36 +00:00
|
|
|
* Mirror a pad in the vertical axis passing through a point (mirror left to right)
|
2017-01-23 06:47:39 +00:00
|
|
|
*/
|
|
|
|
static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
|
|
|
|
{
|
2019-01-17 04:55:40 +00:00
|
|
|
if( aPad.GetShape() == PAD_SHAPE_CUSTOM )
|
2020-07-25 15:41:36 +00:00
|
|
|
aPad.FlipPrimitives( true ); // mirror primitives left to right
|
2019-01-17 04:55:40 +00:00
|
|
|
|
2020-07-25 15:41:36 +00:00
|
|
|
wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
|
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 )
|
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2020-02-05 12:49:12 +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:
|
2020-06-14 14:23:10 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
2017-01-23 06:47:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-14 14:23:10 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
|
|
|
{
|
|
|
|
auto& zone = static_cast<MODULE_ZONE_CONTAINER&>( *item );
|
|
|
|
zone.Mirror( mirrorPoint, false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
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
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2020-02-05 12:49:12 +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
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-05 12:49:12 +00:00
|
|
|
ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
|
2018-04-24 17:44:28 +00:00
|
|
|
|
|
|
|
// 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 )
|
2020-02-05 12:49:12 +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 )
|
2020-02-05 12:49:12 +00:00
|
|
|
{
|
|
|
|
EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED );
|
|
|
|
},
|
|
|
|
&lockedItems );
|
2018-12-13 01:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
2020-06-14 14:04:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
|
|
|
{
|
|
|
|
auto zone = static_cast<MODULE_ZONE_CONTAINER*>( item );
|
|
|
|
auto parent = static_cast<MODULE*>( item->GetParent() );
|
|
|
|
|
|
|
|
m_commit->Modify( parent );
|
|
|
|
getView()->Remove( zone );
|
|
|
|
parent->Remove( zone );
|
2019-12-17 12:56:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-04-14 16:57:18 +00:00
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
// We process the zones special so that cutouts can be deleted when the delete tool
|
|
|
|
// is called from inside a cutout when the zone is selected.
|
|
|
|
{
|
|
|
|
// Only interact with cutouts when deleting and a single item is selected
|
|
|
|
if( !isCut && selectionCopy.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
VECTOR2I curPos = getViewControls()->GetCursorPosition();
|
|
|
|
auto zone = static_cast<ZONE_CONTAINER*>( item );
|
|
|
|
|
|
|
|
int outlineIdx, holeIdx;
|
|
|
|
|
|
|
|
if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) )
|
|
|
|
{
|
|
|
|
// Remove the cutout
|
|
|
|
m_commit->Modify( zone );
|
|
|
|
zone->RemoveCutout( outlineIdx, holeIdx );
|
|
|
|
|
|
|
|
std::vector<ZONE_CONTAINER*> toFill;
|
|
|
|
toFill.emplace_back( zone );
|
|
|
|
|
|
|
|
// Fill the modified zone
|
|
|
|
ZONE_FILLER filler( board() );
|
|
|
|
filler.InstallNewProgressReporter( frame(), _( "Fill Zone" ), 4 );
|
|
|
|
filler.Fill( toFill );
|
|
|
|
|
|
|
|
// Update the display
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->HatchBorder();
|
2020-04-14 16:57:18 +00:00
|
|
|
canvas()->Refresh();
|
|
|
|
|
|
|
|
// Restore the selection on the original zone
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, zone );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the entire zone otherwise
|
|
|
|
m_commit->Remove( item );
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
2020-01-31 15:41:47 +00:00
|
|
|
|
|
|
|
// Ensure statusPopup is hidden after use and before deleting it:
|
|
|
|
statusPopup.Hide();
|
2018-12-13 01:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2020-02-05 12:49:12 +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;
|
|
|
|
|
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();
|
|
|
|
|
2020-07-01 12:28:10 +00:00
|
|
|
DIALOG_MOVE_EXACT dialog( frame(), 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:
|
2020-07-01 12:28:10 +00:00
|
|
|
item->Rotate( (wxPoint) frame()->GetScreen()->m_LocalOrigin, rotation );
|
2018-06-12 07:36:35 +00:00
|
|
|
break;
|
|
|
|
case ROTATE_AROUND_AUX_ORIGIN:
|
2020-07-01 12:28:10 +00:00
|
|
|
item->Rotate( board()->GetDesignSettings().m_AuxOrigin, rotation );
|
2018-06-12 07:36:35 +00:00
|
|
|
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
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 )
|
2020-02-05 12:49:12 +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 )
|
2020-02-05 12:49:12 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
MODULE* editModule = editFrame->GetBoard()->GetFirstModule();
|
2020-05-03 07:59:05 +00:00
|
|
|
dupe_item = editModule->DuplicateItem( orig_item );
|
|
|
|
|
|
|
|
if( increment && item->Type() == PCB_PAD_T
|
|
|
|
&& PAD_NAMING::PadCanHaveName( *static_cast<D_PAD*>( dupe_item ) ) )
|
|
|
|
{
|
2020-06-27 11:57:40 +00:00
|
|
|
PAD_TOOL* padTool = m_toolMgr->GetTool<PAD_TOOL>();
|
|
|
|
wxString padName = padTool->GetLastPadName();
|
2020-05-03 07:59:05 +00:00
|
|
|
padName = editModule->GetNextPadName( padName );
|
2020-06-27 11:57:40 +00:00
|
|
|
padTool->SetLastPadName( padName );
|
2020-05-03 07:59:05 +00:00
|
|
|
static_cast<D_PAD*>( dupe_item )->SetName( padName );
|
|
|
|
}
|
2020-02-05 12:49:12 +00:00
|
|
|
}
|
|
|
|
else if( orig_item->GetParent() && orig_item->GetParent()->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
MODULE* parent = static_cast<MODULE*>( orig_item->GetParent() );
|
|
|
|
|
|
|
|
m_commit->Modify( parent );
|
2020-05-03 07:59:05 +00:00
|
|
|
dupe_item = parent->DuplicateItem( orig_item, true /* add to parent */ );
|
2020-02-05 12:49:12 +00:00
|
|
|
}
|
2015-02-18 19:29:52 +00:00
|
|
|
else
|
2020-02-05 12:49:12 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
switch( orig_item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_T:
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
case PCB_LINE_T:
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_VIA_T:
|
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
case PCB_TARGET_T:
|
|
|
|
case PCB_DIMENSION_T:
|
|
|
|
dupe_item = orig_item->Duplicate();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Silently drop other items (such as footprint texts) from duplication
|
|
|
|
break;
|
|
|
|
}
|
2020-02-05 12:49:12 +00:00
|
|
|
}
|
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 )
|
|
|
|
{
|
2020-08-05 15:01:10 +00:00
|
|
|
if( isRouterActive() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2020-02-05 12:49:12 +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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
bool EDIT_TOOL::pickReferencePoint( const wxString& aTooltip, const wxString& aSuccessMessage,
|
|
|
|
const wxString& aCanceledMessage, VECTOR2I& aReferencePoint )
|
2017-09-22 15:17:38 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
|
2020-02-03 14:02:25 +00:00
|
|
|
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
|
|
|
|
2020-07-05 21:36:12 +00:00
|
|
|
statusPopup.SetText( aTooltip );
|
2019-07-09 14:01:43 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetClickHandler(
|
2020-07-05 21:36:12 +00:00
|
|
|
[&]( const VECTOR2D& aPoint ) -> bool
|
|
|
|
{
|
|
|
|
pickedPoint = aPoint;
|
|
|
|
|
|
|
|
if( !aSuccessMessage.empty() )
|
|
|
|
{
|
|
|
|
statusPopup.SetText( aSuccessMessage );
|
|
|
|
statusPopup.Expire( 800 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusPopup.Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; // we don't need any more points
|
|
|
|
} );
|
2019-07-15 23:44:01 +00:00
|
|
|
|
|
|
|
picker->SetMotionHandler(
|
2020-07-05 21:36:12 +00:00
|
|
|
[&]( const VECTOR2D& aPos )
|
|
|
|
{
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
|
|
|
|
} );
|
2019-07-15 23:44:01 +00:00
|
|
|
|
|
|
|
picker->SetCancelHandler(
|
2020-07-05 21:36:12 +00:00
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if( !aCanceledMessage.empty() )
|
|
|
|
{
|
|
|
|
statusPopup.SetText( aCanceledMessage );
|
|
|
|
statusPopup.Expire( 800 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusPopup.Hide();
|
|
|
|
}
|
|
|
|
} );
|
2019-07-17 20:19:23 +00:00
|
|
|
|
|
|
|
picker->SetFinalizeHandler(
|
2020-07-05 21:36:12 +00:00
|
|
|
[&]( const int& aFinalState )
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
} );
|
2018-08-22 18:05:40 +00:00
|
|
|
|
2020-02-03 14:02:25 +00:00
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
|
|
|
|
statusPopup.Popup();
|
2018-08-22 18:05:40 +00:00
|
|
|
|
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();
|
|
|
|
|
2020-01-31 15:41:47 +00:00
|
|
|
// Ensure statusPopup is hidden after use and before deleting it:
|
2020-02-03 14:02:25 +00:00
|
|
|
statusPopup.Hide();
|
2020-01-31 15:41:47 +00:00
|
|
|
|
2019-07-17 20:19:23 +00:00
|
|
|
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(
|
2020-07-05 21:36:12 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) {
|
2020-02-20 12:11:04 +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;
|
2020-07-05 21:36:12 +00:00
|
|
|
bool rv = pickReferencePoint( _( "Select reference point for the copy..." ),
|
|
|
|
_( "Selection copied." ), _( "Copy cancelled." ), refPoint );
|
2019-06-13 13:34:38 +00:00
|
|
|
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() );
|
2020-07-27 17:56:15 +00:00
|
|
|
io.SaveSelection( selection, m_editModules );
|
2017-09-17 17:49:06 +00:00
|
|
|
|
|
|
|
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() );
|
2020-07-05 21:36:12 +00:00
|
|
|
Go( &EDIT_TOOL::MoveExact, PCB_ACTIONS::moveExact.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::MoveWithReference, PCB_ACTIONS::moveWithReference.MakeEvent() );
|
|
|
|
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::copyToClipboard, ACTIONS::copy.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
|
2019-05-14 19:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|