2013-12-09 10:01:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-03-03 10:55:23 +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>
|
|
|
|
#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>
|
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>
|
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>
|
2014-04-02 14:30:48 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
#include <cassert>
|
2014-01-07 16:23:17 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2014-04-02 14:30:48 +00:00
|
|
|
#include <boost/bind.hpp>
|
2013-12-09 10:01:05 +00:00
|
|
|
|
|
|
|
#include "common_actions.h"
|
|
|
|
#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_create_array.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>
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
EDIT_TOOL::EDIT_TOOL() :
|
2015-02-15 22:21:52 +00:00
|
|
|
TOOL_INTERACTIVE( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ),
|
2015-02-21 13:58:39 +00:00
|
|
|
m_dragging( false ), m_editModules( false ), m_undoInhibit( 0 ),
|
|
|
|
m_updateFlag( KIGFX::VIEW_ITEM::NONE )
|
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;
|
2015-02-15 22:21:52 +00:00
|
|
|
m_updateFlag = KIGFX::VIEW_ITEM::NONE;
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-09 11:35:51 +00:00
|
|
|
// Vector storing track & via types, used for specifying 'Properties' menu entry condition
|
|
|
|
m_tracksViasType.push_back( PCB_TRACE_T );
|
|
|
|
m_tracksViasType.push_back( PCB_VIA_T );
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Add context menu entries that are displayed when selection tool is active
|
2015-04-30 08:46:08 +00:00
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
|
2015-07-09 11:35:51 +00:00
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 )
|
|
|
|
|| SELECTION_CONDITIONS::OnlyTypes( m_tracksViasType ) );
|
2015-04-30 08:46:08 +00:00
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
// Footprint actions
|
2015-04-30 08:46:08 +00:00
|
|
|
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editFootprintInFpEditor,
|
|
|
|
SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) &&
|
|
|
|
SELECTION_CONDITIONS::Count( 1 ) );
|
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
|
|
|
|
2015-07-24 07:42:45 +00:00
|
|
|
if( isUndoInhibited() )
|
|
|
|
return false;
|
|
|
|
|
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;
|
|
|
|
|
2015-07-02 14:09:56 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::routerInlineDrag, true, track ? track : via );
|
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-07-09 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
// Shall the selection be cleared at the end?
|
|
|
|
bool unselect = selection.Empty();
|
|
|
|
|
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)
|
2015-02-18 00:10:20 +00:00
|
|
|
if( !hoverSelection( selection ) )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
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
|
|
|
|
2014-02-04 15:03:56 +00:00
|
|
|
// By default, modified items need to update their geometry
|
|
|
|
m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY;
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
controls->ShowCursor( true );
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if( evt->IsCancel() )
|
|
|
|
{
|
|
|
|
restore = true; // Cancelling the tool means that items have to be restored
|
|
|
|
break; // Finish
|
|
|
|
}
|
|
|
|
|
2014-04-04 10:56:50 +00:00
|
|
|
else if( evt->Action() == TA_UNDO_REDO )
|
|
|
|
{
|
|
|
|
unselect = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::editActivate )
|
|
|
|
|| evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2015-07-15 12:08:51 +00:00
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( 0 );
|
|
|
|
|
2015-07-15 12:08:52 +00:00
|
|
|
if( m_dragging && evt->Category() == TC_MOUSE )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2015-07-15 12:08:51 +00:00
|
|
|
m_cursor = grid.BestSnapAnchor( evt->Position(), item );
|
2015-07-15 15:32:30 +00:00
|
|
|
controls->ForceCursorPosition( true, m_cursor );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-07-15 12:08:51 +00:00
|
|
|
wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) - 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
|
2013-12-18 13:33:34 +00:00
|
|
|
for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
|
2014-06-23 14:12:59 +00:00
|
|
|
selection.Item<BOARD_ITEM>( i )->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
|
|
|
{
|
2015-07-02 14:09:56 +00:00
|
|
|
m_selectionTool->SanitizeSelection();
|
|
|
|
|
|
|
|
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
|
|
|
|
if( !isUndoInhibited() )
|
|
|
|
{
|
|
|
|
editFrame->OnModify();
|
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
|
|
|
}
|
|
|
|
|
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
|
2015-07-15 12:08:51 +00:00
|
|
|
m_cursor = grid.BestDragOrigin( originalCursorPos, 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 );
|
|
|
|
|
2015-07-15 12:08:51 +00:00
|
|
|
VECTOR2I o = VECTOR2I( 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;
|
|
|
|
incUndoInhibit();
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-02 14:30:48 +00:00
|
|
|
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:50 +00:00
|
|
|
// Dispatch TOOL_ACTIONs
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
|
|
|
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
|
|
|
|
{
|
|
|
|
Rotate( aEvent );
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
|
|
|
|
{
|
|
|
|
Flip( aEvent );
|
|
|
|
|
|
|
|
// Flip causes change of layers
|
|
|
|
enableUpdateFlag( KIGFX::VIEW_ITEM::LAYERS );
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::remove ) )
|
|
|
|
{
|
|
|
|
Remove( aEvent );
|
|
|
|
|
|
|
|
break; // exit the loop, as there is no further processing for removed items
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::duplicate ) )
|
|
|
|
{
|
|
|
|
// On duplicate, stop moving this item
|
|
|
|
// The duplicate tool should then select the new item and start
|
|
|
|
// a new move procedure
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::moveExact ) )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
|
|
|
|
item->SetPosition( item->GetPosition() - totalMovement );
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2015-07-07 16:36:50 +00:00
|
|
|
if( !lockOverride )
|
2015-02-18 00:10:20 +00:00
|
|
|
break; // Finish
|
|
|
|
|
|
|
|
lockOverride = false;
|
|
|
|
}
|
2015-07-07 16:36:50 +00:00
|
|
|
} while( evt = Wait() );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
if( m_dragging )
|
2015-02-19 13:53:31 +00:00
|
|
|
decUndoInhibit();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
if( restore )
|
|
|
|
{
|
2014-02-04 15:03:56 +00:00
|
|
|
// Modifications have to be rollbacked, so restore the previous state of items
|
2013-12-19 10:15:27 +00:00
|
|
|
wxCommandEvent dummy;
|
2014-07-09 11:50:27 +00:00
|
|
|
editFrame->RestoreCopyFromUndoList( dummy );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Changes are applied, so update the items
|
2013-12-18 13:33:34 +00:00
|
|
|
selection.group->ItemsViewUpdate( m_updateFlag );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
if( unselect )
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2014-06-06 12:59:25 +00:00
|
|
|
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
|
2014-01-07 16:23:17 +00:00
|
|
|
ratsnest->ClearSimple();
|
|
|
|
ratsnest->Recalculate();
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
controls->ShowCursor( false );
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
|
|
|
|
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 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
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
|
|
|
|
2015-07-09 11:35:51 +00:00
|
|
|
// Shall the selection be cleared at the end?
|
|
|
|
bool unselect = selection.Empty();
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
if( !hoverSelection( selection, false ) )
|
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:
|
|
|
|
if( ( SELECTION_CONDITIONS::OnlyTypes( m_tracksViasType ) )( selection ) )
|
|
|
|
{
|
|
|
|
DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() )
|
|
|
|
{
|
|
|
|
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
|
|
|
|
|
|
|
|
editFrame->OnModify();
|
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
|
|
|
dlg.Apply();
|
|
|
|
|
|
|
|
selection.ForAll<KIGFX::VIEW_ITEM>( boost::bind( &KIGFX::VIEW_ITEM::ViewUpdate, _1,
|
|
|
|
KIGFX::VIEW_ITEM::ALL ) );
|
|
|
|
selection.ForAll<BOARD_ITEM>( boost::bind( &RN_DATA::Update, ratsnest, _1 ) );
|
|
|
|
ratsnest->Recalculate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
2014-06-04 16:01:01 +00:00
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( 0 );
|
2014-02-05 08:05:27 +00:00
|
|
|
|
2015-07-24 07:42:46 +00:00
|
|
|
// Store the head of the undo list to compare if anything has changed
|
2014-05-22 10:06:45 +00:00
|
|
|
std::vector<PICKED_ITEMS_LIST*>& undoList = editFrame->GetScreen()->m_UndoList.m_CommandsList;
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-05-22 13:01:58 +00:00
|
|
|
// Some of properties dialogs alter pointers, so we should deselect them
|
2014-07-09 14:44:23 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-05-22 13:01:58 +00:00
|
|
|
STATUS_FLAGS flags = item->GetFlags();
|
|
|
|
item->ClearFlags();
|
|
|
|
|
2015-07-31 15:40:19 +00:00
|
|
|
// It is necessary to determine if anything has changed, so store the current undo save point
|
|
|
|
PICKED_ITEMS_LIST* undoSavePoint = undoList.empty() ? NULL : undoList.back();
|
2014-02-04 16:27:00 +00:00
|
|
|
|
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 );
|
|
|
|
|
2015-07-31 15:40:19 +00:00
|
|
|
if( !undoList.empty() && undoList.back() != undoSavePoint ) // Undo buffer has changed
|
2014-05-22 10:06:45 +00:00
|
|
|
{
|
2015-07-31 15:40:19 +00:00
|
|
|
// Process changes stored after undoSavePoint
|
|
|
|
processUndoBuffer( undoSavePoint );
|
2014-05-22 10:06:45 +00:00
|
|
|
|
2015-07-31 15:40:19 +00:00
|
|
|
// Update the modified item
|
|
|
|
item->ViewUpdate();
|
2015-06-25 15:36:57 +00:00
|
|
|
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
|
|
|
|
ratsnest->Recalculate();
|
|
|
|
|
2015-07-31 15:40:19 +00:00
|
|
|
// TODO OBSERVER! I miss you so much..
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
|
2014-05-22 10:06:45 +00:00
|
|
|
}
|
2014-05-22 13:01:58 +00:00
|
|
|
|
|
|
|
item->SetFlags( flags );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 11:35:51 +00:00
|
|
|
if( unselect )
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, 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 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
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
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
// Shall the selection be cleared at the end?
|
|
|
|
bool unselect = selection.Empty();
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
if( !hoverSelection( selection ) )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
wxPoint rotatePoint = getModificationPoint( selection );
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
// If it is being dragged, then it is already saved with UR_CHANGED flag
|
2015-02-19 13:53:31 +00:00
|
|
|
if( !isUndoInhibited() )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2013-12-18 13:33:34 +00:00
|
|
|
editFrame->OnModify();
|
2014-02-04 16:27:00 +00:00
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_ROTATED, rotatePoint );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
|
|
|
|
{
|
2014-06-04 16:01:01 +00:00
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
item->Rotate( rotatePoint, editFrame->GetRotationAngle() );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
if( !m_dragging )
|
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 14:33:13 +00:00
|
|
|
updateRatsnest( m_dragging );
|
|
|
|
|
2014-06-23 14:12:59 +00:00
|
|
|
// Update dragging offset (distance between cursor and the first dragged item)
|
|
|
|
m_offset = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( 0 ) )->GetPosition() -
|
|
|
|
rotatePoint;
|
|
|
|
|
2014-01-29 09:17:14 +00:00
|
|
|
if( m_dragging )
|
|
|
|
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
else
|
2014-06-06 12:59:25 +00:00
|
|
|
getModel<BOARD>()->GetRatsnest()->Recalculate();
|
2014-01-29 09:17:14 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
if( unselect )
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, 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::Flip( const TOOL_EVENT& aEvent )
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2014-07-09 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
// Shall the selection be cleared at the end?
|
|
|
|
bool unselect = selection.Empty();
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
if( !hoverSelection( selection ) )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
wxPoint flipPoint = getModificationPoint( selection );
|
|
|
|
|
2015-02-19 13:53:31 +00:00
|
|
|
if( !isUndoInhibited() ) // If it is being dragged, then it is already saved with UR_CHANGED flag
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2013-12-18 13:33:34 +00:00
|
|
|
editFrame->OnModify();
|
2014-02-04 16:27:00 +00:00
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_FLIPPED, flipPoint );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
|
|
|
|
{
|
2014-06-04 16:01:01 +00:00
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
item->Flip( flipPoint );
|
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
if( !m_dragging )
|
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 14:33:13 +00:00
|
|
|
updateRatsnest( m_dragging );
|
|
|
|
|
2014-06-23 14:12:59 +00:00
|
|
|
// Update dragging offset (distance between cursor and the first dragged item)
|
|
|
|
m_offset = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( 0 ) )->GetPosition() -
|
|
|
|
flipPoint;
|
|
|
|
|
2014-01-29 09:17:14 +00:00
|
|
|
if( m_dragging )
|
|
|
|
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
else
|
2014-06-06 12:59:25 +00:00
|
|
|
getModel<BOARD>()->GetRatsnest()->Recalculate();
|
2014-01-29 09:17:14 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
if( unselect )
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, 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
|
|
|
{
|
2014-07-09 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
if( !hoverSelection( selection ) )
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Get a copy of the selected items set
|
2014-02-04 16:27:00 +00:00
|
|
|
PICKED_ITEMS_LIST selectedItems = selection.items;
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
|
2013-12-09 10:01:05 +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
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
// Save them
|
|
|
|
for( unsigned int i = 0; i < selectedItems.GetCount(); ++i )
|
|
|
|
selectedItems.SetPickedItemStatus( UR_DELETED, i );
|
2014-04-01 11:30:31 +00:00
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
editFrame->OnModify();
|
|
|
|
editFrame->SaveCopyInUndoList( selectedItems, UR_DELETED );
|
|
|
|
|
|
|
|
// And now remove
|
|
|
|
for( unsigned int i = 0; i < selectedItems.GetCount(); ++i )
|
2014-06-04 16:01:01 +00:00
|
|
|
remove( static_cast<BOARD_ITEM*>( selectedItems.GetPickedItem( i ) ) );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2014-06-06 12:59:25 +00:00
|
|
|
getModel<BOARD>()->GetRatsnest()->Recalculate();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDIT_TOOL::remove( BOARD_ITEM* aItem )
|
|
|
|
{
|
2014-06-06 12:59:25 +00:00
|
|
|
BOARD* board = getModel<BOARD>();
|
2013-12-09 10:01:05 +00:00
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_T:
|
|
|
|
{
|
|
|
|
MODULE* module = static_cast<MODULE*>( aItem );
|
2013-12-18 13:33:34 +00:00
|
|
|
module->ClearFlags();
|
2014-04-02 14:30:48 +00:00
|
|
|
module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, getView(), _1 ) );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
2013-12-09 10:07:30 +00:00
|
|
|
// Module itself is deleted after the switch scope is finished
|
2013-12-09 10:01:05 +00:00
|
|
|
// list of pads is rebuild by BOARD::BuildListOfNets()
|
|
|
|
|
|
|
|
// Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore
|
|
|
|
board->m_Status_Pcb = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
// Default removal procedure
|
2013-12-09 10:01:05 +00:00
|
|
|
case PCB_MODULE_TEXT_T:
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2015-02-18 00:10:20 +00:00
|
|
|
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( aItem );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
switch( text->GetType() )
|
|
|
|
{
|
2014-07-09 12:01:06 +00:00
|
|
|
case TEXTE_MODULE::TEXT_is_REFERENCE:
|
2015-02-18 00:10:20 +00:00
|
|
|
DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete component reference." ) );
|
2014-07-09 12:01:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case TEXTE_MODULE::TEXT_is_VALUE:
|
2015-02-18 00:10:20 +00:00
|
|
|
DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete component value." ) );
|
2014-07-09 12:01:06 +00:00
|
|
|
return;
|
2014-07-09 12:22:29 +00:00
|
|
|
|
2014-09-10 15:18:42 +00:00
|
|
|
case TEXTE_MODULE::TEXT_is_DIVERS: // suppress warnings
|
2014-07-09 12:22:29 +00:00
|
|
|
break;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_editModules )
|
|
|
|
{
|
|
|
|
MODULE* module = static_cast<MODULE*>( aItem->GetParent() );
|
|
|
|
module->SetLastEditTime();
|
|
|
|
board->m_Status_Pcb = 0; // it is done in the legacy view
|
|
|
|
aItem->DeleteStructure();
|
|
|
|
}
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
MODULE* module = static_cast<MODULE*>( aItem->GetParent() );
|
|
|
|
module->SetLastEditTime();
|
|
|
|
|
|
|
|
board->m_Status_Pcb = 0; // it is done in the legacy view
|
|
|
|
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_editModules )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
|
|
|
getView()->Remove( aItem );
|
|
|
|
board->Remove( aItem );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
aItem->DeleteStructure();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
|
|
|
|
case PCB_LINE_T: // a segment not on copper layers
|
|
|
|
case PCB_TEXT_T: // a text on a layer
|
|
|
|
case PCB_TRACE_T: // a track segment (segment on a copper layer)
|
|
|
|
case PCB_VIA_T: // a via (like track segment on a copper layer)
|
|
|
|
case PCB_DIMENSION_T: // a dimension (graphic item)
|
|
|
|
case PCB_TARGET_T: // a target (graphic item)
|
|
|
|
case PCB_MARKER_T: // a marker used to show something
|
|
|
|
case PCB_ZONE_T: // SEG_ZONE items are now deprecated
|
2013-12-18 16:16:15 +00:00
|
|
|
case PCB_ZONE_AREA_T:
|
2013-12-09 10:01:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: // other types do not need to (or should not) be handled
|
|
|
|
assert( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getView()->Remove( aItem );
|
2013-12-18 13:33:34 +00:00
|
|
|
board->Remove( aItem );
|
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
|
|
|
{
|
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
|
|
|
|
// Shall the selection be cleared at the end?
|
|
|
|
bool unselect = selection.Empty();
|
|
|
|
|
2015-03-03 10:50:50 +00:00
|
|
|
if( !hoverSelection( selection ) )
|
2015-02-12 03:22:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
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-19 13:53:31 +00:00
|
|
|
if( !isUndoInhibited() )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
editFrame->OnModify();
|
|
|
|
// Record an action of move and rotate
|
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
|
|
|
|
|
|
|
|
item->Move( translation );
|
|
|
|
item->Rotate( rotPoint, rotation );
|
|
|
|
|
|
|
|
if( !m_dragging )
|
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRatsnest( m_dragging );
|
|
|
|
|
|
|
|
if( m_dragging )
|
|
|
|
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
else
|
|
|
|
getModel<BOARD>()->GetRatsnest()->Recalculate();
|
|
|
|
|
|
|
|
if( unselect )
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
bool increment = aEvent.IsAction( &COMMON_ACTIONS::duplicateIncrement );
|
|
|
|
|
|
|
|
// first, check if we have a selection, or try to get one
|
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selTool->GetSelection();
|
|
|
|
|
|
|
|
// Be sure that there is at least one item that we can modify
|
2015-03-03 10:50:50 +00:00
|
|
|
if( !hoverSelection( selection ) )
|
2015-02-12 03:22:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// we have a selection to work on now, so start the tool process
|
|
|
|
|
|
|
|
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
|
|
|
|
editFrame->OnModify();
|
|
|
|
|
|
|
|
// prevent other tools making undo points while the duplicate is going on
|
|
|
|
// so that if you cancel, you don't get a duplicate object hiding over
|
|
|
|
// the original
|
2015-02-19 13:53:31 +00:00
|
|
|
incUndoInhibit();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-03-16 09:25:40 +00:00
|
|
|
if( m_editModules )
|
|
|
|
editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_MODEDIT );
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
std::vector<BOARD_ITEM*> old_items;
|
|
|
|
|
|
|
|
for( int i = 0; i < selection.Size(); ++i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
old_items.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::unselectItem, true, item );
|
|
|
|
|
|
|
|
BOARD_ITEM* new_item = NULL;
|
|
|
|
|
2015-02-18 19:29:52 +00:00
|
|
|
if( m_editModules )
|
|
|
|
new_item = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment );
|
|
|
|
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
|
2015-07-24 07:42:45 +00:00
|
|
|
new_item = editFrame->GetBoard()->DuplicateAndAddItem( item, increment );
|
2015-04-03 19:10:09 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
if( new_item )
|
|
|
|
{
|
|
|
|
if( new_item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
static_cast<MODULE*>( new_item )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add,
|
|
|
|
getView(), _1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
editFrame->GetGalCanvas()->GetView()->Add( new_item );
|
|
|
|
|
|
|
|
// Select the new item, so we can pick it up
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, new_item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// record the new items as added
|
2015-03-16 09:25:40 +00:00
|
|
|
if( !m_editModules )
|
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_NEW );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
|
|
|
|
(int) old_items.size() ) );
|
|
|
|
|
|
|
|
// pick up the selected item(s) and start moving
|
|
|
|
// this works well for "dropping" copies around
|
|
|
|
TOOL_EVENT evt = COMMON_ACTIONS::editActivate.MakeEvent();
|
|
|
|
Main( evt );
|
|
|
|
|
|
|
|
// and re-enable undos
|
2015-02-19 13:53:31 +00:00
|
|
|
decUndoInhibit();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 19:27:00 +00:00
|
|
|
int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
// first, check if we have a selection, or try to get one
|
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selTool->GetSelection();
|
|
|
|
|
|
|
|
// Be sure that there is at least one item that we can modify
|
2015-03-03 10:50:50 +00:00
|
|
|
if( !hoverSelection( selection ) )
|
2015-02-12 03:22:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
bool originalItemsModified = false;
|
|
|
|
|
|
|
|
// we have a selection to work on now, so start the tool process
|
|
|
|
|
|
|
|
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
|
|
|
|
editFrame->OnModify();
|
|
|
|
|
2015-02-18 19:29:52 +00:00
|
|
|
if( m_editModules )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
// Module editors do their undo point upfront for the whole module
|
|
|
|
editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_MODEDIT );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We may also change the original item
|
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_CREATE_ARRAY::ARRAY_OPTIONS* array_opts = NULL;
|
|
|
|
|
2015-02-20 10:40:36 +00:00
|
|
|
VECTOR2I rp = selection.GetCenter();
|
|
|
|
const wxPoint rotPoint( rp.x, rp.y );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
DIALOG_CREATE_ARRAY dialog( editFrame, rotPoint, &array_opts );
|
|
|
|
int ret = dialog.ShowModal();
|
|
|
|
|
2015-04-22 16:39:49 +00:00
|
|
|
if( ret == wxID_OK && array_opts != NULL )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST newItemList;
|
|
|
|
|
|
|
|
for( int i = 0; i < selection.Size(); ++i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString cachedString;
|
|
|
|
|
|
|
|
if( item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
cachedString = static_cast<MODULE*>( item )->GetReferencePrefix();
|
|
|
|
}
|
|
|
|
else if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item ) )
|
|
|
|
{
|
|
|
|
// Copy the text (not just take a reference
|
|
|
|
cachedString = text->GetText();
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterate across the array, laying out the item at the
|
|
|
|
// correct position
|
|
|
|
const unsigned nPoints = array_opts->GetArraySize();
|
|
|
|
|
|
|
|
for( unsigned ptN = 0; ptN < nPoints; ++ptN )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* newItem = NULL;
|
|
|
|
|
|
|
|
if( ptN == 0 )
|
|
|
|
newItem = item;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if renumbering, no need to increment
|
|
|
|
const bool increment = !array_opts->ShouldRenumberItems();
|
|
|
|
|
2015-04-03 19:10:09 +00:00
|
|
|
// Some items cannot be duplicated
|
|
|
|
// i.e. the ref and value fields of a footprint or zones
|
|
|
|
// therefore newItem can be null
|
|
|
|
|
2015-02-18 19:29:52 +00:00
|
|
|
if( m_editModules )
|
|
|
|
newItem = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment );
|
|
|
|
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 )
|
|
|
|
newItem = NULL;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
newItem = editFrame->GetBoard()->DuplicateAndAddItem( item, increment );
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
if( newItem )
|
|
|
|
{
|
|
|
|
array_opts->TransformItem( ptN, newItem, rotPoint );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::unselectItem, true, newItem );
|
|
|
|
|
|
|
|
newItemList.PushItem( newItem );
|
|
|
|
|
|
|
|
if( newItem->Type() == PCB_MODULE_T)
|
|
|
|
{
|
|
|
|
static_cast<MODULE*>( newItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add,
|
|
|
|
getView(), _1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
editFrame->GetGalCanvas()->GetView()->Add( newItem );
|
2015-02-18 19:29:52 +00:00
|
|
|
getModel<BOARD>()->GetRatsnest()->Update( newItem );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the number if needed:
|
2015-04-03 19:10:09 +00:00
|
|
|
if( newItem && array_opts->ShouldRenumberItems() )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
switch( newItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
const wxString padName = array_opts->GetItemNumber( ptN );
|
|
|
|
static_cast<D_PAD*>( newItem )->SetPadName( padName );
|
|
|
|
|
|
|
|
originalItemsModified = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PCB_MODULE_T:
|
|
|
|
{
|
|
|
|
const wxString moduleName = array_opts->GetItemNumber( ptN );
|
|
|
|
MODULE* module = static_cast<MODULE*>( newItem );
|
|
|
|
module->SetReference( cachedString + moduleName );
|
|
|
|
|
|
|
|
originalItemsModified = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
{
|
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( newItem );
|
2015-04-12 17:44:46 +00:00
|
|
|
if( text )
|
|
|
|
text->SetText( array_opts->InterpolateNumberIntoString( ptN, cachedString ) );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
originalItemsModified = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// no renumbering of other items
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 19:29:52 +00:00
|
|
|
if( !m_editModules )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
if( originalItemsModified )
|
|
|
|
{
|
|
|
|
// Update the appearance of the original items
|
|
|
|
selection.group->ItemsViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add all items as a single undo point for PCB editors
|
|
|
|
// TODO: Can this be merged into the previous undo point (where
|
|
|
|
// we saved the original items)
|
|
|
|
editFrame->SaveCopyInUndoList( newItemList, UR_NEW );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 19:29:52 +00:00
|
|
|
getModel<BOARD>()->GetRatsnest()->Recalculate();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 08:46:03 +00:00
|
|
|
void EDIT_TOOL::SetTransitions()
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
|
|
|
Go( &EDIT_TOOL::Main, COMMON_ACTIONS::editActivate.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Rotate, COMMON_ACTIONS::rotate.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Flip, COMMON_ACTIONS::flip.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Remove, COMMON_ACTIONS::remove.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Properties, COMMON_ACTIONS::properties.MakeEvent() );
|
2015-02-12 03:22:24 +00:00
|
|
|
Go( &EDIT_TOOL::MoveExact, COMMON_ACTIONS::moveExact.MakeEvent() );
|
2015-02-12 03:22:24 +00:00
|
|
|
Go( &EDIT_TOOL::Duplicate, COMMON_ACTIONS::duplicate.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::Duplicate, COMMON_ACTIONS::duplicateIncrement.MakeEvent() );
|
|
|
|
Go( &EDIT_TOOL::CreateArray,COMMON_ACTIONS::createArray.MakeEvent() );
|
2015-02-18 00:10:20 +00:00
|
|
|
Go( &EDIT_TOOL::editFootprintInFpEditor, COMMON_ACTIONS::editFootprintInFpEditor.MakeEvent() );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
2014-01-07 16:23:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
void EDIT_TOOL::updateRatsnest( bool aRedraw )
|
|
|
|
{
|
2014-07-09 13:10:32 +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
|
|
|
|
2014-01-07 16:23:17 +00:00
|
|
|
for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
|
|
|
|
{
|
2014-06-04 16:01:01 +00:00
|
|
|
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
|
2014-01-07 16:23:17 +00:00
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
ratsnest->Update( item );
|
2014-01-07 16:23:17 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( aRedraw )
|
|
|
|
ratsnest->AddSimple( 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 )
|
|
|
|
{
|
2014-06-23 14:12:59 +00:00
|
|
|
return aSelection.Item<BOARD_ITEM>( 0 )->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
|
|
|
bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize )
|
2014-02-04 16:27:00 +00:00
|
|
|
{
|
2014-04-01 12:35:09 +00:00
|
|
|
if( aSelection.Empty() ) // Try to find an item that could be modified
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2014-11-21 10:49:28 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true );
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2015-02-18 00:10:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aSanitize )
|
2015-02-18 00:10:20 +00:00
|
|
|
m_selectionTool->SanitizeSelection();
|
|
|
|
|
2015-07-15 12:08:52 +00:00
|
|
|
if( aSelection.Empty() ) // TODO is it necessary?
|
2015-02-18 00:10:20 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-04-01 12:35:09 +00:00
|
|
|
return !aSelection.Empty();
|
2014-02-04 16:27:00 +00:00
|
|
|
}
|
2014-05-22 10:06:45 +00:00
|
|
|
|
2015-07-31 15:40:19 +00:00
|
|
|
void EDIT_TOOL::processUndoBuffer( const PICKED_ITEMS_LIST* aLastChange )
|
|
|
|
{
|
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
const std::vector<PICKED_ITEMS_LIST*>& undoList = editFrame->GetScreen()->m_UndoList.m_CommandsList;
|
|
|
|
bool process = false;
|
|
|
|
|
|
|
|
BOOST_FOREACH( const PICKED_ITEMS_LIST* list, undoList )
|
|
|
|
{
|
|
|
|
if( process )
|
|
|
|
processPickedList( list );
|
|
|
|
else if( list == aLastChange )
|
|
|
|
process = true; // Start processing starting with the next undo save point
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we could not find the requested save point in the current undo list
|
|
|
|
// then the undo list must have been completely altered, so process everything
|
|
|
|
if( !process )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( const PICKED_ITEMS_LIST* list, undoList )
|
|
|
|
processPickedList( list );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:06:45 +00:00
|
|
|
|
2015-07-31 15:40:19 +00:00
|
|
|
void EDIT_TOOL::processPickedList( const PICKED_ITEMS_LIST* aList )
|
2014-05-22 10:06:45 +00:00
|
|
|
{
|
2015-07-28 15:33:18 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
|
|
|
|
|
2014-05-22 10:06:45 +00:00
|
|
|
for( unsigned int i = 0; i < aList->GetCount(); ++i )
|
|
|
|
{
|
|
|
|
UNDO_REDO_T operation = aList->GetPickedItemStatus( i );
|
2015-07-28 15:33:18 +00:00
|
|
|
BOARD_ITEM* updItem = static_cast<BOARD_ITEM*>( aList->GetPickedItem( i ) );
|
2014-05-22 10:06:45 +00:00
|
|
|
|
|
|
|
switch( operation )
|
|
|
|
{
|
|
|
|
case UR_CHANGED:
|
2015-07-28 15:33:18 +00:00
|
|
|
ratsnest->Update( updItem );
|
|
|
|
// fall through
|
|
|
|
|
2014-07-09 09:22:43 +00:00
|
|
|
case UR_MODEDIT:
|
2014-05-22 10:06:45 +00:00
|
|
|
updItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_DELETED:
|
|
|
|
if( updItem->Type() == PCB_MODULE_T )
|
|
|
|
static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove,
|
2015-07-28 15:33:18 +00:00
|
|
|
view, _1 ) );
|
2014-05-22 10:06:45 +00:00
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
view->Remove( updItem );
|
|
|
|
//ratsnest->Remove( updItem ); // this is done in BOARD::Remove
|
2014-05-22 10:06:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_NEW:
|
|
|
|
if( updItem->Type() == PCB_MODULE_T )
|
|
|
|
static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add,
|
2015-07-28 15:33:18 +00:00
|
|
|
view, _1 ) );
|
2014-05-22 10:06:45 +00:00
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
view->Add( updItem );
|
|
|
|
//ratsnest->Add( updItem ); // this is done in BOARD::Add
|
2014-05-22 10:06:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert( false ); // Not handled
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2015-06-16 13:27:59 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
bool unselect = selection.Empty();
|
|
|
|
|
|
|
|
if( !hoverSelection( selection ) )
|
|
|
|
return 0;
|
|
|
|
|
2015-03-03 10:50:50 +00:00
|
|
|
MODULE* mod = uniqueSelected<MODULE>();
|
|
|
|
|
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
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
editFrame-> SetCurItem( mod );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2015-06-16 13:27:59 +00:00
|
|
|
if( unselect )
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|