Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/interactive_markers/menu_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <functional>
#include <set>
#include <span> // NOLINT(build/include_order): cpplint misclassifies the C++20 header as C
#include <string>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -137,7 +138,7 @@ class MenuHandler
// entries_out. Calls itself recursively to add the entire menu
// tree.
bool pushMenuEntries(
std::vector<EntryHandle> & handles_in,
std::span<const EntryHandle> handles_in,
std::vector<visualization_msgs::msg::MenuEntry> & entries_out,
EntryHandle parent_handle);

Expand Down
5 changes: 3 additions & 2 deletions include/interactive_markers/message_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <list>
#include <memory>
#include <span> // NOLINT(build/include_order): cpplint misclassifies the C++20 header as C
#include <string>
#include <vector>

Expand Down Expand Up @@ -75,10 +76,10 @@ class MessageContext
bool getTransform(std_msgs::msg::Header & header, geometry_msgs::msg::Pose & pose_msg);

void getTfTransforms(
std::vector<visualization_msgs::msg::InteractiveMarker> & msg_vec,
std::span<visualization_msgs::msg::InteractiveMarker> msg_vec,
std::list<size_t> & indices);
void getTfTransforms(
std::vector<visualization_msgs::msg::InteractiveMarkerPose> & msg_vec,
std::span<visualization_msgs::msg::InteractiveMarkerPose> msg_vec,
std::list<size_t> & indices);

// array indices of marker/pose updates with missing tf info
Expand Down
36 changes: 18 additions & 18 deletions src/menu_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <exception>
#include <functional>
#include <set>
#include <span> // NOLINT(build/include_order): cpplint misclassifies the C++20 header as C
#include <string>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -186,14 +187,12 @@ bool MenuHandler::apply(InteractiveMarkerServer & server, const std::string & ma
}

bool MenuHandler::pushMenuEntries(
std::vector<EntryHandle> & handles_in,
std::span<const EntryHandle> handles_in,
std::vector<visualization_msgs::msg::MenuEntry> & entries_out,
EntryHandle parent_handle)
{
for (unsigned t = 0; t < handles_in.size(); t++) {
EntryHandle handle = handles_in[t];
std::unordered_map<EntryHandle, EntryContext>::iterator context_it =
entry_contexts_.find(handle);
for (const EntryHandle handle : handles_in) {
auto context_it = entry_contexts_.find(handle);

if (context_it == entry_contexts_.end()) {
RCUTILS_LOG_ERROR("Internal error: context handle not found! This is a bug in MenuHandler.");
Expand All @@ -207,7 +206,7 @@ bool MenuHandler::pushMenuEntries(
}

entries_out.push_back(makeEntry(context, handle, parent_handle));
if (false == pushMenuEntries(context.sub_entries, entries_out, handle)) {
if (!pushMenuEntries(context.sub_entries, entries_out, handle)) {
return false;
}
}
Expand Down Expand Up @@ -235,18 +234,19 @@ MenuHandler::EntryHandle MenuHandler::doInsert(
const std::string & command,
const FeedbackCallback & feedback_cb)
{
EntryHandle handle = current_handle_;
current_handle_++;

EntryContext context;
context.title = title;
context.command = command;
context.command_type = command_type;
context.visible = true;
context.check_state = NO_CHECKBOX;
context.feedback_cb = feedback_cb;

entry_contexts_[handle] = context;
const EntryHandle handle = current_handle_++;

entry_contexts_.try_emplace(
handle,
EntryContext{
.title = title,
.command = command,
.command_type = command_type,
.sub_entries = {},
.visible = true,
.check_state = NO_CHECKBOX,
.feedback_cb = feedback_cb,
});
return handle;
}

Expand Down
11 changes: 5 additions & 6 deletions src/message_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <format> // NOLINT(build/include_order): cpplint misclassifies the C++20 header as C
#include <list>
#include <memory>
#include <span> // NOLINT(build/include_order): cpplint misclassifies the C++20 header as C
#include <string>
#include <vector>

Expand Down Expand Up @@ -135,10 +136,9 @@ bool MessageContext<MsgT>::getTransform(

template<class MsgT>
void MessageContext<MsgT>::getTfTransforms(
std::vector<visualization_msgs::msg::InteractiveMarker> & msg_vec, std::list<size_t> & indices)
std::span<visualization_msgs::msg::InteractiveMarker> msg_vec, std::list<size_t> & indices)
{
std::list<size_t>::iterator idx_it;
for (idx_it = indices.begin(); idx_it != indices.end(); ) {
for (auto idx_it = indices.begin(); idx_it != indices.end(); ) {
visualization_msgs::msg::InteractiveMarker & im_msg = msg_vec[*idx_it];
// transform interactive marker
bool success = getTransform(im_msg.header, im_msg.pose);
Expand Down Expand Up @@ -167,11 +167,10 @@ void MessageContext<MsgT>::getTfTransforms(

template<class MsgT>
void MessageContext<MsgT>::getTfTransforms(
std::vector<visualization_msgs::msg::InteractiveMarkerPose> & msg_vec,
std::span<visualization_msgs::msg::InteractiveMarkerPose> msg_vec,
std::list<size_t> & indices)
{
std::list<size_t>::iterator idx_it;
for (idx_it = indices.begin(); idx_it != indices.end(); ) {
for (auto idx_it = indices.begin(); idx_it != indices.end(); ) {
visualization_msgs::msg::InteractiveMarkerPose & msg = msg_vec[*idx_it];
if (getTransform(msg.header, msg.pose)) {
idx_it = indices.erase(idx_it);
Expand Down