Converted global deletion, global text size setting & module exchange to BOARD_COMMIT.

This commit is contained in:
Maciej Suminski 2016-08-17 17:24:04 +02:00
parent 91ea4242ca
commit 6701b80f77
6 changed files with 55 additions and 140 deletions

View File

@ -39,6 +39,7 @@
/* Forward declarations of classes. */ /* Forward declarations of classes. */
class PCB_SCREEN; class PCB_SCREEN;
class BOARD; class BOARD;
class BOARD_COMMIT;
class BOARD_ITEM_CONTAINER; class BOARD_ITEM_CONTAINER;
class TEXTE_PCB; class TEXTE_PCB;
class MODULE; class MODULE;
@ -1088,11 +1089,9 @@ public:
* OldModule is deleted or put in undo list. * OldModule is deleted or put in undo list.
* @param aOldModule = footprint to replace * @param aOldModule = footprint to replace
* @param aNewModule = footprint to put * @param aNewModule = footprint to put
* @param aUndoPickList = the undo list used to save OldModule. If null, * @param aCommit = commit that should store the changes
* OldModule is deleted
*/ */
void Exchange_Module( MODULE* aOldModule, MODULE* aNewModule, void Exchange_Module( MODULE* aOldModule, MODULE* aNewModule, BOARD_COMMIT& aCommit );
PICKED_ITEMS_LIST* aUndoPickList );
// loading modules: see PCB_BASE_FRAME // loading modules: see PCB_BASE_FRAME

View File

@ -30,6 +30,7 @@ using namespace std::placeholders;
#include <pcbnew.h> #include <pcbnew.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <ratsnest_data.h> #include <ratsnest_data.h>
#include <board_commit.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
@ -108,11 +109,9 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete()
return; return;
BOARD* pcb = m_Parent->GetBoard(); BOARD* pcb = m_Parent->GetBoard();
PICKED_ITEMS_LIST pickersList; BOARD_COMMIT commit( m_Parent );
ITEM_PICKER itemPicker( NULL, UR_DELETED );
BOARD_ITEM* item; BOARD_ITEM* item;
BOARD_ITEM* nextitem; BOARD_ITEM* nextitem;
RN_DATA* ratsnest = pcb->GetRatsnest();
LSET layers_filter = LSET().set(); LSET layers_filter = LSET().set();
@ -128,11 +127,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete()
{ {
if( delAll || layers_filter[item->GetLayer()] ) if( delAll || layers_filter[item->GetLayer()] )
{ {
itemPicker.SetItem( item ); commit.Remove( item );
pickersList.PushItem( itemPicker );
pcb->Remove( item );
item->ViewRelease();
ratsnest->Remove( item );
gen_rastnest = true; gen_rastnest = true;
} }
else else
@ -160,13 +155,9 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete()
{ {
nextitem = item->Next(); nextitem = item->Next();
if( delAll || if( delAll || ( item->Type() == PCB_LINE_T && masque_layer[item->GetLayer()] ) )
( item->Type() == PCB_LINE_T && masque_layer[item->GetLayer()] ) )
{ {
itemPicker.SetItem( item ); commit.Remove( item );
pickersList.PushItem( itemPicker );
item->ViewRelease();
item->UnLink();
} }
} }
} }
@ -179,13 +170,9 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete()
{ {
nextitem = item->Next(); nextitem = item->Next();
if( delAll || if( delAll || ( item->Type() == PCB_TEXT_T && del_text_layers[item->GetLayer()] ) )
( item->Type() == PCB_TEXT_T && del_text_layers[item->GetLayer()] ) )
{ {
itemPicker.SetItem( item ); commit.Remove( item );
pickersList.PushItem( itemPicker );
item->ViewRelease();
item->UnLink();
} }
} }
} }
@ -205,13 +192,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete()
if( del_fp ) if( del_fp )
{ {
itemPicker.SetItem( item ); commit.Remove( item );
pickersList.PushItem( itemPicker );
static_cast<MODULE*>( item )->RunOnChildren(
std::bind( &KIGFX::VIEW_ITEM::ViewRelease, _1 ) );
ratsnest->Remove( item );
item->ViewRelease();
item->UnLink();
gen_rastnest = true; gen_rastnest = true;
} }
} }
@ -249,17 +230,12 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete()
continue; continue;
} }
itemPicker.SetItem( track ); commit.Remove( track );
pickersList.PushItem( itemPicker );
track->ViewRelease();
ratsnest->Remove( track );
track->UnLink();
gen_rastnest = true; gen_rastnest = true;
} }
} }
if( pickersList.GetCount() ) commit.Push( wxT( "Global delete" ) );
m_Parent->SaveCopyInUndoList( pickersList, UR_DELETED );
if( m_DelMarkers->GetValue() ) if( m_DelMarkers->GetValue() )
pcb->DeleteMARKERs(); pcb->DeleteMARKERs();
@ -268,9 +244,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete()
m_Parent->Compile_Ratsnest( NULL, true ); m_Parent->Compile_Ratsnest( NULL, true );
// There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch
if( m_Parent->IsGalCanvasActive() ) // TODO necessary? if not, remove rn_data.h header as well
pcb->GetRatsnest()->ProcessBoard(); //if( m_Parent->IsGalCanvasActive() )
//pcb->GetRatsnest()->ProcessBoard();
m_Parent->GetCanvas()->Refresh();
m_Parent->OnModify();
} }

