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.

183 lines
6.0 KiB

17 years ago
17 years ago
17 years ago
17 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2014-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <fctsys.h>
  25. #include <sch_draw_panel.h>
  26. #include <lib_edit_frame.h>
  27. #include <class_libentry.h>
  28. #include <lib_manager.h>
  29. #include <widgets/lib_tree.h>
  30. #include <symbol_tree_pane.h>
  31. #include <tool/tool_manager.h>
  32. #include <tools/ee_actions.h>
  33. #include <tools/ee_selection_tool.h>
  34. void LIB_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* ItemToCopy, UNDO_REDO_T undoType, bool aAppend )
  35. {
  36. wxASSERT_MSG( !aAppend, "Append not needed/supported for LibEdit" );
  37. if( !ItemToCopy )
  38. return;
  39. LIB_PART* CopyItem;
  40. PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
  41. CopyItem = new LIB_PART( * (LIB_PART*) ItemToCopy );
  42. // Clear current flags (which can be temporary set by a current edit command).
  43. CopyItem->ClearTempFlags();
  44. CopyItem->ClearEditFlags();
  45. CopyItem->SetFlags( UR_TRANSIENT );
  46. ITEM_PICKER wrapper( CopyItem, undoType );
  47. lastcmd->PushItem( wrapper );
  48. GetScreen()->PushCommandToUndoList( lastcmd );
  49. // Clear redo list, because after new save there is no redo to do.
  50. GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
  51. }
  52. void LIB_EDIT_FRAME::GetComponentFromRedoList()
  53. {
  54. if( GetScreen()->GetRedoCommandCount() <= 0 )
  55. return;
  56. m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
  57. // Load the last redo entry
  58. PICKED_ITEMS_LIST* redoCommand = GetScreen()->PopCommandFromRedoList();
  59. ITEM_PICKER redoWrapper = redoCommand->PopItem();
  60. delete redoCommand;
  61. LIB_PART* part = (LIB_PART*) redoWrapper.GetItem();
  62. wxCHECK( part, /* void */ );
  63. part->ClearFlags( UR_TRANSIENT );
  64. UNDO_REDO_T undoRedoType = redoWrapper.GetStatus();
  65. // Store the current part in the undo buffer
  66. PICKED_ITEMS_LIST* undoCommand = new PICKED_ITEMS_LIST();
  67. LIB_PART* oldPart = m_my_part;
  68. oldPart->SetFlags( UR_TRANSIENT );
  69. ITEM_PICKER undoWrapper( oldPart, undoRedoType );
  70. undoCommand->PushItem( undoWrapper );
  71. GetScreen()->PushCommandToUndoList( undoCommand );
  72. // Do not delete the previous part by calling SetCurPart( part )
  73. // which calls delete <previous part>.
  74. // <previous part> is now put in undo list and is owned by this list
  75. // Just set the current part to the part which come from the redo list
  76. m_my_part = part;
  77. if( undoRedoType == UR_LIB_RENAME )
  78. {
  79. wxString lib = GetCurLib();
  80. m_libMgr->UpdatePartAfterRename( part, oldPart->GetName(), lib );
  81. // Reselect the renamed part
  82. m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
  83. }
  84. RebuildSymbolUnitsList();
  85. SetShowDeMorgan( part->HasConversion() );
  86. updateTitle();
  87. RebuildView();
  88. OnModify();
  89. }
  90. void LIB_EDIT_FRAME::GetComponentFromUndoList()
  91. {
  92. if( GetScreen()->GetUndoCommandCount() <= 0 )
  93. return;
  94. m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
  95. // Load the last undo entry
  96. PICKED_ITEMS_LIST* undoCommand = GetScreen()->PopCommandFromUndoList();
  97. ITEM_PICKER undoWrapper = undoCommand->PopItem();
  98. delete undoCommand;
  99. LIB_PART* part = (LIB_PART*) undoWrapper.GetItem();
  100. wxCHECK( part, /* void */ );
  101. part->ClearFlags( UR_TRANSIENT );
  102. UNDO_REDO_T undoRedoType = undoWrapper.GetStatus();
  103. // Store the current part in the redo buffer
  104. PICKED_ITEMS_LIST* redoCommand = new PICKED_ITEMS_LIST();
  105. LIB_PART* oldPart = m_my_part;
  106. oldPart->SetFlags( UR_TRANSIENT );
  107. ITEM_PICKER redoWrapper( oldPart, undoRedoType );
  108. redoCommand->PushItem( redoWrapper );
  109. GetScreen()->PushCommandToRedoList( redoCommand );
  110. // Do not delete the previous part by calling SetCurPart( part ),
  111. // which calls delete <previous part>.
  112. // <previous part> is now put in redo list and is owned by this list.
  113. // Just set the current part to the part which come from the undo list
  114. m_my_part = part;
  115. if( undoRedoType == UR_LIB_RENAME )
  116. {
  117. wxString lib = GetCurLib();
  118. m_libMgr->UpdatePartAfterRename( part, oldPart->GetName(), lib );
  119. // Reselect the renamed part
  120. m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
  121. }
  122. RebuildSymbolUnitsList();
  123. SetShowDeMorgan( part->HasConversion() );
  124. updateTitle();
  125. RebuildView();
  126. OnModify();
  127. }
  128. void LIB_EDIT_FRAME::RollbackPartFromUndo()
  129. {
  130. m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
  131. // Load the last undo entry
  132. PICKED_ITEMS_LIST* undoCommand = GetScreen()->PopCommandFromUndoList();
  133. // Check if we were already at the top of the stack
  134. if( !undoCommand )
  135. return;
  136. ITEM_PICKER undoWrapper = undoCommand->PopItem();
  137. delete undoCommand;
  138. LIB_PART* part = (LIB_PART*) undoWrapper.GetItem();
  139. part->ClearFlags( UR_TRANSIENT );
  140. SetCurPart( part );
  141. EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
  142. selTool->RebuildSelection();
  143. RebuildSymbolUnitsList();
  144. SetShowDeMorgan( part->HasConversion() );
  145. RebuildView();
  146. }