kicad/pcbnew/board_commit.cpp

797 lines
25 KiB
C++
Raw Normal View History

2016-05-10 15:57:21 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 CERN
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
2016-05-10 15:57:21 +00:00
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* 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 <board.h>
#include <footprint.h>
#include <pcb_group.h>
#include <pcb_track.h>
2016-05-10 15:57:21 +00:00
#include <tool/tool_manager.h>
#include <tools/pcb_selection_tool.h>
#include <tools/zone_filler_tool.h>
2016-05-10 15:57:21 +00:00
#include <view/view.h>
#include <board_commit.h>
#include <tools/pcb_tool_base.h>
#include <tools/pcb_actions.h>
#include <connectivity/connectivity_data.h>
#include <teardrop/teardrop.h>
2016-05-10 15:57:21 +00:00
2016-11-28 14:31:56 +00:00
#include <functional>
using namespace std::placeholders;
2023-07-03 14:51:09 +00:00
BOARD_COMMIT::BOARD_COMMIT( TOOL_BASE* aTool ) :
m_toolMgr( aTool->GetManager() ),
m_isFootprintEditor( false ),
m_isBoardEditor( false )
2016-05-10 15:57:21 +00:00
{
2023-07-03 14:51:09 +00:00
if( PCB_TOOL_BASE* pcb_tool = dynamic_cast<PCB_TOOL_BASE*>( aTool ) )
{
m_isFootprintEditor = pcb_tool->IsFootprintEditor();
m_isBoardEditor = pcb_tool->IsBoardEditor();
}
}
2023-07-03 14:51:09 +00:00
BOARD_COMMIT::BOARD_COMMIT( EDA_DRAW_FRAME* aFrame ) :
m_toolMgr( aFrame->GetToolManager() ),
m_isFootprintEditor( aFrame->IsType( FRAME_FOOTPRINT_EDITOR ) ),
m_isBoardEditor( aFrame->IsType( FRAME_PCB_EDITOR ) )
{
2016-05-10 15:57:21 +00:00
}
BOARD_COMMIT::~BOARD_COMMIT()
{
}
2020-11-29 20:00:16 +00:00
BOARD* BOARD_COMMIT::GetBoard() const
{
return static_cast<BOARD*>( m_toolMgr->GetModel() );
}
COMMIT& BOARD_COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType, BASE_SCREEN* aScreen )
{
2023-03-02 14:04:37 +00:00
wxCHECK( aItem, *this );
aItem->ClearFlags( IS_MODIFIED_CHILD );
// If aItem belongs a footprint, the full footprint will be saved because undo/redo does
// not handle "sub items" modifications. This has implications for some udpate mechanisms,
// such as auto-zone-refill and teardrop regeneration, so we need to store a bit more
// information.
2023-03-02 14:04:37 +00:00
if( aChangeType == CHT_MODIFY )
{
if( aItem->Type() == PCB_FOOTPRINT_T )
{
static_cast<FOOTPRINT*>( aItem )->RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->SetFlags( IS_MODIFIED_CHILD );
} );
return COMMIT::Stage( aItem, aChangeType );
}
else if( aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T )
{
FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
bool parentFootprintStaged = alg::contains( m_changedItems, parentFootprint );
if( !parentFootprintStaged )
{
parentFootprint->RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->ClearFlags( IS_MODIFIED_CHILD );
} );
}
if( aItem->Type() == PCB_GROUP_T )
{
static_cast<PCB_GROUP*>( aItem )->RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->SetFlags( IS_MODIFIED_CHILD );
} );
}
else
{
aItem->SetFlags( IS_MODIFIED_CHILD );
}
if( !parentFootprintStaged )
return COMMIT::Stage( parentFootprint, aChangeType );
return *this;
}
else if( aItem->Type() == PCB_GROUP_T )
{
// Many operations on group (move, rotate, etc.) are applied directly to their
// children, so it's the children that must be staged.
static_cast<PCB_GROUP*>( aItem )->RunOnChildren(
[&]( BOARD_ITEM* child )
{
COMMIT::Stage( child, aChangeType );
} );
return COMMIT::Stage( aItem, aChangeType );
}
}
return COMMIT::Stage( aItem, aChangeType );
}
2020-11-29 20:00:16 +00:00
COMMIT& BOARD_COMMIT::Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType,
BASE_SCREEN* aScreen )
{
return COMMIT::Stage( container, aChangeType, aScreen );
}
2020-11-29 20:00:16 +00:00
COMMIT& BOARD_COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO aModFlag,
BASE_SCREEN* aScreen )
{
return COMMIT::Stage( aItems, aModFlag, aScreen );
}
2016-05-10 15:57:21 +00:00
2020-11-29 20:00:16 +00:00
void BOARD_COMMIT::dirtyIntersectingZones( BOARD_ITEM* item, int aChangeType )
{
2022-03-25 19:51:05 +00:00
wxCHECK( item, /* void */ );
ZONE_FILLER_TOOL* zoneFillerTool = m_toolMgr->GetTool<ZONE_FILLER_TOOL>();
if( item->Type() == PCB_ZONE_T )
zoneFillerTool->DirtyZone( static_cast<ZONE*>( item ) );
if( item->Type() == PCB_FOOTPRINT_T )
{
static_cast<FOOTPRINT*>( item )->RunOnChildren(
[&]( BOARD_ITEM* child )
{
if( aChangeType != CHT_MODIFY || ( child->GetFlags() & IS_MODIFIED_CHILD ) )
dirtyIntersectingZones( child, aChangeType );
child->ClearFlags( IS_MODIFIED_CHILD );
} );
}
else if( item->Type() == PCB_GROUP_T )
{
static_cast<PCB_GROUP*>( item )->RunOnChildren(
[&]( BOARD_ITEM* child )
{
dirtyIntersectingZones( child, aChangeType );
child->ClearFlags( IS_MODIFIED_CHILD );
} );
}
else
{
2022-08-31 09:15:42 +00:00
BOARD* board = static_cast<BOARD*>( m_toolMgr->GetModel() );
BOX2I bbox = item->GetBoundingBox();
LSET layers = item->GetLayerSet();
if( layers.test( Edge_Cuts ) || layers.test( Margin ) )
layers = LSET::PhysicalLayersMask();
else
layers &= LSET::AllCuMask();
if( layers.any() )
{
for( ZONE* zone : board->Zones() )
{
if( zone->GetIsRuleArea() )
continue;
if( ( zone->GetLayerSet() & layers ).any()
&& zone->GetBoundingBox().Intersects( bbox ) )
{
zoneFillerTool->DirtyZone( zone );
}
}
}
item->ClearFlags( IS_MODIFIED_CHILD );
}
}
2022-02-25 13:05:25 +00:00
void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
2016-05-10 15:57:21 +00:00
{
KIGFX::VIEW* view = m_toolMgr->GetView();
BOARD* board = static_cast<BOARD*>( m_toolMgr->GetModel() );
2021-08-04 12:51:38 +00:00
PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
// Notification info
PICKED_ITEMS_LIST undoList;
std::set<EDA_ITEM*> savedModules;
bool itemsDeselected = false;
bool selectedModified = false;
2016-05-10 15:57:21 +00:00
// Dirty flags and lists
bool solderMaskDirty = false;
bool autofillZones = false;
std::vector<BOARD_ITEM*> staleTeardropPadsAndVias;
std::set<PCB_TRACK*> staleTeardropTracks;
if( Empty() )
return;
undoList.SetDescription( aMessage );
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
// Note:
// frame == nullptr happens in QA tests
// in this case m_isBoardEditor and m_isFootprintEditor are set to false
// But we also test frame == nullptr mainly to make Coverity happy
2022-10-17 13:19:39 +00:00
std::vector<BOARD_ITEM*> bulkAddedItems;
std::vector<BOARD_ITEM*> bulkRemovedItems;
std::vector<BOARD_ITEM*> itemsChanged;
2022-02-25 13:05:25 +00:00
if( m_isBoardEditor
&& !( aCommitFlags & ZONE_FILL_OP )
&& ( frame && frame->GetPcbNewSettings()->m_AutoRefillZones ) )
{
autofillZones = true;
for( ZONE* zone : board->Zones() )
zone->CacheBoundingBox();
}
for( COMMIT_LINE& ent : m_changes )
2016-05-10 15:57:21 +00:00
{
int changeType = ent.m_type & CHT_TYPE;
int changeFlags = ent.m_type & CHT_FLAGS;
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( ent.m_item );
wxASSERT( ent.m_item );
// Module items need to be saved in the undo buffer before modification
2020-11-08 21:29:04 +00:00
if( m_isFootprintEditor )
{
2020-11-13 11:17:15 +00:00
// Be sure that we are storing a footprint
2020-11-13 12:21:02 +00:00
if( ent.m_item->Type() != PCB_FOOTPRINT_T )
{
ent.m_item = ent.m_item->GetParent();
wxASSERT( ent.m_item );
}
2016-05-10 15:57:21 +00:00
2020-11-13 11:17:15 +00:00
// We have not saved the footprint yet, so let's create an entry
if( savedModules.count( ent.m_item ) == 0 )
{
if( !ent.m_copy )
{
wxASSERT( changeType != CHT_MODIFY ); // too late to make a copy..
ent.m_copy = makeImage( ent.m_item );
}
2020-11-13 12:21:02 +00:00
wxASSERT( ent.m_item->Type() == PCB_FOOTPRINT_T );
wxASSERT( ent.m_copy->Type() == PCB_FOOTPRINT_T );
2016-12-09 11:04:32 +00:00
if( !( aCommitFlags & SKIP_UNDO ) && frame )
{
2020-08-26 18:04:32 +00:00
ITEM_PICKER itemWrapper( nullptr, ent.m_item, UNDO_REDO::CHANGED );
itemWrapper.SetLink( ent.m_copy );
undoList.PushItem( itemWrapper );
2020-08-26 18:04:32 +00:00
frame->SaveCopyInUndoList( undoList, UNDO_REDO::CHANGED );
}
savedModules.insert( ent.m_item );
}
}
2016-05-10 15:57:21 +00:00
if( m_isBoardEditor )
{
if( boardItem->Type() == PCB_VIA_T || boardItem->Type() == PCB_FOOTPRINT_T
|| boardItem->IsOnLayer( F_Mask ) || boardItem->IsOnLayer( B_Mask ) )
{
solderMaskDirty = true;
}
if( !( aCommitFlags & SKIP_TEARDROPS ) )
{
if( boardItem->Type() == PCB_PAD_T || boardItem->Type() == PCB_VIA_T )
{
staleTeardropPadsAndVias.push_back( boardItem );
}
else if( boardItem->Type() == PCB_TRACE_T || boardItem->Type() == PCB_ARC_T )
{
PCB_TRACK* track = static_cast<PCB_TRACK*>( boardItem );
staleTeardropTracks.insert( track );
std::vector<PAD*> connectedPads;
std::vector<PCB_VIA*> connectedVias;
connectivity->GetConnectedPadsAndVias( track, &connectedPads, &connectedVias );
for( PAD* pad : connectedPads )
staleTeardropPadsAndVias.push_back( pad );
for( PCB_VIA* via : connectedVias )
staleTeardropPadsAndVias.push_back( via );
}
else if( boardItem->Type() == PCB_FOOTPRINT_T )
{
for( PAD* pad : static_cast<FOOTPRINT*>( boardItem )->Pads() )
{
if( pad->GetFlags() & IS_MODIFIED_CHILD )
staleTeardropPadsAndVias.push_back( pad );
}
}
}
}
if( boardItem->IsSelected() )
selectedModified = true;
// If we're the footprint editor, the boardItem will always be the containing footprint
if( m_isFootprintEditor && boardItem->Type() == PCB_FOOTPRINT_T )
{
static_cast<FOOTPRINT*>( boardItem )->RunOnChildren(
[&selectedModified]( BOARD_ITEM* aItem )
{
if( aItem->HasFlag( IS_MODIFIED_CHILD ) )
selectedModified = true;
} );
}
switch( changeType )
2016-05-10 15:57:21 +00:00
{
2022-10-17 13:19:39 +00:00
case CHT_ADD:
{
if( selTool && selTool->GetEnteredGroup() && !boardItem->GetParentGroup()
&& PCB_GROUP::IsGroupableType( boardItem->Type() ) )
{
2022-10-17 13:19:39 +00:00
selTool->GetEnteredGroup()->AddItem( boardItem );
}
2022-10-17 13:19:39 +00:00
if( m_isFootprintEditor )
2016-05-10 15:57:21 +00:00
{
2022-10-17 13:19:39 +00:00
// footprints inside footprints are not supported yet
wxASSERT( boardItem->Type() != PCB_FOOTPRINT_T );
2022-10-17 13:19:39 +00:00
boardItem->SetParent( board->Footprints().front() );
2022-10-17 13:19:39 +00:00
if( !( changeFlags & CHT_DONE ) )
board->Footprints().front()->Add( boardItem );
}
else if( !boardItem->GetParentFootprint() )
2022-10-17 13:19:39 +00:00
{
if( !( aCommitFlags & SKIP_UNDO ) )
undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::NEWITEM ) );
2022-10-17 13:19:39 +00:00
if( !( changeFlags & CHT_DONE ) )
{
2022-10-17 13:19:39 +00:00
board->Add( boardItem, ADD_MODE::BULK_INSERT ); // handles connectivity
bulkAddedItems.push_back( boardItem );
}
2022-10-17 13:19:39 +00:00
}
2022-10-17 13:19:39 +00:00
if( autofillZones && boardItem->Type() != PCB_MARKER_T )
dirtyIntersectingZones( boardItem, changeType );
2016-05-10 15:57:21 +00:00
2022-10-17 13:19:39 +00:00
if( view && boardItem->Type() != PCB_NETINFO_T )
view->Add( boardItem );
2022-10-17 13:19:39 +00:00
break;
}
2022-10-17 13:19:39 +00:00
case CHT_REMOVE:
{
FOOTPRINT* parentFP = boardItem->GetParentFootprint();
2022-10-17 13:19:39 +00:00
PCB_GROUP* parentGroup = boardItem->GetParentGroup();
if( !m_isFootprintEditor && !( aCommitFlags & SKIP_UNDO ) )
undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::DELETED ) );
2016-05-10 15:57:21 +00:00
2022-10-17 13:19:39 +00:00
if( boardItem->IsSelected() )
2016-05-10 15:57:21 +00:00
{
if( selTool )
selTool->RemoveItemFromSel( boardItem, true /* quiet mode */ );
2022-10-17 13:19:39 +00:00
itemsDeselected = true;
}
if( parentGroup && !( parentGroup->GetFlags() & STRUCT_DELETED ) )
parentGroup->RemoveItem( boardItem );
2022-10-17 13:19:39 +00:00
if( autofillZones )
dirtyIntersectingZones( boardItem, changeType );
2022-10-17 13:19:39 +00:00
switch( boardItem->Type() )
{
2023-06-15 19:37:07 +00:00
case PCB_FIELD_T:
case PCB_TEXT_T:
case PCB_PAD_T:
2022-10-17 13:19:39 +00:00
case PCB_SHAPE_T: // a shape (normally not on copper layers)
case PCB_BITMAP_T: // a bitmap on a user layer
case PCB_TEXTBOX_T: // a wrapped text on a layer
case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_ARC_T: // an arced track segment (segment on a copper layer)
case PCB_VIA_T: // a via (like track segment on a copper layer)
case PCB_DIM_ALIGNED_T: // a dimension (graphic item)
case PCB_DIM_CENTER_T:
case PCB_DIM_RADIAL_T:
case PCB_DIM_ORTHOGONAL_T:
case PCB_DIM_LEADER_T: // a leader dimension
case PCB_TARGET_T: // a target (graphic item)
case PCB_MARKER_T: // a marker used to show something
case PCB_ZONE_T:
if( view )
view->Remove( boardItem );
2022-10-17 13:19:39 +00:00
if( !( changeFlags & CHT_DONE ) )
{
if( parentFP )
{
parentFP->Delete( boardItem );
}
else
{
board->Remove( boardItem, REMOVE_MODE::BULK );
bulkRemovedItems.push_back( boardItem );
}
2022-10-17 13:19:39 +00:00
}
2022-10-17 13:19:39 +00:00
break;
2022-10-17 13:19:39 +00:00
case PCB_FOOTPRINT_T:
{
// No support for nested footprints (yet)
wxASSERT( !m_isFootprintEditor );
2022-10-17 13:19:39 +00:00
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
2022-10-17 13:19:39 +00:00
if( view )
view->Remove( footprint );
2022-10-17 13:19:39 +00:00
footprint->ClearFlags();
2022-10-17 13:19:39 +00:00
if( !( changeFlags & CHT_DONE ) )
{
board->Remove( footprint, REMOVE_MODE::BULK ); // handles connectivity
bulkRemovedItems.push_back( footprint );
}
}
break;
2022-10-17 13:19:39 +00:00
case PCB_GROUP_T:
if( view )
view->Remove( boardItem );
2022-10-17 13:19:39 +00:00
if( !( changeFlags & CHT_DONE ) )
{
if( parentFP )
{
parentFP->Remove( boardItem );
}
2022-10-17 13:19:39 +00:00
else
{
2022-10-17 13:19:39 +00:00
board->Remove( boardItem, REMOVE_MODE::BULK );
bulkRemovedItems.push_back( boardItem );
}
}
2022-10-17 13:19:39 +00:00
break;
2022-10-17 13:19:39 +00:00
// Metadata items
case PCB_NETINFO_T:
board->Remove( boardItem, REMOVE_MODE::BULK );
bulkRemovedItems.push_back( boardItem );
break;
2022-10-17 13:19:39 +00:00
default: // other types do not need to (or should not) be handled
wxASSERT( false );
break;
}
2022-10-17 13:19:39 +00:00
break;
}
2022-10-17 13:19:39 +00:00
case CHT_MODIFY:
{
if( !m_isFootprintEditor && !( aCommitFlags & SKIP_UNDO ) )
{
ITEM_PICKER itemWrapper( nullptr, boardItem, UNDO_REDO::CHANGED );
wxASSERT( ent.m_copy );
itemWrapper.SetLink( ent.m_copy );
undoList.PushItem( itemWrapper );
2016-05-10 15:57:21 +00:00
}
2022-10-17 13:19:39 +00:00
if( !( aCommitFlags & SKIP_CONNECTIVITY ) )
2016-05-10 15:57:21 +00:00
{
2022-10-17 13:19:39 +00:00
if( ent.m_copy )
connectivity->MarkItemNetAsDirty( static_cast<BOARD_ITEM*>( ent.m_copy ) );
2022-10-17 13:19:39 +00:00
connectivity->Update( boardItem );
}
2022-10-17 13:19:39 +00:00
if( autofillZones )
{
dirtyIntersectingZones( static_cast<BOARD_ITEM*>( ent.m_copy ), changeType ); // before
dirtyIntersectingZones( boardItem, changeType ); // after
2022-10-17 13:19:39 +00:00
}
2022-10-17 13:19:39 +00:00
if( view )
{
view->Update( boardItem );
2022-10-17 13:19:39 +00:00
if( m_isFootprintEditor )
{
2022-10-17 13:19:39 +00:00
static_cast<FOOTPRINT*>( boardItem )->RunOnChildren(
[&]( BOARD_ITEM* aChild )
{
view->Update( aChild );
});
}
2022-10-17 13:19:39 +00:00
}
2022-10-17 13:19:39 +00:00
itemsChanged.push_back( boardItem );
2022-10-17 13:19:39 +00:00
// if no undo entry is needed, the copy would create a memory leak
if( aCommitFlags & SKIP_UNDO )
delete ent.m_copy;
2022-10-17 13:19:39 +00:00
break;
}
2016-05-10 15:57:21 +00:00
2022-10-17 13:19:39 +00:00
default:
wxASSERT( false );
break;
2016-05-10 15:57:21 +00:00
}
boardItem->ClearEditFlags();
2016-05-10 15:57:21 +00:00
}
if( bulkAddedItems.size() > 0 )
board->FinalizeBulkAdd( bulkAddedItems );
if( bulkRemovedItems.size() > 0 )
board->FinalizeBulkRemove( bulkRemovedItems );
if( itemsChanged.size() > 0 )
board->OnItemsChanged( itemsChanged );
if( m_isBoardEditor )
{
size_t num_changes = m_changes.size();
if( aCommitFlags & SKIP_CONNECTIVITY )
{
connectivity->ClearRatsnest();
connectivity->ClearLocalRatsnest();
}
else
{
connectivity->RecalculateRatsnest( this );
board->UpdateRatsnestExclusions();
connectivity->ClearLocalRatsnest();
if( frame )
frame->GetCanvas()->RedrawRatsnest();
}
if( solderMaskDirty )
{
if( frame )
frame->HideSolderMask();
}
if( !staleTeardropPadsAndVias.empty() || !staleTeardropTracks.empty() )
{
TEARDROP_MANAGER teardropMgr( board, m_toolMgr );
teardropMgr.UpdateTeardrops( *this, &staleTeardropPadsAndVias, &staleTeardropTracks );
}
// Log undo items for any connectivity or teardrop changes
for( size_t i = num_changes; i < m_changes.size(); ++i )
{
COMMIT_LINE& ent = m_changes[i];
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( ent.m_item );
2022-02-25 13:05:25 +00:00
if( !( aCommitFlags & SKIP_UNDO ) )
{
ITEM_PICKER itemWrapper( nullptr, boardItem, convert( ent.m_type & CHT_TYPE ) );
itemWrapper.SetLink( ent.m_copy );
undoList.PushItem( itemWrapper );
}
else
{
delete ent.m_copy;
}
if( view )
{
if( ( ent.m_type & CHT_TYPE ) == CHT_ADD )
view->Add( boardItem );
else if( ( ent.m_type & CHT_TYPE ) == CHT_REMOVE )
view->Remove( boardItem );
else
view->Update( boardItem );
}
}
}
if( m_isBoardEditor && !( aCommitFlags & SKIP_UNDO ) && frame )
2022-02-25 13:05:25 +00:00
{
if( aCommitFlags & APPEND_UNDO )
frame->AppendCopyToUndoList( undoList, UNDO_REDO::UNSPECIFIED );
else
frame->SaveCopyInUndoList( undoList, UNDO_REDO::UNSPECIFIED );
}
m_toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } );
if( itemsDeselected )
m_toolMgr->PostEvent( EVENTS::UnselectedEvent );
if( autofillZones )
m_toolMgr->PostAction( PCB_ACTIONS::zoneFillDirty );
if( selectedModified )
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
2021-08-04 12:51:38 +00:00
if( frame )
{
2022-02-25 13:05:25 +00:00
if( !( aCommitFlags & SKIP_SET_DIRTY ) )
2021-08-04 12:51:38 +00:00
frame->OnModify();
else
frame->Update3DView( true, frame->GetPcbNewSettings()->m_Display.m_Live3DRefresh );
2021-08-04 12:51:38 +00:00
}
clear();
2016-05-10 15:57:21 +00:00
}
EDA_ITEM* BOARD_COMMIT::parentObject( EDA_ITEM* aItem ) const
{
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem ) )
2016-05-10 15:57:21 +00:00
{
if( FOOTPRINT* parentFP = boardItem->GetParentFootprint() )
return parentFP;
2016-05-10 15:57:21 +00:00
}
return aItem;
}
EDA_ITEM* BOARD_COMMIT::makeImage( EDA_ITEM* aItem ) const
{
BOARD_ITEM* clone = static_cast<BOARD_ITEM*>( aItem->Clone() );
clone->SetParentGroup( nullptr );
return clone;
}
2016-05-10 15:57:21 +00:00
void BOARD_COMMIT::Revert()
{
PICKED_ITEMS_LIST undoList;
KIGFX::VIEW* view = m_toolMgr->GetView();
BOARD* board = (BOARD*) m_toolMgr->GetModel();
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
2016-05-10 15:57:21 +00:00
board->IncrementTimeStamp(); // clear caches
std::vector<BOARD_ITEM*> bulkAddedItems;
std::vector<BOARD_ITEM*> bulkRemovedItems;
std::vector<BOARD_ITEM*> itemsChanged;
for( auto it = m_changes.rbegin(); it != m_changes.rend(); ++it )
2016-05-10 15:57:21 +00:00
{
COMMIT_LINE& ent = *it;
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( ent.m_item );
BOARD_ITEM* copy = static_cast<BOARD_ITEM*>( ent.m_copy );
int changeType = ent.m_type & CHT_TYPE;
int changeFlags = ent.m_type & CHT_FLAGS;
2016-05-10 15:57:21 +00:00
switch( changeType )
{
2016-06-21 14:54:14 +00:00
case CHT_ADD:
if( !( changeFlags & CHT_DONE ) )
break;
2016-06-21 14:54:14 +00:00
view->Remove( item );
2017-03-22 13:43:10 +00:00
connectivity->Remove( item );
board->Remove( item, REMOVE_MODE::BULK );
bulkRemovedItems.push_back( item );
2016-06-21 14:54:14 +00:00
break;
case CHT_REMOVE:
if( !( changeFlags & CHT_DONE ) )
break;
2016-06-21 14:54:14 +00:00
view->Add( item );
2017-03-22 13:43:10 +00:00
connectivity->Add( item );
board->Add( item, ADD_MODE::INSERT );
bulkAddedItems.push_back( item );
2016-06-21 14:54:14 +00:00
break;
case CHT_MODIFY:
2016-05-10 15:57:21 +00:00
{
view->Remove( item );
2017-03-22 13:43:10 +00:00
connectivity->Remove( item );
2016-06-21 14:54:14 +00:00
item->SwapItemData( copy );
2016-06-21 14:54:14 +00:00
if( item->Type() == PCB_GROUP_T )
{
PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
group->RunOnChildren( [&]( BOARD_ITEM* child )
{
child->SetParentGroup( group );
} );
}
2016-05-10 15:57:21 +00:00
view->Add( item );
2017-03-22 13:43:10 +00:00
connectivity->Add( item );
2020-04-12 19:29:16 +00:00
board->OnItemChanged( item );
itemsChanged.push_back( item );
delete copy;
break;
}
2016-05-10 15:57:21 +00:00
default:
wxASSERT( false );
2016-05-10 15:57:21 +00:00
break;
}
item->ClearEditFlags();
2016-05-10 15:57:21 +00:00
}
if( bulkAddedItems.size() > 0 )
board->FinalizeBulkAdd( bulkAddedItems );
if( bulkRemovedItems.size() > 0 )
board->FinalizeBulkRemove( bulkRemovedItems );
if( itemsChanged.size() > 0 )
board->OnItemsChanged( itemsChanged );
2020-11-08 21:29:04 +00:00
if ( !m_isFootprintEditor )
{
connectivity->RecalculateRatsnest();
board->UpdateRatsnestExclusions();
}
2016-06-21 14:54:14 +00:00
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
selTool->RebuildSelection();
// Property panel needs to know about the reselect
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
clear();
2016-05-10 15:57:21 +00:00
}