Skip to content

Commit

Permalink
Rolling namespace in title (backport ros-visualization#1074) (ros-vis…
Browse files Browse the repository at this point in the history
…ualization#1099)

* Rolling namespace in title (ros-visualization#1074)

Signed-off-by: Markus Bader <markus.bader@tirol.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
(cherry picked from commit ea2dbb3097f095dd24add190c242f3048a747c63)
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
  • Loading branch information
3 people authored Nov 27, 2023
1 parent 432542f commit 02c5cd0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 162 deletions.
14 changes: 14 additions & 0 deletions rviz_common/include/rviz_common/visualization_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ class VisualizationFrame : public QMainWindow, public WindowManagerInterface
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node,
const QString & display_config_file = "");

/// Set the display title format.
/**
* Sets the format of the window title.
* Three replacement tokens are supported:
* - {NAMESPACE} - replace with the namespace this node is in
* - {CONFIG_PATH} - replace with the path (but not the filename) of the configuration file in use.
* - {CONFIG_FILENAME} - replace with the filename (but not the path) of the configuration file in use.
* The default is "RViz[*]" if the default configuration file is in use,
* or "{CONFIG_PATH}/{CONFIG_FILENAME}[*] - RViz" if a custom configuration file is in use.
*/
void
setDisplayTitleFormat(const QString & title_format);

/// Return the visualization manager.
VisualizationManager *
getManager();
Expand Down Expand Up @@ -466,6 +479,7 @@ protected Q_SLOTS:

std::string config_dir_;
std::string persistent_settings_file_;
std::string display_title_format_;
std::string display_config_file_;
std::string default_display_config_file_;
std::string last_config_dir_;
Expand Down
36 changes: 32 additions & 4 deletions rviz_common/src/rviz_common/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "rviz_common/visualization_frame.hpp"

#include <exception>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
Expand Down Expand Up @@ -751,16 +752,43 @@ void VisualizationFrame::setDisplayConfigModified()
}
}

void VisualizationFrame::setDisplayTitleFormat(const QString & title_format)
{
display_title_format_ = title_format.toStdString();
}

