2013-12-09 10:01:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
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"
|
|
|
|
|
|
|
|
EDIT_TOOL::EDIT_TOOL() :
|
2014-07-09 12:01:06 +00:00
|
|
|
TOOL_INTERACTIVE( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), m_editModules( false )
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add context menu entries that are displayed when selection tool is active
|
2014-07-09 13:10:32 +00:00
|
|
|
m_selectionTool->AddMenuItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->AddMenuItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->AddMenuItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->AddMenuItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
|
|
|
|
m_selectionTool->AddMenuItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::NotEmpty );
|
2013-12-09 10:01:05 +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
|
|
|
setTransitions();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
|
|
|
|
{
|
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();
|
|
|
|
|
|
|
|
// Be sure that there is at least one item that we can modify
|
|
|
|
if( !makeSelection( selection ) )
|
2014-04-01 12:35:09 +00:00
|
|
|
{
|
|
|
|
setTransitions();
|
|
|
|
|
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?
|
|
|
|
|
2014-02-04 15:03:56 +00:00
|
|
|
// By default, modified items need to update their geometry
|
|
|
|
m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY;
|
|
|
|
|
2014-04-02 14:30:48 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
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
|
|
|
controls->ShowCursor( true );
|
|
|
|
controls->SetSnapping( true );
|
2014-01-07 16:23:17 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
2013-12-09 10:01:05 +00:00
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Dispatch TOOL_ACTIONs
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
|
|
|
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
|
2013-12-18 13:33:34 +00:00
|
|
|
{
|
2013-12-09 10:01:05 +00:00
|
|
|
Rotate( aEvent );
|
2013-12-18 13:33:34 +00:00
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
|
2013-12-18 13:33:34 +00:00
|
|
|
{
|
2013-12-09 10:01:05 +00:00
|
|
|
Flip( aEvent );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
|
|
|
// Flip causes change of layers
|
|
|
|
enableUpdateFlag( KIGFX::VIEW_ITEM::LAYERS );
|
|
|
|
}
|
2013-12-18 14:38:38 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::remove ) )
|
|
|
|
{
|
|
|
|
Remove( aEvent );
|
2014-01-07 16:23:17 +00:00
|
|
|
|
2014-01-29 09:17:14 +00:00
|
|
|
break; // exit the loop, as there is no further processing for removed items
|
2013-12-18 14:38:38 +00:00
|
|
|
}
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
m_cursor = controls->GetCursorPosition();
|
2014-04-01 11:30:31 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
if( m_dragging )
|
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) -
|
2014-06-05 07:55:53 +00:00
|
|
|
selection.Item<BOARD_ITEM>( 0 )->GetPosition();
|
2014-04-01 11:30:31 +00:00
|
|
|
|
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
|
|
|
}
|
2014-04-01 11:30:31 +00:00
|
|
|
else // Prepare to start dragging
|
2013-12-09 10:01:05 +00:00
|
|
|
{
|
2014-08-01 09:28:08 +00:00
|
|
|
if( m_selectionTool->CheckLock() || selection.Empty() )
|
2014-07-09 14:50:31 +00:00
|
|
|
break;
|
|
|
|
|
2014-04-01 11:30:31 +00:00
|
|
|
// Save items, so changes can be undone
|
2013-12-18 13:33:34 +00:00
|
|
|
editFrame->OnModify();
|
|
|
|
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
|
|
|
|
2014-08-06 07:35:03 +00:00
|
|
|
if( selection.Size() == 1 )
|
2014-06-23 14:12:59 +00:00
|
|
|
{
|
|
|
|
// Set the current cursor position to the first dragged item origin, so the
|
|
|
|
// movement vector could be computed later
|
|
|
|
m_cursor = VECTOR2I( selection.Item<BOARD_ITEM>( 0 )->GetPosition() );
|
|
|
|
m_offset.x = 0;
|
|
|
|
m_offset.y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-15 14:33:46 +00:00
|
|
|
VECTOR2D origin;
|
|
|
|
|
|
|
|
if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
origin = getView()->GetGAL()->GetGridPoint( evt->DragOrigin() );
|
|
|
|
else
|
|
|
|
origin = getViewControls()->GetCursorPosition();
|
2014-07-09 14:50:31 +00:00
|
|
|
|
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() -
|
2014-07-15 14:33:46 +00:00
|
|
|
wxPoint( origin.x, origin.y );
|
2014-06-23 14:12:59 +00:00
|
|
|
}
|
|
|
|
|
2014-08-01 09:28:08 +00:00
|
|
|
controls->SetAutoPan( true );
|
2013-12-09 10:01:05 +00:00
|
|
|
m_dragging = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
|
|
|
break; // Finish
|
|
|
|
}
|
|
|
|
|
|
|
|
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->SetSnapping( false );
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
|
|
|
|
setTransitions();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
|
|
|
|
{
|
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
|
|
|
if( !makeSelection( selection ) )
|
2014-04-01 12:35:09 +00:00
|
|
|
{
|
|
|
|
setTransitions();
|
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
2014-04-01 12:35:09 +00:00
|
|
|
}
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
// Properties are displayed when there is only one item selected
|
2013-12-18 13:33:34 +00:00
|
|
|
if( selection.Size() == 1 )
|
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
|
|
|
|
|
|
|
// Check if user wants to edit pad or module properties
|
|
|
|
if( item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
2014-07-09 09:59:24 +00:00
|
|
|
VECTOR2D cursor = getViewControls()->GetCursorPosition();
|
|
|
|
|
2014-02-05 08:05:27 +00:00
|
|
|
for( D_PAD* pad = static_cast<MODULE*>( item )->Pads(); pad; pad = pad->Next() )
|
|
|
|
{
|
2014-07-09 09:59:24 +00:00
|
|
|
if( pad->ViewBBox().Contains( cursor ) )
|
2014-02-05 08:05:27 +00:00
|
|
|
{
|
|
|
|
// Turns out that user wants to edit a pad properties
|
|
|
|
item = pad;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-18 13:33:34 +00:00
|
|
|
|
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();
|
|
|
|
|
2014-05-22 10:06:45 +00:00
|
|
|
// It is necessary to determine if anything has changed
|
|
|
|
PICKED_ITEMS_LIST* lastChange = undoList.empty() ? NULL : undoList.back();
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2014-05-22 10:06:45 +00:00
|
|
|
// Display properties dialog
|
|
|
|
editFrame->OnEditItemRequest( NULL, item );
|
|
|
|
|
|
|
|
PICKED_ITEMS_LIST* currentChange = undoList.empty() ? NULL : undoList.back();
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2014-05-22 10:06:45 +00:00
|
|
|
if( lastChange != currentChange ) // Something has changed
|
|
|
|
{
|
|
|
|
processChanges( currentChange );
|
|
|
|
|
2014-05-22 13:01:58 +00:00
|
|
|
updateRatsnest( true );
|
2014-06-06 12:59:25 +00:00
|
|
|
getModel<BOARD>()->GetRatsnest()->Recalculate();
|
2014-07-09 09:22:43 +00:00
|
|
|
item->ViewUpdate();
|
2014-05-22 10:06:45 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
setTransitions();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
|
|
|
|
{
|
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();
|
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
if( !makeSelection( selection ) || m_selectionTool->CheckLock() )
|
2014-04-03 08:24:27 +00:00
|
|
|
{
|
|
|
|
setTransitions();
|
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
2014-04-03 08:24:27 +00:00
|
|
|
}
|
2014-02-04 16:27:00 +00:00
|
|
|
|
|
|
|
wxPoint rotatePoint = getModificationPoint( selection );
|
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
if( !m_dragging ) // 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_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
|
|
|
setTransitions();
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
|
|
|
|
{
|
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();
|
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
if( !makeSelection( selection ) || m_selectionTool->CheckLock() )
|
2014-04-03 08:24:27 +00:00
|
|
|
{
|
|
|
|
setTransitions();
|
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
2014-04-03 08:24:27 +00:00
|
|
|
}
|
2014-02-04 16:27:00 +00:00
|
|
|
|
|
|
|
wxPoint flipPoint = getModificationPoint( selection );
|
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
if( !m_dragging ) // 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
|
|
|
setTransitions();
|
|
|
|
|
2013-12-09 10:01:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
|
|
|
|
{
|
2014-07-09 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
2014-02-04 16:27:00 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
if( !makeSelection( selection ) || m_selectionTool->CheckLock() )
|
2014-04-03 08:24:27 +00:00
|
|
|
{
|
|
|
|
setTransitions();
|
|
|
|
|
2014-02-04 16:27:00 +00:00
|
|
|
return 0;
|
2014-04-03 08:24:27 +00:00
|
|
|
}
|
2014-02-04 16:27:00 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
setTransitions();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if( m_editModules )
|
|
|
|
{
|
|
|
|
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( aItem );
|
|
|
|
|
|
|
|
switch( text->GetType() )
|
|
|
|
{
|
|
|
|
case TEXTE_MODULE::TEXT_is_REFERENCE:
|
|
|
|
DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete REFERENCE!" ) );
|
|
|
|
return;
|
|
|
|
|
|
|
|
case TEXTE_MODULE::TEXT_is_VALUE:
|
|
|
|
DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete VALUE!" ) );
|
|
|
|
return;
|
2014-07-09 12:22:29 +00:00
|
|
|
|
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* no break */
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
2013-12-09 10:01:05 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
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;
|
2014-07-09 12:01:06 +00:00
|
|
|
break;
|
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;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
getView()->Remove( aItem );
|
2013-12-18 13:33:34 +00:00
|
|
|
board->Remove( aItem );
|
2013-12-09 10:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDIT_TOOL::setTransitions()
|
|
|
|
{
|
|
|
|
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() );
|
|
|
|
}
|
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();
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
bool EDIT_TOOL::makeSelection( const SELECTION& aSelection )
|
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
|
2014-07-09 14:25:50 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionSingle, true );
|
2014-02-04 16:27:00 +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
|
|
|
|
|
|
|
|
|
|
|
void EDIT_TOOL::processChanges( const PICKED_ITEMS_LIST* aList )
|
|
|
|
{
|
|
|
|
for( unsigned int i = 0; i < aList->GetCount(); ++i )
|
|
|
|
{
|
|
|
|
UNDO_REDO_T operation = aList->GetPickedItemStatus( i );
|
|
|
|
EDA_ITEM* updItem = aList->GetPickedItem( i );
|
|
|
|
|
|
|
|
switch( operation )
|
|
|
|
{
|
|
|
|
case UR_CHANGED:
|
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,
|
|
|
|
getView(), _1 ) );
|
|
|
|
|
|
|
|
getView()->Remove( updItem );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_NEW:
|
|
|
|
if( updItem->Type() == PCB_MODULE_T )
|
|
|
|
static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add,
|
|
|
|
getView(), _1 ) );
|
|
|
|
|
|
|
|
getView()->Add( updItem );
|
2014-05-22 13:01:58 +00:00
|
|
|
updItem->ViewUpdate();
|
2014-05-22 10:06:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert( false ); // Not handled
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|