From f153ff8453fa43d52657bb4b59078ed4e2a73791 Mon Sep 17 00:00:00 2001 From: qu1ck Date: Wed, 28 Dec 2022 17:45:02 -0800 Subject: [PATCH] Add GetCurrentSelection() python scripting helper --- .../scripting/pcbnew_scripting_helpers.cpp | 19 +++++++++++++++++++ .../scripting/pcbnew_scripting_helpers.h | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp index e8a7ebe1d2..047cd40f43 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp @@ -418,6 +418,25 @@ int GetUserUnits() } +std::deque GetCurrentSelection() +{ + std::deque items; + + if( s_PcbEditFrame ) + { + SELECTION& selection = s_PcbEditFrame->GetCurrentSelection(); + + std::for_each( selection.begin(), selection.end(), + [&items]( EDA_ITEM* item ) + { + items.push_back( static_cast( item ) ); + } ); + } + + return items; +} + + bool IsActionRunning() { return ACTION_PLUGINS::IsActionRunning(); diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.h b/pcbnew/python/scripting/pcbnew_scripting_helpers.h index 3341667744..1d522dd02f 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.h +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.h @@ -167,6 +167,11 @@ void UpdateUserInterface(); */ int GetUserUnits(); +/** + * Get the list of selected objects. + */ +std::deque GetCurrentSelection(); + /** * Are we currently in an action plugin? */