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
|
2021-12-26 00:36:12 +00:00
|
|
|
* Copyright (C) 2020-2021 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
|
|
|
|
*/
|
|
|
|
|
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>
|
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>
|
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>
|
2021-12-26 00:36:12 +00:00
|
|
|
#include <pcbnew_settings.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
|
|
|
|
2021-07-31 00:50:42 +00:00
|
|
|
BOARD_COMMIT::BOARD_COMMIT( TOOL_MANAGER* aToolMgr ) :
|
|
|
|
m_toolMgr( aToolMgr ),
|
|
|
|
m_isFootprintEditor( false ),
|
|
|
|
m_resolveNetConflicts( false )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-23 21:42:56 +00:00
|
|
|
BOARD_COMMIT::BOARD_COMMIT( PCB_TOOL_BASE* aTool ) :
|
|
|
|
m_resolveNetConflicts( false )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2016-06-16 10:19:07 +00:00
|
|
|
m_toolMgr = aTool->GetManager();
|
2020-11-08 21:29:04 +00:00
|
|
|
m_isFootprintEditor = aTool->IsFootprintEditor();
|
2016-06-16 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-23 21:42:56 +00:00
|
|
|
BOARD_COMMIT::BOARD_COMMIT( EDA_DRAW_FRAME* aFrame ) :
|
|
|
|
m_resolveNetConflicts( false )
|
2016-06-16 10:19:07 +00:00
|
|
|
{
|
|
|
|
m_toolMgr = aFrame->GetToolManager();
|
2020-11-08 21:29:04 +00:00
|
|
|
m_isFootprintEditor = aFrame->IsType( FRAME_FOOTPRINT_EDITOR );
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOARD_COMMIT::~BOARD_COMMIT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
|
2019-11-16 22:31:18 +00:00
|
|
|
COMMIT& BOARD_COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType )
|
|
|
|
{
|
|
|
|
// if aItem belongs a footprint, the full footprint will be saved
|
|
|
|
// because undo/redo does not handle "sub items" modifications
|
2020-11-13 12:21:02 +00:00
|
|
|
if( aItem && aItem->Type() != PCB_FOOTPRINT_T && aChangeType == CHT_MODIFY )
|
2019-11-16 22:31:18 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* item = aItem->GetParent();
|
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
if( item && item->Type() == PCB_FOOTPRINT_T ) // means aItem belongs a footprint
|
2019-11-16 22:31:18 +00:00
|
|
|
aItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return COMMIT::Stage( aItem, aChangeType );
|
|
|
|
}
|
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
|
2019-11-16 22:31:18 +00:00
|
|
|
COMMIT& BOARD_COMMIT::Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType )
|
|
|
|
{
|
|
|
|
return COMMIT::Stage( container, aChangeType );
|
|
|
|
}
|
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
COMMIT& BOARD_COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO aModFlag )
|
2019-11-16 22:31:18 +00:00
|
|
|
{
|
|
|
|
return COMMIT::Stage( aItems, aModFlag );
|
|
|
|
}
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
|
2018-04-09 19:56:27 +00:00
|
|
|
void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool aSetDirtyBit )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
|
|
|
// Objects potentially interested in changes:
|
2019-11-16 22:31:18 +00:00
|
|
|
PICKED_ITEMS_LIST undoList;
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
BOARD* board = (BOARD*) m_toolMgr->GetModel();
|
2021-08-04 12:51:38 +00:00
|
|
|
PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
|
2019-11-16 22:31:18 +00:00
|
|
|
auto connectivity = board->GetConnectivity();
|
|
|
|
std::set<EDA_ITEM*> savedModules;
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2019-11-16 22:31:18 +00:00
|
|
|
bool itemsDeselected = false;
|
2021-08-12 16:58:30 +00:00
|
|
|
bool solderMaskDirty = false;
|
2016-05-10 15:57:21 +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;
|
|
|
|
|
2016-06-16 10:19:07 +00:00
|
|
|
if( Empty() )
|
|
|
|
return;
|
2016-05-10 15:57:21 +00:00
|
|
|
|
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;
|
2016-06-20 09:21:37 +00:00
|
|
|
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( ent.m_item );
|
|
|
|
|
2016-06-16 10:19:07 +00:00
|
|
|
// Module items need to be saved in the undo buffer before modification
|
2020-11-08 21:29:04 +00:00
|
|
|
if( m_isFootprintEditor )
|
2016-06-16 10:19:07 +00:00
|
|
|
{
|
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 )
|
2016-06-20 09:20:22 +00:00
|
|
|
ent.m_item = ent.m_item->GetParent();
|
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
|
2016-06-20 09:20:22 +00:00
|
|
|
if( savedModules.count( ent.m_item ) == 0 )
|
|
|
|
{
|
|
|
|
if( !ent.m_copy )
|
|
|
|
{
|
2017-10-19 07:49:09 +00:00
|
|
|
wxASSERT( changeType != CHT_MODIFY ); // too late to make a copy..
|
2016-06-20 09:20:22 +00:00
|
|
|
ent.m_copy = ent.m_item->Clone();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-08-04 12:51:38 +00:00
|
|
|
if( aCreateUndoEntry && frame )
|
2017-03-03 12:41:41 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER itemWrapper( nullptr, ent.m_item, UNDO_REDO::CHANGED );
|
2017-03-03 12:41:41 +00:00
|
|
|
itemWrapper.SetLink( ent.m_copy );
|
|
|
|
undoList.PushItem( itemWrapper );
|
2020-08-26 18:04:32 +00:00
|
|
|
frame->SaveCopyInUndoList( undoList, UNDO_REDO::CHANGED );
|
2017-03-03 12:41:41 +00:00
|
|
|
}
|
2016-06-20 09:21:37 +00:00
|
|
|
|
2016-06-20 09:20:22 +00:00
|
|
|
savedModules.insert( ent.m_item );
|
2020-11-13 15:15:52 +00:00
|
|
|
static_cast<FOOTPRINT*>( ent.m_item )->SetLastEditTime();
|
2016-06-20 09:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2021-08-12 16:58:30 +00:00
|
|
|
if( boardItem->Type() == PCB_VIA_T || boardItem->Type() == PCB_FOOTPRINT_T
|
|
|
|
|| boardItem->IsOnLayer( F_Mask ) || boardItem->IsOnLayer( B_Mask ) )
|
|
|
|
{
|
|
|
|
solderMaskDirty = true;
|
|
|
|
}
|
|
|
|
|
2016-08-18 14:28:04 +00:00
|
|
|
switch( changeType )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
|
|
|
case CHT_ADD:
|
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
if( m_isFootprintEditor )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2020-10-21 03:48:06 +00:00
|
|
|
// footprints inside footprints are not supported yet
|
2020-11-13 12:21:02 +00:00
|
|
|
wxASSERT( boardItem->Type() != PCB_FOOTPRINT_T );
|
2016-08-18 14:28:04 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
boardItem->SetParent( board->Footprints().front() );
|
2018-03-05 15:37:39 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
2020-11-12 23:50:33 +00:00
|
|
|
board->Footprints().front()->Add( boardItem );
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
2021-04-28 22:53:31 +00:00
|
|
|
else if( boardItem->Type() == PCB_PAD_T ||
|
|
|
|
boardItem->Type() == PCB_FP_TEXT_T ||
|
2020-10-04 14:19:33 +00:00
|
|
|
boardItem->Type() == PCB_FP_SHAPE_T ||
|
2021-12-04 23:52:00 +00:00
|
|
|
boardItem->Type() == PCB_FP_DIM_ALIGNED_T ||
|
|
|
|
boardItem->Type() == PCB_FP_DIM_LEADER_T ||
|
|
|
|
boardItem->Type() == PCB_FP_DIM_CENTER_T ||
|
|
|
|
boardItem->Type() == PCB_FP_DIM_RADIAL_T ||
|
|
|
|
boardItem->Type() == PCB_FP_DIM_ORTHOGONAL_T ||
|
2020-11-11 23:05:59 +00:00
|
|
|
boardItem->Type() == PCB_FP_ZONE_T )
|
2020-02-05 12:49:12 +00:00
|
|
|
{
|
|
|
|
wxASSERT( boardItem->GetParent() &&
|
2020-11-13 12:21:02 +00:00
|
|
|
boardItem->GetParent()->Type() == PCB_FOOTPRINT_T );
|
2020-02-05 12:49:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aCreateUndoEntry )
|
2020-08-26 18:04:32 +00:00
|
|
|
undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::NEWITEM ) );
|
2020-02-05 12:49:12 +00:00
|
|
|
|
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
2020-12-07 23:29:30 +00:00
|
|
|
{
|
|
|
|
board->Add( boardItem, ADD_MODE::BULK_INSERT ); // handles connectivity
|
|
|
|
bulkAddedItems.push_back( boardItem );
|
|
|
|
}
|
2020-02-05 12:49:12 +00:00
|
|
|
}
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2021-07-30 16:08:12 +00:00
|
|
|
if( view && boardItem->Type() != PCB_NETINFO_T )
|
2020-07-13 21:35:05 +00:00
|
|
|
view->Add( boardItem );
|
|
|
|
|
2016-05-10 15:57:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CHT_REMOVE:
|
|
|
|
{
|
2021-02-15 13:49:40 +00:00
|
|
|
PCB_GROUP* parentGroup = boardItem->GetParentGroup();
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !m_isFootprintEditor && aCreateUndoEntry )
|
2020-08-26 18:04:32 +00:00
|
|
|
undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::DELETED ) );
|
2018-09-26 12:41:14 +00:00
|
|
|
|
2019-11-16 22:31:18 +00:00
|
|
|
if( boardItem->IsSelected() )
|
|
|
|
{
|
|
|
|
selTool->RemoveItemFromSel( boardItem, true /* quiet mode */ );
|
|
|
|
itemsDeselected = true;
|
|
|
|
}
|
|
|
|
|
2016-06-16 10:20:56 +00:00
|
|
|
switch( boardItem->Type() )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2021-02-02 11:57:48 +00:00
|
|
|
// Footprint items
|
2016-06-16 10:20:56 +00:00
|
|
|
case PCB_PAD_T:
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
|
|
|
case PCB_FP_TEXT_T:
|
2021-12-04 23:52:00 +00:00
|
|
|
case PCB_FP_DIM_ALIGNED_T:
|
|
|
|
case PCB_FP_DIM_LEADER_T:
|
|
|
|
case PCB_FP_DIM_CENTER_T:
|
|
|
|
case PCB_FP_DIM_RADIAL_T:
|
|
|
|
case PCB_FP_DIM_ORTHOGONAL_T:
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
2021-02-02 11:57:48 +00:00
|
|
|
// This level can only handle footprint children in the footprint editor as
|
|
|
|
// only in that case has the entire footprint (and all its children) already
|
|
|
|
// been saved for undo.
|
2020-11-08 21:29:04 +00:00
|
|
|
wxASSERT( m_isFootprintEditor );
|
2016-06-16 10:20:56 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( boardItem->Type() == PCB_FP_TEXT_T )
|
2016-06-16 10:20:56 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* text = static_cast<FP_TEXT*>( boardItem );
|
2016-06-16 10:20:56 +00:00
|
|
|
|
2018-09-15 23:30:10 +00:00
|
|
|
// don't allow deletion of Reference or Value
|
2020-10-04 23:34:59 +00:00
|
|
|
if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
|
2018-09-15 23:30:10 +00:00
|
|
|
break;
|
2016-06-16 10:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 13:49:40 +00:00
|
|
|
if( parentGroup && !( parentGroup->GetFlags() & STRUCT_DELETED ) )
|
|
|
|
parentGroup->RemoveItem( boardItem );
|
2021-02-02 11:57:48 +00:00
|
|
|
|
2021-07-30 16:08:12 +00:00
|
|
|
if( view )
|
|
|
|
view->Remove( boardItem );
|
2016-06-16 10:20:56 +00:00
|
|
|
|
2018-09-15 23:30:10 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem->GetParent() );
|
2020-11-13 12:21:02 +00:00
|
|
|
wxASSERT( footprint && footprint->Type() == PCB_FOOTPRINT_T );
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Delete( boardItem );
|
2016-06-16 10:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2016-06-20 09:21:37 +00:00
|
|
|
// Board items
|
2020-11-29 20:00:16 +00:00
|
|
|
case PCB_SHAPE_T: // a shape (normally not on copper layers)
|
|
|
|
case PCB_TEXT_T: // a 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)
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
2021-07-13 18:46:33 +00:00
|
|
|
case PCB_DIM_RADIAL_T:
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
2020-11-29 20:00:16 +00:00
|
|
|
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
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2021-07-30 16:08:12 +00:00
|
|
|
if( view )
|
|
|
|
view->Remove( boardItem );
|
2016-08-18 14:28:04 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
2020-12-07 23:29:30 +00:00
|
|
|
{
|
|
|
|
board->Remove( boardItem, REMOVE_MODE::BULK );
|
|
|
|
bulkRemovedItems.push_back( boardItem );
|
|
|
|
}
|
2016-08-18 14:28:04 +00:00
|
|
|
|
2016-06-16 10:20:56 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2016-06-20 09:21:37 +00:00
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
// No support for nested footprints (yet)
|
2020-11-08 21:29:04 +00:00
|
|
|
wxASSERT( !m_isFootprintEditor );
|
2016-06-20 09:21:37 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
|
2021-07-30 16:08:12 +00:00
|
|
|
|
|
|
|
if( view )
|
|
|
|
view->Remove( footprint );
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->ClearFlags();
|
2018-09-17 13:14:23 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
2020-12-07 23:29:30 +00:00
|
|
|
{
|
|
|
|
board->Remove( footprint, REMOVE_MODE::BULK ); // handles connectivity
|
|
|
|
bulkRemovedItems.push_back( footprint );
|
|
|
|
}
|
2016-06-20 09:21:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-09-26 00:52:03 +00:00
|
|
|
case PCB_GROUP_T:
|
2021-07-30 16:08:12 +00:00
|
|
|
if( view )
|
|
|
|
view->Remove( boardItem );
|
2020-11-27 23:33:48 +00:00
|
|
|
|
2020-07-13 21:35:05 +00:00
|
|
|
if( !( changeFlags & CHT_DONE ) )
|
2020-10-07 23:27:10 +00:00
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
if( m_isFootprintEditor )
|
|
|
|
board->GetFirstFootprint()->Remove( boardItem );
|
2020-10-07 23:27:10 +00:00
|
|
|
else
|
2020-12-07 23:29:30 +00:00
|
|
|
{
|
|
|
|
board->Remove( boardItem, REMOVE_MODE::BULK );
|
|
|
|
bulkRemovedItems.push_back( boardItem );
|
|
|
|
}
|
2020-10-07 23:27:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Metadata items
|
|
|
|
case PCB_NETINFO_T:
|
2020-12-07 23:29:30 +00:00
|
|
|
board->Remove( boardItem, REMOVE_MODE::BULK );
|
|
|
|
bulkRemovedItems.push_back( boardItem );
|
2020-07-13 21:35:05 +00:00
|
|
|
break;
|
|
|
|
|
2016-06-16 10:20:56 +00:00
|
|
|
default: // other types do not need to (or should not) be handled
|
2017-10-19 07:49:09 +00:00
|
|
|
wxASSERT( false );
|
2016-06-16 10:20:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-26 12:41:14 +00:00
|
|
|
|
2016-05-10 15:57:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CHT_MODIFY:
|
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !m_isFootprintEditor && aCreateUndoEntry )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER itemWrapper( nullptr, boardItem, UNDO_REDO::CHANGED );
|
2017-10-19 07:49:09 +00:00
|
|
|
wxASSERT( ent.m_copy );
|
2016-05-10 15:57:21 +00:00
|
|
|
itemWrapper.SetLink( ent.m_copy );
|
|
|
|
undoList.PushItem( itemWrapper );
|
|
|
|
}
|
|
|
|
|
2017-10-31 08:14:03 +00:00
|
|
|
if( ent.m_copy )
|
|
|
|
connectivity->MarkItemNetAsDirty( static_cast<BOARD_ITEM*>( ent.m_copy ) );
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Update( boardItem );
|
2020-10-08 09:59:17 +00:00
|
|
|
|
2021-07-30 16:08:12 +00:00
|
|
|
if( view )
|
2020-10-08 09:59:17 +00:00
|
|
|
{
|
2021-07-30 16:08:12 +00:00
|
|
|
view->Update( boardItem );
|
|
|
|
|
|
|
|
if( m_isFootprintEditor )
|
|
|
|
{
|
|
|
|
static_cast<FOOTPRINT*>( boardItem )->RunOnChildren(
|
|
|
|
[&]( BOARD_ITEM* aChild )
|
|
|
|
{
|
|
|
|
view->Update( aChild );
|
|
|
|
});
|
|
|
|
}
|
2020-10-08 09:59:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 23:29:30 +00:00
|
|
|
itemsChanged.push_back( boardItem );
|
2017-10-31 08:14:03 +00:00
|
|
|
|
|
|
|
// if no undo entry is needed, the copy would create a memory leak
|
|
|
|
if( !aCreateUndoEntry )
|
|
|
|
delete ent.m_copy;
|
|
|
|
|
2016-05-10 15:57:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2017-10-19 07:49:09 +00:00
|
|
|
wxASSERT( false );
|
2016-05-10 15:57:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
2020-11-29 20:00:16 +00:00
|
|
|
if( !m_isFootprintEditor )
|
2017-09-28 16:38:54 +00:00
|
|
|
{
|
2019-05-25 01:55:40 +00:00
|
|
|
size_t num_changes = m_changes.size();
|
|
|
|
|
2021-03-23 21:42:56 +00:00
|
|
|
if( m_resolveNetConflicts )
|
|
|
|
connectivity->PropagateNets( this, PROPAGATE_MODE::RESOLVE_CONFLICTS );
|
|
|
|
|
2019-05-25 01:55:40 +00:00
|
|
|
connectivity->RecalculateRatsnest( this );
|
2018-12-30 19:17:00 +00:00
|
|
|
connectivity->ClearDynamicRatsnest();
|
2021-07-30 16:08:12 +00:00
|
|
|
|
2021-12-24 00:03:51 +00:00
|
|
|
if( frame && solderMaskDirty )
|
2021-08-12 16:58:30 +00:00
|
|
|
frame->HideSolderMask();
|
2021-12-24 00:03:51 +00:00
|
|
|
|
|
|
|
if( frame )
|
2021-07-30 16:08:12 +00:00
|
|
|
frame->GetCanvas()->RedrawRatsnest();
|
2019-05-25 01:55:40 +00:00
|
|
|
|
|
|
|
if( m_changes.size() > num_changes )
|
|
|
|
{
|
|
|
|
for( size_t i = num_changes; i < m_changes.size(); ++i )
|
|
|
|
{
|
|
|
|
COMMIT_LINE& ent = m_changes[i];
|
|
|
|
|
|
|
|
// This should only be modifications from the connectivity algo
|
|
|
|
wxASSERT( ( ent.m_type & CHT_TYPE ) == CHT_MODIFY );
|
|
|
|
|
2021-07-30 16:08:12 +00:00
|
|
|
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( ent.m_item );
|
2019-05-25 01:55:40 +00:00
|
|
|
|
|
|
|
if( aCreateUndoEntry )
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER itemWrapper( nullptr, boardItem, UNDO_REDO::CHANGED );
|
2019-05-25 01:55:40 +00:00
|
|
|
wxASSERT( ent.m_copy );
|
|
|
|
itemWrapper.SetLink( ent.m_copy );
|
|
|
|
undoList.PushItem( itemWrapper );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ent.m_copy;
|
|
|
|
}
|
|
|
|
|
2021-07-30 16:08:12 +00:00
|
|
|
if( view )
|
|
|
|
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
|
|
|
|
2021-08-04 12:51:38 +00:00
|
|
|
if( !m_isFootprintEditor && aCreateUndoEntry && frame )
|
2020-08-26 18:04:32 +00:00
|
|
|
frame->SaveCopyInUndoList( undoList, UNDO_REDO::UNSPECIFIED );
|
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
|
|
|
|
2021-08-04 12:51:38 +00:00
|
|
|
if( frame )
|
|
|
|
{
|
|
|
|
if( aSetDirtyBit )
|
|
|
|
frame->OnModify();
|
|
|
|
else
|
2021-12-26 00:36:12 +00:00
|
|
|
frame->Update3DView( true, frame->Settings().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
|
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
|
|
|
case PCB_FP_TEXT_T:
|
2021-12-04 23:52:00 +00:00
|
|
|
case PCB_FP_DIM_ALIGNED_T:
|
|
|
|
case PCB_FP_DIM_LEADER_T:
|
|
|
|
case PCB_FP_DIM_CENTER_T:
|
|
|
|
case PCB_FP_DIM_RADIAL_T:
|
|
|
|
case PCB_FP_DIM_ORTHOGONAL_T:
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
2016-05-10 15:57:21 +00:00
|
|
|
return aItem->GetParent();
|
2019-10-26 15:49:29 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2020-11-13 15:15:52 +00:00
|
|
|
wxASSERT( !dynamic_cast<FOOTPRINT*>( aItem->GetParent() ) );
|
2016-05-10 15:57:21 +00:00
|
|
|
return aItem;
|
2019-10-26 15:49:29 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BOARD_COMMIT::Revert()
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST undoList;
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
2016-06-16 10:19:58 +00:00
|
|
|
BOARD* board = (BOARD*) m_toolMgr->GetModel();
|
2017-03-22 13:43:10 +00:00
|
|
|
auto connectivity = board->GetConnectivity();
|
2016-05-10 15:57:21 +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;
|
|
|
|
|
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;
|
2016-06-16 10:19:58 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( ent.m_item );
|
|
|
|
BOARD_ITEM* copy = static_cast<BOARD_ITEM*>( ent.m_copy );
|
2017-12-14 16:07:44 +00:00
|
|
|
int changeType = ent.m_type & CHT_TYPE;
|
|
|
|
int changeFlags = ent.m_type & CHT_FLAGS;
|
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
|
|
|
|
|
|
|
view->Remove( item );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Remove( item );
|
2020-12-07 23:29:30 +00:00
|
|
|
board->Remove( item, REMOVE_MODE::BULK );
|
|
|
|
bulkRemovedItems.push_back( item );
|
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;
|
|
|
|
|
2016-06-21 14:54:14 +00:00
|
|
|
view->Add( item );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Add( item );
|
2020-12-07 23:29:30 +00:00
|
|
|
board->Add( item, ADD_MODE::INSERT );
|
|
|
|
bulkAddedItems.push_back( item );
|
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
|
|
|
{
|
2016-06-16 10:19:58 +00:00
|
|
|
view->Remove( item );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Remove( item );
|
2016-06-21 14:54:14 +00:00
|
|
|
|
2016-05-10 15:57:21 +00:00
|
|
|
item->SwapData( copy );
|
2016-06-21 14:54:14 +00:00
|
|
|
|
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 );
|
2020-12-07 23:29:30 +00:00
|
|
|
itemsChanged.push_back( item );
|
|
|
|
|
2016-06-20 09:25:40 +00:00
|
|
|
delete 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:
|
2017-10-19 07:49:09 +00:00
|
|
|
wxASSERT( false );
|
2016-05-10 15:57:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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 );
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if ( !m_isFootprintEditor )
|
2017-06-29 18:39:11 +00:00
|
|
|
connectivity->RecalculateRatsnest();
|
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();
|
|
|
|
|
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
|
|
|
|