2023-04-29 00:02:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <macros.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/ee_tool_base.h>
|
|
|
|
|
|
|
|
#include <lib_item.h>
|
|
|
|
#include <lib_symbol.h>
|
|
|
|
|
|
|
|
#include <sch_screen.h>
|
|
|
|
#include <schematic.h>
|
|
|
|
|
|
|
|
#include <view/view.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT::SCH_COMMIT( TOOL_MANAGER* aToolMgr ) :
|
2023-04-29 00:02:42 +00:00
|
|
|
m_toolMgr( aToolMgr ),
|
|
|
|
m_isLibEditor( false )
|
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_BASE_FRAME* frame = static_cast<SCH_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
|
|
|
|
m_isLibEditor = frame && frame->IsType( FRAME_SCH_SYMBOL_EDITOR );
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT::SCH_COMMIT( EE_TOOL_BASE<SCH_BASE_FRAME>* aTool )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
m_toolMgr = aTool->GetManager();
|
|
|
|
m_isLibEditor = aTool->IsSymbolEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT::SCH_COMMIT( EDA_DRAW_FRAME* aFrame )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
m_toolMgr = aFrame->GetToolManager();
|
|
|
|
m_isLibEditor = aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT::~SCH_COMMIT()
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
COMMIT& SCH_COMMIT::Stage( EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
wxCHECK( aItem, *this );
|
|
|
|
|
2023-07-08 19:36:00 +00:00
|
|
|
// If aItem belongs a symbol, sheet or label, the full parent will be saved because undo/redo
|
|
|
|
// does not handle "sub items" modifications.
|
2023-07-11 13:51:33 +00:00
|
|
|
if( aItem->Type() != SCH_SHEET_T
|
|
|
|
&& aItem->GetParent() && aItem->GetParent()->IsType( { SCH_SYMBOL_T, LIB_SYMBOL_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
SCH_LABEL_LOCATE_ANY_T } ) )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
aItem = aItem->GetParent();
|
2023-06-09 16:24:49 +00:00
|
|
|
aChangeType = CHT_MODIFY;
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
// IS_SELECTED flag should not be set on undo items which were added for
|
|
|
|
// a drag operation.
|
|
|
|
if( aItem->IsSelected() && aItem->HasFlag( SELECTED_BY_DRAG ) )
|
|
|
|
{
|
|
|
|
aItem->ClearSelected();
|
|
|
|
COMMIT::Stage( aItem, aChangeType, aScreen );
|
|
|
|
aItem->SetSelected();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
COMMIT::Stage( aItem, aChangeType, aScreen );
|
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
return *this;
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
COMMIT& SCH_COMMIT::Stage( std::vector<EDA_ITEM*> &container, CHANGE_TYPE aChangeType,
|
|
|
|
BASE_SCREEN *aScreen )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : container )
|
|
|
|
Stage( item, aChangeType, aScreen );
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
COMMIT& SCH_COMMIT::Stage( const PICKED_ITEMS_LIST &aItems, UNDO_REDO aModFlag,
|
|
|
|
BASE_SCREEN *aScreen )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
return COMMIT::Stage( aItems, aModFlag, aScreen );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
void SCH_COMMIT::pushLibEdit( const wxString& aMessage, int aCommitFlags )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
2023-06-10 18:02:49 +00:00
|
|
|
SYMBOL_EDIT_FRAME* frame = static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
if( Empty() )
|
|
|
|
return;
|
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
// Symbol editor just saves copies of the whole symbol, so grab the first and discard the rest
|
|
|
|
LIB_SYMBOL* symbol = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_item );
|
|
|
|
LIB_SYMBOL* copy = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_copy );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( symbol )
|
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
if( view )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
view->Update( symbol );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
symbol->RunOnChildren(
|
|
|
|
[&]( LIB_ITEM* aChild )
|
|
|
|
{
|
|
|
|
view->Update( aChild );
|
|
|
|
});
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 10:16:55 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
if( frame && copy )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
frame->SaveCopyInUndoList( aMessage, copy );
|
|
|
|
copy = nullptr; // we've transferred ownership to the undo stack
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-10 17:35:59 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( copy )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-10 17:35:59 +00:00
|
|
|
// if no undo entry was needed, the copy would create a memory leak
|
2023-06-10 18:02:49 +00:00
|
|
|
delete copy;
|
|
|
|
copy = nullptr;
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } );
|
2023-07-15 21:23:36 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-10 10:16:55 +00:00
|
|
|
if( !( aCommitFlags & SKIP_SET_DIRTY ) )
|
2023-06-10 17:35:59 +00:00
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
if( frame )
|
|
|
|
frame->OnModify();
|
2023-06-10 17:35:59 +00:00
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
for( size_t ii = 1; ii < m_changes.size(); ++ii )
|
|
|
|
delete m_changes[ii].m_copy;
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
void SCH_COMMIT::pushSchEdit( const wxString& aMessage, int aCommitFlags )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
// Objects potentially interested in changes:
|
|
|
|
PICKED_ITEMS_LIST undoList;
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
|
|
|
|
SCH_EDIT_FRAME* frame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
|
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
bool itemsDeselected = false;
|
|
|
|
bool selectedModified = false;
|
2023-06-10 17:35:59 +00:00
|
|
|
bool dirtyConnectivity = false;
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
if( Empty() )
|
|
|
|
return;
|
|
|
|
|
2023-06-07 13:35:25 +00:00
|
|
|
undoList.SetDescription( aMessage );
|
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
SCHEMATIC* schematic = nullptr;
|
|
|
|
std::vector<SCH_ITEM*> bulkAddedItems;
|
|
|
|
std::vector<SCH_ITEM*> bulkRemovedItems;
|
|
|
|
std::vector<SCH_ITEM*> itemsChanged;
|
2023-05-11 02:53:10 +00:00
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
for( COMMIT_LINE& ent : m_changes )
|
|
|
|
{
|
2023-06-10 17:35:59 +00:00
|
|
|
int changeType = ent.m_type & CHT_TYPE;
|
|
|
|
int changeFlags = ent.m_type & CHT_FLAGS;
|
|
|
|
SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( ent.m_item );
|
|
|
|
SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( ent.m_screen );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
wxCHECK2( schItem && screen, continue );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( !schematic )
|
|
|
|
schematic = schItem->Schematic();
|
|
|
|
|
|
|
|
if( schItem->IsSelected() )
|
2023-04-29 00:02:42 +00:00
|
|
|
selectedModified = true;
|
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( !( aCommitFlags & SKIP_CONNECTIVITY ) )
|
|
|
|
dirtyConnectivity = true;
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
switch( changeType )
|
|
|
|
{
|
|
|
|
case CHT_ADD:
|
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
|
|
|
undoList.PushItem( ITEM_PICKER( screen, schItem, UNDO_REDO::NEWITEM ) );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
{
|
2023-06-18 15:36:28 +00:00
|
|
|
if( !screen->CheckIfOnDrawList( schItem ) ) // don't want a loop!
|
2023-06-10 17:35:59 +00:00
|
|
|
screen->Append( schItem );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
if( view )
|
|
|
|
view->Add( schItem );
|
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-07-07 14:34:43 +00:00
|
|
|
if( frame )
|
|
|
|
frame->UpdateItem( schItem, true, true );
|
|
|
|
|
2023-05-11 02:53:10 +00:00
|
|
|
bulkAddedItems.push_back( schItem );
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CHT_REMOVE:
|
|
|
|
{
|
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
|
|
|
undoList.PushItem( ITEM_PICKER( screen, schItem, UNDO_REDO::DELETED ) );
|
|
|
|
|
|
|
|
if( schItem->IsSelected() )
|
|
|
|
{
|
|
|
|
if( selTool )
|
|
|
|
selTool->RemoveItemFromSel( schItem, true /* quiet mode */ );
|
|
|
|
|
|
|
|
itemsDeselected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( schItem->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
static_cast<SCH_FIELD*>( schItem )->SetVisible( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
2023-06-09 16:24:49 +00:00
|
|
|
{
|
2023-06-10 17:35:59 +00:00
|
|
|
screen->Remove( schItem );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
if( view )
|
|
|
|
view->Remove( schItem );
|
|
|
|
}
|
|
|
|
|
2023-07-07 14:34:43 +00:00
|
|
|
if( frame )
|
|
|
|
frame->UpdateItem( schItem, true, true );
|
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
bulkRemovedItems.push_back( schItem );
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CHT_MODIFY:
|
|
|
|
{
|
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
|
|
|
{
|
|
|
|
ITEM_PICKER itemWrapper( screen, schItem, UNDO_REDO::CHANGED );
|
|
|
|
wxASSERT( ent.m_copy );
|
|
|
|
itemWrapper.SetLink( ent.m_copy );
|
|
|
|
undoList.PushItem( itemWrapper );
|
2023-06-10 17:35:59 +00:00
|
|
|
ent.m_copy = nullptr; // We've transferred ownership to the undo list
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
|
2023-07-07 14:34:43 +00:00
|
|
|
if( frame )
|
|
|
|
frame->UpdateItem( schItem, false, true );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-05-11 02:53:10 +00:00
|
|
|
itemsChanged.push_back( schItem );
|
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( ent.m_copy )
|
|
|
|
{
|
|
|
|
// if no undo entry is needed, the copy would create a memory leak
|
2023-04-29 00:02:42 +00:00
|
|
|
delete ent.m_copy;
|
2023-06-10 17:35:59 +00:00
|
|
|
ent.m_copy = nullptr;
|
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxASSERT( false );
|
|
|
|
break;
|
|
|
|
}
|
2023-06-24 16:06:57 +00:00
|
|
|
|
2023-06-25 15:00:50 +00:00
|
|
|
schItem->ClearEditFlags();
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( schematic )
|
|
|
|
{
|
|
|
|
if( bulkAddedItems.size() > 0 )
|
|
|
|
schematic->OnItemsAdded( bulkAddedItems );
|
2023-05-11 02:53:10 +00:00
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( bulkRemovedItems.size() > 0 )
|
|
|
|
schematic->OnItemsRemoved( bulkRemovedItems );
|
2023-05-11 02:53:10 +00:00
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( itemsChanged.size() > 0 )
|
|
|
|
schematic->OnItemsChanged( itemsChanged );
|
|
|
|
}
|
2023-05-11 02:53:10 +00:00
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
2023-06-07 22:45:06 +00:00
|
|
|
{
|
2023-06-10 17:35:59 +00:00
|
|
|
if( frame )
|
2023-08-30 21:21:58 +00:00
|
|
|
{
|
2023-06-10 17:35:59 +00:00
|
|
|
frame->SaveCopyInUndoList( undoList, UNDO_REDO::UNSPECIFIED, false, dirtyConnectivity );
|
2023-08-30 21:21:58 +00:00
|
|
|
frame->RecalculateConnections( this, NO_CLEANUP );
|
|
|
|
}
|
2023-06-07 22:45:06 +00:00
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
m_toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } );
|
|
|
|
|
|
|
|
if( itemsDeselected )
|
|
|
|
m_toolMgr->PostEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
|
|
|
if( selectedModified )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
|
|
|
|
2023-07-07 14:34:43 +00:00
|
|
|
if( frame && frame->GetCanvas() )
|
|
|
|
frame->GetCanvas()->Refresh();
|
|
|
|
|
2023-06-10 17:35:59 +00:00
|
|
|
if( !( aCommitFlags & SKIP_SET_DIRTY ) )
|
|
|
|
{
|
|
|
|
if( frame )
|
|
|
|
frame->OnModify();
|
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
void SCH_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
if( m_isLibEditor )
|
|
|
|
pushLibEdit( aMessage, aCommitFlags );
|
|
|
|
else
|
|
|
|
pushSchEdit( aMessage, aCommitFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
EDA_ITEM* SCH_COMMIT::parentObject( EDA_ITEM* aItem ) const
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
EDA_ITEM* parent = aItem->GetParent();
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-24 17:19:44 +00:00
|
|
|
if( parent && parent->Type() == SCH_SYMBOL_T )
|
|
|
|
return parent;
|
|
|
|
|
|
|
|
if( parent && parent->Type() == LIB_SYMBOL_T )
|
|
|
|
return parent;
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
if( m_isLibEditor )
|
|
|
|
return static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() )->GetCurSymbol();
|
|
|
|
|
|
|
|
return aItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
EDA_ITEM* SCH_COMMIT::makeImage( EDA_ITEM* aItem ) const
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
|
|
|
if( m_isLibEditor )
|
2023-06-09 16:24:49 +00:00
|
|
|
{
|
|
|
|
SYMBOL_EDIT_FRAME* frame = static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
|
|
|
|
return new LIB_SYMBOL( *frame->GetCurSymbol() );
|
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
return aItem->Clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
void SCH_COMMIT::revertLibEdit()
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
if( Empty() )
|
|
|
|
return;
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
// Symbol editor just saves copies of the whole symbol, so grab the first and discard the rest
|
|
|
|
SYMBOL_EDIT_FRAME* frame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
|
|
|
|
LIB_SYMBOL* copy = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_copy );
|
2023-07-01 21:35:39 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2023-06-10 18:02:49 +00:00
|
|
|
|
|
|
|
if( frame && copy )
|
|
|
|
{
|
|
|
|
frame->SetCurSymbol( copy, false );
|
|
|
|
m_toolMgr->ResetTools( TOOL_BASE::MODEL_RELOAD );
|
|
|
|
}
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
for( size_t ii = 1; ii < m_changes.size(); ++ii )
|
2023-06-10 18:02:49 +00:00
|
|
|
delete m_changes[ii].m_copy;
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-07-01 21:35:39 +00:00
|
|
|
if( selTool )
|
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
void SCH_COMMIT::Revert()
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
|
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
if( m_changes.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_isLibEditor )
|
|
|
|
{
|
|
|
|
revertLibEdit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
SCHEMATIC* schematic = nullptr;
|
2023-05-11 02:53:10 +00:00
|
|
|
std::vector<SCH_ITEM*> bulkAddedItems;
|
2023-06-09 16:24:49 +00:00
|
|
|
std::vector<SCH_ITEM*> bulkRemovedItems;
|
2023-05-11 02:53:10 +00:00
|
|
|
std::vector<SCH_ITEM*> itemsChanged;
|
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
for( COMMIT_LINE& ent : m_changes )
|
2023-04-29 00:02:42 +00:00
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
int changeType = ent.m_type & CHT_TYPE;
|
|
|
|
int changeFlags = ent.m_type & CHT_FLAGS;
|
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( ent.m_item );
|
|
|
|
SCH_ITEM* copy = dynamic_cast<SCH_ITEM*>( ent.m_copy );
|
|
|
|
SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( ent.m_screen );
|
|
|
|
|
|
|
|
wxCHECK2( item && screen, continue );
|
|
|
|
|
|
|
|
if( !schematic )
|
|
|
|
schematic = item->Schematic();
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
switch( changeType )
|
|
|
|
{
|
|
|
|
case CHT_ADD:
|
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
break;
|
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( view )
|
|
|
|
view->Remove( item );
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
screen->Remove( item );
|
2023-05-11 02:53:10 +00:00
|
|
|
bulkRemovedItems.push_back( item );
|
2023-04-29 00:02:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHT_REMOVE:
|
2023-06-09 16:24:49 +00:00
|
|
|
item->SetConnectivityDirty();
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
break;
|
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( view )
|
|
|
|
view->Add( item );
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
screen->Append( item );
|
2023-05-11 02:53:10 +00:00
|
|
|
bulkAddedItems.push_back( item );
|
2023-04-29 00:02:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHT_MODIFY:
|
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
if( view )
|
|
|
|
view->Remove( item );
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
item->SwapData( copy );
|
2023-06-09 16:24:49 +00:00
|
|
|
item->SetConnectivityDirty();
|
2023-04-29 00:02:42 +00:00
|
|
|
|
|
|
|
// Special cases for items which have instance data
|
|
|
|
if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T
|
|
|
|
&& item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
|
|
|
|
|
|
|
|
if( field->GetId() == REFERENCE_FIELD )
|
|
|
|
{
|
2023-08-27 18:02:12 +00:00
|
|
|
SCH_SHEET_PATH sheet = schematic->GetSheets().FindSheetForScreen( screen );
|
|
|
|
symbol->SetRef( &sheet, field->GetText() );
|
2023-04-29 00:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( view )
|
|
|
|
view->Add( item );
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-23 18:59:18 +00:00
|
|
|
screen->Update( item );
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
delete copy;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxASSERT( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( schematic )
|
|
|
|
{
|
|
|
|
if( bulkAddedItems.size() > 0 )
|
|
|
|
schematic->OnItemsAdded( bulkAddedItems );
|
2023-05-11 02:53:10 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( bulkRemovedItems.size() > 0 )
|
|
|
|
schematic->OnItemsRemoved( bulkRemovedItems );
|
2023-05-11 02:53:10 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( itemsChanged.size() > 0 )
|
|
|
|
schematic->OnItemsChanged( itemsChanged );
|
|
|
|
}
|
2023-05-11 02:53:10 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( selTool )
|
|
|
|
selTool->RebuildSelection();
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-06-10 18:02:49 +00:00
|
|
|
if( frame )
|
2023-06-23 18:59:18 +00:00
|
|
|
{
|
2023-06-10 18:02:49 +00:00
|
|
|
frame->RecalculateConnections( nullptr, NO_CLEANUP );
|
2023-06-23 18:59:18 +00:00
|
|
|
}
|
2023-06-09 16:24:49 +00:00
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|