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
|
2023-01-23 16:23:43 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <macros.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <pcb_group.h>
|
2023-05-12 21:03:54 +00:00
|
|
|
#include <pcb_track.h>
|
2016-05-10 15:57:21 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2022-02-24 09:59:54 +00:00
|
|
|
#include <tools/zone_filler_tool.h>
|
2016-05-10 15:57:21 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <board_commit.h>
|
2019-05-12 11:49:58 +00:00
|
|
|
#include <tools/pcb_tool_base.h>
|
2018-09-17 13:14:23 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2023-05-12 21:03:54 +00:00
|
|
|
#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;
|
|
|
|
|
2017-09-28 16:38:54 +00:00
|
|
|
|
2023-07-03 14:51:09 +00:00
|
|
|
BOARD_COMMIT::BOARD_COMMIT( TOOL_BASE* aTool ) :
|
|
|
|
m_toolMgr( aTool->GetManager() ),
|
|
|
|
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_isBoardEditor = pcb_tool->IsBoardEditor();
|
2016-06-16 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-03 14:51:09 +00:00
|
|
|
BOARD_COMMIT::BOARD_COMMIT( EDA_DRAW_FRAME* aFrame ) :
|
|
|
|
m_toolMgr( aFrame->GetToolManager() ),
|
|
|
|
m_isBoardEditor( aFrame->IsType( FRAME_PCB_EDITOR ) )
|
2016-06-16 10:19:07 +00:00
|
|
|
{
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
BOARD* BOARD_COMMIT::GetBoard() const
|
|
|
|
{
|
|
|
|
return static_cast<BOARD*>( m_toolMgr->GetModel() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
COMMIT& BOARD_COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType, BASE_SCREEN* aScreen )
|
2019-11-16 22:31:18 +00:00
|
|
|
{
|
2023-03-02 14:04:37 +00:00
|
|
|
wxCHECK( aItem, *this );
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( aChangeType == CHT_MODIFY && aItem->Type() == PCB_GROUP_T )
|
2023-01-13 19:07:52 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
// 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 );
|
|
|
|
} );
|
2019-11-16 22:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return COMMIT::Stage( aItem, aChangeType );
|
|
|
|
}
|
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
COMMIT& BOARD_COMMIT::Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType,
|
|
|
|
BASE_SCREEN* aScreen )
|
2019-11-16 22:31:18 +00:00
|
|
|
{
|
2023-04-29 00:02:42 +00:00
|
|
|
return COMMIT::Stage( container, aChangeType, aScreen );
|
2019-11-16 22:31:18 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
COMMIT& BOARD_COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO aModFlag,
|
|
|
|
BASE_SCREEN* aScreen )
|
2019-11-16 22:31:18 +00:00
|
|
|
{
|
2023-04-29 00:02:42 +00:00
|
|
|
return COMMIT::Stage( aItems, aModFlag, aScreen );
|
2019-11-16 22:31:18 +00:00
|
|
|
}
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
|
2023-01-13 19:07:52 +00:00
|
|
|
void BOARD_COMMIT::dirtyIntersectingZones( BOARD_ITEM* item, int aChangeType )
|
2022-02-24 09:59:54 +00:00
|
|
|
{
|
2022-03-25 19:51:05 +00:00
|
|
|
wxCHECK( item, /* void */ );
|
|
|
|
|
2022-07-30 16:30:22 +00:00
|
|
|
ZONE_FILLER_TOOL* zoneFillerTool = m_toolMgr->GetTool<ZONE_FILLER_TOOL>();
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T )
|
2022-07-30 16:30:22 +00:00
|
|
|
zoneFillerTool->DirtyZone( static_cast<ZONE*>( item ) );
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( item->Type() == PCB_GROUP_T )
|
2022-02-24 09:59:54 +00:00
|
|
|
{
|
|
|
|
static_cast<PCB_GROUP*>( item )->RunOnChildren(
|
|
|
|
[&]( BOARD_ITEM* child )
|
|
|
|
{
|
2023-01-13 19:07:52 +00:00
|
|
|
dirtyIntersectingZones( child, aChangeType );
|
2022-02-24 09:59:54 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
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();
|
2022-02-24 09:59:54 +00:00
|
|
|
|
2022-07-11 02:31:56 +00:00
|
|
|
if( layers.test( Edge_Cuts ) || layers.test( Margin ) )
|
|
|
|
layers = LSET::PhysicalLayersMask();
|
2022-07-30 16:30:22 +00:00
|
|
|
else
|
|
|
|
layers &= LSET::AllCuMask();
|
2022-07-11 02:31:56 +00:00
|
|
|
|
2022-07-30 16:30:22 +00:00
|
|
|
if( layers.any() )
|
2022-02-24 09:59:54 +00:00
|
|
|
{
|
2022-07-30 16:30:22 +00:00
|
|
|
for( ZONE* zone : board->Zones() )
|
2022-02-24 09:59:54 +00:00
|
|
|
{
|
2022-07-30 16:30:22 +00:00
|
|
|
if( zone->GetIsRuleArea() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ( zone->GetLayerSet() & layers ).any()
|
2022-10-01 21:09:38 +00:00
|
|
|
&& zone->GetBoundingBox().Intersects( bbox ) )
|
2022-07-30 16:30:22 +00:00
|
|
|
{
|
|
|
|
zoneFillerTool->DirtyZone( zone );
|
|
|
|
}
|
2022-02-24 09:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-11-16 22:31:18 +00:00
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
2022-02-24 09:59:54 +00:00
|
|
|
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() );
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2023-05-12 21:03:54 +00:00
|
|
|
|
|
|
|
// Notification info
|
|
|
|
PICKED_ITEMS_LIST undoList;
|
2019-11-16 22:31:18 +00:00
|
|
|
bool itemsDeselected = false;
|
2022-12-27 01:57:58 +00:00
|
|
|
bool selectedModified = false;
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
// Dirty flags and lists
|
|
|
|
bool solderMaskDirty = false;
|
|
|
|
bool autofillZones = false;
|
|
|
|
std::vector<BOARD_ITEM*> staleTeardropPadsAndVias;
|
|
|
|
std::set<PCB_TRACK*> staleTeardropTracks;
|
|
|
|
|
2022-10-29 14:28:06 +00:00
|
|
|
if( Empty() )
|
|
|
|
return;
|
|
|
|
|
2023-06-07 13:35:25 +00:00
|
|
|
undoList.SetDescription( aMessage );
|
|
|
|
|
2022-11-30 12:18:58 +00:00
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
// Note: frame == nullptr happens in QA tests
|
2022-10-17 13:19:39 +00:00
|
|
|
|
2020-12-07 23:29:30 +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
|
2022-07-11 02:31:56 +00:00
|
|
|
&& !( aCommitFlags & ZONE_FILL_OP )
|
|
|
|
&& ( frame && frame->GetPcbNewSettings()->m_AutoRefillZones ) )
|
2022-02-24 09:59:54 +00:00
|
|
|
{
|
|
|
|
autofillZones = true;
|
|
|
|
|
|
|
|
for( ZONE* zone : board->Zones() )
|
|
|
|
zone->CacheBoundingBox();
|
|
|
|
}
|
|
|
|
|
2016-06-16 10:19:07 +00:00
|
|
|
for( COMMIT_LINE& ent : m_changes )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2016-08-18 14:28:04 +00:00
|
|
|
int changeType = ent.m_type & CHT_TYPE;
|
|
|
|
int changeFlags = ent.m_type & CHT_FLAGS;
|
2023-07-14 19:43:13 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( ent.m_item );
|
2016-06-20 09:21:37 +00:00
|
|
|
|
2022-01-05 02:28:04 +00:00
|
|
|
wxASSERT( ent.m_item );
|
2023-07-13 10:24:33 +00:00
|
|
|
wxCHECK2( boardItem, continue );
|
|
|
|
|
2023-07-14 19:43:13 +00:00
|
|
|
if( m_isBoardEditor )
|
2021-08-12 16:58:30 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2021-08-12 16:58:30 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 01:57:58 +00:00
|
|
|
if( boardItem->IsSelected() )
|
|
|
|
selectedModified = true;
|
|
|
|
|
2016-08-18 14:28:04 +00:00
|
|
|
switch( changeType )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2022-10-17 13:19:39 +00:00
|
|
|
case CHT_ADD:
|
2022-11-28 17:10:02 +00:00
|
|
|
if( selTool && selTool->GetEnteredGroup() && !boardItem->GetParentGroup()
|
|
|
|
&& PCB_GROUP::IsGroupableType( boardItem->Type() ) )
|
|
|
|
{
|
2022-10-17 13:19:39 +00:00
|
|
|
selTool->GetEnteredGroup()->AddItem( boardItem );
|
2022-11-28 17:10:02 +00:00
|
|
|
}
|
2022-10-17 13:19:39 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
|
|
|
undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::NEWITEM ) );
|
2016-08-18 14:28:04 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
2022-10-17 13:19:39 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
if( FOOTPRINT* parentFP = boardItem->GetParentFootprint() )
|
|
|
|
{
|
|
|
|
parentFP->Add( boardItem );
|
|
|
|
}
|
|
|
|
else
|
2020-02-05 12:49:12 +00:00
|
|
|
{
|
2022-10-17 13:19:39 +00:00
|
|
|
board->Add( boardItem, ADD_MODE::BULK_INSERT ); // handles connectivity
|
|
|
|
bulkAddedItems.push_back( boardItem );
|
2020-02-05 12:49:12 +00:00
|
|
|
}
|
2022-10-17 13:19:39 +00:00
|
|
|
}
|
2020-02-05 12:49:12 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
if( autofillZones && boardItem->Type() != PCB_MARKER_T )
|
2023-01-13 19:07:52 +00:00
|
|
|
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-02-24 09:59:54 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
break;
|
2020-07-13 21:35:05 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
case CHT_REMOVE:
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
FOOTPRINT* parentFP = boardItem->GetParentFootprint();
|
2022-10-17 13:19:39 +00:00
|
|
|
PCB_GROUP* parentGroup = boardItem->GetParentGroup();
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
2022-10-17 13:19:39 +00:00
|
|
|
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
|
|
|
{
|
2022-10-29 14:28:06 +00:00
|
|
|
if( selTool )
|
|
|
|
selTool->RemoveItemFromSel( boardItem, true /* quiet mode */ );
|
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
itemsDeselected = true;
|
|
|
|
}
|
2021-02-15 13:49:40 +00:00
|
|
|
|
2022-11-11 17:09:25 +00:00
|
|
|
if( parentGroup && !( parentGroup->GetFlags() & STRUCT_DELETED ) )
|
|
|
|
parentGroup->RemoveItem( boardItem );
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( parentFP && !( parentFP->GetFlags() & STRUCT_DELETED ) )
|
|
|
|
ent.m_parent = parentFP->m_Uuid;
|
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
if( autofillZones )
|
2023-01-13 19:07:52 +00:00
|
|
|
dirtyIntersectingZones( boardItem, changeType );
|
2018-09-26 12:41:14 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
switch( boardItem->Type() )
|
|
|
|
{
|
2023-06-15 19:37:07 +00:00
|
|
|
case PCB_FIELD_T:
|
2023-03-30 11:49:23 +00:00
|
|
|
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:
|
2023-07-15 16:37:17 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2022-10-17 13:19:39 +00:00
|
|
|
if( view )
|
|
|
|
view->Remove( boardItem );
|
2021-02-02 11:57:48 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP )
|
|
|
|
{
|
|
|
|
parentFP->Delete( boardItem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
board->Remove( boardItem, REMOVE_MODE::BULK );
|
|
|
|
bulkRemovedItems.push_back( boardItem );
|
|
|
|
}
|
2022-10-17 13:19:39 +00:00
|
|
|
}
|
2016-06-16 10:20:56 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
break;
|
2016-06-16 10:20:56 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
case PCB_GROUP_T:
|
|
|
|
if( view )
|
|
|
|
view->Remove( boardItem );
|
2018-09-17 13:14:23 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP )
|
|
|
|
{
|
|
|
|
parentFP->Remove( boardItem );
|
|
|
|
}
|
2022-10-17 13:19:39 +00:00
|
|
|
else
|
2020-12-07 23:29:30 +00:00
|
|
|
{
|
2022-10-17 13:19:39 +00:00
|
|
|
board->Remove( boardItem, REMOVE_MODE::BULK );
|
|
|
|
bulkRemovedItems.push_back( boardItem );
|
2020-12-07 23:29:30 +00:00
|
|
|
}
|
2016-06-20 09:21:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
break;
|
2020-11-27 23:33:48 +00:00
|
|
|
|
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;
|
2020-10-07 23:27:10 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
default: // other types do not need to (or should not) be handled
|
|
|
|
wxASSERT( false );
|
|
|
|
break;
|
|
|
|
}
|
2020-07-13 21:35:05 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-26 12:41:14 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
case CHT_MODIFY:
|
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
BOARD_ITEM* boardItemCopy = dynamic_cast<BOARD_ITEM*>( ent.m_copy );
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
2022-10-17 13:19:39 +00:00
|
|
|
{
|
|
|
|
ITEM_PICKER itemWrapper( nullptr, boardItem, UNDO_REDO::CHANGED );
|
2023-07-13 10:24:33 +00:00
|
|
|
wxASSERT( boardItemCopy );
|
|
|
|
itemWrapper.SetLink( boardItemCopy );
|
2022-10-17 13:19:39 +00:00
|
|
|
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
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
if( boardItemCopy )
|
|
|
|
connectivity->MarkItemNetAsDirty( boardItemCopy );
|
2022-02-14 17:19:28 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
connectivity->Update( boardItem );
|
|
|
|
}
|
2017-10-31 08:14:03 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( m_isBoardEditor && autofillZones )
|
2022-10-17 13:19:39 +00:00
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
dirtyIntersectingZones( boardItemCopy, changeType ); // before
|
|
|
|
dirtyIntersectingZones( boardItem, changeType ); // after
|
2022-10-17 13:19:39 +00:00
|
|
|
}
|
2020-10-08 09:59:17 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
if( view )
|
|
|
|
view->Update( boardItem );
|
2022-02-24 09:59:54 +00:00
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
itemsChanged.push_back( boardItem );
|
2017-10-31 08:14:03 +00:00
|
|
|
|
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;
|
2017-10-31 08:14:03 +00:00
|
|
|
|
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:
|
2023-07-13 10:24:33 +00:00
|
|
|
UNIMPLEMENTED_FOR( boardItem->GetClass() );
|
2022-10-17 13:19:39 +00:00
|
|
|
break;
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
2023-06-27 15:52:50 +00:00
|
|
|
|
|
|
|
boardItem->ClearEditFlags();
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 23:29:30 +00:00
|
|
|
if( bulkAddedItems.size() > 0 )
|
|
|
|
board->FinalizeBulkAdd( bulkAddedItems );
|
|
|
|
|
|
|
|
if( bulkRemovedItems.size() > 0 )
|
|
|
|
board->FinalizeBulkRemove( bulkRemovedItems );
|
|
|
|
|
|
|
|
if( itemsChanged.size() > 0 )
|
|
|
|
board->OnItemsChanged( itemsChanged );
|
|
|
|
|
2022-02-24 09:59:54 +00:00
|
|
|
if( m_isBoardEditor )
|
2017-09-28 16:38:54 +00:00
|
|
|
{
|
2019-05-25 01:55:40 +00:00
|
|
|
size_t num_changes = m_changes.size();
|
|
|
|
|
2022-11-30 12:18:58 +00:00
|
|
|
if( aCommitFlags & SKIP_CONNECTIVITY )
|
|
|
|
{
|
|
|
|
connectivity->ClearRatsnest();
|
|
|
|
connectivity->ClearLocalRatsnest();
|
|
|
|
}
|
|
|
|
else
|
2022-02-14 17:19:28 +00:00
|
|
|
{
|
|
|
|
connectivity->RecalculateRatsnest( this );
|
2022-09-29 16:07:42 +00:00
|
|
|
board->UpdateRatsnestExclusions();
|
2022-09-03 18:29:02 +00:00
|
|
|
connectivity->ClearLocalRatsnest();
|
2022-11-30 12:18:58 +00:00
|
|
|
|
|
|
|
if( frame )
|
|
|
|
frame->GetCanvas()->RedrawRatsnest();
|
2022-02-14 17:19:28 +00:00
|
|
|
}
|
2021-07-30 16:08:12 +00:00
|
|
|
|
2022-11-30 12:18:58 +00:00
|
|
|
if( solderMaskDirty )
|
2022-10-29 14:28:06 +00:00
|
|
|
{
|
2022-11-30 12:18:58 +00:00
|
|
|
if( frame )
|
2022-10-29 14:28:06 +00:00
|
|
|
frame->HideSolderMask();
|
|
|
|
}
|
2019-05-25 01:55:40 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
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
|
2022-02-24 09:59:54 +00:00
|
|
|
for( size_t i = num_changes; i < m_changes.size(); ++i )
|
2019-05-25 01:55:40 +00:00
|
|
|
{
|
2022-02-24 09:59:54 +00:00
|
|
|
COMMIT_LINE& ent = m_changes[i];
|
2023-07-13 10:24:33 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( ent.m_item );
|
|
|
|
BOARD_ITEM* boardItemCopy = dynamic_cast<BOARD_ITEM*>( ent.m_copy );
|
|
|
|
|
|
|
|
wxCHECK2( boardItem, continue );
|
2019-05-25 01:55:40 +00:00
|
|
|
|
2022-02-25 13:05:25 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
2022-02-24 09:59:54 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
ITEM_PICKER itemWrapper( nullptr, boardItem, convert( ent.m_type & CHT_TYPE ) );
|
2023-07-13 10:24:33 +00:00
|
|
|
wxASSERT( boardItemCopy );
|
|
|
|
itemWrapper.SetLink( boardItemCopy );
|
2022-02-24 09:59:54 +00:00
|
|
|
undoList.PushItem( itemWrapper );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ent.m_copy;
|
2019-05-25 01:55:40 +00:00
|
|
|
}
|
2022-02-24 09:59:54 +00:00
|
|
|
|
|
|
|
if( view )
|
2023-05-12 21:03:54 +00:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
2019-05-25 01:55:40 +00:00
|
|
|
}
|
2017-09-28 16:38:54 +00:00
|
|
|
}
|
2017-06-29 18:39:11 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( frame )
|
2022-02-25 13:05:25 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
if( !( aCommitFlags & SKIP_UNDO ) )
|
|
|
|
{
|
|
|
|
if( aCommitFlags & APPEND_UNDO )
|
|
|
|
frame->AppendCopyToUndoList( undoList, UNDO_REDO::UNSPECIFIED );
|
|
|
|
else
|
|
|
|
frame->SaveCopyInUndoList( undoList, UNDO_REDO::UNSPECIFIED );
|
|
|
|
}
|
2022-02-25 13:05:25 +00:00
|
|
|
}
|
2019-05-25 01:55:40 +00:00
|
|
|
|
2019-11-16 22:31:18 +00:00
|
|
|
m_toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } );
|
|
|
|
|
|
|
|
if( itemsDeselected )
|
|
|
|
m_toolMgr->PostEvent( EVENTS::UnselectedEvent );
|
2019-05-25 01:55:40 +00:00
|
|
|
|
2022-02-24 09:59:54 +00:00
|
|
|
if( autofillZones )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( PCB_ACTIONS::zoneFillDirty );
|
2022-02-24 09:59:54 +00:00
|
|
|
|
2022-12-27 01:57:58 +00:00
|
|
|
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
|
2022-07-24 15:49:46 +00:00
|
|
|
frame->Update3DView( true, frame->GetPcbNewSettings()->m_Display.m_Live3DRefresh );
|
2021-08-04 12:51:38 +00:00
|
|
|
}
|
2018-04-09 19:56:27 +00:00
|
|
|
|
2016-06-16 10:19:07 +00:00
|
|
|
clear();
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* BOARD_COMMIT::parentObject( EDA_ITEM* aItem ) const
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem ) )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( FOOTPRINT* parentFP = boardItem->GetParentFootprint() )
|
|
|
|
return parentFP;
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-15 23:51:42 +00:00
|
|
|
EDA_ITEM* BOARD_COMMIT::makeImage( EDA_ITEM* aItem ) const
|
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
EDA_ITEM* clone = aItem->Clone();
|
|
|
|
|
|
|
|
if( BOARD_ITEM* board_item = dynamic_cast<BOARD_ITEM*>( clone ) )
|
|
|
|
board_item->SetParentGroup( nullptr );
|
2022-11-15 23:51:42 +00:00
|
|
|
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 15:57:21 +00:00
|
|
|
void BOARD_COMMIT::Revert()
|
|
|
|
{
|
2022-09-29 16:07:42 +00:00
|
|
|
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
|
|
|
|
2022-12-10 22:05:33 +00:00
|
|
|
board->IncrementTimeStamp(); // clear caches
|
|
|
|
|
2020-12-07 23:29:30 +00:00
|
|
|
std::vector<BOARD_ITEM*> bulkAddedItems;
|
|
|
|
std::vector<BOARD_ITEM*> bulkRemovedItems;
|
|
|
|
std::vector<BOARD_ITEM*> itemsChanged;
|
|
|
|
|
2016-06-21 15:35:30 +00:00
|
|
|
for( auto it = m_changes.rbegin(); it != m_changes.rend(); ++it )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2016-06-21 15:35:30 +00:00
|
|
|
COMMIT_LINE& ent = *it;
|
2023-07-13 10:24:33 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( ent.m_item );
|
|
|
|
int changeType = ent.m_type & CHT_TYPE;
|
|
|
|
int changeFlags = ent.m_type & CHT_FLAGS;
|
|
|
|
|
|
|
|
wxCHECK2( boardItem, continue );
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2017-12-14 16:07:44 +00:00
|
|
|
switch( changeType )
|
2016-06-16 10:19:58 +00:00
|
|
|
{
|
2016-06-21 14:54:14 +00:00
|
|
|
case CHT_ADD:
|
2017-12-14 16:07:44 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
break;
|
2016-06-21 14:54:14 +00:00
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
view->Remove( boardItem );
|
|
|
|
connectivity->Remove( boardItem );
|
2023-07-15 16:37:17 +00:00
|
|
|
|
|
|
|
if( FOOTPRINT* parentFP = boardItem->GetParentFootprint() )
|
|
|
|
{
|
|
|
|
parentFP->Remove( boardItem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
board->Remove( boardItem, REMOVE_MODE::BULK );
|
|
|
|
bulkRemovedItems.push_back( boardItem );
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:54:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHT_REMOVE:
|
2017-12-14 16:07:44 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
break;
|
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
view->Add( boardItem );
|
|
|
|
connectivity->Add( boardItem );
|
2023-07-15 16:37:17 +00:00
|
|
|
|
|
|
|
if( FOOTPRINT* parentFP = dynamic_cast<FOOTPRINT*>( board->GetItem( ent.m_parent ) ) )
|
|
|
|
{
|
|
|
|
parentFP->Add( boardItem, ADD_MODE::INSERT );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
board->Add( boardItem, ADD_MODE::INSERT );
|
|
|
|
bulkAddedItems.push_back( boardItem );
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:54:14 +00:00
|
|
|
break;
|
|
|
|
|
2016-06-16 10:19:58 +00:00
|
|
|
case CHT_MODIFY:
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
view->Remove( boardItem );
|
|
|
|
connectivity->Remove( boardItem );
|
2016-06-21 14:54:14 +00:00
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
BOARD_ITEM* boardItemCopy = dynamic_cast<BOARD_ITEM*>( ent.m_copy );
|
|
|
|
wxASSERT( boardItemCopy );
|
|
|
|
boardItem->SwapItemData( boardItemCopy );
|
2016-06-21 14:54:14 +00:00
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
if( boardItem->Type() == PCB_GROUP_T )
|
2022-11-15 23:51:42 +00:00
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
PCB_GROUP* group = static_cast<PCB_GROUP*>( boardItem );
|
2022-11-15 23:51:42 +00:00
|
|
|
|
|
|
|
group->RunOnChildren( [&]( BOARD_ITEM* child )
|
|
|
|
{
|
|
|
|
child->SetParentGroup( group );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
view->Add( boardItem );
|
|
|
|
connectivity->Add( boardItem );
|
|
|
|
board->OnItemChanged( boardItem );
|
|
|
|
itemsChanged.push_back( boardItem );
|
2020-12-07 23:29:30 +00:00
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
delete ent.m_copy;
|
2016-06-16 10:19:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2016-06-16 10:19:58 +00:00
|
|
|
default:
|
2023-07-13 10:24:33 +00:00
|
|
|
UNIMPLEMENTED_FOR( boardItem->GetClass() );
|
2016-05-10 15:57:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-06-27 15:52:50 +00:00
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
boardItem->ClearEditFlags();
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
2016-06-16 10:19:58 +00:00
|
|
|
|
2020-12-07 23:29:30 +00:00
|
|
|
if( bulkAddedItems.size() > 0 )
|
|
|
|
board->FinalizeBulkAdd( bulkAddedItems );
|
|
|
|
|
|
|
|
if( bulkRemovedItems.size() > 0 )
|
|
|
|
board->FinalizeBulkRemove( bulkRemovedItems );
|
|
|
|
|
|
|
|
if( itemsChanged.size() > 0 )
|
|
|
|
board->OnItemsChanged( itemsChanged );
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( m_isBoardEditor )
|
2022-09-29 16:07:42 +00:00
|
|
|
{
|
2017-06-29 18:39:11 +00:00
|
|
|
connectivity->RecalculateRatsnest();
|
2022-09-29 16:07:42 +00:00
|
|
|
board->UpdateRatsnestExclusions();
|
|
|
|
}
|
2016-06-21 14:54:14 +00:00
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2019-05-11 10:06:28 +00:00
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
2023-06-27 15:52:50 +00:00
|
|
|
// Property panel needs to know about the reselect
|
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
|
2016-06-16 10:19:58 +00:00
|
|
|
clear();
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
2020-08-11 19:37:07 +00:00
|
|
|
|