2013-12-09 10:01:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-18 21:04:35 +00:00
|
|
|
* Copyright (C) 2013-2015 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>
|
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>
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <wxPcbStruct.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>
|
|
|
|
#include <module_editor_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>
|
2014-07-09 12:22:29 +00:00
|
|
|
|
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>
|
2014-01-07 16:23:17 +00:00
|
|
|
#include <ratsnest_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"
|
2015-02-18 00:10:20 +00:00
|
|
|
#include "grid_helper.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>
|
2017-01-31 08:03:07 +00:00
|
|
|
#include <dialogs/dialog_exchange_modules.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>
|
|
|
|
|
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::copyPadToSettings( "pcbnew.InteractiveEdit.copyPadToSettings",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Copy Pad Settings to Current Settings" ),
|
|
|
|
_( "Copies the properties of selected pad to the current template pad settings." ) );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::copySettingsToPads( "pcbnew.InteractiveEdit.copySettingsToPads",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Copy Current Settings to Pads" ),
|
|
|
|
_( "Copies the current template pad settings to the selected pad(s)." ) );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::globalEditPads( "pcbnew.InteractiveEdit.globalPadEdit",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Global Pad Edition" ),
|
|
|
|
_( "Changes pad properties globally." ), push_pad_settings_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::editActivate( "pcbnew.InteractiveEdit",
|
|
|
|
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 ),
|
|
|
|
_( "Duplicate" ), _( "Duplicates the selected item(s)" ), duplicate_module_xpm );
|
|
|
|
|
|
|
|
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 ),
|
|
|
|
_( "Move Exactly..." ), _( "Moves the selected item(s) by an exact amount" ),
|
|
|
|
move_module_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::createArray( "pcbnew.InteractiveEdit.createArray",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_CREATE_ARRAY ),
|
|
|
|
_( "Create Array" ), _( "Create array" ), array_module_xpm, AF_ACTIVATE );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::rotateCw( "pcbnew.InteractiveEdit.rotateCw",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ROTATE_ITEM ),
|
|
|
|
_( "Rotate Clockwise" ), _( "Rotates selected item(s) clockwise" ),
|
|
|
|
rotate_cw_xpm, AF_NONE, (void*) 1 );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::rotateCcw( "pcbnew.InteractiveEdit.rotateCcw",
|
|
|
|
AS_GLOBAL, MD_SHIFT + 'R',
|
|
|
|
_( "Rotate Counter-clockwise" ), _( "Rotates selected item(s) counter-clockwise" ),
|
|
|
|
rotate_ccw_xpm, AF_NONE, (void*) -1 );
|
|
|
|
|
|
|
|
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 ),
|
|
|
|
_( "Remove" ), _( "Deletes selected item(s)" ), delete_xpm,
|
|
|
|
AF_NONE, (void*) REMOVE_FLAGS::NORMAL );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::removeAlt( "pcbnew.InteractiveEdit.removeAlt",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DELETE ),
|
|
|
|
_( "Remove (Alternative)" ), _( "Deletes selected item(s)" ), delete_xpm,
|
|
|
|
AF_NONE, (void*) REMOVE_FLAGS::ALT );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::exchangeFootprints( "pcbnew.InteractiveEdit.ExchangeFootprints",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Exchange Footprint(s)" ), _( "Change the footprint used for modules" ),
|
|
|
|
import_module_xpm );
|
|
|
|
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::properties( "pcbnew.InteractiveEdit.properties",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_ITEM ),
|
|
|
|
_( "Properties..." ), _( "Displays item properties dialog" ), editor_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::editModifiedSelection( "pcbnew.InteractiveEdit.ModifiedSelection",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
2017-03-09 09:09:13 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::measureTool( "pcbnew.InteractiveEdit.measureTool",
|
|
|
|
AS_GLOBAL, MD_CTRL + MD_SHIFT + 'M',
|
|
|
|
_( "Measure tool" ), _( "Interactively measure distance between points" ),
|
|
|
|
nullptr, AF_ACTIVATE );
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
|
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 ),
|
2016-12-02 17:58:12 +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 );
|
|
|
|
|
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-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
menu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
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-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
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-01-23 06:47:39 +00:00
|
|
|
// Mirror only available in modedit
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
|
2017-01-23 06:47:39 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
// Footprint actions
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::editFootprintInFpEditor,
|
2017-01-31 08:03:07 +00:00
|
|
|
singleModuleCondition );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::exchangeFootprints,
|
2017-01-31 08:03:07 +00:00
|
|
|
singleModuleCondition );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_offset.x = 0;
|
|
|
|
m_offset.y = 0;
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
bool EDIT_TOOL::invokeInlineRouter()
|
|
|
|
{
|
2015-03-03 10:50:50 +00:00
|
|
|
TRACK* track = uniqueSelected<TRACK>();
|
|
|
|
VIA* via = uniqueSelected<VIA>();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
if( track || via )
|
|
|
|
{
|
2015-07-07 16:36:50 +00:00
|
|
|
ROUTER_TOOL* theRouter = static_cast<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
|
2015-07-02 14:11:15 +00:00
|
|
|
assert( theRouter );
|
2015-07-02 14:10:07 +00:00
|
|
|
|
|
|
|
if( !theRouter->PNSSettings().InlineDragEnabled() )
|
|
|
|
return false;
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::routerInlineDrag, true );
|
2015-02-18 00:10:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
|
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)
|
2017-03-03 12:42:28 +00:00
|
|
|
auto& selection = m_selectionTool->RequestSelection( SELECTION_DELETABLE );
|
|
|
|
|
|
|
|
if( selection.Empty() )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
2014-04-01 12:35:09 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
bool unselect = selection.IsHover();
|
|
|
|
|
2014-04-01 12:35:09 +00:00
|
|
|
Activate();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
m_dragging = false; // Are selected items being dragged?
|
2013-12-09 10:01:05 +00:00
|
|
|
bool restore = false; // Should items' state be restored when finishing the tool?
|
2015-02-18 00:10:20 +00:00
|
|
|
bool lockOverride = false;
|
2013-12-09 10:01:05 +00:00
|
|
|
|
|
|
|
controls->ShowCursor( true );
|
2017-03-02 14:21:28 +00:00
|
|
|
controls->SetSnapping( true );
|
|
|
|
controls->SetAutoPan( true );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
// cumulative translation
|
|
|
|
wxPoint totalMovement( 0, 0 );
|
|
|
|
|
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;
|
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
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
if( evt->IsAction( &PCB_ACTIONS::editActivate )
|
2015-02-12 03:22:24 +00:00
|
|
|
|| evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2017-02-02 22:31:33 +00:00
|
|
|
if( selection.Empty() )
|
|
|
|
break;
|
|
|
|
|
2017-02-28 03:04:44 +00:00
|
|
|
BOARD_ITEM* curr_item = static_cast<BOARD_ITEM*>( selection.Front() );
|
2015-07-15 12:08:51 +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
|
|
|
{
|
2016-12-20 16:51:55 +00:00
|
|
|
m_cursor = grid.BestSnapAnchor( evt->Position(), curr_item );
|
2015-07-15 15:32:30 +00:00
|
|
|
controls->ForceCursorPosition( true, m_cursor );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2016-12-20 16:51:55 +00:00
|
|
|
wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) - curr_item->GetPosition();
|
2015-02-12 03:22:24 +00:00
|
|
|
totalMovement += movement;
|
|
|
|
|
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-02-28 03:04:44 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Move( movement + m_offset );
|
2014-01-07 16:23:17 +00:00
|
|
|
|
|
|
|
updateRatsnest( true );
|
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
|
|
|
{
|
2015-07-07 16:36:50 +00:00
|
|
|
if( !invokeInlineRouter() )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
selection = m_selectionTool->RequestSelection( SELECTION_DEFAULT );
|
2015-07-02 14:09:56 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// deal with locked items (override lock or abort the operation)
|
|
|
|
SELECTION_LOCK_FLAGS lockFlags = m_selectionTool->CheckLock();
|
|
|
|
|
|
|
|
if( lockFlags == SELECTION_LOCKED )
|
|
|
|
break;
|
|
|
|
else if( lockFlags == SELECTION_LOCK_OVERRIDE )
|
|
|
|
lockOverride = true;
|
|
|
|
|
|
|
|
// Save items, so changes can be undone
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : selection )
|
2016-11-04 21:29:47 +00:00
|
|
|
m_commit->Modify( item );
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2015-07-15 15:32:30 +00:00
|
|
|
m_cursor = controls->GetCursorPosition();
|
2015-07-02 14:09:56 +00:00
|
|
|
|
|
|
|
if( selection.Size() == 1 )
|
|
|
|
{
|
|
|
|
// Set the current cursor position to the first dragged item origin, so the
|
|
|
|
// movement vector could be computed later
|
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
|
|
|
|
{
|
|
|
|
m_cursor = grid.Align( m_cursor );
|
|
|
|
}
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2015-07-15 15:32:30 +00:00
|
|
|
controls->ForceCursorPosition( true, m_cursor );
|
|
|
|
controls->WarpCursor( m_cursor, true );
|
|
|
|
|
2016-12-20 16:51:55 +00:00
|
|
|
VECTOR2I o = VECTOR2I( curr_item->GetPosition() );
|
2015-07-07 16:36:50 +00:00
|
|
|
m_offset.x = o.x - m_cursor.x;
|
|
|
|
m_offset.y = o.y - m_cursor.y;
|
|
|
|
|
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-01-18 21:04:35 +00:00
|
|
|
getView()->Update( &selection );
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::editModifiedSelection, true );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-01-30 13:05:26 +00:00
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
restore = true; // Cancelling the tool means that items have to be restored
|
|
|
|
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 )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
wxPoint modPoint = getModificationPoint( selection );
|
|
|
|
|
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 );
|
|
|
|
i->SetPosition( i->GetPosition() - totalMovement );
|
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
|
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
if( m_dragging )
|
|
|
|
{
|
|
|
|
// Update dragging offset (distance between cursor and the first dragged item)
|
2017-02-28 03:04:44 +00:00
|
|
|
m_offset = static_cast<BOARD_ITEM*>( selection.Front() )->GetPosition() - modPoint;
|
2017-01-18 21:04:35 +00:00
|
|
|
getView()->Update( &selection );
|
2016-06-21 15:06:28 +00:00
|
|
|
updateRatsnest( true );
|
|
|
|
}
|
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
|
|
|
{
|
2015-07-07 16:36:50 +00:00
|
|
|
if( !lockOverride )
|
2015-02-18 00:10:20 +00:00
|
|
|
break; // Finish
|
|
|
|
|
|
|
|
lockOverride = false;
|
|
|
|
}
|
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;
|
2014-07-09 14:50:31 +00:00
|
|
|
m_offset.x = 0;
|
|
|
|
m_offset.y = 0;
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
if( unselect || restore )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
if( restore )
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection ( SELECTION_EDITABLE | SELECTION_DELETABLE );
|
2015-07-09 11:35:51 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.Empty() )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
dlg.Apply( *m_commit );
|
|
|
|
m_commit->Push( _( "Edit track/via properties" ) );
|
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
|
|
|
|
2014-05-22 13:01:58 +00:00
|
|
|
// Some of properties dialogs alter pointers, so we should deselect them
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
// Store flags, so they can be restored later
|
2014-05-22 13:01:58 +00:00
|
|
|
STATUS_FLAGS flags = item->GetFlags();
|
|
|
|
item->ClearFlags();
|
|
|
|
|
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 );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::editModifiedSelection, true );
|
2014-05-22 13:01:58 +00:00
|
|
|
item->SetFlags( flags );
|
2013-12-09 10:01:05 +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-07-09 11:35:51 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection();
|
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
// Shall the selection be cleared at the end?
|
2014-02-04 16:27:00 +00:00
|
|
|
wxPoint rotatePoint = getModificationPoint( 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
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : selection )
|
2013-12-18 13:33:34 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Modify( item );
|
2017-02-28 03:04:44 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Rotate( rotatePoint, 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" ) );
|
2017-02-10 09:04:38 +00:00
|
|
|
else
|
|
|
|
updateRatsnest( true );
|
2014-01-29 09:17:14 +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 );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
// TODO selectionModified
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::editModifiedSelection, true );
|
2017-01-18 08:04:11 +00:00
|
|
|
editFrame->Refresh();
|
2014-02-28 15:53:28 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection();
|
|
|
|
|
|
|
|
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
|
|
|
return 0;
|
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;
|
|
|
|
|
|
|
|
wxPoint mirrorPoint = getModificationPoint( selection );
|
|
|
|
|
|
|
|
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:
|
|
|
|
m_commit->Modify( item );
|
|
|
|
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-02-10 09:04:38 +00:00
|
|
|
else
|
|
|
|
updateRatsnest( true );
|
2017-01-23 06:47:39 +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 );
|
2017-01-23 06:47:39 +00:00
|
|
|
|
|
|
|
// TODO selectionModified
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::editModifiedSelection, true );
|
2017-01-23 06:47:39 +00:00
|
|
|
editFrame->Refresh();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
|
|
|
return 0;
|
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;
|
|
|
|
|
|
|
|
wxPoint flipPoint = getModificationPoint( selection );
|
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
for( auto item : selection )
|
2013-12-18 13:33:34 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Modify( item );
|
2017-02-28 03:04:44 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Flip( flipPoint );
|
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" ) );
|
2017-02-10 09:04:38 +00:00
|
|
|
else
|
|
|
|
updateRatsnest( true );
|
2014-01-29 09:17:14 +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 );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::editModifiedSelection, true );
|
2017-01-18 08:04:11 +00:00
|
|
|
getEditFrame<PCB_BASE_EDIT_FRAME>()->Refresh();
|
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
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
// get a copy instead of reference (as we're going to clear the selectio before removing items)
|
|
|
|
auto selection = m_selectionTool->RequestSelection( SELECTION_DELETABLE | SELECTION_SANITIZE_PADS );
|
|
|
|
|
|
|
|
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( selection.Empty() )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-02-04 06:45:52 +00:00
|
|
|
// is this "alternative" remove?
|
|
|
|
const bool isAlt = aEvent.Parameter<intptr_t>() ==
|
2017-02-21 12:42:08 +00:00
|
|
|
(int) PCB_ACTIONS::REMOVE_FLAGS::ALT;
|
2017-02-04 06:45:52 +00:00
|
|
|
|
|
|
|
// in "alternative" mode, deletion is not just a simple list
|
|
|
|
// of selected items, it is:
|
|
|
|
// - whole tracks, not just segments
|
2017-03-03 12:42:28 +00:00
|
|
|
if( isAlt && selection.IsHover() )
|
2017-02-04 06:45:52 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectConnection, true );
|
2017-03-03 12:42:28 +00:00
|
|
|
selection = m_selectionTool->RequestSelection( SELECTION_DELETABLE | SELECTION_SANITIZE_PADS );
|
2017-02-04 06:45:52 +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
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
for( auto item : selection )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Remove( item );
|
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
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
|
|
|
return 0;
|
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;
|
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
wxPoint translation;
|
|
|
|
double rotation = 0;
|
|
|
|
|
|
|
|
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
|
|
|
|
|
|
|
|
DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation );
|
|
|
|
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();
|
|
|
|
wxPoint rotPoint( rp.x, rp.y );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
for( auto item : selection )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Modify( item );
|
2017-02-28 03:04:44 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Move( translation );
|
|
|
|
static_cast<BOARD_ITEM*>( item )->Rotate( rotPoint, rotation );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
if( !m_dragging )
|
2017-03-03 12:42:28 +00:00
|
|
|
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-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::editModifiedSelection, 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
|
|
|
{
|
2016-03-07 07:13:06 +00:00
|
|
|
// Note: original items are no more modified.
|
|
|
|
|
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
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection( SELECTION_DELETABLE | SELECTION_SANITIZE_PADS );
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
std::vector<BOARD_ITEM*> old_items;
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : selection )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
if( item )
|
2017-02-28 03:04:44 +00:00
|
|
|
old_items.push_back( static_cast<BOARD_ITEM*>( item ) );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < old_items.size(); ++i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = old_items[i];
|
|
|
|
|
|
|
|
// Unselect the item, so we won't pick it up again
|
|
|
|
// Do this first, so a single-item duplicate will correctly call
|
|
|
|
// SetCurItem and show the item properties
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::unselectItem, true, item );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
BOARD_ITEM* new_item = NULL;
|
|
|
|
|
2015-02-18 19:29:52 +00:00
|
|
|
if( m_editModules )
|
2016-12-09 11:04:32 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
new_item = editFrame->GetBoard()->m_Modules->Duplicate( 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
|
2016-06-21 15:06:28 +00:00
|
|
|
new_item = editFrame->GetBoard()->Duplicate( item );
|
2015-04-03 19:10:09 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
if( new_item )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Add( new_item );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
// Select the new item, so we can pick it up
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, new_item );
|
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)" ),
|
|
|
|
(int) old_items.size() ) );
|
2015-02-12 03:22:24 +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
|
2017-02-21 12:42:08 +00:00
|
|
|
TOOL_EVENT evt = PCB_ACTIONS::editActivate.MakeEvent();
|
2016-03-18 11:15:50 +00:00
|
|
|
Main( evt );
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-04-02 12:52:29 +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
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
void prePushAction( BOARD_ITEM* new_item ) override
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
m_parent.GetToolManager()->RunAction( PCB_ACTIONS::unselectItem,
|
2016-04-02 12:52:29 +00:00
|
|
|
true, new_item );
|
|
|
|
}
|
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 )
|
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-31 08:03:07 +00:00
|
|
|
int EDIT_TOOL::ExchangeFootprints( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection();
|
2017-01-31 08:03:07 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( selection.Empty() )
|
2017-01-31 08:03:07 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
MODULE* mod = selection.FirstOfKind<MODULE> ();
|
2017-01-31 08:03:07 +00:00
|
|
|
|
2017-03-03 12:42:28 +00:00
|
|
|
if( !mod )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
DIALOG_EXCHANGE_MODULE dialog( frame(), mod );
|
2017-01-31 08:03:07 +00:00
|
|
|
dialog.ShowQuasiModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The current item can be deleted by exchange module, and the
|
|
|
|
// selection is emptied, so remove current item from frame info area
|
2017-03-03 12:42:28 +00:00
|
|
|
frame()->SetCurItem( nullptr );
|
2017-01-31 08:03:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-09 09:09:13 +00:00
|
|
|
int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
auto& view = *getView();
|
|
|
|
auto& controls = *getViewControls();
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
frame()->SetToolID( EditingModules() ? ID_MODEDIT_MEASUREMENT_TOOL
|
|
|
|
: ID_PCB_MEASUREMENT_TOOL,
|
|
|
|
wxCURSOR_PENCIL, _( "Measure distance between two points" ) );
|
|
|
|
|
|
|
|
KIGFX::PREVIEW::RULER_ITEM ruler;
|
|
|
|
view.Add( &ruler );
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
|
|
|
|
bool originSet = false;
|
|
|
|
|
|
|
|
controls.ShowCursor( true );
|
|
|
|
controls.SetSnapping( true );
|
|
|
|
|
|
|
|
while( auto evt = Wait() )
|
|
|
|
{
|
|
|
|
const VECTOR2I cursorPos = controls.GetCursorPosition();
|
|
|
|
|
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// click or drag starts
|
|
|
|
else if( !originSet &&
|
|
|
|
( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
if( !evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
ruler.SetOrigin( cursorPos );
|
|
|
|
ruler.SetEnd( cursorPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
controls.CaptureCursor( true );
|
|
|
|
controls.SetAutoPan( true );
|
|
|
|
|
|
|
|
originSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( !originSet && evt->IsMotion() )
|
|
|
|
{
|
|
|
|
// make sure the origin is set before a drag starts
|
|
|
|
// otherwise you can miss a step
|
|
|
|
ruler.SetOrigin( cursorPos );
|
|
|
|
ruler.SetEnd( cursorPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
// second click or mouse up after drag ends
|
|
|
|
else if( originSet &&
|
|
|
|
( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
originSet = false;
|
|
|
|
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// move or drag when origin set updates rules
|
|
|
|
else if( originSet &&
|
|
|
|
( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
ruler.SetEnd( cursorPos );
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, true );
|
|
|
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
GetManager()->PassEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
view.Remove( &ruler );
|
|
|
|
|
|
|
|
frame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 08:46:03 +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() );
|
|
|
|
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() );
|
|
|
|
Go( &EDIT_TOOL::editFootprintInFpEditor, PCB_ACTIONS::editFootprintInFpEditor.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::exchangeFootprints.MakeEvent() );
|
2017-03-09 09:09:13 +00:00
|
|
|
Go( &EDIT_TOOL::MeasureTool, PCB_ACTIONS::measureTool.MakeEvent() );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
2014-01-07 16:23:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
void EDIT_TOOL::updateRatsnest( bool aRedraw )
|
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
2014-06-06 12:59:25 +00:00
|
|
|
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
|
2014-01-07 16:23:17 +00:00
|
|
|
|
|
|
|
ratsnest->ClearSimple();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
for( auto item : selection )
|
2014-01-07 16:23:17 +00:00
|
|
|
{
|
2017-02-28 03:04:44 +00:00
|
|
|
ratsnest->Update( static_cast<BOARD_ITEM*>( item ) );
|
2014-01-07 16:23:17 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( aRedraw )
|
2017-02-28 03:04:44 +00:00
|
|
|
ratsnest->AddSimple( static_cast<BOARD_ITEM*>( item ) );
|
2014-01-07 16:23:17 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-04 16:27:00 +00:00
|
|
|
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
wxPoint EDIT_TOOL::getModificationPoint( const SELECTION& aSelection )
|
2014-02-04 16:27:00 +00:00
|
|
|
{
|
|
|
|
if( aSelection.Size() == 1 )
|
|
|
|
{
|
2017-02-28 03:04:44 +00:00
|
|
|
return static_cast<BOARD_ITEM*>( aSelection.Front() )->GetPosition() - m_offset;
|
2014-02-04 16:27:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
// If EDIT_TOOL is not currently active then it means that the cursor position is not
|
|
|
|
// updated, so we have to fetch the latest value
|
|
|
|
if( m_toolMgr->GetCurrentToolId() != m_toolId )
|
|
|
|
m_cursor = getViewControls()->GetCursorPosition();
|
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
return wxPoint( m_cursor.x, m_cursor.y );
|
2014-02-04 16:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
const auto& selection = m_selectionTool->RequestSelection();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T* EDIT_TOOL::uniqueSelected()
|
|
|
|
{
|
|
|
|
const auto selection = m_selectionTool->GetSelection();
|
|
|
|
|
|
|
|
if( selection.Size() != 1 )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto item = selection[0];
|
|
|
|
return dyn_cast<T*>( item );
|
|
|
|
}
|