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>
|
2017-04-22 20:07:29 +00:00
|
|
|
* Copyright (C) 2017 KiCad Developers, see CHANGELOG.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>
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <class_zone.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>
|
2015-02-12 03:22:24 +00:00
|
|
|
#include <class_draw_panel_gal.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>
|
|
|
|
#include <view/view_controls.h>
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2014-07-09 14:50:31 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.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>
|
|
|
|
#include <hotkeys.h>
|
2014-04-02 14:30:48 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <cassert>
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2013-12-09 10:01:05 +00:00
|
|
|
#include "selection_tool.h"
|
|
|
|
#include "edit_tool.h"
|
2017-09-22 15:17:38 +00:00
|
|
|
#include "picker_tool.h"
|
2015-02-18 00:10:20 +00:00
|
|
|
#include "grid_helper.h"
|
2017-09-17 17:49:06 +00:00
|
|
|
#include "kicad_clipboard.h"
|
|
|
|
#include "pcbnew_control.h"
|
2013-12-09 10:01:05 +00:00
|
|
|
|
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>
|
2018-02-16 19:26:55 +00:00
|
|
|
#include <dialogs/dialog_exchange_footprints.h>
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-02-04 05:09:50 +00:00
|
|
|
#include <tools/tool_event_utils.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
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
// Edit tool actions
|
|
|
|
TOOL_ACTION PCB_ACTIONS::editFootprintInFpEditor( "pcbnew.InteractiveEdit.editFootprintInFpEditor",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_MODULE_WITH_MODEDIT ),
|
|
|
|
_( "Open in Footprint Editor" ),
|
|
|
|
_( "Opens the selected footprint in the Footprint Editor" ),
|
|
|
|
module_editor_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::editActivate( "pcbnew.InteractiveEdit",
|
2017-08-03 15:53:07 +00:00
|
|
|
AS_GLOBAL, 0,
|
2017-08-09 06:28:55 +00:00
|
|
|
_( "Edit Activate" ), "", move_xpm, AF_ACTIVATE );
|
2017-08-03 15:53:07 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::move( "pcbnew.InteractiveEdit.move",
|
2017-02-20 18:10:20 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_MOVE_ITEM ),
|
|
|
|
_( "Move" ), _( "Moves the selected item(s)" ), move_xpm, AF_ACTIVATE );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::duplicate( "pcbnew.InteractiveEdit.duplicate",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DUPLICATE_ITEM ),
|
2017-07-04 15:17:55 +00:00
|
|
|
_( "Duplicate" ), _( "Duplicates the selected item(s)" ), duplicate_xpm );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::duplicateIncrement( "pcbnew.InteractiveEdit.duplicateIncrementPads",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DUPLICATE_ITEM_AND_INCREMENT ),
|
|
|
|
_( "Duplicate" ), _( "Duplicates the selected item(s), incrementing pad numbers" ) );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::moveExact( "pcbnew.InteractiveEdit.moveExact",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_MOVE_ITEM_EXACT ),
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Move Exactly..." ), _( "Moves the selected item(s) by an exact amount" ),
|
2017-07-04 15:17:55 +00:00
|
|
|
move_exactly_xpm );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::createArray( "pcbnew.InteractiveEdit.createArray",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_CREATE_ARRAY ),
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Create Array..." ), _( "Create array" ), array_xpm, AF_ACTIVATE );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::rotateCw( "pcbnew.InteractiveEdit.rotateCw",
|
2018-02-25 18:30:59 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ROTATE_ITEM_CLOCKWISE ),
|
2017-07-20 12:37:11 +00:00
|
|
|
_( "Rotate Clockwise" ), _( "Rotates selected item(s) clockwise" ),
|
2017-03-30 08:48:00 +00:00
|
|
|
rotate_cw_xpm, AF_NONE, (void*) -1 );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::rotateCcw( "pcbnew.InteractiveEdit.rotateCcw",
|
2017-03-30 11:49:47 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ROTATE_ITEM ),
|
2017-07-20 12:37:11 +00:00
|
|
|
_( "Rotate Counterclockwise" ), _( "Rotates selected item(s) counterclockwise" ),
|
2017-03-30 08:48:00 +00:00
|
|
|
rotate_ccw_xpm, AF_NONE, (void*) 1 );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::flip( "pcbnew.InteractiveEdit.flip",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_FLIP_ITEM ),
|
|
|
|
_( "Flip" ), _( "Flips selected item(s)" ), swap_layer_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::mirror( "pcbnew.InteractiveEdit.mirror",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Mirror" ), _( "Mirrors selected item" ), mirror_h_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::remove( "pcbnew.InteractiveEdit.remove",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_BACK_SPACE ),
|
2017-06-02 09:51:11 +00:00
|
|
|
_( "Delete" ), _( "Deletes selected item(s)" ), delete_xpm,
|
2017-02-20 18:10:20 +00:00
|
|
|
AF_NONE, (void*) REMOVE_FLAGS::NORMAL );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::removeAlt( "pcbnew.InteractiveEdit.removeAlt",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DELETE ),
|
2017-06-02 09:51:11 +00:00
|
|
|
_( "Delete (Alternative)" ), _( "Deletes selected item(s)" ), delete_xpm,
|
2017-02-20 18:10:20 +00:00
|
|
|
AF_NONE, (void*) REMOVE_FLAGS::ALT );
|
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::updateFootprints( "pcbnew.InteractiveEdit.updateFootprints",
|
|
|
|
AS_GLOBAL, 0,
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Update Footprint..." ), _( "Update the footprint from the library" ),
|
2018-01-12 19:36:15 +00:00
|
|
|
reload_xpm );
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::exchangeFootprints( "pcbnew.InteractiveEdit.ExchangeFootprints",
|
|
|
|
AS_GLOBAL, 0,
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Change Footprint..." ), _( "Assign a different footprint from the library" ),
|
2017-06-02 09:51:11 +00:00
|
|
|
exchange_xpm );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::properties( "pcbnew.InteractiveEdit.properties",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_ITEM ),
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Properties..." ), _( "Displays item properties dialog" ), config_xpm );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::selectionModified( "pcbnew.InteractiveEdit.ModifiedSelection",
|
2017-02-20 18:10:20 +00:00
|
|
|
AS_GLOBAL, 0,
|
2017-04-20 10:06:58 +00:00
|
|
|
"", "", nullptr, AF_NOTIFY );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2017-03-09 09:09:13 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::measureTool( "pcbnew.InteractiveEdit.measureTool",
|
2018-02-25 18:30:59 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_MEASURE_TOOL ),
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Measuring Tool" ), _( "Interactively measure distance between points" ),
|
2017-03-09 09:09:13 +00:00
|
|
|
nullptr, AF_ACTIVATE );
|
|
|
|
|
2017-09-17 17:49:06 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::copyToClipboard( "pcbnew.InteractiveEdit.CopyToClipboard",
|
2018-03-12 15:46:38 +00:00
|
|
|
AS_GLOBAL, 0, // do not define a hotkey and let TranslateLegacyId() handle the event
|
2017-09-18 11:09:18 +00:00
|
|
|
_( "Copy" ), _( "Copy selected content to clipboard" ),
|
2017-09-17 17:49:06 +00:00
|
|
|
copy_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::cutToClipboard( "pcbnew.InteractiveEdit.CutToClipboard",
|
2018-03-12 15:46:38 +00:00
|
|
|
AS_GLOBAL, 0, // do not define a hotkey and let TranslateLegacyId() handle the event
|
2017-09-18 11:09:18 +00:00
|
|
|
_( "Cut" ), _( "Cut selected content to clipboard" ),
|
2017-09-17 17:49:06 +00:00
|
|
|
cut_xpm );
|
|
|
|
|
2018-10-10 09:48:16 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::updateUnits( "pcbnew.InteractiveEdit.updateUnits",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
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() :
|
2016-05-10 16:09:39 +00:00
|
|
|
PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ),
|
2018-08-01 16:58:27 +00:00
|
|
|
m_dragging( 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" ) );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
if( !m_selectionTool )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
|
|
|
DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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 ) {
|
|
|
|
return ( frame()->GetToolId() == ID_NO_TOOL_SELECTED );
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
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 );
|
|
|
|
menu.AddItem( PCB_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
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-10-19 21:16:06 +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 );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
menu.AddItem( PCB_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2018-09-29 16:14:02 +00:00
|
|
|
menu.AddSeparator( SELECTION_CONDITIONS::NotEmpty );
|
2017-09-17 17:49:06 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::copyToClipboard, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
menu.AddItem( PCB_ACTIONS::cutToClipboard, 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.
|
|
|
|
menu.AddItem( PCB_ACTIONS::pasteFromClipboard, noActiveToolCondition );
|
2017-09-17 17:49:06 +00:00
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
// Mirror only available in modedit
|
2018-09-29 16:14:02 +00:00
|
|
|
menu.AddSeparator( editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
|
2017-10-19 21:16:06 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::createPadFromShapes, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
menu.AddItem( PCB_ACTIONS::explodePadToShapes, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
|
2017-01-23 06:47:39 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
// Footprint actions
|
2018-09-29 16:14:02 +00:00
|
|
|
menu.AddSeparator( singleModuleCondition );
|
2018-01-12 19:36:15 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::editFootprintInFpEditor, singleModuleCondition );
|
|
|
|
menu.AddItem( PCB_ACTIONS::updateFootprints, singleModuleCondition );
|
|
|
|
menu.AddItem( PCB_ACTIONS::exchangeFootprints, singleModuleCondition );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2017-08-29 23:15:23 +00:00
|
|
|
auto theRouter = static_cast<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int EDIT_TOOL::Main( 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();
|
2014-02-04 16:27: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)
|
2018-09-25 14:23:38 +00:00
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
2018-10-04 05:45:10 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | 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
|
|
|
|
2018-10-04 05:45:10 +00:00
|
|
|
LSET item_layers = static_cast<BOARD_ITEM*>( selection.Front() )->GetLayerSet();
|
|
|
|
bool unselect = selection.IsHover(); //N.B. This must be saved before the re-selection below
|
|
|
|
|
|
|
|
// Filter out locked pads here
|
|
|
|
// We cannot do this in the selection filter as we need the pad layers
|
|
|
|
// when it is the curr_item.
|
|
|
|
selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
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;
|
|
|
|
|
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-10-04 05:45:10 +00:00
|
|
|
auto curr_item = static_cast<BOARD_ITEM*>( selection.Front() );
|
|
|
|
bool restore_state = false;
|
2017-09-22 15:17:38 +00:00
|
|
|
VECTOR2I totalMovement;
|
2015-07-07 16:36:32 +00:00
|
|
|
GRID_HELPER grid( editFrame );
|
2015-07-07 16:36:50 +00:00
|
|
|
OPT_TOOL_EVENT evt = aEvent;
|
2017-09-22 15:17:38 +00:00
|
|
|
VECTOR2I prevPos;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2018-06-18 21:02:16 +00:00
|
|
|
if( evt->IsAction( &PCB_ACTIONS::editActivate ) ||
|
|
|
|
evt->IsAction( &PCB_ACTIONS::move ) ||
|
|
|
|
evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
|
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
|
|
|
{
|
2018-10-07 03:20:38 +00:00
|
|
|
m_cursor = grid.BestSnapAnchor( controls->GetMousePosition(), item_layers );
|
2018-11-03 18:05:11 +00:00
|
|
|
controls->ForceCursorPosition(true, m_cursor );
|
2017-09-28 16:38:54 +00:00
|
|
|
VECTOR2I movement( m_cursor - prevPos );
|
2018-06-18 21:02:16 +00:00
|
|
|
selection.SetReferencePoint( m_cursor );
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
totalMovement += movement;
|
2017-09-22 15:17:38 +00:00
|
|
|
prevPos = m_cursor;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Drag items to the current cursor position
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : selection )
|
2017-12-18 17:24:25 +00:00
|
|
|
{
|
2018-06-18 21:02:16 +00:00
|
|
|
// Don't double move footprint pads, fields, etc.
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
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-03 15:53:07 +00:00
|
|
|
bool invokedRouter = false;
|
|
|
|
|
2017-08-22 14:44:47 +00:00
|
|
|
if ( !evt->IsAction( &PCB_ACTIONS::move ) && isInteractiveDragEnabled() )
|
2017-08-03 15:53:07 +00:00
|
|
|
invokedRouter = invokeInlineRouter( PNS::DM_ANY );
|
|
|
|
|
|
|
|
if( !invokedRouter )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2015-07-02 14:09:56 +00:00
|
|
|
// deal with locked items (override lock or abort the operation)
|
|
|
|
SELECTION_LOCK_FLAGS lockFlags = m_selectionTool->CheckLock();
|
|
|
|
|
|
|
|
if( lockFlags == SELECTION_LOCKED )
|
|
|
|
break;
|
|
|
|
|
2018-07-31 04:52:21 +00:00
|
|
|
// When editing modules, all items have the same parent
|
|
|
|
if( EditingModules() )
|
2018-06-18 21:02:16 +00:00
|
|
|
{
|
2018-07-31 04:52:21 +00:00
|
|
|
m_commit->Modify( selection.Front() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Save items, so changes can be undone
|
|
|
|
for( auto item : selection )
|
|
|
|
{
|
|
|
|
// Don't double move footprint pads, fields, etc.
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
2018-06-18 21:02:16 +00:00
|
|
|
|
2018-07-31 04:52:21 +00:00
|
|
|
m_commit->Modify( item );
|
|
|
|
}
|
2018-06-18 21:02:16 +00:00
|
|
|
}
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2018-09-23 13:02:01 +00:00
|
|
|
editFrame->UndoRedoBlock( true );
|
2015-07-15 15:32:30 +00:00
|
|
|
m_cursor = controls->GetCursorPosition();
|
2017-09-22 15:17:38 +00:00
|
|
|
|
|
|
|
if ( selection.HasReferencePoint() )
|
|
|
|
{
|
|
|
|
// start moving with the reference point attached to the cursor
|
|
|
|
grid.SetAuxAxes( false );
|
|
|
|
|
|
|
|
auto delta = m_cursor - selection.GetReferencePoint();
|
|
|
|
|
|
|
|
// Drag items to the current cursor position
|
|
|
|
for( auto item : selection )
|
2018-06-18 21:02:16 +00:00
|
|
|
{
|
|
|
|
// Don't double move footprint pads, fields, etc.
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Move( delta );
|
2018-06-18 21:02:16 +00:00
|
|
|
}
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
selection.SetReferencePoint( m_cursor );
|
2017-09-22 15:17:38 +00:00
|
|
|
}
|
|
|
|
else if( selection.Size() == 1 )
|
2015-07-02 14:09:56 +00:00
|
|
|
{
|
|
|
|
// Set the current cursor position to the first dragged item origin, so the
|
|
|
|
// movement vector could be computed later
|
2017-11-20 16:14:41 +00:00
|
|
|
updateModificationPoint( selection );
|
2016-12-20 16:51:55 +00:00
|
|
|
m_cursor = grid.BestDragOrigin( originalCursorPos, curr_item );
|
2015-07-02 14:09:56 +00:00
|
|
|
grid.SetAuxAxes( true, m_cursor );
|
|
|
|
}
|
2015-07-28 08:28:59 +00:00
|
|
|
else
|
|
|
|
{
|
2017-11-20 16:14:41 +00:00
|
|
|
updateModificationPoint( selection );
|
2015-07-28 08:28:59 +00:00
|
|
|
m_cursor = grid.Align( m_cursor );
|
|
|
|
}
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2017-09-22 08:59:42 +00:00
|
|
|
controls->SetCursorPosition( m_cursor, false );
|
2015-07-15 15:32:30 +00:00
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
prevPos = m_cursor;
|
2015-07-02 14:09:56 +00:00
|
|
|
controls->SetAutoPan( true );
|
|
|
|
m_dragging = true;
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, false );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-01-30 13:05:26 +00:00
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
2018-10-04 05:45:10 +00:00
|
|
|
restore_state = true; // Canceling the tool means that items have to be restored
|
2017-01-30 13:05:26 +00:00
|
|
|
break; // Finish
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
|
|
|
unselect = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:50 +00:00
|
|
|
// Dispatch TOOL_ACTIONs
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
if( evt->IsAction( &PCB_ACTIONS::remove ) )
|
2015-07-07 16:36:50 +00:00
|
|
|
{
|
2017-01-18 08:04:11 +00:00
|
|
|
// exit the loop, as there is no further processing for removed items
|
|
|
|
break;
|
2015-07-07 16:36:50 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::duplicate ) )
|
2015-07-07 16:36:50 +00:00
|
|
|
{
|
|
|
|
// On duplicate, stop moving this item
|
|
|
|
// The duplicate tool should then select the new item and start
|
|
|
|
// a new move procedure
|
|
|
|
break;
|
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
|
2015-07-07 16:36:50 +00:00
|
|
|
{
|
|
|
|
// Can't do this, because the selection will then contain
|
|
|
|
// stale pointers and it will all go horribly wrong...
|
|
|
|
//editFrame->RestoreCopyFromUndoList( dummy );
|
|
|
|
//
|
|
|
|
// So, instead, reset the position manually
|
2016-11-04 21:29:47 +00:00
|
|
|
for( auto 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 );
|
2017-09-22 15:17:38 +00:00
|
|
|
auto delta = VECTOR2I( i->GetPosition() ) - totalMovement;
|
|
|
|
i->SetPosition( wxPoint( delta.x, delta.y ) );
|
2015-07-07 16:36:50 +00:00
|
|
|
|
|
|
|
// And what about flipping and rotation?
|
|
|
|
// for now, they won't be undone, but maybe that is how
|
|
|
|
// it should be, so you can flip and move exact in the
|
|
|
|
// same action?
|
|
|
|
}
|
|
|
|
|
|
|
|
// This causes a double event, so we will get the dialogue
|
|
|
|
// correctly, somehow - why does Rotate not?
|
|
|
|
//MoveExact( aEvent );
|
|
|
|
break; // exit the loop - we move exactly, so we have finished moving
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-11-28 14:07:49 +00:00
|
|
|
break; // Finish
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
2016-01-11 22:12:11 +00:00
|
|
|
} while( ( evt = Wait() ) ); //Should be assignment not equality test
|
2013-12-09 10:01:05 +00:00
|
|
|
|
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
|
|
|
|
2018-10-04 05:45:10 +00:00
|
|
|
if( unselect || restore_state )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2018-10-04 05:45:10 +00:00
|
|
|
if( restore_state )
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Revert();
|
|
|
|
else
|
|
|
|
m_commit->Push( _( "Drag" ) );
|
2014-01-07 16:23:17 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
bool EDIT_TOOL::changeTrackWidthOnClick( const SELECTION& selection )
|
|
|
|
{
|
|
|
|
if ( selection.Size() == 1 && frame()->Settings().m_editActionChangesTrackWidth )
|
|
|
|
{
|
|
|
|
auto item = static_cast<BOARD_ITEM *>( selection[0] );
|
|
|
|
|
|
|
|
m_commit->Modify( item );
|
|
|
|
|
|
|
|
if( auto via = dyn_cast<VIA*>( item ) )
|
|
|
|
{
|
|
|
|
int new_width, new_drill;
|
|
|
|
|
|
|
|
if( via->GetViaType() == VIA_MICROVIA )
|
|
|
|
{
|
|
|
|
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 ) )
|
|
|
|
{
|
|
|
|
int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
|
|
|
|
track->SetWidth( new_width );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_commit->Push( _("Edit track width/via size") );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-09 10:01:05 +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>();
|
2013-12-09 10:01:05 +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
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
if ( !changeTrackWidthOnClick( 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
|
|
|
|
2016-08-17 15:24:04 +00:00
|
|
|
// Do not handle undo buffer, it is done by the properties dialogs @todo LEGACY
|
2015-07-09 11:35:51 +00:00
|
|
|
// Display properties dialog provided by the legacy canvas frame
|
2014-05-22 10:06:45 +00:00
|
|
|
editFrame->OnEditItemRequest( NULL, item );
|
|
|
|
|
2018-09-17 13:14:23 +00:00
|
|
|
// Notify other tools of the changes
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
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
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
|
|
|
}
|
|
|
|
|
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>();
|
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 )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
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 );
|
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 );
|
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Rotate( selection.GetReferencePoint(), 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
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
2014-02-28 15:53:28 +00:00
|
|
|
|
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 );
|
|
|
|
|
|
|
|
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 )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
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() );
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:47:39 +00:00
|
|
|
for( auto item : selection )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
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 )
|
2018-09-26 20:55:43 +00:00
|
|
|
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
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 );
|
|
|
|
auto modPoint = selection.GetReferencePoint();
|
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-11-04 21:29:47 +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 );
|
|
|
|
|
2017-04-20 14:38:19 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Flip( modPoint );
|
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
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
2014-02-28 15:53:28 +00:00
|
|
|
|
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() )
|
|
|
|
return 0;
|
|
|
|
|
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)
|
2018-09-30 10:36:18 +00:00
|
|
|
auto selectionCopy = 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 | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } );
|
2017-03-03 12:42:28 +00:00
|
|
|
|
2017-02-04 06:45:52 +00:00
|
|
|
// is this "alternative" remove?
|
2018-02-12 09:17:35 +00:00
|
|
|
const bool isAlt = aEvent.Parameter<intptr_t>() == (int) PCB_ACTIONS::REMOVE_FLAGS::ALT;
|
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-09-30 10:36:18 +00:00
|
|
|
if( isAlt && selectionCopy.IsHover()
|
|
|
|
&& ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
|
2017-02-04 06:45:52 +00:00
|
|
|
{
|
2018-02-13 10:20:14 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::expandSelectedConnection, true );
|
2018-09-30 10:36:18 +00:00
|
|
|
selectionCopy = m_selectionTool->GetSelection();
|
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;
|
|
|
|
|
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
|
|
|
|
2018-09-30 10:36:18 +00:00
|
|
|
for( auto 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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_commit->Remove( item );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Push( _( "Delete" ) );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
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
|
|
|
|
2018-06-12 07:36:35 +00:00
|
|
|
DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation, rotationAnchor );
|
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() );
|
|
|
|
}
|
|
|
|
|
2018-06-12 07:36:35 +00:00
|
|
|
for( auto selItem : selection )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2018-06-12 07:36:35 +00:00
|
|
|
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selItem );
|
|
|
|
|
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:
|
|
|
|
item->Rotate( editFrame->GetScreen()->m_O_Curseur, rotation );
|
|
|
|
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
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
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
|
|
|
|
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.
|
|
|
|
for( auto item : selection )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-06-12 09:16:30 +00:00
|
|
|
if( !item )
|
|
|
|
continue;
|
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 )
|
2016-12-09 11:04:32 +00:00
|
|
|
{
|
2017-06-12 09:16:30 +00:00
|
|
|
dupe_item = editFrame->GetBoard()->m_Modules->Duplicate( orig_item, increment );
|
2016-12-09 11:04:32 +00:00
|
|
|
}
|
2015-02-18 19:29:52 +00:00
|
|
|
else
|
2015-04-03 19:10:09 +00:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
// @TODO: see if we allow zone duplication here
|
|
|
|
// Duplicate zones is especially tricky (overlaping zones must be merged)
|
|
|
|
// so zones are not duplicated
|
|
|
|
if( item->Type() != PCB_ZONE_AREA_T )
|
|
|
|
#endif
|
2017-06-12 09:16:30 +00:00
|
|
|
dupe_item = editFrame->GetBoard()->Duplicate( orig_item );
|
2015-04-03 19:10:09 +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)" ),
|
2017-06-12 09:16:30 +00:00
|
|
|
(int) new_items.size() ) );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
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();
|
2016-03-18 11:15:50 +00:00
|
|
|
Main( evt );
|
|
|
|
}
|
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
|
|
|
class GAL_ARRAY_CREATOR: public ARRAY_CREATOR
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2016-04-02 12:52:29 +00:00
|
|
|
public:
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
GAL_ARRAY_CREATOR( PCB_BASE_FRAME& editFrame, bool editModules,
|
|
|
|
const SELECTION& selection ):
|
|
|
|
ARRAY_CREATOR( editFrame ),
|
|
|
|
m_editModules( editModules ),
|
|
|
|
m_selection( selection )
|
|
|
|
{}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
private:
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
int getNumberOfItemsToArray() const override
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
// only handle single items
|
|
|
|
return m_selection.Size();
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
BOARD_ITEM* getNthItemToArray( int n ) const override
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-02-28 03:04:44 +00:00
|
|
|
return static_cast<BOARD_ITEM*>( m_selection[n] );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
BOARD* getBoard() const override
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
return m_parent.GetBoard();
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
MODULE* getModule() const override
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
// Remember this is valid and used only in the module editor.
|
|
|
|
// in board editor, the parent of items is usually the board.
|
|
|
|
return m_editModules ? m_parent.GetBoard()->m_Modules.GetFirst() : NULL;
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
wxPoint getRotationCentre() const override
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
const VECTOR2I rp = m_selection.GetCenter();
|
|
|
|
return wxPoint( rp.x, rp.y );
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-04-19 12:15:11 +00:00
|
|
|
void prePushAction( BOARD_ITEM* aItem ) override
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-04-19 12:15:11 +00:00
|
|
|
// Because aItem is/can be created from a selected item, and inherits from
|
|
|
|
// it this state, reset the selected stated of aItem:
|
|
|
|
aItem->ClearSelected();
|
|
|
|
|
|
|
|
if( aItem->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
|
|
|
|
{
|
|
|
|
item->ClearSelected();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-04-02 12:52:29 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
void postPushAction( BOARD_ITEM* new_item ) override
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
}
|
2015-04-03 19:10:09 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
void finalise() override
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
bool m_editModules;
|
|
|
|
const SELECTION& m_selection;
|
|
|
|
};
|
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>();
|
2016-06-21 15:06:28 +00:00
|
|
|
GAL_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-01-31 08:03:07 +00:00
|
|
|
int EDIT_TOOL::ExchangeFootprints( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-03-09 06:25:06 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection( FootprintFilter );
|
2017-01-31 08:03:07 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
bool updateMode = aEvent.IsAction( &PCB_ACTIONS::updateFootprints );
|
2017-01-31 08:03:07 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
MODULE* mod = (selection.Empty() ? nullptr : selection.FirstOfKind<MODULE> () );
|
2017-03-03 12:42:28 +00:00
|
|
|
|
|
|
|
frame()->SetCurItem( mod );
|
2017-01-31 08:03:07 +00:00
|
|
|
|
|
|
|
// Footprint exchange could remove modules, so they have to be
|
|
|
|
// removed from the selection first
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2017-01-31 08:03:07 +00:00
|
|
|
|
|
|
|
// invoke the exchange dialog process
|
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
DIALOG_EXCHANGE_FOOTPRINTS dialog( frame(), mod, updateMode, mod != nullptr );
|
2017-01-31 08:03:07 +00:00
|
|
|
dialog.ShowQuasiModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2018-04-25 22:32:05 +00:00
|
|
|
int toolID = EditingModules() ? ID_MODEDIT_MEASUREMENT_TOOL : ID_PCB_MEASUREMENT_TOOL;
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
Activate();
|
2018-04-25 22:32:05 +00:00
|
|
|
frame()->SetToolID( toolID, wxCURSOR_PENCIL, _( "Measure distance" ) );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
2018-10-10 09:48:16 +00:00
|
|
|
EDA_UNITS_T 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 );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
while( auto evt = Wait() )
|
|
|
|
{
|
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
|
|
|
|
2018-07-23 11:37:01 +00:00
|
|
|
if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
|
2017-03-09 09:09:13 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-10-10 09:48:16 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::switchUnits )
|
|
|
|
|| 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 ) )
|
|
|
|
{
|
2018-08-01 16:58:27 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2018-01-12 03:12:46 +00:00
|
|
|
}
|
2017-03-09 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
view.Remove( &ruler );
|
|
|
|
|
2017-06-12 13:10:43 +00:00
|
|
|
frame()->SetNoToolSelected();
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void EDIT_TOOL::setTransitions()
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &EDIT_TOOL::Main, PCB_ACTIONS::editActivate.MakeEvent() );
|
2017-08-03 15:53:07 +00:00
|
|
|
Go( &EDIT_TOOL::Main, PCB_ACTIONS::move.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Drag, PCB_ACTIONS::drag45Degree.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Drag, PCB_ACTIONS::dragFreeAngle.MakeEvent() );
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCcw.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Remove, PCB_ACTIONS::remove.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Remove, PCB_ACTIONS::removeAlt.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Properties, PCB_ACTIONS::properties.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::MoveExact, PCB_ACTIONS::moveExact.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Duplicate, PCB_ACTIONS::duplicate.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Duplicate, PCB_ACTIONS::duplicateIncrement.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::CreateArray,PCB_ACTIONS::createArray.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
|
2017-09-29 09:40:10 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &EDIT_TOOL::editFootprintInFpEditor, PCB_ACTIONS::editFootprintInFpEditor.MakeEvent() );
|
2018-01-12 19:36:15 +00:00
|
|
|
Go( &EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::updateFootprints.MakeEvent() );
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::exchangeFootprints.MakeEvent() );
|
2017-03-09 09:09:13 +00:00
|
|
|
Go( &EDIT_TOOL::MeasureTool, PCB_ACTIONS::measureTool.MakeEvent() );
|
2017-09-29 09:40:10 +00:00
|
|
|
Go( &EDIT_TOOL::copyToClipboard, PCB_ACTIONS::copyToClipboard.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::cutToClipboard, PCB_ACTIONS::cutToClipboard.MakeEvent() );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
2014-01-07 16:23:17 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
bool EDIT_TOOL::updateModificationPoint( 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
|
|
|
}
|
2018-04-19 14:55:40 +00:00
|
|
|
// ...otherwise modify items with regard to the cursor position
|
2014-02-04 16:27:00 +00:00
|
|
|
else
|
|
|
|
{
|
2018-04-19 14:55:40 +00:00
|
|
|
m_cursor = getViewControls()->GetCursorPosition();
|
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
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
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
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
editFrame->SetCurItem( mod );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
if( editFrame->GetCurItem()->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
|
|
|
|
{
|
|
|
|
editFrame->GetCurItem()->SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
editFrame->OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
FOOTPRINT_EDIT_FRAME* editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_PCB_MODULE_EDITOR, true );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
editor->Load_Module_From_BOARD( (MODULE*) editFrame->GetCurItem() );
|
2015-02-18 00:10:20 +00:00
|
|
|
editFrame->SetCurItem( NULL ); // the current module could be deleted by
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP )
|
|
|
|
{
|
2018-08-22 18:05:40 +00:00
|
|
|
STATUS_TEXT_POPUP statusPopup( frame() );
|
2017-09-22 15:17:38 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
2018-08-22 18:05:40 +00:00
|
|
|
bool picking = true;
|
|
|
|
bool retVal = true;
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
statusPopup.SetText( _( "Select reference point for the copy..." ) );
|
2017-09-22 15:17:38 +00:00
|
|
|
picker->Activate();
|
2018-08-22 18:05:40 +00:00
|
|
|
picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool
|
|
|
|
{
|
|
|
|
aP = aPoint;
|
|
|
|
statusPopup.SetText( _( "Selection copied." ) );
|
|
|
|
statusPopup.Expire( 800 );
|
|
|
|
picking = false;
|
|
|
|
return false; // we don't need any more points
|
|
|
|
} );
|
|
|
|
picker->SetCancelHandler( [&]()
|
|
|
|
{
|
|
|
|
statusPopup.SetText( _( "Copy cancelled." ) );
|
|
|
|
statusPopup.Expire( 800 );
|
|
|
|
picking = false;
|
|
|
|
retVal = false;
|
|
|
|
} );
|
|
|
|
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
|
|
|
|
statusPopup.Popup();
|
|
|
|
|
|
|
|
while( picking )
|
|
|
|
{
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
|
2017-09-22 15:17:38 +00:00
|
|
|
Wait();
|
2018-08-22 18:05:40 +00:00
|
|
|
}
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
statusPopup.Hide();
|
|
|
|
return retVal;
|
2017-09-22 15:17:38 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 06:49:25 +00:00
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
int EDIT_TOOL::doCopyToClipboard( bool withAnchor )
|
2017-09-17 17:49:06 +00:00
|
|
|
{
|
|
|
|
CLIPBOARD_IO io;
|
2017-09-22 15:17:38 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
2018-09-25 14:23:38 +00:00
|
|
|
SELECTION& 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-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
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
if( withAnchor )
|
|
|
|
{
|
|
|
|
VECTOR2I refPoint;
|
|
|
|
bool rv = pickCopyReferencePoint( refPoint );
|
|
|
|
frame()->SetMsgPanel( board() );
|
2017-09-29 08:58:05 +00:00
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
if( !rv )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return doCopyToClipboard( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::copyToClipboardWithAnchor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return doCopyToClipboard( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 ) )
|
|
|
|
Remove( aEvent );
|
|
|
|
|
2017-09-17 17:49:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|