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
|
|
|
*
|
2018-01-31 08:23:20 +00:00
|
|
|
* Copyright (C) 2018 jp.charras at wanadoo.fr
|
2021-07-15 19:26:35 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
|
|
|
* Copyright (C) 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
|
|
|
|
*/
|
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2018-01-31 08:23:20 +00:00
|
|
|
#include <undo_redo_container.h>
|
2009-07-23 15:49:39 +00:00
|
|
|
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER::ITEM_PICKER()
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
m_undoRedoStatus = UNDO_REDO::UNSPECIFIED;
|
2020-07-13 11:21:40 +00:00
|
|
|
SetItem( nullptr );
|
|
|
|
m_pickerFlags = 0;
|
2021-07-15 19:26:35 +00:00
|
|
|
m_link = nullptr;
|
2020-07-13 11:21:40 +00:00
|
|
|
m_screen = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER::ITEM_PICKER( BASE_SCREEN* aScreen, EDA_ITEM* aItem, UNDO_REDO aUndoRedoStatus )
|
2020-07-13 11:21:40 +00:00
|
|
|
{
|
|
|
|
m_undoRedoStatus = aUndoRedoStatus;
|
|
|
|
SetItem( aItem );
|
|
|
|
m_pickerFlags = 0;
|
2021-07-15 19:26:35 +00:00
|
|
|
m_link = nullptr;
|
2020-07-13 11:21:40 +00:00
|
|
|
m_screen = aScreen;
|
2009-07-31 05:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 02:29:33 +00:00
|
|
|
void ITEM_PICKER::SetItem( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
m_pickedItem = aItem;
|
|
|
|
m_pickedItemType = aItem ? aItem->Type() : TYPE_NOT_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
PICKED_ITEMS_LIST::PICKED_ITEMS_LIST()
|
|
|
|
{
|
2010-10-04 12:58:07 +00:00
|
|
|
}
|
2009-07-23 15:49:39 +00:00
|
|
|
|
2021-06-08 02:29:33 +00:00
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
void PICKED_ITEMS_LIST::PushItem( const ITEM_PICKER& aItem )
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
m_ItemsList.push_back( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-06 18:10:10 +00:00
|
|
|
ITEM_PICKER PICKED_ITEMS_LIST::PopItem()
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
ITEM_PICKER item;
|
|
|
|
|
|
|
|
if( m_ItemsList.size() != 0 )
|
|
|
|
{
|
|
|
|
item = m_ItemsList.back();
|
|
|
|
m_ItemsList.pop_back();
|
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
bool PICKED_ITEMS_LIST::ContainsItem( const EDA_ITEM* aItem ) const
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const ITEM_PICKER& picker : m_ItemsList )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( picker.GetItem() == aItem )
|
2011-03-10 19:36:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
int PICKED_ITEMS_LIST::FindItem( const EDA_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_ItemsList.size(); i++ )
|
|
|
|
{
|
|
|
|
if( m_ItemsList[i].GetItem() == aItem )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-06 18:10:10 +00:00
|
|
|
void PICKED_ITEMS_LIST::ClearItemsList()
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
m_ItemsList.clear();
|
|
|
|
}
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
// Delete items is they are not flagged NEWITEM, or if this is a block operation
|
2009-08-06 07:11:04 +00:00
|
|
|
while( GetCount() > 0 )
|
|
|
|
{
|
|
|
|
ITEM_PICKER wrapper = PopItem();
|
2021-07-15 19:26:35 +00:00
|
|
|
|
|
|
|
if( wrapper.GetItem() == nullptr ) // No more items in list.
|
2009-08-06 07:11:04 +00:00
|
|
|
break;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2018-01-24 21:27:56 +00:00
|
|
|
// The Link is an undo construct; it is always owned by the undo/redo container
|
|
|
|
if( wrapper.GetLink() )
|
|
|
|
delete wrapper.GetLink();
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2018-01-24 21:27:56 +00:00
|
|
|
if( wrapper.GetFlags() & UR_TRANSIENT )
|
|
|
|
{
|
|
|
|
delete wrapper.GetItem();
|
|
|
|
}
|
2020-08-26 18:04:32 +00:00
|
|
|
else if( wrapper.GetStatus() == UNDO_REDO::DELETED )
|
2018-01-24 21:27:56 +00:00
|
|
|
{
|
|
|
|
// This should really be replaced with UR_TRANSIENT, but currently many clients
|
|
|
|
// (eeschema in particular) abuse this to achieve non-undo-related deletions.
|
2012-02-05 13:02:46 +00:00
|
|
|
delete wrapper.GetItem();
|
2009-08-06 07:11:04 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx ) const
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
ITEM_PICKER picker;
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
if( aIdx < m_ItemsList.size() )
|
|
|
|
picker = m_ItemsList[aIdx];
|
|
|
|
|
|
|
|
return picker;
|
|
|
|
}
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItem( unsigned int aIdx ) const
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
2012-02-05 13:02:46 +00:00
|
|
|
return m_ItemsList[aIdx].GetItem();
|
2020-07-13 11:21:40 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2020-07-13 11:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BASE_SCREEN* PICKED_ITEMS_LIST::GetScreenForItem( unsigned int aIdx ) const
|
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
|
|
|
return m_ItemsList[aIdx].GetScreen();
|
2017-11-01 20:33:32 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItemLink( unsigned int aIdx ) const
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
2012-02-05 13:02:46 +00:00
|
|
|
return m_ItemsList[aIdx].GetLink();
|
2017-11-01 20:33:32 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx ) const
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
2012-02-05 13:02:46 +00:00
|
|
|
return m_ItemsList[aIdx].GetStatus();
|
2017-11-01 20:33:32 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
return UNDO_REDO::UNSPECIFIED;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
EDA_ITEM_FLAGS PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx ) const
|
2009-08-27 13:51:02 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
2012-02-05 13:02:46 +00:00
|
|
|
return m_ItemsList[aIdx].GetFlags();
|
2017-11-01 20:33:32 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-08-27 13:51:02 +00:00
|
|
|
}
|
2009-07-23 15:49:39 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, unsigned aIdx )
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
|
|
|
{
|
2012-02-05 13:02:46 +00:00
|
|
|
m_ItemsList[aIdx].SetItem( aItem );
|
2009-07-23 15:49:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-01 20:33:32 +00:00
|
|
|
|
|
|
|
return false;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx )
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
|
|
|
{
|
2012-02-05 13:02:46 +00:00
|
|
|
m_ItemsList[aIdx].SetLink( aLink );
|
2009-07-23 15:49:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-01 20:33:32 +00:00
|
|
|
|
|
|
|
return false;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UNDO_REDO aStatus, unsigned aIdx )
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
|
|
|
{
|
2012-02-05 13:02:46 +00:00
|
|
|
m_ItemsList[aIdx].SetItem( aItem );
|
|
|
|
m_ItemsList[aIdx].SetStatus( aStatus );
|
2009-07-23 15:49:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-01 20:33:32 +00:00
|
|
|
|
|
|
|
return false;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
bool PICKED_ITEMS_LIST::SetPickedItemStatus( UNDO_REDO aStatus, unsigned aIdx )
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
|
|
|
{
|
2012-02-05 13:02:46 +00:00
|
|
|
m_ItemsList[aIdx].SetStatus( aStatus );
|
2009-07-23 15:49:39 +00:00
|
|
|
return true;
|
2009-08-27 13:51:02 +00:00
|
|
|
}
|
2017-11-01 20:33:32 +00:00
|
|
|
|
|
|
|
return false;
|
2009-08-27 13:51:02 +00:00
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
bool PICKED_ITEMS_LIST::SetPickerFlags( EDA_ITEM_FLAGS aFlags, unsigned aIdx )
|
2009-08-27 13:51:02 +00:00
|
|
|
{
|
|
|
|
if( aIdx < m_ItemsList.size() )
|
|
|
|
{
|
2012-02-05 13:02:46 +00:00
|
|
|
m_ItemsList[aIdx].SetFlags( aFlags );
|
2009-08-27 13:51:02 +00:00
|
|
|
return true;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
2017-11-01 20:33:32 +00:00
|
|
|
|
|
|
|
return false;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
bool PICKED_ITEMS_LIST::RemovePicker( unsigned aIdx )
|
2009-07-23 15:49:39 +00:00
|
|
|
{
|
|
|
|
if( aIdx >= m_ItemsList.size() )
|
|
|
|
return false;
|
2017-11-01 20:33:32 +00:00
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
m_ItemsList.erase( m_ItemsList.begin() + aIdx );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
|
|
|
|
void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
2009-08-06 15:42:09 +00:00
|
|
|
m_ItemsList = aSource.m_ItemsList; // Vector's copy
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
void PICKED_ITEMS_LIST::ReversePickersListOrder()
|
|
|
|
{
|
|
|
|
std::vector <ITEM_PICKER> tmp;
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
while( !m_ItemsList.empty() )
|
|
|
|
{
|
|
|
|
tmp.push_back( m_ItemsList.back() );
|
|
|
|
m_ItemsList.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ItemsList.swap( tmp );
|
|
|
|
}
|
|
|
|
|
2009-07-23 15:49:39 +00:00
|
|
|
|
|
|
|
UNDO_REDO_CONTAINER::UNDO_REDO_CONTAINER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UNDO_REDO_CONTAINER::~UNDO_REDO_CONTAINER()
|
|
|
|
{
|
|
|
|
ClearCommandList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNDO_REDO_CONTAINER::ClearCommandList()
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < m_CommandsList.size(); ii++ )
|
|
|
|
delete m_CommandsList[ii];
|
|
|
|
|
|
|
|
m_CommandsList.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNDO_REDO_CONTAINER::PushCommand( PICKED_ITEMS_LIST* aItem )
|
|
|
|
{
|
|
|
|
m_CommandsList.push_back( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PICKED_ITEMS_LIST* UNDO_REDO_CONTAINER::PopCommand()
|
|
|
|
{
|
|
|
|
if( m_CommandsList.size() != 0 )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* item = m_CommandsList.back();
|
|
|
|
m_CommandsList.pop_back();
|
|
|
|
return item;
|
|
|
|
}
|
2015-08-04 21:08:13 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2009-07-23 15:49:39 +00:00
|
|
|
}
|