From ad0aa64f4a5868636b90848721a6f94fc9dda37b Mon Sep 17 00:00:00 2001 From: v4hn Date: Fri, 6 Sep 2019 14:44:58 +0200 Subject: [PATCH] enable `rviz -d my_config` as shortcut to ~/.rviz/my_config.rviz --- src/rviz/visualization_frame.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index 9e1f2fa798..9fc58463b6 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -721,16 +721,38 @@ void VisualizationFrame::loadDisplayConfig( const QString& qpath ) { std::string path = qpath.toStdString(); std::string actual_load_path = path; - if( !fs::exists( path ) || fs::is_directory( path ) || fs::is_empty( path )) + bool valid_load_path = false; + + if( fs::is_regular_file( actual_load_path ) || fs::is_symlink( actual_load_path ) ) + { + valid_load_path = true; + } + + if( !valid_load_path && fs::portable_posix_name( path ) ) + { + actual_load_path = (fs::path(config_dir_) / (path+".rviz") ).BOOST_FILE_STRING(); + if( fs::is_regular_file( actual_load_path ) || fs::is_symlink( actual_load_path ) ) + { + valid_load_path = true; + } + } + + if( !valid_load_path ) { actual_load_path = (fs::path(package_path_) / "default.rviz").BOOST_FILE_STRING(); - if( !fs::exists( actual_load_path )) + if( !fs::is_regular_file( actual_load_path ) && !fs::is_symlink( actual_load_path ) ) { ROS_ERROR( "Default display config '%s' not found. RViz will be very empty at first.", actual_load_path.c_str() ); return; } + else + { + valid_load_path = true; + } } + assert( valid_load_path ); + // Check if we have unsaved changes to the current config the same // as we do during exit, with the same option to cancel. if( !prepareToExit() )