Sync pcbnew selection with selected items after plugin is run

This commit is contained in:
qu1ck 2023-02-11 01:03:19 -08:00 committed by Jon Evans
parent 0f18a36f8f
commit 9f10c142c4
3 changed files with 53 additions and 18 deletions

View File

@ -2344,3 +2344,21 @@ void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer,
}
const std::set<BOARD_ITEM*> BOARD::GetItemSet()
{
std::set<BOARD_ITEM*> items;
#define INSERT_ITEMS( collection ) \
for( BOARD_ITEM * item : collection ) \
items.insert( item );
INSERT_ITEMS( m_tracks )
INSERT_ITEMS( m_footprints )
INSERT_ITEMS( m_drawings )
INSERT_ITEMS( m_zones )
INSERT_ITEMS( m_markers )
#undef INSERT_ITEMS
return items;
}

View File

@ -316,6 +316,8 @@ public:
MARKERS& Markers() { return m_markers; }
const MARKERS& Markers() const { return m_markers; }
const std::set<BOARD_ITEM*> GetItemSet();
/**
* The groups must maintain the following invariants. These are checked by
* GroupsSanityCheck():

View File

@ -37,6 +37,8 @@
#include <tool/action_menu.h>
#include <tool/action_toolbar.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <tools/pcb_selection_tool.h>
#include <pcb_painter.h>
#include <wx/msgdlg.h>
#include "../../scripting/python_scripting.h"
@ -281,23 +283,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
PICKED_ITEMS_LIST deletedItemsList;
// The list of existing items after running the action script
std::set<BOARD_ITEM*> currItemList;
// Append tracks:
for( PCB_TRACK* item : currentPcb->Tracks() )
currItemList.insert( item );
// Append footprints:
for( FOOTPRINT* item : currentPcb->Footprints() )
currItemList.insert( item );
// Append drawings
for( BOARD_ITEM* item : currentPcb->Drawings() )
currItemList.insert( item );
// Append zones outlines
for( ZONE* zone : currentPcb->Zones() )
currItemList.insert( zone );
const std::set<BOARD_ITEM*> currItemList = currentPcb->GetItemSet();
// Found deleted items
for( unsigned int i = 0; i < oldBuffer->GetCount(); i++ )
@ -362,7 +348,6 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
}
}
if( oldBuffer->GetCount() )
{
OnModify();
@ -382,6 +367,36 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
void PCB_EDIT_FRAME::RebuildAndRefresh()
{
// The list of existing items after running the action script
const std::set<BOARD_ITEM*> items = GetBoard()->GetItemSet();
// Sync selection with items selection state
SELECTION& selection = GetCurrentSelection();
PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
EDA_ITEMS to_add;
EDA_ITEMS to_remove;
for( BOARD_ITEM* item : items )
{
if( item->IsSelected() && !selection.Contains( item ) )
{
item->ClearSelected(); // temporarily
to_add.push_back( item );
}
}
for( EDA_ITEM* item : selection.GetItems() )
{
if( !item->IsSelected() )
to_remove.push_back( static_cast<BOARD_ITEM*>( item ) );
}
if( !to_add.empty() )
selTool->AddItemsToSel( &to_add );
if( !to_remove.empty() )
selTool->RemoveItemsFromSel( &to_remove );
m_pcb->BuildConnectivity();
PCB_DRAW_PANEL_GAL* canvas = GetCanvas();