Skip to content

Commit

Permalink
fixes for ament
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Faconti committed Nov 23, 2020
1 parent 663d21f commit 5e5636b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 32 deletions.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@ if( CATKIN_DEVEL_PREFIX OR catkin_FOUND OR CATKIN_BUILD_BINARY_PACKAGE)
LIBRARIES plotjuggler_plugin_base
)

add_definitions(-DCOMPILED_WITH_CATKIN)


elseif( DEFINED ENV{AMENT_PREFIX_PATH})
set(COMPILING_WITH_AMENT 1)

find_package(ament_index_cpp REQUIRED)
include_directories(${ament_index_cpp_INCLUDE_DIRS})

message(STATUS "---------------------------------------------------------------------")
message(STATUS "PlotJuggler is being built using AMENT. ROS2 plugins will be compiled")
message(STATUS "---------------------------------------------------------------------")

add_definitions(-DCOMPILED_WITH_AMENT)

else()
message(STATUS "---------------------------------------------------------------------")
message(STATUS "PlotJuggler is being WITHOUT any ROS support")
Expand Down Expand Up @@ -137,17 +146,12 @@ if(COMPILING_WITH_CATKIN)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} )

add_definitions(-DCOMPILED_FOR_ROS)

elseif(COMPILING_WITH_AMENT)
find_package(ament_cmake REQUIRED)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_definitions(-DCOMPILED_FOR_ROS)

ament_export_targets(export_plotjuggler_plugin_base HAS_LIBRARY_TARGET)

ament_package()

else()
Expand Down
2 changes: 1 addition & 1 deletion PlotJuggler.desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Desktop Entry]
Type=Application
Name=PlotJuggler
Exec=PlotJuggler
Exec=plotjuggler
Icon=plotjuggler
Comment=Visualize timeseries like a pro
Terminal=false
Expand Down
3 changes: 3 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>

<depend condition="$ROS_VERSION == 2">ament_index_cpp</depend>

<!-- common dependancies -->
<depend>qtbase5-dev</depend>
<depend>libqt5-svg-dev</depend>
Expand All @@ -23,6 +25,7 @@
<depend>boost</depend>
<depend>libzmqpp-dev</depend>


<!-- The export tag contains other, unspecified, tags -->
<export>
<build_type condition="$ROS_VERSION == 1">catkin</build_type>
Expand Down
24 changes: 16 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,36 @@ SET( PLOTTER_SRC
nlohmann_parsers.cpp
)

add_executable(PlotJuggler ${PLOTTER_SRC} ${RES_SRC} ${UI_SRC} ${BACKWARD_ENABLE})

add_executable(plotjuggler ${PLOTTER_SRC} ${RES_SRC} ${UI_SRC} ${BACKWARD_ENABLE})

if (NOT WIN32)
add_backward(PlotJuggler)
add_backward(plotjuggler)
endif()

target_link_libraries(PlotJuggler PUBLIC
target_link_libraries(plotjuggler
${QT_LINK_LIBRARIES}
colorwidgets
qwt_static
lua_static )

target_link_libraries(PlotJuggler PRIVATE qt_advanced_docking)
lua_static
qt_advanced_docking
)

if(COMPILING_WITH_CATKIN)
install(TARGETS PlotJuggler

target_link_libraries(plotjuggler ${catkin_LIBRARIES} )

install(TARGETS plotjuggler
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

elseif(COMPILING_WITH_AMENT)
install(TARGETS PlotJuggler

target_link_libraries(plotjuggler ${ament_index_cpp_LIBRARIES} )

install(TARGETS plotjuggler
DESTINATION lib/${PROJECT_NAME} )
else()
install(TARGETS PlotJuggler
Expand Down
30 changes: 30 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#include "nlohmann_parsers.h"
#include "new_release_dialog.h"

#ifdef COMPILED_WITH_AMENT
#include <ament_index_cpp/get_package_prefix.hpp>
#include <ament_index_cpp/get_package_share_directory.hpp>
#endif

static QString VERSION_STRING = QString("%1.%2.%3").arg(PJ_MAJOR_VERSION).arg(PJ_MINOR_VERSION).arg(PJ_PATCH_VERSION);

inline int GetVersionNumber(QString str)
Expand Down Expand Up @@ -101,6 +106,23 @@ int main(int argc, char* argv[])

app.setApplicationVersion(VERSION_STRING);

QString extra_path;

try {
#ifdef COMPILED_WITH_AMENT
extra_path = QString::fromStdString(ament_index_cpp::get_package_prefix("plotjuggler_ros"));
extra_path += "/lib/plotjuggler_ros";
#else

#endif
} catch (...) {

QMessageBox::warning(nullptr, "Missing package [plotjuggler-ros]",
"If you just upgraded from PlotJuggler 2.x to 3.x , try installing this package:\n\n"
"sudo apt install ros-${ROS_DISTRO}-plotjuggler-ros",
QMessageBox::Cancel, QMessageBox::Cancel);
}

//---------------------------
TransformFactory::registerTransform<FirstDerivative>();
TransformFactory::registerTransform<ScaleTransform>();
Expand Down Expand Up @@ -139,6 +161,14 @@ int main(int argc, char* argv[])
"Automatically start publisher when loading the layout file");
parser.addOption(publish_option);

QCommandLineOption folder_option(QStringList() << "extra-plugin-folders",
"Add semicolon-separated list of folders where you should look for plugins.");
if(!extra_path.isEmpty())
{
folder_option.setDefaultValue( extra_path );
}
parser.addOption(folder_option);

QCommandLineOption buffersize_option(QStringList() << "buffer_size",
QCoreApplication::translate("main", "Change the maximum size of the streaming "
"buffer (minimum: 10 default: 60)"),
Expand Down
25 changes: 7 additions & 18 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "nlohmann_parsers.h"
#include "cheatsheet/cheatsheet_dialog.h"


MainWindow::MainWindow(const QCommandLineParser& commandline_parser, QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
Expand Down Expand Up @@ -146,28 +147,16 @@ MainWindow::MainWindow(const QCommandLineParser& commandline_parser, QWidget* pa

initializeActions();

QStringList loaded;
loaded += initializePlugins(QCoreApplication::applicationDirPath());
loaded += initializePlugins( QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation) + "/PlotJuggler" );

auto loaded_A = initializePlugins(QCoreApplication::applicationDirPath());
auto loaded_B = initializePlugins( QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation) + "/PlotJuggler" );
auto extra_folders = commandline_parser.value("extra-plugin-folders").split(";", QString::SkipEmptyParts);

#ifdef COMPILED_FOR_ROS
auto loaded = loaded_A + loaded_B;
bool has_ros_plugin = false;
for (const auto& class_name: loaded)
{
if( class_name.contains("ROS") ){
has_ros_plugin = true;
}
}
if( !has_ros_plugin )
for(const auto& folder: extra_folders)
{
QMessageBox::warning(this, "Missing package",
tr("PlotJuggler was compiled with ROS, but it wasn't able to load any ROS specific plugin.\n\n"
"If you just upgraded from PlotJuggler 2.x to 3.x , try installing this package:\n\n"
"sudo apt install ros-${ROS_DISTRO}-plotjuggler-ros"),
QMessageBox::Cancel, QMessageBox::Cancel);
loaded += initializePlugins(folder);
}
#endif

_undo_timer.start();

Expand Down

0 comments on commit 5e5636b

Please sign in to comment.