You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

680 lines
23 KiB

1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 months ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2016 CERN
  7. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  8. * @author Maciej Suminski <maciej.suminski@cern.ch>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <functional>
  28. using namespace std::placeholders;
  29. #include <macros.h>
  30. #include <pcb_edit_frame.h>
  31. #include <pcb_track.h>
  32. #include <pcb_group.h>
  33. #include <pcb_shape.h>
  34. #include <pcb_generator.h>
  35. #include <pcb_target.h>
  36. #include <footprint.h>
  37. #include <lset.h>
  38. #include <pad.h>
  39. #include <origin_viewitem.h>
  40. #include <connectivity/connectivity_data.h>
  41. #include <tool/tool_manager.h>
  42. #include <tool/actions.h>
  43. #include <tools/pcb_actions.h>
  44. #include <tools/pcb_selection_tool.h>
  45. #include <tools/pcb_control.h>
  46. #include <tools/board_editor_control.h>
  47. #include <board_commit.h>
  48. #include <drawing_sheet/ds_proxy_undo_item.h>
  49. #include <wx/msgdlg.h>
  50. #include <pcb_board_outline.h>
  51. /* Functions to undo and redo edit commands.
  52. * commands to undo are stored in CurrentScreen->m_UndoList
  53. * commands to redo are stored in CurrentScreen->m_RedoList
  54. *
  55. * m_UndoList and m_RedoList handle a std::vector of PICKED_ITEMS_LIST
  56. * Each PICKED_ITEMS_LIST handle a std::vector of pickers (class ITEM_PICKER),
  57. * that store the list of schematic items that are concerned by the command to undo or redo
  58. * and is created for each command to undo (handle also a command to redo).
  59. * each picker has a pointer pointing to an item to undo or redo (in fact: deleted, added or
  60. * modified),
  61. * and has a pointer to a copy of this item, when this item has been modified
  62. * (the old values of parameters are therefore saved)
  63. *
  64. * there are 3 cases:
  65. * - delete item(s) command
  66. * - change item(s) command
  67. * - add item(s) command
  68. *
  69. * Undo command
  70. * - delete item(s) command:
  71. * => deleted items are moved in undo list
  72. *
  73. * - change item(s) command
  74. * => A copy of item(s) is made (a DrawPickedStruct list of wrappers)
  75. * the .m_Link member of each wrapper points the modified item.
  76. * the .m_Item member of each wrapper points the old copy of this item.
  77. *
  78. * - add item(s) command
  79. * =>A list of item(s) is made. The .m_Item member of each wrapper points the new item.
  80. *
  81. * Redo command
  82. * - delete item(s) old command:
  83. * => deleted items are moved in EEDrawList list, and in
  84. *
  85. * - change item(s) command
  86. * => the copy of item(s) is moved in Undo list
  87. *
  88. * - add item(s) command
  89. * => The list of item(s) is used to create a deleted list in undo list(same as a delete
  90. * command)
  91. *
  92. * Some block operations that change items can be undone without memorize items, just the
  93. * coordinates of the transform:
  94. * move list of items (undo/redo is made by moving with the opposite move vector)
  95. * mirror (Y) and flip list of items (undo/redo is made by mirror or flip items)
  96. * so they are handled specifically.
  97. *
  98. */
  99. void PCB_BASE_EDIT_FRAME::saveCopyInUndoList( PICKED_ITEMS_LIST* commandToUndo,
  100. const PICKED_ITEMS_LIST& aItemsList,
  101. UNDO_REDO aCommandType )
  102. {
  103. int preExisting = (int) commandToUndo->GetCount();
  104. for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
  105. commandToUndo->PushItem( aItemsList.GetItemWrapper(ii) );
  106. for( unsigned ii = preExisting; ii < commandToUndo->GetCount(); ii++ )
  107. {
  108. EDA_ITEM* item = commandToUndo->GetPickedItem( ii );
  109. UNDO_REDO command = commandToUndo->GetPickedItemStatus( ii );
  110. if( command == UNDO_REDO::UNSPECIFIED )
  111. {
  112. command = aCommandType;
  113. commandToUndo->SetPickedItemStatus( command, ii );
  114. }
  115. wxASSERT( item );
  116. switch( command )
  117. {
  118. case UNDO_REDO::CHANGED:
  119. case UNDO_REDO::DRILLORIGIN:
  120. case UNDO_REDO::GRIDORIGIN:
  121. // If we don't yet have a copy in the link, set one up
  122. if( !commandToUndo->GetPickedItemLink( ii ) )
  123. commandToUndo->SetPickedItemLink( BOARD_COMMIT::MakeImage( item ), ii );
  124. break;
  125. case UNDO_REDO::NEWITEM:
  126. case UNDO_REDO::DELETED:
  127. case UNDO_REDO::PAGESETTINGS:
  128. break;
  129. default:
  130. wxFAIL_MSG( wxString::Format( wxT( "Unrecognized undo command: %X" ), command ) );
  131. break;
  132. }
  133. }
  134. if( commandToUndo->GetCount() )
  135. {
  136. /* Save the copy in undo list */
  137. PushCommandToUndoList( commandToUndo );
  138. /* Clear redo list, because after a new command one cannot redo a command */
  139. ClearUndoORRedoList( REDO_LIST );
  140. }
  141. else
  142. {
  143. // Should not occur
  144. wxASSERT( false );
  145. delete commandToUndo;
  146. }
  147. }
  148. void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* aItem, UNDO_REDO aCommandType )
  149. {
  150. PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
  151. PICKED_ITEMS_LIST itemsList;
  152. itemsList.PushItem( ITEM_PICKER( nullptr, aItem, aCommandType ) );
  153. saveCopyInUndoList( commandToUndo, itemsList, aCommandType );
  154. }
  155. void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
  156. UNDO_REDO aCommandType )
  157. {
  158. PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
  159. commandToUndo->SetDescription( aItemsList.GetDescription() );
  160. saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
  161. }
  162. void PCB_BASE_EDIT_FRAME::AppendCopyToUndoList( const PICKED_ITEMS_LIST& aItemsList,
  163. UNDO_REDO aCommandType )
  164. {
  165. PICKED_ITEMS_LIST* commandToUndo = PopCommandFromUndoList();
  166. if( !commandToUndo )
  167. {
  168. commandToUndo = new PICKED_ITEMS_LIST();
  169. commandToUndo->SetDescription( aItemsList.GetDescription() );
  170. }
  171. saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
  172. }
  173. void PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent )
  174. {
  175. if( UndoRedoBlocked() )
  176. return;
  177. if( GetUndoCommandCount() <= 0 )
  178. return;
  179. // Inform tools that undo command was issued
  180. m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
  181. // Get the old list
  182. PICKED_ITEMS_LIST* list = PopCommandFromUndoList();
  183. // Undo the command
  184. PutDataInPreviousState( list );
  185. // Put the old list in RedoList
  186. list->ReversePickersListOrder();
  187. PushCommandToRedoList( list );
  188. OnModify();
  189. m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_POST, AS_GLOBAL } );
  190. m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
  191. m_pcb->UpdateBoardOutline();
  192. GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
  193. GetCanvas()->Refresh();
  194. }
  195. void PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent )
  196. {
  197. if( UndoRedoBlocked() )
  198. return;
  199. if( GetRedoCommandCount() == 0 )
  200. return;
  201. // Inform tools that redo command was issued
  202. m_toolManager->ProcessEvent( EVENTS::UndoRedoPreEvent );
  203. // Get the old list
  204. PICKED_ITEMS_LIST* list = PopCommandFromRedoList();
  205. // Redo the command
  206. PutDataInPreviousState( list );
  207. // Put the old list in UndoList
  208. list->ReversePickersListOrder();
  209. PushCommandToUndoList( list );
  210. OnModify();
  211. m_toolManager->ProcessEvent( EVENTS::UndoRedoPostEvent );
  212. m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
  213. m_pcb->UpdateBoardOutline();
  214. GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
  215. GetCanvas()->Refresh();
  216. }
  217. void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
  218. {
  219. bool not_found = false;
  220. bool reBuild_ratsnest = false;
  221. bool deep_reBuild_ratsnest = false; // true later if pointers must be rebuilt
  222. bool solder_mask_dirty = false;
  223. std::vector<BOX2I> dirty_rule_areas;
  224. KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
  225. std::shared_ptr<CONNECTIVITY_DATA> connectivity = GetBoard()->GetConnectivity();
  226. GetBoard()->IncrementTimeStamp(); // clear caches
  227. // Enum to track the modification type of items. Used to enable bulk BOARD_LISTENER
  228. // callbacks at the end of the undo / redo operation
  229. enum ITEM_CHANGE_TYPE
  230. {
  231. ADDED,
  232. DELETED,
  233. CHANGED
  234. };
  235. std::unordered_map<EDA_ITEM*, ITEM_CHANGE_TYPE> item_changes;
  236. auto update_item_change_state =
  237. [&]( EDA_ITEM* item, ITEM_CHANGE_TYPE change_type )
  238. {
  239. auto item_itr = item_changes.find( item );
  240. if( item_itr == item_changes.end() )
  241. {
  242. // First time we've seen this item - tag the current change type
  243. item_changes.insert( { item, change_type } );
  244. return;
  245. }
  246. // Update the item state based on the current and next change type
  247. switch( item_itr->second )
  248. {
  249. case ITEM_CHANGE_TYPE::ADDED:
  250. {
  251. if( change_type == ITEM_CHANGE_TYPE::DELETED )
  252. {
  253. // The item was previously added, now deleted - as far as bulk callbacks
  254. // are concerned, the item has never existed
  255. item_changes.erase( item_itr );
  256. }
  257. else if( change_type == ITEM_CHANGE_TYPE::ADDED )
  258. {
  259. // Error condition - added an already added item
  260. wxASSERT_MSG( false, wxT( "UndoRedo: should not add already added item" ) );
  261. }
  262. // For all other cases, the item remains as ADDED as seen by the bulk callbacks
  263. break;
  264. }
  265. case ITEM_CHANGE_TYPE::DELETED:
  266. {
  267. // This is an error condition - item has already been deleted so should not
  268. // be operated on further
  269. wxASSERT_MSG( false, wxT( "UndoRedo: should not alter already deleted item" ) );
  270. break;
  271. }
  272. case ITEM_CHANGE_TYPE::CHANGED:
  273. {
  274. if( change_type == ITEM_CHANGE_TYPE::DELETED )
  275. {
  276. item_itr->second = ITEM_CHANGE_TYPE::DELETED;
  277. }
  278. else if( change_type == ITEM_CHANGE_TYPE::ADDED )
  279. {
  280. // This is an error condition - item has already been changed so should not
  281. // be added
  282. wxASSERT_MSG( false, wxT( "UndoRedo: should not add already changed item" ) );
  283. }
  284. // Otherwise, item remains CHANGED
  285. break;
  286. }
  287. }
  288. };
  289. // Undo in the reverse order of list creation: (this can allow stacked changes
  290. // like the same item can be changes and deleted in the same complex command
  291. // Restore changes in reverse order
  292. for( int ii = (int) aList->GetCount() - 1; ii >= 0 ; ii-- )
  293. {
  294. EDA_ITEM* eda_item = aList->GetPickedItem( (unsigned) ii );
  295. /* Test for existence of item on board.
  296. * It could be deleted, and no more on board:
  297. * - if a call to SaveCopyInUndoList was forgotten in Pcbnew
  298. * - in zones outlines, when a change in one zone merges this zone with an other
  299. * This test avoids a Pcbnew crash
  300. * Obviously, this test is not made for deleted items
  301. */
  302. UNDO_REDO status = aList->GetPickedItemStatus( ii );
  303. if( status != UNDO_REDO::DELETED
  304. && status != UNDO_REDO::DRILLORIGIN // origin markers never on board
  305. && status != UNDO_REDO::GRIDORIGIN // origin markers never on board
  306. && status != UNDO_REDO::PAGESETTINGS ) // nor are page settings proxy items
  307. {
  308. if( !GetBoard()->ResolveItem( eda_item->m_Uuid, true ) )
  309. {
  310. // Remove this non existent item
  311. aList->RemovePicker( ii );
  312. not_found = true;
  313. if( aList->GetCount() == 0 )
  314. break;
  315. continue;
  316. }
  317. }
  318. // see if we must rebuild ratsnets and pointers lists
  319. switch( eda_item->Type() )
  320. {
  321. case PCB_FOOTPRINT_T:
  322. deep_reBuild_ratsnest = true; // Pointers on pads can be invalid
  323. KI_FALLTHROUGH;
  324. case PCB_ZONE_T:
  325. case PCB_TRACE_T:
  326. case PCB_ARC_T:
  327. case PCB_VIA_T:
  328. case PCB_PAD_T:
  329. reBuild_ratsnest = true;
  330. break;
  331. case PCB_NETINFO_T:
  332. reBuild_ratsnest = true;
  333. deep_reBuild_ratsnest = true;
  334. break;
  335. default:
  336. break;
  337. }
  338. switch( eda_item->Type() )
  339. {
  340. case PCB_FOOTPRINT_T:
  341. solder_mask_dirty = true;
  342. break;
  343. case PCB_VIA_T:
  344. solder_mask_dirty = true;
  345. break;
  346. case PCB_ZONE_T:
  347. case PCB_TRACE_T:
  348. case PCB_ARC_T:
  349. case PCB_PAD_T:
  350. case PCB_SHAPE_T:
  351. {
  352. LSET layers = static_cast<BOARD_ITEM*>( eda_item )->GetLayerSet();
  353. if( layers.test( F_Mask ) || layers.test( B_Mask ) )
  354. solder_mask_dirty = true;
  355. break;
  356. }
  357. default:
  358. break;
  359. }
  360. switch( aList->GetPickedItemStatus( ii ) )
  361. {
  362. case UNDO_REDO::CHANGED: /* Exchange old and new data for each item */
  363. {
  364. BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
  365. BOARD_ITEM_CONTAINER* parent = GetBoard();
  366. if( item->GetParentFootprint() )
  367. {
  368. // We need the current item and it's parent, which may be different from what
  369. // was stored if we're multiple frames up the undo stack.
  370. item = GetBoard()->ResolveItem( item->m_Uuid );
  371. parent = item->GetParentFootprint();
  372. }
  373. BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii );
  374. view->Remove( item );
  375. parent->Remove( item );
  376. item->SwapItemData( image );
  377. item->ClearFlags( UR_TRANSIENT );
  378. image->SetFlags( UR_TRANSIENT );
  379. view->Add( item );
  380. view->Hide( item, false );
  381. parent->Add( item );
  382. if( item->Type() == PCB_ZONE_T && static_cast<ZONE*>( item )->GetIsRuleArea() )
  383. {
  384. dirty_rule_areas.push_back( item->GetBoundingBox() );
  385. dirty_rule_areas.push_back( image->GetBoundingBox() );
  386. }
  387. update_item_change_state( item, ITEM_CHANGE_TYPE::CHANGED );
  388. break;
  389. }
  390. case UNDO_REDO::NEWITEM: /* new items are deleted */
  391. aList->SetPickedItemStatus( UNDO_REDO::DELETED, ii );
  392. GetModel()->Remove( (BOARD_ITEM*) eda_item, REMOVE_MODE::BULK );
  393. update_item_change_state( eda_item, ITEM_CHANGE_TYPE::DELETED );
  394. if( eda_item->Type() != PCB_NETINFO_T )
  395. view->Remove( eda_item );
  396. eda_item->SetFlags( UR_TRANSIENT );
  397. if( eda_item->Type() == PCB_ZONE_T && static_cast<ZONE*>( eda_item )->GetIsRuleArea() )
  398. dirty_rule_areas.push_back( eda_item->GetBoundingBox() );
  399. break;
  400. case UNDO_REDO::DELETED: /* deleted items are put in List, as new items */
  401. aList->SetPickedItemStatus( UNDO_REDO::NEWITEM, ii );
  402. eda_item->ClearFlags( UR_TRANSIENT );
  403. GetModel()->Add( (BOARD_ITEM*) eda_item, ADD_MODE::BULK_APPEND );
  404. update_item_change_state( eda_item, ITEM_CHANGE_TYPE::ADDED );
  405. if( eda_item->Type() != PCB_NETINFO_T )
  406. view->Add( eda_item );
  407. if( eda_item->Type() == PCB_ZONE_T && static_cast<ZONE*>( eda_item )->GetIsRuleArea() )
  408. dirty_rule_areas.push_back( eda_item->GetBoundingBox() );
  409. break;
  410. case UNDO_REDO::DRILLORIGIN:
  411. case UNDO_REDO::GRIDORIGIN:
  412. {
  413. // Warning: DRILLORIGIN and GRIDORIGIN undo/redo command create EDA_ITEMs
  414. // that cannot be casted to BOARD_ITEMs
  415. EDA_ITEM* image = aList->GetPickedItemLink( ii );
  416. VECTOR2D origin = image->GetPosition();
  417. image->SetPosition( eda_item->GetPosition() );
  418. if( aList->GetPickedItemStatus( ii ) == UNDO_REDO::DRILLORIGIN )
  419. BOARD_EDITOR_CONTROL::DoSetDrillOrigin( view, this, eda_item, origin );
  420. else
  421. PCB_CONTROL::DoSetGridOrigin( view, this, eda_item, origin );
  422. break;
  423. }
  424. case UNDO_REDO::PAGESETTINGS:
  425. {
  426. // swap current settings with stored settings
  427. DS_PROXY_UNDO_ITEM alt_item( this );
  428. DS_PROXY_UNDO_ITEM* item = static_cast<DS_PROXY_UNDO_ITEM*>( eda_item );
  429. item->Restore( this );
  430. *item = std::move( alt_item );
  431. break;
  432. }
  433. default:
  434. wxFAIL_MSG( wxString::Format( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
  435. aList->GetPickedItemStatus( ii ) ) );
  436. break;
  437. }
  438. if( eda_item->Type() == PCB_FOOTPRINT_T )
  439. {
  440. FOOTPRINT* fp = static_cast<FOOTPRINT*>( eda_item );
  441. fp->InvalidateComponentClassCache();
  442. m_pcb->GetComponentClassManager().RebuildRequiredCaches( fp );
  443. }
  444. }
  445. if( not_found )
  446. wxMessageBox( _( "Incomplete undo/redo operation: some items not found" ) );
  447. // We have now swapped all the group parent and group member pointers. But it is a
  448. // risky proposition to bet on the pointers being invariant, so validate them all.
  449. for( int ii = 0; ii < (int) aList->GetCount(); ++ii )
  450. {
  451. ITEM_PICKER& wrapper = aList->GetItemWrapper( ii );
  452. if( wrapper.GetStatus() == UNDO_REDO::DELETED )
  453. continue;
  454. BOARD_ITEM* parentGroup = GetBoard()->ResolveItem( wrapper.GetGroupId(), true );
  455. wrapper.GetItem()->SetParentGroup( dynamic_cast<PCB_GROUP*>( parentGroup ) );
  456. if( EDA_GROUP* group = dynamic_cast<PCB_GROUP*>( wrapper.GetItem() ) )
  457. {
  458. // Items list may contain dodgy pointers, so don't use RemoveAll()
  459. group->GetItems().clear();
  460. for( const KIID& member : wrapper.GetGroupMembers() )
  461. {
  462. if( BOARD_ITEM* memberItem = GetBoard()->ResolveItem( member, true ) )
  463. group->AddItem( memberItem );
  464. }
  465. }
  466. // And prepare for a redo by updating group info based on current image
  467. if( EDA_ITEM* item = wrapper.GetLink() )
  468. wrapper.SetLink( item );
  469. }
  470. if( IsType( FRAME_PCB_EDITOR ) )
  471. {
  472. if( !dirty_rule_areas.empty() && ( GetPcbNewSettings()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
  473. || GetPcbNewSettings()->m_Display.m_PadClearance ) )
  474. {
  475. view->UpdateCollidingItems( dirty_rule_areas, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T } );
  476. }
  477. if( reBuild_ratsnest || deep_reBuild_ratsnest )
  478. {
  479. // Connectivity may have changed; rebuild internal caches to remove stale items
  480. GetBoard()->BuildConnectivity();
  481. Compile_Ratsnest( false );
  482. }
  483. if( solder_mask_dirty )
  484. HideSolderMask();
  485. }
  486. GetBoard()->GetComponentClassManager().InvalidateComponentClasses();
  487. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  488. selTool->RebuildSelection();
  489. GetBoard()->SanitizeNetcodes();
  490. // Invoke bulk BOARD_LISTENER callbacks
  491. std::vector<BOARD_ITEM*> added_items, deleted_items, changed_items;
  492. for( auto& [item, changeType] : item_changes )
  493. {
  494. switch( changeType )
  495. {
  496. case ITEM_CHANGE_TYPE::ADDED:
  497. added_items.push_back( static_cast<BOARD_ITEM*>( item ) );
  498. break;
  499. case ITEM_CHANGE_TYPE::DELETED:
  500. deleted_items.push_back( static_cast<BOARD_ITEM*>( item ) );
  501. break;
  502. case ITEM_CHANGE_TYPE::CHANGED:
  503. changed_items.push_back( static_cast<BOARD_ITEM*>( item ) );
  504. break;
  505. }
  506. }
  507. GetToolManager()->PostAction( PCB_ACTIONS::rehatchShapes );
  508. if( added_items.size() > 0 || deleted_items.size() > 0 || changed_items.size() > 0 )
  509. GetBoard()->OnItemsCompositeUpdate( added_items, deleted_items, changed_items );
  510. }
  511. void PCB_BASE_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount )
  512. {
  513. if( aItemCount == 0 )
  514. return;
  515. UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
  516. if( aItemCount < 0 )
  517. {
  518. list.ClearCommandList();
  519. }
  520. else
  521. {
  522. for( int ii = 0; ii < aItemCount; ii++ )
  523. {
  524. if( list.m_CommandsList.size() == 0 )
  525. break;
  526. PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
  527. list.m_CommandsList.erase( list.m_CommandsList.begin() );
  528. ClearListAndDeleteItems( curr_cmd );
  529. delete curr_cmd; // Delete command
  530. }
  531. }
  532. }
  533. void PCB_BASE_EDIT_FRAME::ClearListAndDeleteItems( PICKED_ITEMS_LIST* aList )
  534. {
  535. aList->ClearListAndDeleteItems(
  536. []( EDA_ITEM* item )
  537. {
  538. wxASSERT_MSG( item->HasFlag( UR_TRANSIENT ),
  539. "Item on undo/redo list not owned by undo/redo!" );
  540. delete item;
  541. } );
  542. }
  543. void PCB_BASE_EDIT_FRAME::RollbackFromUndo()
  544. {
  545. PICKED_ITEMS_LIST* undo = PopCommandFromUndoList();
  546. PutDataInPreviousState( undo );
  547. ClearListAndDeleteItems( undo );
  548. delete undo;
  549. m_pcb->UpdateBoardOutline();
  550. GetCanvas()->GetView()->Update( m_pcb->BoardOutline() );
  551. GetCanvas()->Refresh();
  552. }