2007-08-20 01:20:48 +00:00
|
|
|
/********************************************/
|
|
|
|
/* library editor: undo and redo functions */
|
|
|
|
/********************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-07-09 10:10:27 +00:00
|
|
|
#include <boost/bind.hpp>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
2014-07-09 10:10:27 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wxPcbStruct.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <module_editor_frame.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem,
|
|
|
|
UNDO_REDO_T aTypeCommand,
|
|
|
|
const wxPoint& aTransformPoint )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* item;
|
2009-08-03 18:54:48 +00:00
|
|
|
MODULE* CopyItem;
|
2009-07-23 15:37:00 +00:00
|
|
|
PICKED_ITEMS_LIST* lastcmd;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
CopyItem = new MODULE( *( (MODULE*) aItem ) );
|
2009-01-05 05:21:35 +00:00
|
|
|
CopyItem->SetParent( GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
lastcmd = new PICKED_ITEMS_LIST();
|
2009-08-03 18:54:48 +00:00
|
|
|
ITEM_PICKER wrapper( CopyItem, UR_MODEDIT );
|
|
|
|
lastcmd->PushItem( wrapper );
|
2009-07-23 15:37:00 +00:00
|
|
|
|
|
|
|
GetScreen()->PushCommandToUndoList( lastcmd );
|
2013-12-03 08:50:58 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
/* Clear current flags (which can be temporary set by a current edit command) */
|
2013-03-18 19:36:07 +00:00
|
|
|
for( item = CopyItem->GraphicalItems(); item != NULL; item = item->Next() )
|
2011-12-21 13:42:02 +00:00
|
|
|
item->ClearFlags();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-12-03 08:50:58 +00:00
|
|
|
for( D_PAD* pad = CopyItem->Pads(); pad; pad = pad->Next() )
|
|
|
|
pad->ClearFlags();
|
|
|
|
|
|
|
|
CopyItem->Reference().ClearFlags();
|
|
|
|
CopyItem->Value().ClearFlags();
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
/* Clear redo list, because after new save there is no redo to do */
|
2009-08-03 18:54:48 +00:00
|
|
|
GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
|
2011-08-26 17:01:17 +00:00
|
|
|
UNDO_REDO_T aTypeCommand,
|
|
|
|
const wxPoint& aTransformPoint )
|
2009-08-03 18:54:48 +00:00
|
|
|
{
|
2014-07-09 10:10:27 +00:00
|
|
|
assert( aItemsList.GetPickedItem( 0 )->GetParent()->Type() == PCB_MODULE_T );
|
|
|
|
MODULE* owner = static_cast<MODULE*>( aItemsList.GetPickedItem( 0 )->GetParent() );
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// All items should have the same parent (MODULE) to make undo/redo entry valid
|
|
|
|
for( unsigned int i = 0; i < aItemsList.GetCount(); ++i )
|
|
|
|
assert( aItemsList.GetPickedItem( i )->GetParent() == owner );
|
|
|
|
#endif /* not NDEBUG */
|
|
|
|
|
|
|
|
SaveCopyInUndoList( owner, aTypeCommand, aTransformPoint );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-03 18:54:48 +00:00
|
|
|
if( GetScreen()->GetRedoCommandCount() <= 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2014-07-09 10:10:27 +00:00
|
|
|
// Inform tools that undo command was issued
|
|
|
|
TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL );
|
|
|
|
m_toolManager->ProcessEvent( event );
|
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
// Save current module state in undo list
|
2009-07-23 15:37:00 +00:00
|
|
|
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
2014-07-09 10:10:27 +00:00
|
|
|
MODULE* module = GetBoard()->m_Modules.PopFront();
|
|
|
|
ITEM_PICKER wrapper( module, UR_MODEDIT );
|
|
|
|
KIGFX::VIEW* view = GetGalCanvas()->GetView();
|
2009-08-03 18:54:48 +00:00
|
|
|
lastcmd->PushItem( wrapper );
|
2009-07-23 15:37:00 +00:00
|
|
|
GetScreen()->PushCommandToUndoList( lastcmd );
|
|
|
|
|
2014-07-09 10:10:27 +00:00
|
|
|
view->Remove( module );
|
|
|
|
module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) );
|
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
// Retrieve last module state from undo list
|
2009-08-03 18:54:48 +00:00
|
|
|
lastcmd = GetScreen()->PopCommandFromRedoList();
|
2009-07-23 15:37:00 +00:00
|
|
|
wrapper = lastcmd->PopItem();
|
2014-07-09 10:10:27 +00:00
|
|
|
module = (MODULE*) wrapper.GetItem();
|
2009-08-04 18:21:32 +00:00
|
|
|
delete lastcmd;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
if( module )
|
2014-07-09 10:10:27 +00:00
|
|
|
{
|
2009-08-04 18:21:32 +00:00
|
|
|
GetBoard()->Add( module );
|
2014-07-09 10:10:27 +00:00
|
|
|
GetGalCanvas()->GetView()->Add( module );
|
|
|
|
module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) );
|
|
|
|
module->ViewUpdate();
|
|
|
|
}
|
2009-08-04 18:21:32 +00:00
|
|
|
|
|
|
|
SetCurItem( NULL );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-03 18:54:48 +00:00
|
|
|
if( GetScreen()->GetUndoCommandCount() <= 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2014-07-09 10:10:27 +00:00
|
|
|
// Inform tools that undo command was issued
|
|
|
|
TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL );
|
|
|
|
m_toolManager->ProcessEvent( event );
|
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
// Save current module state in redo list
|
2009-07-23 15:37:00 +00:00
|
|
|
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
2014-07-09 10:10:27 +00:00
|
|
|
MODULE* module = GetBoard()->m_Modules.PopFront();
|
|
|
|
ITEM_PICKER wrapper( module, UR_MODEDIT );
|
|
|
|
KIGFX::VIEW* view = GetGalCanvas()->GetView();
|
2009-08-03 18:54:48 +00:00
|
|
|
lastcmd->PushItem( wrapper );
|
2009-07-23 15:37:00 +00:00
|
|
|
GetScreen()->PushCommandToRedoList( lastcmd );
|
|
|
|
|
2014-07-09 10:10:27 +00:00
|
|
|
view->Remove( module );
|
|
|
|
module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) );
|
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
// Retrieve last module state from undo list
|
2009-08-03 18:54:48 +00:00
|
|
|
lastcmd = GetScreen()->PopCommandFromUndoList();
|
2009-07-23 15:37:00 +00:00
|
|
|
wrapper = lastcmd->PopItem();
|
2014-07-09 10:10:27 +00:00
|
|
|
module = (MODULE*) wrapper.GetItem();
|
2009-08-04 18:21:32 +00:00
|
|
|
delete lastcmd;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
if( module )
|
2014-07-09 10:10:27 +00:00
|
|
|
{
|
2009-08-04 18:21:32 +00:00
|
|
|
GetBoard()->Add( module, ADD_APPEND );
|
2014-07-09 10:10:27 +00:00
|
|
|
view->Add( module );
|
|
|
|
module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) );
|
|
|
|
module->ViewUpdate();
|
|
|
|
}
|
2008-12-06 08:21:54 +00:00
|
|
|
|
2011-03-03 19:08:13 +00:00
|
|
|
SetCurItem( NULL );
|
2009-08-04 18:21:32 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|