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.

149 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 <drawing_sheet/ds_data_model.h>
  26. #include <drawing_sheet/ds_proxy_undo_item.h>
  27. #include <tool/tool_manager.h>
  28. #include <tool/actions.h>
  29. #include "pl_editor_frame.h"
  30. #include "tools/pl_selection_tool.h"
  31. void PL_EDITOR_FRAME::SaveCopyInUndoList()
  32. {
  33. PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
  34. DS_PROXY_UNDO_ITEM* copyItem = new DS_PROXY_UNDO_ITEM( this );
  35. ITEM_PICKER wrapper( GetScreen(), copyItem, UNDO_REDO::LIBEDIT );
  36. lastcmd->PushItem( wrapper );
  37. PushCommandToUndoList( lastcmd );
  38. // Clear redo list, because after new save there is no redo to do.
  39. ClearUndoORRedoList( REDO_LIST );
  40. }
  41. /* Redo the last edit:
  42. * - Place the current edited layout in undo list
  43. * - Get previous version of the current edited layput
  44. */
  45. void PL_EDITOR_FRAME::GetLayoutFromRedoList()
  46. {
  47. PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  48. if ( GetRedoCommandCount() <= 0 )
  49. return;
  50. ITEM_PICKER redoWrapper = PopCommandFromRedoList()->PopItem();
  51. DS_PROXY_UNDO_ITEM* redoItem = static_cast<DS_PROXY_UNDO_ITEM*>( redoWrapper.GetItem() );
  52. bool pageSettingsAndTitleBlock = redoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
  53. PICKED_ITEMS_LIST* undoCmd = new PICKED_ITEMS_LIST();
  54. DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
  55. ITEM_PICKER undoWrapper( GetScreen(), undoItem );
  56. undoCmd->PushItem( undoWrapper );
  57. PushCommandToUndoList( undoCmd );
  58. selTool->ClearSelection();
  59. redoItem->Restore( this, GetCanvas()->GetView() );
  60. selTool->RebuildSelection();
  61. delete redoItem;
  62. if( pageSettingsAndTitleBlock )
  63. HardRedraw(); // items based off of corners will need re-calculating
  64. else
  65. GetCanvas()->Refresh();
  66. OnModify();
  67. }
  68. /* Undo the last edit:
  69. * - Place the current layout in Redo list
  70. * - Get previous version of the current edited layout
  71. */
  72. void PL_EDITOR_FRAME::GetLayoutFromUndoList()
  73. {
  74. PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  75. if ( GetUndoCommandCount() <= 0 )
  76. return;
  77. ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
  78. DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
  79. bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
  80. PICKED_ITEMS_LIST* redoCmd = new PICKED_ITEMS_LIST();
  81. DS_PROXY_UNDO_ITEM* redoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
  82. ITEM_PICKER redoWrapper( GetScreen(), redoItem );
  83. redoCmd->PushItem( redoWrapper );
  84. PushCommandToRedoList( redoCmd );
  85. selTool->ClearSelection();
  86. undoItem->Restore( this, GetCanvas()->GetView() );
  87. selTool->RebuildSelection();
  88. delete undoItem;
  89. if( pageSettingsAndTitleBlock )
  90. HardRedraw(); // items based off of corners will need re-calculating
  91. else
  92. GetCanvas()->Refresh();
  93. OnModify();
  94. }
  95. /* Remove the last command in Undo List.
  96. * Used to clean the uUndo stack after a cancel command
  97. */
  98. void PL_EDITOR_FRAME::RollbackFromUndo()
  99. {
  100. PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  101. if ( GetUndoCommandCount() <= 0 )
  102. return;
  103. ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
  104. DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
  105. bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
  106. selTool->ClearSelection();
  107. undoItem->Restore( this, GetCanvas()->GetView() );
  108. selTool->RebuildSelection();
  109. delete undoItem;
  110. if( pageSettingsAndTitleBlock )
  111. {
  112. GetToolManager()->RunAction( ACTIONS::zoomFitScreen );
  113. HardRedraw(); // items based off of corners will need re-calculating
  114. }
  115. else
  116. GetCanvas()->Refresh();
  117. }