2009-07-23 15:49:39 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2009-07-23 15:49:39 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 jean-pierre.charras@gipsa-lab.inpg.fr
|
2020-12-21 15:17:52 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2021-08-28 09:44:01 +00:00
|
|
|
* Copyright (C) 2009-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2009-07-23 15:49:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CLASS_UNDOREDO_CONTAINER_H
|
|
|
|
#define _CLASS_UNDOREDO_CONTAINER_H
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2021-06-08 02:29:33 +00:00
|
|
|
#include <core/typeinfo.h>
|
2021-06-08 03:06:11 +00:00
|
|
|
#include <eda_item_flags.h>
|
2022-11-16 04:30:01 +00:00
|
|
|
#include <functional>
|
2021-06-08 02:29:33 +00:00
|
|
|
#include <vector>
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2021-06-08 02:29:33 +00:00
|
|
|
class EDA_ITEM;
|
2011-03-10 19:36:30 +00:00
|
|
|
class PICKED_ITEMS_LIST;
|
2020-07-13 11:21:40 +00:00
|
|
|
class BASE_SCREEN;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
/**
|
2010-12-14 15:56:30 +00:00
|
|
|
* Undo Redo considerations:
|
2009-07-23 15:49:39 +00:00
|
|
|
* Basically we have 3 cases
|
|
|
|
* New item
|
|
|
|
* Deleted item
|
|
|
|
* Modified item
|
2011-09-30 18:15:37 +00:00
|
|
|
* there is also a specific case in Eeschema, when wires are modified
|
2009-07-23 15:49:39 +00:00
|
|
|
* If an item is modified, a copy of the "old" item parameters value is held.
|
|
|
|
* When an item is deleted or added (new item) the pointer points the item, and there is
|
|
|
|
* no other copy.
|
|
|
|
*/
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
/**
|
|
|
|
* Type of undo/redo operations
|
|
|
|
*
|
|
|
|
* Each type must be redo/undone by a specific operation.
|
2009-07-26 17:16:42 +00:00
|
|
|
*/
|
2020-08-26 18:04:32 +00:00
|
|
|
enum class UNDO_REDO {
|
2021-08-28 09:44:01 +00:00
|
|
|
UNSPECIFIED = 0, // illegal
|
|
|
|
NOP, // Undo/redo will ignore this entry. Only forces the start of a new stack
|
|
|
|
CHANGED, // params of items have a value changed: undo is made by exchange
|
|
|
|
// values with a copy of these values
|
|
|
|
NEWITEM, // new item, undo by changing in deleted
|
|
|
|
DELETED, // deleted item, undo by changing in deleted
|
|
|
|
LIBEDIT, // Specific to the component editor (symbol_editor creates a full copy
|
|
|
|
// of the current component when changed)
|
|
|
|
LIB_RENAME, // As LIBEDIT, but old copy should be removed from library
|
|
|
|
EXCHANGE_T, // Use for changing the schematic text type where swapping
|
|
|
|
// data structure is insufficient to restore the change.
|
|
|
|
DRILLORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
|
|
|
|
GRIDORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
|
|
|
|
PAGESETTINGS, // page settings or title block changes
|
|
|
|
REGROUP, // new group of items created (do not use GROUP to avoid collision
|
|
|
|
// with an header on msys2)
|
|
|
|
UNGROUP // existing group destroyed (items not destroyed)
|
2009-07-26 17:16:42 +00:00
|
|
|
};
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
class ITEM_PICKER
|
|
|
|
{
|
2012-02-04 20:30:00 +00:00
|
|
|
public:
|
2020-08-26 18:04:32 +00:00
|
|
|
// ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO aStatus = UNSPECIFIED );
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER();
|
2020-12-21 15:17:52 +00:00
|
|
|
ITEM_PICKER( BASE_SCREEN* aScreen, EDA_ITEM* aItem,
|
|
|
|
UNDO_REDO aStatus = UNDO_REDO::UNSPECIFIED );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2012-02-05 13:02:46 +00:00
|
|
|
EDA_ITEM* GetItem() const { return m_pickedItem; }
|
|
|
|
|
2021-06-08 02:29:33 +00:00
|
|
|
void SetItem( EDA_ITEM* aItem );
|
2012-02-05 13:02:46 +00:00
|
|
|
|
|
|
|
KICAD_T GetItemType() const { return m_pickedItemType; }
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
void SetStatus( UNDO_REDO aStatus ) { m_undoRedoStatus = aStatus; }
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO GetStatus() const { return m_undoRedoStatus; }
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
void SetFlags( EDA_ITEM_FLAGS aFlags ) { m_pickerFlags = aFlags; }
|
2012-02-04 20:30:00 +00:00
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
EDA_ITEM_FLAGS GetFlags() const { return m_pickerFlags; }
|
2011-04-05 14:46:51 +00:00
|
|
|
|
2012-02-05 13:02:46 +00:00
|
|
|
void SetLink( EDA_ITEM* aItem ) { m_link = aItem; }
|
2011-04-05 14:46:51 +00:00
|
|
|
|
2012-02-05 13:02:46 +00:00
|
|
|
EDA_ITEM* GetLink() const { return m_link; }
|
2020-07-13 11:21:40 +00:00
|
|
|
|
|
|
|
BASE_SCREEN* GetScreen() const { return m_screen; }
|
2020-12-21 15:17:52 +00:00
|
|
|
|
|
|
|
private:
|
2021-06-08 03:06:11 +00:00
|
|
|
EDA_ITEM_FLAGS m_pickerFlags; /* a copy of m_flags member. useful in mode/drag
|
2020-12-21 15:17:52 +00:00
|
|
|
* undo/redo commands */
|
|
|
|
UNDO_REDO m_undoRedoStatus; /* type of operation to undo/redo for this item */
|
|
|
|
EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
|
|
|
|
* (picked), or in undo redo commands, the copy of an
|
|
|
|
* edited item. */
|
|
|
|
KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
|
|
|
|
|
|
|
|
EDA_ITEM* m_link; /* Pointer on another item. Used in undo redo command
|
|
|
|
* used when a duplicate exists i.e. when an item is
|
|
|
|
* modified, and the copy of initial item exists (the
|
|
|
|
* duplicate) m_Item points the duplicate (i.e the old
|
|
|
|
* copy of an active item) and m_Link points the active
|
|
|
|
* item in schematic */
|
|
|
|
|
|
|
|
BASE_SCREEN* m_screen; /* For new and deleted items the screen the item should
|
|
|
|
* be added to/removed from. */
|
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
};
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A holder to handle information on schematic or board items.
|
|
|
|
*
|
2009-07-23 15:49:39 +00:00
|
|
|
* The information held is a pointer on each item, and the command made.
|
|
|
|
*/
|
|
|
|
class PICKED_ITEMS_LIST
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::vector <ITEM_PICKER> m_ItemsList;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PICKED_ITEMS_LIST();
|
|
|
|
~PICKED_ITEMS_LIST();
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Push \a aItem to the top of the list.
|
|
|
|
*
|
2011-03-10 19:36:30 +00:00
|
|
|
* @param aItem Picker to push on to the list.
|
2009-08-06 07:11:04 +00:00
|
|
|
*/
|
2013-12-18 12:27:18 +00:00
|
|
|
void PushItem( const ITEM_PICKER& aItem );
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
/**
|
|
|
|
* @return The picker removed from the top of the list.
|
2009-08-06 07:11:04 +00:00
|
|
|
*/
|
2009-07-23 15:49:39 +00:00
|
|
|
ITEM_PICKER PopItem();
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
/**
|
|
|
|
* @return True if \a aItem is found in the pick list.
|
|
|
|
*/
|
2013-12-18 12:27:18 +00:00
|
|
|
bool ContainsItem( const EDA_ITEM* aItem ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Index of the searched item. If the item is not stored in the list, negative value
|
2020-12-21 15:17:52 +00:00
|
|
|
* is returned.
|
2013-12-18 12:27:18 +00:00
|
|
|
*/
|
|
|
|
int FindItem( const EDA_ITEM* aItem ) const;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Delete only the list of pickers NOT the picked data itself.
|
2009-07-25 04:53:39 +00:00
|
|
|
*/
|
2011-03-10 19:36:30 +00:00
|
|
|
void ClearItemsList();
|
2009-07-23 15:49:39 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Delete the list of pickers AND the data pointed by #m_PickedItem or #m_PickedItemLink
|
|
|
|
* according to the type of undo/redo command recorded.
|
2009-07-25 04:53:39 +00:00
|
|
|
*/
|
2022-11-15 23:51:42 +00:00
|
|
|
void ClearListAndDeleteItems( std::function<void(EDA_ITEM*)> aItemDeleter );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2011-03-10 19:36:30 +00:00
|
|
|
* @return The count of pickers stored in this list.
|
2009-08-06 07:11:04 +00:00
|
|
|
*/
|
2011-03-10 19:36:30 +00:00
|
|
|
unsigned GetCount() const
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
return m_ItemsList.size();
|
|
|
|
}
|
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Reverse the order of pickers stored in this list.
|
|
|
|
*
|
2011-03-10 19:36:30 +00:00
|
|
|
* This is useful when pop a list from Undo to Redo (and vice-versa) because
|
|
|
|
* sometimes undo (or redo) a command needs to keep the order of successive
|
|
|
|
* changes. Obviously, undo and redo are in reverse order
|
2009-08-08 06:07:08 +00:00
|
|
|
*/
|
2011-03-10 19:36:30 +00:00
|
|
|
void ReversePickersListOrder();
|
2009-07-23 15:49:39 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2011-03-10 19:36:30 +00:00
|
|
|
* @return The picker of a picked item.
|
2020-12-21 15:17:52 +00:00
|
|
|
* @param aIdx Index of the picker in the picked list if this picker does not exist,
|
|
|
|
* a picker is returned, with its members set to 0 or NULL.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2013-12-18 12:27:18 +00:00
|
|
|
ITEM_PICKER GetItemWrapper( unsigned int aIdx ) const;
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* @return A pointer to the picked item.
|
|
|
|
* @param aIdx Index of the picked item in the picked list.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2013-12-18 12:27:18 +00:00
|
|
|
EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
/**
|
2021-06-09 19:32:58 +00:00
|
|
|
* @return A pointer to the picked item's screen.
|
2020-12-21 15:17:52 +00:00
|
|
|
* @param aIdx Index of the picked item in the picked list.
|
2020-07-13 11:21:40 +00:00
|
|
|
*/
|
|
|
|
BASE_SCREEN* GetScreenForItem( unsigned int aIdx ) const;
|
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* @return link of the picked item, or null if does not exist.
|
|
|
|
* @param aIdx Index of the picked item in the picked list.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2013-12-18 12:27:18 +00:00
|
|
|
EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2011-03-10 19:36:30 +00:00
|
|
|
* @return The type of undo/redo operation associated to the picked item,
|
2020-12-21 15:17:52 +00:00
|
|
|
* or UNSPECIFIED if does not exist.
|
|
|
|
* @param aIdx Index of the picked item in the picked list.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO GetPickedItemStatus( unsigned int aIdx ) const;
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return the value of the picker flag.
|
|
|
|
*
|
|
|
|
* @param aIdx Index of the picker in the picked list.
|
|
|
|
* @return The value stored in the picker, if the picker exists, or 0 if does not exist.
|
2009-08-27 13:51:02 +00:00
|
|
|
*/
|
2021-06-08 03:06:11 +00:00
|
|
|
EDA_ITEM_FLAGS GetPickerFlags( unsigned aIdx ) const;
|
2009-08-27 13:51:02 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* @param aItem A pointer to the item to pick.
|
|
|
|
* @param aIdx Index of the picker in the picked list.
|
|
|
|
* @return True if the picker exists or false if does not exist.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2011-03-10 19:36:30 +00:00
|
|
|
bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* @param aItem A pointer to the item to pick.
|
|
|
|
* @param aStatus The type of undo/redo operation associated to the item to pick.
|
|
|
|
* @param aIdx Index of the picker in the picked list.
|
|
|
|
* @return True if the picker exists or false if does not exist.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2020-08-26 18:04:32 +00:00
|
|
|
bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO aStatus, unsigned aIdx );
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Set the link associated to a given picked item.
|
|
|
|
*
|
|
|
|
* @param aLink is the link to the item associated to the picked item.
|
|
|
|
* @param aIdx is index of the picker in the picked list.
|
|
|
|
* @return true if the picker exists, or false if does not exist.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2011-03-10 19:36:30 +00:00
|
|
|
bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Set the type of undo/redo operation for a given picked item.
|
|
|
|
*
|
2011-03-10 19:36:30 +00:00
|
|
|
* @param aStatus The type of undo/redo operation associated to the picked item
|
|
|
|
* @param aIdx Index of the picker in the picked list
|
|
|
|
* @return True if the picker exists or false if does not exist
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2020-08-26 18:04:32 +00:00
|
|
|
bool SetPickedItemStatus( UNDO_REDO aStatus, unsigned aIdx );
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Set the flags of the picker (usually to the picked item m_flags value).
|
|
|
|
*
|
|
|
|
* @param aFlags The flag value to save in picker.
|
|
|
|
* @param aIdx Index of the picker in the picked list.
|
|
|
|
* @return True if the picker exists or false if does not exist.
|
2009-08-27 13:51:02 +00:00
|
|
|
*/
|
2021-06-08 03:06:11 +00:00
|
|
|
bool SetPickerFlags( EDA_ITEM_FLAGS aFlags, unsigned aIdx );
|
2009-08-27 13:51:02 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Remove one entry (one picker) from the list of picked items.
|
|
|
|
*
|
|
|
|
* @param aIdx Index of the picker in the picked list.
|
|
|
|
* @return True if ok or false if did not exist.
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2011-03-10 19:36:30 +00:00
|
|
|
bool RemovePicker( unsigned aIdx );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Copy all data from aSource to the list.
|
|
|
|
*
|
|
|
|
* Items picked are not copied. just pointer in them are copied.
|
|
|
|
*
|
2011-03-10 19:36:30 +00:00
|
|
|
* @param aSource The list of items to copy to the list.
|
2009-07-25 04:53:39 +00:00
|
|
|
*/
|
2011-03-10 19:36:30 +00:00
|
|
|
void CopyList( const PICKED_ITEMS_LIST& aSource );
|
2009-07-23 15:49:39 +00:00
|
|
|
};
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A holder to handle a list of undo (or redo) commands.
|
2009-07-23 15:49:39 +00:00
|
|
|
*/
|
|
|
|
class UNDO_REDO_CONTAINER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UNDO_REDO_CONTAINER();
|
|
|
|
~UNDO_REDO_CONTAINER();
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
void PushCommand( PICKED_ITEMS_LIST* aCommand );
|
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
PICKED_ITEMS_LIST* PopCommand();
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
void ClearCommandList();
|
2020-12-21 15:17:52 +00:00
|
|
|
|
|
|
|
std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
|
2009-07-23 15:49:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _CLASS_UNDOREDO_CONTAINER_H
|