Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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: 3 additions & 0 deletions mapviz/include/mapviz/config_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ namespace mapviz
Q_SIGNALS:
void UpdateSizeHint();
void ToggledDraw(QListWidgetItem* plugin, bool visible);
void DuplicateRequest(QListWidgetItem* plugin);
void RemoveRequest(QListWidgetItem* plugin);

public Q_SLOTS:
void Hide();
void EditName();
void Duplicate();
void Remove();
void ToggleDraw(bool toggled);

Expand All @@ -82,6 +84,7 @@ namespace mapviz
QString name_;
QString type_;
QAction* edit_name_action_;
QAction* duplicate_item_action_;
QAction* remove_item_action_;
bool visible_;
};
Expand Down
3 changes: 3 additions & 0 deletions mapviz/include/mapviz/mapviz.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <QWidget>
#include <QStringList>
#include <QMainWindow>
#include <QShortcut>

// ROS libraries
#include <ros/ros.h>
Expand Down Expand Up @@ -92,6 +93,8 @@ namespace mapviz
void SelectNewDisplay();
void RemoveDisplay();
void RemoveDisplay(QListWidgetItem* item);
void DuplicateDisplay();
void DuplicateDisplay(QListWidgetItem *item);
void ReorderDisplays();
void FixedFrameSelected(const QString& text);
void TargetFrameSelected(const QString& text);
Expand Down
9 changes: 9 additions & 0 deletions mapviz/src/config_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ namespace mapviz
ui_.setupUi(this);

edit_name_action_ = new QAction("Edit Name", this);
duplicate_item_action_ = new QAction("Duplicate", this);
duplicate_item_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D));
remove_item_action_ = new QAction("Remove", this);
remove_item_action_->setIcon(QIcon(":/images/remove-icon-th.png"));

connect(edit_name_action_, SIGNAL(triggered()), this, SLOT(EditName()));
connect(duplicate_item_action_, SIGNAL(triggered()), this, SLOT(Duplicate()));
connect(remove_item_action_, SIGNAL(triggered()), this, SLOT(Remove()));
}

Expand All @@ -71,6 +74,7 @@ namespace mapviz
{
QMenu menu(this);
menu.addAction(edit_name_action_);
menu.addAction(duplicate_item_action_);
menu.addAction(remove_item_action_);
menu.exec(event->globalPos());
}
Expand Down Expand Up @@ -109,6 +113,11 @@ namespace mapviz
}
}

void ConfigItem::Duplicate()
{
Q_EMIT DuplicateRequest(item_);
}

void ConfigItem::Remove()
{
Q_EMIT RemoveRequest(item_);
Expand Down
65 changes: 65 additions & 0 deletions mapviz/src/mapviz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ Mapviz::Mapviz(bool is_standalone, int argc, char** argv, QWidget *parent, Qt::W

ui_.bg_color->setColor(background_);
canvas_->SetBackground(background_);

// Keyboard shortcuts for the main window
QShortcut *duplicate_display_shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_D), this);
connect(duplicate_display_shortcut, SIGNAL(activated()), this, SLOT(DuplicateDisplay()));
}

Mapviz::~Mapviz()
Expand Down Expand Up @@ -1188,6 +1192,7 @@ MapvizPluginPtr Mapviz::CreateNewDisplay(
item->setSizeHint(config_item->sizeHint());
connect(config_item, SIGNAL(UpdateSizeHint()), this, SLOT(UpdateSizeHints()));
connect(config_item, SIGNAL(ToggledDraw(QListWidgetItem*, bool)), this, SLOT(ToggleShowPlugin(QListWidgetItem*, bool)));
connect(config_item, SIGNAL(DuplicateRequest(QListWidgetItem*)), this, SLOT(DuplicateDisplay(QListWidgetItem*)));
connect(config_item, SIGNAL(RemoveRequest(QListWidgetItem*)), this, SLOT(RemoveDisplay(QListWidgetItem*)));
connect(plugin.get(), SIGNAL(VisibleChanged(bool)), config_item, SLOT(ToggleDraw(bool)));
connect(plugin.get(), SIGNAL(SizeChanged()), this, SLOT(UpdateSizeHints()));
Expand Down Expand Up @@ -1499,6 +1504,66 @@ void Mapviz::RemoveDisplay(QListWidgetItem* item)
}
}

void Mapviz::DuplicateDisplay()
{
QListWidgetItem* item = ui_.configs->item(ui_.configs->currentRow());
if (item != nullptr)
{
DuplicateDisplay(item);
}
}

void Mapviz::DuplicateDisplay(QListWidgetItem* item)
{
ROS_INFO("Duplicating active display... ");
// - Get plugin associated with QListWidgetItem
if (plugins_.count(item) != 1)
{
ROS_ERROR("Item attempted to duplicate is not a plugin.");
return;
}
MapvizPluginPtr target_plugin = plugins_[item];
ConfigItem* target_config_item = static_cast<ConfigItem*>(ui_.configs->itemWidget(item));

// - Save plugin config to a temporary string via an emitter
YAML::Emitter out;
out << YAML::BeginMap;
out << YAML::Key << "type" << YAML::Value << target_plugin->Type();
out << YAML::Key << "name" << YAML::Value << target_config_item->Name().toStdString();
out << YAML::Key << "config" << YAML::Value;
out << YAML::BeginMap;
out << YAML::Key << "visible" << YAML::Value << target_plugin->Visible();
out << YAML::Key << "collapsed" << YAML::Value << target_config_item->Collapsed();
target_plugin->SaveConfig(out, "");
out << YAML::EndMap;
out << YAML::EndMap;

// - Create the new display via existing MapvizPlugin::LoadConfig interface
YAML::Node temp_node;
swri_yaml_util::LoadString(out.c_str(), temp_node);
YAML::Node temp_config_node = temp_node["config"];
if (!temp_config_node)
{
ROS_ERROR("Cannot duplicate plugin of type %s. Invalid config.",
target_plugin->Type().c_str());
return;
}
try
{
MapvizPluginPtr duplicate_plugin = CreateNewDisplay(
target_config_item->Name().toStdString(),
target_plugin->Type(),
target_plugin->Visible(),
target_config_item->Collapsed());
duplicate_plugin->LoadConfig(temp_config_node, "");
duplicate_plugin->DrawIcon();
}
catch (const pluginlib::LibraryLoadException& e)
{
ROS_ERROR("%s", e.what());
}
}

void Mapviz::ClearDisplays()
{
while (ui_.configs->count() > 0)
Expand Down