1 #ifndef RADIAL_MENU_MODEL_MODEL_HPP 2 #define RADIAL_MENU_MODEL_MODEL_HPP 11 #include <radial_menu_msgs/State.h> 20 typedef std::shared_ptr< Model >
ModelPtr;
47 bool isPointed(
const std::string &path,
const char separator =
'.')
const {
49 return p ? (path == p->path(separator)) :
false;
53 std::vector< ItemConstPtr > items;
54 for (
const std::int32_t iid :
state_.selected_ids) {
55 if (iid >= 0 && iid <
items_.size()) {
56 items.push_back(
items_[iid]);
66 for (
const std::int32_t iid :
state_.selected_ids) {
67 if (iid >= 0 && iid <
items_.size() && item ==
items_[iid]) {
74 bool isSelected(
const std::string &path,
const char separator =
'.')
const {
75 for (
const std::int32_t iid :
state_.selected_ids) {
76 if (iid >= 0 && iid <
items_.size() && path ==
items_[iid]->path(separator)) {
89 const double span_angle(2. * M_PI / n_sibilings);
90 const int sid(static_cast< int >(std::round(angle / span_angle)) % n_sibilings);
102 if (new_items.empty()) {
103 ROS_ERROR(
"Model::setDescription(): No items");
108 const ItemConstPtr new_current_level(new_items.front()->childLevel());
109 if (!new_current_level) {
110 ROS_ERROR(
"Model::setDescription(): No children of the root item");
127 ROS_ERROR_STREAM(
"Model::setDescriptionFromParam(): Cannot get the param '" << param_name
137 return "<item name=\"Menu\">\n" 138 " <item name=\"Item\" />\n" 147 radial_menu_msgs::StatePtr state(
new radial_menu_msgs::State(
state_));
148 state->header.stamp = stamp;
153 bool setState(
const radial_menu_msgs::State &new_state) {
158 for (
const std::int32_t iid :
state_.selected_ids) {
159 if (iid >= 0 && iid <
items_.size()) {
163 level = item->sibilingLevel();
177 radial_menu_msgs::State state;
178 state.is_enabled =
false;
179 state.pointed_id = -1;
203 state_.pointed_id = item->itemId();
229 return item && item->sibilingLevel() ==
current_level_ && !item->childLevel() &&
237 if (!allow_multi_selection) {
250 return item && item->sibilingLevel() ==
current_level_ && !item->childLevel() &&
269 return item && item->sibilingLevel() ==
current_level_ && item->childLevel();
278 if (!allow_multi_selection) {
314 const int n_indent = 0) {
315 std::string str(n_indent,
' ');
317 if (item->depth() > 0) {
318 str += itemStateStr(model, item) +
" ";
320 str += item->name() +
" " + itemIdStr(item) +
"\n";
322 str +=
toString(model, child, n_indent + 2);
330 static std::string itemStateStr(
const Model *
const model,
const ItemConstPtr &item) {
331 std::ostringstream str;
332 str <<
"[" << (model->
isPointed(item) ?
"P" :
" ") << (model->
isSelected(item) ?
"S" :
" ")
337 static std::string itemIdStr(
const ItemConstPtr &item) {
338 std::ostringstream str;
339 str <<
"(i" << item->itemId() <<
"-d" << item->depth() <<
")";
344 return Internal::toString(
this,
items_.front());
354 std::vector< std::int32_t > &ids(
state_.selected_ids);
355 if (std::find(ids.begin(), ids.end(), item->itemId()) == ids.end()) {
356 ids.push_back(item->itemId());
363 std::vector< std::int32_t > &ids(
state_.selected_ids);
364 ids.erase(std::remove(ids.begin(), ids.end(), item->itemId()), ids.end());
ROSCPP_DECL bool get(const std::string &key, std::string &s)
#define ROS_ERROR_STREAM(args)