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.

150 lines
5.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <fctsys.h>
  26. #include <ws_data_model.h>
  27. #include <pl_editor_frame.h>
  28. #include <tool/tool_manager.h>
  29. #include <tools/pl_selection_tool.h>
  30. #include <ws_proxy_undo_item.h>
  31. #include <tool/actions.h>
  32. void PL_EDITOR_FRAME::SaveCopyInUndoList()
  33. {
  34. PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
  35. WS_PROXY_UNDO_ITEM* copyItem = new WS_PROXY_UNDO_ITEM( this );
  36. ITEM_PICKER wrapper( GetScreen(), copyItem, UNDO_REDO::LIBEDIT );
  37. lastcmd->PushItem( wrapper );
  38. PushCommandToUndoList( lastcmd );
  39. // Clear redo list, because after new save there is no redo to do.
  40. ClearUndoORRedoList( REDO_LIST );
  41. }
  42. /* Redo the last edit:
  43. * - Place the current edited layout in undo list
  44. * - Get previous version of the current edited layput
  45. */
  46. void PL_EDITOR_FRAME::GetLayoutFromRedoList()
  47. {
  48. PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  49. if ( GetRedoCommandCount() <= 0 )
  50. return;
  51. ITEM_PICKER redoWrapper = PopCommandFromRedoList()->PopItem();
  52. WS_PROXY_UNDO_ITEM* redoItem = static_cast<WS_PROXY_UNDO_ITEM*>( redoWrapper.GetItem() );
  53. bool pageSettingsAndTitleBlock = redoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
  54. PICKED_ITEMS_LIST* undoCmd = new PICKED_ITEMS_LIST();
  55. WS_PROXY_UNDO_ITEM* undoItem = new WS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
  56. ITEM_PICKER undoWrapper( GetScreen(), undoItem );
  57. undoCmd->PushItem( undoWrapper );
  58. PushCommandToUndoList( undoCmd );
  59. selTool->ClearSelection();
  60. redoItem->Restore( this, GetCanvas()->GetView() );
  61. selTool->RebuildSelection();
  62. delete redoItem;
  63. if( pageSettingsAndTitleBlock )
  64. HardRedraw(); // items based off of corners will need re-calculating
  65. else
  66. GetCanvas()->Refresh();
  67. OnModify();
  68. }
  69. /* Undo the last edit:
  70. * - Place the current layout in Redo list
  71. * - Get previous version of the current edited layout
  72. */
  73. void PL_EDITOR_FRAME::GetLayoutFromUndoList()
  74. {
  75. PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  76. if ( GetUndoCommandCount() <= 0 )
  77. return;
  78. ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
  79. WS_PROXY_UNDO_ITEM* undoItem = static_cast<WS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
  80. bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
  81. PICKED_ITEMS_LIST* redoCmd = new PICKED_ITEMS_LIST();
  82. WS_PROXY_UNDO_ITEM* redoItem = new WS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
  83. ITEM_PICKER redoWrapper( GetScreen(), redoItem );
  84. redoCmd->PushItem( redoWrapper );
  85. PushCommandToRedoList( redoCmd );
  86. selTool->ClearSelection();
  87. undoItem->Restore( this, GetCanvas()->GetView() );
  88. selTool->RebuildSelection();
  89. delete undoItem;
  90. if( pageSettingsAndTitleBlock )
  91. HardRedraw(); // items based off of corners will need re-calculating
  92. else
  93. GetCanvas()->Refresh();
  94. OnModify();
  95. }
  96. /* Remove the last command in Undo List.
  97. * Used to clean the uUndo stack after a cancel command
  98. */
  99. void PL_EDITOR_FRAME::RollbackFromUndo()
  100. {
  101. PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  102. if ( GetUndoCommandCount() <= 0 )
  103. return;
  104. ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
  105. WS_PROXY_UNDO_ITEM* undoItem = static_cast<WS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
  106. bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
  107. selTool->ClearSelection();
  108. undoItem->Restore( this, GetCanvas()->GetView() );
  109. selTool->RebuildSelection();
  110. delete undoItem;
  111. if( pageSettingsAndTitleBlock )
  112. {
  113. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
  114. HardRedraw(); // items based off of corners will need re-calculating
  115. }
  116. else
  117. GetCanvas()->Refresh();
  118. }