Skip to content

Commit 02c5cd0

Browse files
mergify[bot]clalancetteahcorde
authored
Rolling namespace in title (backport ros-visualization#1074) (ros-visualization#1099)
* Rolling namespace in title (ros-visualization#1074) Signed-off-by: Markus Bader <[email protected]> Co-authored-by: Chris Lalancette <[email protected]> (cherry picked from commit ea2dbb3) Co-authored-by: Alejandro Hernández Cordero <[email protected]>
1 parent 432542f commit 02c5cd0

File tree

3 files changed

+63
-162
lines changed

3 files changed

+63
-162
lines changed

rviz_common/include/rviz_common/visualization_frame.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ class VisualizationFrame : public QMainWindow, public WindowManagerInterface
133133
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node,
134134
const QString & display_config_file = "");
135135

136+
/// Set the display title format.
137+
/**
138+
* Sets the format of the window title.
139+
* Three replacement tokens are supported:
140+
* - {NAMESPACE} - replace with the namespace this node is in
141+
* - {CONFIG_PATH} - replace with the path (but not the filename) of the configuration file in use.
142+
* - {CONFIG_FILENAME} - replace with the filename (but not the path) of the configuration file in use.
143+
* The default is "RViz[*]" if the default configuration file is in use,
144+
* or "{CONFIG_PATH}/{CONFIG_FILENAME}[*] - RViz" if a custom configuration file is in use.
145+
*/
146+
void
147+
setDisplayTitleFormat(const QString & title_format);
148+
136149
/// Return the visualization manager.
137150
VisualizationManager *
138151
getManager();
@@ -466,6 +479,7 @@ protected Q_SLOTS:
466479

467480
std::string config_dir_;
468481
std::string persistent_settings_file_;
482+
std::string display_title_format_;
469483
std::string display_config_file_;
470484
std::string default_display_config_file_;
471485
std::string last_config_dir_;

rviz_common/src/rviz_common/visualization_frame.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "rviz_common/visualization_frame.hpp"
3333

3434
#include <exception>
35+
#include <filesystem>
3536
#include <fstream>
3637
#include <memory>
3738
#include <string>
@@ -751,16 +752,43 @@ void VisualizationFrame::setDisplayConfigModified()
751752
}
752753
}
753754