View File

@ -34,6 +34,7 @@
#include <base_units.h> #include <base_units.h>
#include <kicad_string.h> #include <kicad_string.h>
#include <macros.h> #include <macros.h>
#include <board_commit.h>
#include <pcbnew.h> #include <pcbnew.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
@ -134,35 +135,21 @@ void DIALOG_GLOBAL_MODULES_FIELDS_EDITION::OnOKClick( wxCommandEvent& event )
void PCB_EDIT_FRAME::OnResetModuleTextSizes( wxCommandEvent& event ) void PCB_EDIT_FRAME::OnResetModuleTextSizes( wxCommandEvent& event )
{ {
DIALOG_GLOBAL_MODULES_FIELDS_EDITION dlg(this); DIALOG_GLOBAL_MODULES_FIELDS_EDITION dlg( this );
dlg.ShowModal(); dlg.ShowModal();
if( IsGalCanvasActive() )
{
for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
{
module->Value().ViewUpdate();
module->Reference().ViewUpdate();
}
}
m_canvas->Refresh();
} }
void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef, void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef,
bool aValue, bool aOthers ) bool aValue, bool aOthers )
{ {
MODULE* module; BOARD_COMMIT commit( this );
BOARD_ITEM* boardItem;
ITEM_PICKER itemWrapper( NULL, UR_CHANGED ); int modTextWidth = GetDesignSettings().m_ModuleTextWidth;
PICKED_ITEMS_LIST undoItemList; const wxSize& modTextSize = GetDesignSettings().m_ModuleTextSize;
unsigned int ii;
// Prepare undo list // Prepare undo list
for( module = GetBoard()->m_Modules; module; module = module->Next() ) for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
{ {
itemWrapper.SetItem( module );
if( ! aFilter.IsEmpty() ) if( ! aFilter.IsEmpty() )
{ {
if( ! WildCompareString( aFilter, FROM_UTF8( module->GetFPID().Format().c_str() ), if( ! WildCompareString( aFilter, FROM_UTF8( module->GetFPID().Format().c_str() ),
@ -173,81 +160,50 @@ void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef,
if( aRef ) if( aRef )
{ {
TEXTE_MODULE *item = &module->Reference(); TEXTE_MODULE* item = &module->Reference();
if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || if( item->GetSize() != GetDesignSettings().m_ModuleTextSize ||
item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) item->GetThickness() != GetDesignSettings().m_ModuleTextWidth )
{ {
undoItemList.PushItem( itemWrapper ); commit.Modify( item );
item->SetThickness( modTextWidth );
item->SetSize( modTextSize );
} }
} }
if( aValue ) if( aValue )
{ {
TEXTE_MODULE *item = &module->Value(); TEXTE_MODULE* item = &module->Value();
if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || if( item->GetSize() != GetDesignSettings().m_ModuleTextSize ||
item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) item->GetThickness() != GetDesignSettings().m_ModuleTextWidth )
{ {
undoItemList.PushItem( itemWrapper ); commit.Modify( item );
item->SetThickness( modTextWidth );
item->SetSize( modTextSize );
} }
} }
if( aOthers ) if( aOthers )
{ {
// Go through all other module text fields // Go through all other module text fields
for( boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() ) for( BOARD_ITEM* boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() )
{ {
if( boardItem->Type() == PCB_MODULE_TEXT_T ) if( boardItem->Type() == PCB_MODULE_TEXT_T )
{ {
TEXTE_MODULE *item = static_cast<TEXTE_MODULE*>( boardItem ); TEXTE_MODULE* item = static_cast<TEXTE_MODULE*>( boardItem );
if( item->GetSize() != GetDesignSettings().m_ModuleTextSize if( item->GetSize() != GetDesignSettings().m_ModuleTextSize
|| item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) || item->GetThickness() != GetDesignSettings().m_ModuleTextWidth )
{ {
undoItemList.PushItem( itemWrapper ); commit.Modify( item );
item->SetThickness( modTextWidth );
item->SetSize( modTextSize );
} }
} }
} }
} }
} }
// Exit if there's nothing to do commit.Push( wxT( "Reset module text size" ) );
if( !undoItemList.GetCount() )
return;
SaveCopyInUndoList( undoItemList, UR_CHANGED );
// Apply changes to modules in the undo list
for( ii = 0; ii < undoItemList.GetCount(); ii++ )
{
module = (MODULE*) undoItemList.GetPickedItem( ii );
if( aRef )
{
module->Reference().SetThickness( GetDesignSettings().m_ModuleTextWidth );
module->Reference().SetSize( GetDesignSettings().m_ModuleTextSize );
}
if( aValue )
{
module->Value().SetThickness( GetDesignSettings().m_ModuleTextWidth );
module->Value().SetSize( GetDesignSettings().m_ModuleTextSize );
}
if( aOthers )
{
for( boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() )
{
if( boardItem->Type() == PCB_MODULE_TEXT_T )
{
TEXTE_MODULE *item = static_cast<TEXTE_MODULE*>( boardItem );
item->SetThickness( GetDesignSettings().m_ModuleTextWidth );
item->SetSize( GetDesignSettings().m_ModuleTextSize );
}
}
}
}
OnModify();
} }

View File

@ -40,6 +40,7 @@
#include <macros.h> #include <macros.h>
#include <invoke_pcb_dialog.h> #include <invoke_pcb_dialog.h>
#include <class_pcb_layer_widget.h> #include <class_pcb_layer_widget.h>
#include <board_commit.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
@ -451,7 +452,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
// the new module replace the old module (pos, orient, ref, value // the new module replace the old module (pos, orient, ref, value
// and connexions are kept) // and connexions are kept)
// and the source_module (old module) is deleted // and the source_module (old module) is deleted
PICKED_ITEMS_LIST pickList; BOARD_COMMIT commit( pcbframe );
if( pcbframe->IsGalCanvasActive() ) if( pcbframe->IsGalCanvasActive() )
{ {
@ -461,11 +462,10 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
view->Remove( source_module ); view->Remove( source_module );
} }
pcbframe->Exchange_Module( source_module, newmodule, &pickList ); pcbframe->Exchange_Module( source_module, newmodule, commit );
newmodule->SetTimeStamp( module_in_edit->GetLink() ); newmodule->SetTimeStamp( module_in_edit->GetLink() );
if( pickList.GetCount() ) commit.Push( wxT( "" ) );
pcbframe->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
else // This is an insert command else // This is an insert command
{ {

View File

@ -375,7 +375,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
STATUS_FLAGS flags = item->GetFlags(); STATUS_FLAGS flags = item->GetFlags();
item->ClearFlags(); item->ClearFlags();
// Do not handle undo buffer, it is done by the properties dialogs // Do not handle undo buffer, it is done by the properties dialogs @todo LEGACY
// Display properties dialog provided by the legacy canvas frame // Display properties dialog provided by the legacy canvas frame
editFrame->OnEditItemRequest( NULL, item ); editFrame->OnEditItemRequest( NULL, item );

View File

@ -35,6 +35,7 @@
#include <kicad_string.h> #include <kicad_string.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <macros.h> #include <macros.h>
#include <board_commit.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
@ -76,7 +77,7 @@ private:
const FPID& aNewFootprintFPID, const FPID& aNewFootprintFPID,
bool eShowError ); bool eShowError );
PICKED_ITEMS_LIST m_undoPickList; BOARD_COMMIT m_commit;
}; };
@ -84,7 +85,7 @@ int DIALOG_EXCHANGE_MODULE::m_selectionMode = 0;
DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( PCB_EDIT_FRAME* parent, MODULE* Module ) : DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( PCB_EDIT_FRAME* parent, MODULE* Module ) :
DIALOG_EXCHANGE_MODULE_BASE( parent ) DIALOG_EXCHANGE_MODULE_BASE( parent ), m_commit( parent )
{ {
m_parent = parent; m_parent = parent;
m_currentModule = Module; m_currentModule = Module;
@ -141,7 +142,6 @@ void DIALOG_EXCHANGE_MODULE::init()
void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event ) void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event )
{ {
m_undoPickList.ClearItemsList();
m_selectionMode = m_Selection->GetSelection(); m_selectionMode = m_Selection->GetSelection();
bool result = false; bool result = false;
@ -172,8 +172,7 @@ void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event )
m_parent->GetCanvas()->Refresh(); m_parent->GetCanvas()->Refresh();
} }
if( m_undoPickList.GetCount() ) m_commit.Push( wxT( "Changed footprint" ) );
m_parent->SaveCopyInUndoList( m_undoPickList, UR_UNSPECIFIED );
} }
@ -367,8 +366,7 @@ bool DIALOG_EXCHANGE_MODULE::change_1_Module( MODULE* aModule,
return false; return false;
} }
m_parent->Exchange_Module( aModule, newModule, &m_undoPickList ); m_parent->Exchange_Module( aModule, newModule, m_commit );
m_parent->GetBoard()->Add( newModule, ADD_APPEND );
if( aModule == m_currentModule ) if( aModule == m_currentModule )
m_currentModule = newModule; m_currentModule = newModule;
@ -381,13 +379,12 @@ bool DIALOG_EXCHANGE_MODULE::change_1_Module( MODULE* aModule,
void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
MODULE* aNewModule, MODULE* aNewModule,
PICKED_ITEMS_LIST* aUndoPickList ) BOARD_COMMIT& aCommit )
{ {
aNewModule->SetParent( GetBoard() ); aNewModule->SetParent( GetBoard() );
/* place module without ratsnest refresh: this will be made later /* place module without ratsnest refresh: this will be made later
* when all modules are on board * when all modules are on board */
*/
PlaceModule( aNewModule, NULL, true ); PlaceModule( aNewModule, NULL, true );
// Copy full placement and pad net names (when possible) // Copy full placement and pad net names (when possible)
@ -402,23 +399,12 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() ); aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() );
aNewModule->SetPath( aOldModule->GetPath() ); aNewModule->SetPath( aOldModule->GetPath() );
if( aUndoPickList ) aCommit.Remove( aOldModule );
{ aCommit.Add( aNewModule );
GetBoard()->Remove( aOldModule );
ITEM_PICKER picker_old( aOldModule, UR_DELETED );
ITEM_PICKER picker_new( aNewModule, UR_NEW );
aUndoPickList->PushItem( picker_old );
aUndoPickList->PushItem( picker_new );
}
else
{
GetGalCanvas()->GetView()->Remove( aOldModule );
aOldModule->DeleteStructure();
}
// @todo LEGACY should be unnecessary
GetBoard()->m_Status_Pcb = 0; GetBoard()->m_Status_Pcb = 0;
aNewModule->ClearFlags(); aNewModule->ClearFlags();
OnModify();
} }