void VisualizationFrame::setDisplayConfigFile(const std::string & path)
{
display_config_file_ = path;

std::string title;
if (path == default_display_config_file_) {
title = "RViz[*]";

if (display_title_format_.empty()) {
if (path == default_display_config_file_) {
title = "RViz[*]";
} else {
title = QDir::toNativeSeparators(QString::fromStdString(path)).toStdString() + "[*] - RViz";
}
} else {
title = QDir::toNativeSeparators(QString::fromStdString(path)).toStdString() + "[*] - RViz";
auto find_and_replace_token =
[](std::string & title, const std::string & token, const std::string & replacement)
{
std::size_t found = title.find(token);
if (found != std::string::npos) {
title.replace(found, token.length(), replacement);
}
};
title = display_title_format_;
std::filesystem::path full_filename(path.c_str());
find_and_replace_token(
title, "{NAMESPACE}",
rviz_ros_node_.lock()->get_raw_node()->get_namespace());
find_and_replace_token(title, "{CONFIG_PATH}", full_filename.parent_path().string());
find_and_replace_token(title, "{CONFIG_FILENAME}", full_filename.filename().string());
if (title.find("[*]") == std::string::npos) {
title.append("[*]");
}
}

setWindowTitle(QString::fromStdString(title));
}

Expand Down
175 changes: 17 additions & 158 deletions rviz_common/src/rviz_common/visualizer_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,58 +50,9 @@
#include "rviz_common/visualization_frame.hpp"
#include "rviz_common/visualization_manager.hpp"

// TODO(wjwwood): figure out a non-depricated way to do this
#if 0
#ifdef Q_OS_MAC
#include <ApplicationServices/ApplicationServices.h>
// Apparently OSX #defines 'check' to be an empty string somewhere.
// That was fun to figure out.
#undef check
#endif
#endif

// #include "rviz/env_config.h"
// #include "rviz/ogre_helpers/ogre_logging.h"
// #include "rviz/ogre_helpers/render_system.h"
// #include "rviz/wait_for_master_dialog.h"

namespace rviz_common
{

// TODO(wjwwood): reenable the service to reload the shaders
// bool
// reloadShaders(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
// {
// ROS_INFO("Reloading materials.");
// {
// Ogre::ResourceManager::ResourceMapIterator it =
// Ogre::MaterialManager::getSingleton().getResourceIterator();
// while (it.hasMoreElements()) {
// Ogre::ResourcePtr resource = it.getNext();
// resource->reload();
// }
// }
// ROS_INFO("Reloading high-level gpu shaders.");
// {
// Ogre::ResourceManager::ResourceMapIterator it =
// Ogre::HighLevelGpuProgramManager::getSingleton().getResourceIterator();
// while (it.hasMoreElements()) {
// Ogre::ResourcePtr resource = it.getNext();
// resource->reload();
// }
// }
// ROS_INFO("Reloading gpu shaders.");
// {
// Ogre::ResourceManager::ResourceMapIterator it =
// Ogre::GpuProgramManager::getSingleton().getResourceIterator();
// while (it.hasMoreElements()) {
// Ogre::ResourcePtr resource = it.getNext();
// resource->reload();
// }
// }
// return true;
// }

VisualizerApp::VisualizerApp(
std::unique_ptr<rviz_common::ros_integration::RosClientAbstractionIface> ros_client_abstraction)
: app_(0),
Expand All @@ -128,34 +79,19 @@ void VisualizerApp::loadConfig(QString config_path)

bool VisualizerApp::init(int argc, char ** argv)
{
// TODO(wjwwood): find a way to get the versions and print them here
// also include versions of more things, like rviz_rendering,
// rviz_common, and the plugins
// RVIZ_COMMON_LOG_INFO_STREAM("rviz version " << get_version().c_str());
// RVIZ_COMMON_LOG_INFO("compiled against Qt version " QT_VERSION_STR);
// RVIZ_COMMON_LOG_INFO_STREAM(
// "compiled against OGRE version " <<
// OGRE_VERSION_MAJOR << "." <<
// OGRE_VERSION_MINOR << "." <<
// OGRE_VERSION_PATCH << OGRE_VERSION_SUFFIX <<
// " (" << OGRE_VERSION_NAME << ")");

// TODO(wjwwood): figure out a non-depricated way to do this
#if 0
#ifdef Q_OS_MAC
ProcessSerialNumber PSN;
GetCurrentProcess(&PSN);
TransformProcessType(&PSN, kProcessTransformToForegroundApplication);
SetFrontProcess(&PSN);
#endif
#endif

rviz_common::install_rviz_rendering_log_handlers();

QCommandLineParser parser;
parser.setApplicationDescription("3D visualization tool for ROS2");
parser.addHelpOption();

QCommandLineOption display_title_format_option(
QStringList() << "t" << "display-title-format",
"A display title format like ",
"\"{NAMESPACE} - {CONFIG_PATH}/{CONFIG_FILENAME} - RViz2\" ",
"display_title_format");
parser.addOption(display_title_format_option);

QCommandLineOption display_config_option(
QStringList() << "d" << "display-config",
"A display config file (.rviz) to load",
Expand All @@ -176,43 +112,12 @@ bool VisualizerApp::init(int argc, char ** argv)
"A custom splash-screen image to display", "splash_path");
parser.addOption(splash_screen_option);

// TODO(botteroa-si): enable when possible
// QCommandLineOption help_file_option(
// "help-file", "A custom html file to show as the help screen", "help_path");
// parser.addOption(help_file_option);
//
// QCommandLineOption open_gl_option(
// "opengl",
// "Force OpenGL version (use '--opengl 210' for OpenGL 2.1 compatibility mode)",
// "version");
// parser.addOption(open_gl_option);
//
// QCommandLineOption disable_anti_aliasing_option(
// "disable-anti-aliasing", "Prevent rviz from trying to use anti-aliasing when rendering.");
// parser.addOption(disable_anti_aliasing_option);
//
// QCommandLineOption no_stereo_option("no-stereo", "Disable the use of stereo rendering.");
// parser.addOption(no_stereo_option);
//
// QCommandLineOption log_level_debug_option(
// "log-level-debug", "Sets the ROS logger level to debug.");
// parser.addOption(log_level_debug_option);

// ("in-mc-wrapper", "Signal that this is running inside a master-chooser wrapper")

QString display_config, fixed_frame, splash_path, help_path;
QString display_config, fixed_frame, splash_path, help_path, display_title_format;
bool enable_ogre_log;
// TODO(botteroa-si): enable when possible
// bool in_mc_wrapper = false;
// int force_gl_version = 0;
// bool disable_anti_aliasing = false;
// bool disable_stereo = false;

parser.process(*app_);
if (app_) {parser.process(*app_);}

enable_ogre_log = parser.isSet(ogre_log_option);
// disable_stereo = parser.isSet(no_stereo_option);
// disable_anti_aliasing = parser.isSet(disable_anti_aliasing_option);

if (parser.isSet(display_config_option)) {
display_config = parser.value(display_config_option);
Expand All @@ -224,72 +129,30 @@ bool VisualizerApp::init(int argc, char ** argv)
if (parser.isSet(splash_screen_option)) {
splash_path = parser.value(splash_screen_option);
}
// TODO(botteroa-si): enable when possible
// if (parser.isSet(help_file_option)) {
// help_path = parser.value(help_file_option);
// }
// if (parser.isSet(open_gl_option)) {
// force_gl_version = parser.value(open_gl_option).toInt();
// }

// if (vm.count("in-mc-wrapper")) {
// in_mc_wrapper = true;
// }
//
//
// if (vm.count("log-level-debug")) {
// if (
// ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug))
// {
// ros::console::notifyLoggerLevelsChanged();
// }
// }

//
// if (!ros::master::check() ) {
// TODO(wjwwood): figure out how to support the "wait for master" functionality
// while also using the rviz_common/ros_integration abstraction
// WaitForMasterDialog * dialog = new WaitForMasterDialog;
// if (dialog->exec() != QDialog::Accepted) {
// return false;
// }
// }
//
// nh_.reset(new ros::NodeHandle);
//

if (parser.isSet(display_title_format_option)) {
display_title_format = parser.value(display_title_format_option);
}

if (enable_ogre_log) {
rviz_rendering::OgreLogging::get()->useLogFileAndStandardOut();
rviz_rendering::OgreLogging::get()->configureLogging();
}
//
// if (force_gl_version) {
// RenderSystem::forceGlVersion(force_gl_version);
// }
//
// if (disable_anti_aliasing) {
// RenderSystem::disableAntiAliasing();
// }
//
// if (disable_stereo) {
// RenderSystem::forceNoStereo();
// }

startContinueChecker();

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

frame_ = new VisualizationFrame(node_);

frame_->setDisplayTitleFormat(display_title_format);

frame_->setApp(this->app_);

if (!help_path.isEmpty()) {
frame_->setHelpPath(help_path);
}

// TODO(wjwwood): figure out how to preserve the "choost new master" feature
// frame_->setShowChooseNewMaster(in_mc_wrapper);

if (!splash_path.isEmpty()) {
frame_->setSplashPath(splash_path);
}
Expand All @@ -301,10 +164,6 @@ bool VisualizerApp::init(int argc, char ** argv)

frame_->show();

// TODO(wjwwood): reenable the ROS service to reload the shaders via the ros_integration API
// ros::NodeHandle private_nh("~");
// reload_shaders_service_ = private_nh.advertiseService("reload_shaders", reloadShaders);

return true;
}

Expand Down

0 comments on commit 02c5cd0

Please sign in to comment.