755+
void VisualizationFrame::setDisplayTitleFormat(const QString & title_format)
756+
{
757+
display_title_format_ = title_format.toStdString();
758+
}
759+
754760
void VisualizationFrame::setDisplayConfigFile(const std::string & path)
755761
{
756762
display_config_file_ = path;
757-
758763
std::string title;
759-
if (path == default_display_config_file_) {
760-
title = "RViz[*]";
764+
765+
if (display_title_format_.empty()) {
766+
if (path == default_display_config_file_) {
767+
title = "RViz[*]";
768+
} else {
769+
title = QDir::toNativeSeparators(QString::fromStdString(path)).toStdString() + "[*] - RViz";
770+
}
761771
} else {
762-
title = QDir::toNativeSeparators(QString::fromStdString(path)).toStdString() + "[*] - RViz";
772+
auto find_and_replace_token =
773+
[](std::string & title, const std::string & token, const std::string & replacement)
774+
{
775+
std::size_t found = title.find(token);
776+
if (found != std::string::npos) {
777+
title.replace(found, token.length(), replacement);
778+
}
779+
};
780+
title = display_title_format_;
781+
std::filesystem::path full_filename(path.c_str());
782+
find_and_replace_token(
783+
title, "{NAMESPACE}",
784+
rviz_ros_node_.lock()->get_raw_node()->get_namespace());
785+
find_and_replace_token(title, "{CONFIG_PATH}", full_filename.parent_path().string());
786+
find_and_replace_token(title, "{CONFIG_FILENAME}", full_filename.filename().string());
787+
if (title.find("[*]") == std::string::npos) {
788+
title.append("[*]");
789+
}
763790
}
791+
764792
setWindowTitle(QString::fromStdString(title));
765793
}
766794

rviz_common/src/rviz_common/visualizer_app.cpp

Lines changed: 17 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,9 @@
5050
#include "rviz_common/visualization_frame.hpp"
5151
#include "rviz_common/visualization_manager.hpp"
5252

53-
// TODO(wjwwood): figure out a non-depricated way to do this
54-
#if 0
55-
#ifdef Q_OS_MAC
56-
#include <ApplicationServices/ApplicationServices.h>
57-
// Apparently OSX #defines 'check' to be an empty string somewhere.
58-
// That was fun to figure out.
59-
#undef check
60-
#endif
61-
#endif
62-
63-
// #include "rviz/env_config.h"
64-
// #include "rviz/ogre_helpers/ogre_logging.h"
65-
// #include "rviz/ogre_helpers/render_system.h"
66-
// #include "rviz/wait_for_master_dialog.h"
67-
6853
namespace rviz_common
6954
{
7055

71-
// TODO(wjwwood): reenable the service to reload the shaders
72-
// bool
73-
// reloadShaders(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
74-
// {
75-
// ROS_INFO("Reloading materials.");
76-
// {
77-
// Ogre::ResourceManager::ResourceMapIterator it =
78-
// Ogre::MaterialManager::getSingleton().getResourceIterator();
79-
// while (it.hasMoreElements()) {
80-
// Ogre::ResourcePtr resource = it.getNext();
81-
// resource->reload();
82-
// }
83-
// }
84-
// ROS_INFO("Reloading high-level gpu shaders.");
85-
// {
86-
// Ogre::ResourceManager::ResourceMapIterator it =
87-
// Ogre::HighLevelGpuProgramManager::getSingleton().getResourceIterator();
88-
// while (it.hasMoreElements()) {
89-
// Ogre::ResourcePtr resource = it.getNext();
90-
// resource->reload();
91-
// }
92-
// }
93-
// ROS_INFO("Reloading gpu shaders.");
94-
// {
95-
// Ogre::ResourceManager::ResourceMapIterator it =
96-
// Ogre::GpuProgramManager::getSingleton().getResourceIterator();
97-
// while (it.hasMoreElements()) {
98-
// Ogre::ResourcePtr resource = it.getNext();
99-
// resource->reload();
100-
// }
101-
// }
102-
// return true;
103-
// }
104-
10556
VisualizerApp::VisualizerApp(
10657
std::unique_ptr<rviz_common::ros_integration::RosClientAbstractionIface> ros_client_abstraction)
10758
: app_(0),
@@ -128,34 +79,19 @@ void VisualizerApp::loadConfig(QString config_path)
12879

12980
bool VisualizerApp::init(int argc, char ** argv)
13081
{
131-
// TODO(wjwwood): find a way to get the versions and print them here
132-
// also include versions of more things, like rviz_rendering,
133-
// rviz_common, and the plugins
134-
// RVIZ_COMMON_LOG_INFO_STREAM("rviz version " << get_version().c_str());
135-
// RVIZ_COMMON_LOG_INFO("compiled against Qt version " QT_VERSION_STR);
136-
// RVIZ_COMMON_LOG_INFO_STREAM(
137-
// "compiled against OGRE version " <<
138-
// OGRE_VERSION_MAJOR << "." <<
139-
// OGRE_VERSION_MINOR << "." <<
140-
// OGRE_VERSION_PATCH << OGRE_VERSION_SUFFIX <<
141-
// " (" << OGRE_VERSION_NAME << ")");
142-
143-
// TODO(wjwwood): figure out a non-depricated way to do this
144-
#if 0
145-
#ifdef Q_OS_MAC
146-
ProcessSerialNumber PSN;
147-
GetCurrentProcess(&PSN);
148-
TransformProcessType(&PSN, kProcessTransformToForegroundApplication);
149-
SetFrontProcess(&PSN);
150-
#endif
151-
#endif
152-
15382
rviz_common::install_rviz_rendering_log_handlers();
15483

15584
QCommandLineParser parser;
15685
parser.setApplicationDescription("3D visualization tool for ROS2");
15786
parser.addHelpOption();
15887

88+
QCommandLineOption display_title_format_option(
89+
QStringList() << "t" << "display-title-format",
90+
"A display title format like ",
91+
"\"{NAMESPACE} - {CONFIG_PATH}/{CONFIG_FILENAME} - RViz2\" ",
92+
"display_title_format");
93+
parser.addOption(display_title_format_option);
94+
15995
QCommandLineOption display_config_option(
16096
QStringList() << "d" << "display-config",
16197
"A display config file (.rviz) to load",
@@ -176,43 +112,12 @@ bool VisualizerApp::init(int argc, char ** argv)
176112
"A custom splash-screen image to display", "splash_path");
177113
parser.addOption(splash_screen_option);
178114

179-
// TODO(botteroa-si): enable when possible
180-
// QCommandLineOption help_file_option(
181-
// "help-file", "A custom html file to show as the help screen", "help_path");
182-
// parser.addOption(help_file_option);
183-
//
184-
// QCommandLineOption open_gl_option(
185-
// "opengl",
186-
// "Force OpenGL version (use '--opengl 210' for OpenGL 2.1 compatibility mode)",
187-
// "version");
188-
// parser.addOption(open_gl_option);
189-
//
190-
// QCommandLineOption disable_anti_aliasing_option(
191-
// "disable-anti-aliasing", "Prevent rviz from trying to use anti-aliasing when rendering.");
192-
// parser.addOption(disable_anti_aliasing_option);
193-
//
194-
// QCommandLineOption no_stereo_option("no-stereo", "Disable the use of stereo rendering.");
195-
// parser.addOption(no_stereo_option);
196-
//
197-
// QCommandLineOption log_level_debug_option(
198-
// "log-level-debug", "Sets the ROS logger level to debug.");
199-
// parser.addOption(log_level_debug_option);
200-
201-
// ("in-mc-wrapper", "Signal that this is running inside a master-chooser wrapper")
202-
203-
QString display_config, fixed_frame, splash_path, help_path;
115+
QString display_config, fixed_frame, splash_path, help_path, display_title_format;
204116
bool enable_ogre_log;
205-
// TODO(botteroa-si): enable when possible
206-
// bool in_mc_wrapper = false;
207-
// int force_gl_version = 0;
208-
// bool disable_anti_aliasing = false;
209-
// bool disable_stereo = false;
210117

211-
parser.process(*app_);
118+
if (app_) {parser.process(*app_);}
212119

213120
enable_ogre_log = parser.isSet(ogre_log_option);
214-
// disable_stereo = parser.isSet(no_stereo_option);
215-
// disable_anti_aliasing = parser.isSet(disable_anti_aliasing_option);
216121

217122
if (parser.isSet(display_config_option)) {
218123
display_config = parser.value(display_config_option);
@@ -224,72 +129,30 @@ bool VisualizerApp::init(int argc, char ** argv)
224129
if (parser.isSet(splash_screen_option)) {
225130
splash_path = parser.value(splash_screen_option);
226131
}
227-
// TODO(botteroa-si): enable when possible
228-
// if (parser.isSet(help_file_option)) {
229-
// help_path = parser.value(help_file_option);
230-
// }
231-
// if (parser.isSet(open_gl_option)) {
232-
// force_gl_version = parser.value(open_gl_option).toInt();
233-
// }
234-
235-
// if (vm.count("in-mc-wrapper")) {
236-
// in_mc_wrapper = true;
237-
// }
238-
//
239-
//
240-
// if (vm.count("log-level-debug")) {
241-
// if (
242-
// ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug))
243-
// {
244-
// ros::console::notifyLoggerLevelsChanged();
245-
// }
246-
// }
247-
248-
//
249-
// if (!ros::master::check() ) {
250-
// TODO(wjwwood): figure out how to support the "wait for master" functionality
251-
// while also using the rviz_common/ros_integration abstraction
252-
// WaitForMasterDialog * dialog = new WaitForMasterDialog;
253-
// if (dialog->exec() != QDialog::Accepted) {
254-
// return false;
255-
// }
256-
// }
257-
//
258-
// nh_.reset(new ros::NodeHandle);
259-
//
132+
133+
if (parser.isSet(display_title_format_option)) {
134+
display_title_format = parser.value(display_title_format_option);
135+
}
136+
260137
if (enable_ogre_log) {
261138
rviz_rendering::OgreLogging::get()->useLogFileAndStandardOut();
262139
rviz_rendering::OgreLogging::get()->configureLogging();
263140
}
264-
//
265-
// if (force_gl_version) {
266-
// RenderSystem::forceGlVersion(force_gl_version);
267-
// }
268-
//
269-
// if (disable_anti_aliasing) {
270-
// RenderSystem::disableAntiAliasing();
271-
// }
272-
//
273-
// if (disable_stereo) {
274-
// RenderSystem::forceNoStereo();
275-
// }
276141

277142
startContinueChecker();
278143

279-
// TODO(wjwwood): anonymous is not working right now, reenable later
280-
// node_name_ = rviz_common::ros_integration::init(argc, argv, "rviz", true /* anonymous_name */);
281144
node_ = ros_client_abstraction_->init(argc, argv, "rviz", false /* anonymous_name */);
282145

283146
frame_ = new VisualizationFrame(node_);
147+
148+
frame_->setDisplayTitleFormat(display_title_format);
149+
284150
frame_->setApp(this->app_);
285151

286152
if (!help_path.isEmpty()) {
287153
frame_->setHelpPath(help_path);
288154
}
289155

290-
// TODO(wjwwood): figure out how to preserve the "choost new master" feature
291-
// frame_->setShowChooseNewMaster(in_mc_wrapper);
292-
293156
if (!splash_path.isEmpty()) {
294157
frame_->setSplashPath(splash_path);
295158
}
@@ -301,10 +164,6 @@ bool VisualizerApp::init(int argc, char ** argv)
301164

302165
frame_->show();
303166

304-
// TODO(wjwwood): reenable the ROS service to reload the shaders via the ros_integration API
305-
// ros::NodeHandle private_nh("~");
306-
// reload_shaders_service_ = private_nh.advertiseService("reload_shaders", reloadShaders);
307-
308167
return true;
309168
}
310169

0 commit comments

Comments
 (0)