Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added zcm streaming support #827

Merged
merged 17 commits into from
Jun 6, 2023
Merged
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ add_subdirectory( plotjuggler_plugins/ParserProtobuf )
add_subdirectory( plotjuggler_plugins/ParserROS )
add_subdirectory( plotjuggler_plugins/ParserDataTamer )

add_subdirectory( plotjuggler_plugins/PluginsZcm )

# Install targets

install(
Expand Down
56 changes: 56 additions & 0 deletions plotjuggler_plugins/PluginsZcm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
if(BUILDING_WITH_VCPKG)
message(STATUS "Finding Zcm with vcpkg")
set(Zcm_LIBRARIES libzcm)
elseif(BUILDING_WITH_CONAN)
message(STATUS "Finding Zcm with conan")
set(Zcm_LIBRARIES libzcm)
else()
message(STATUS "Finding Zcm without package managers")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
endif()

find_package(Zcm QUIET)

if(Zcm_FOUND)

message(STATUS "[Zcm] found")

include_directories( ${Zcm_INCLUDE_DIR})

add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)

# Streaming plugin
QT5_WRAP_UI(STREAM_UI datastream_zcm.ui config_zcm.ui )
add_library(DataStreamZcm SHARED
datastream_zcm.h
datastream_zcm.cpp
config_zcm.h
config_zcm.cpp
${STREAM_UI})

# log loading plugin
target_link_libraries(DataStreamZcm
${Qt5Widgets_LIBRARIES}
plotjuggler_base
${Zcm_LIBRARIES} )

QT5_WRAP_UI(LOAD_UI dataload_zcm.ui config_zcm.ui)
add_library(DataLoadZcm SHARED
dataload_zcm.h
dataload_zcm.cpp
config_zcm.h
config_zcm.cpp
${LOAD_UI})

target_link_libraries(DataLoadZcm
${Qt5Widgets_LIBRARIES}
plotjuggler_base
${Zcm_LIBRARIES} )

install(TARGETS DataStreamZcm DataLoadZcm
DESTINATION ${PJ_PLUGIN_INSTALL_DIRECTORY} )
else()
message("[Zcm] not found. Skipping plugin DataStreamZcma and DataLoadZcm.")
endif()

21 changes: 21 additions & 0 deletions plotjuggler_plugins/PluginsZcm/cmake/FindZcm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# - Try to find Zcm
# Once done this will define
# Zcm_FOUND - System has Zcm
# Zcm_INCLUDE_DIRS - The Zcm include directories
# Zcm_LIBRARIES - The libraries needed to use Zcm
# Zcm_DEFINITIONS - Compiler switches required for using Zcm

find_path ( Zcm_INCLUDE_DIR zcm/zcm-cpp.hpp PATHS $ENV{PJ_ZCM_INSTALL_DIR}/include )
find_path ( Zcm_INCLUDE_DIR zcm/zcm-cpp.hpp )
find_library ( Zcm_LIBRARY NAMES zcm PATHS $ENV{PJ_ZCM_INSTALL_DIR}/lib )
find_library ( Zcm_LIBRARY NAMES zcm )
find_library ( ZcmToolsUtil_LIBRARY NAMES zcm_tools_util PATHS $ENV{PJ_ZCM_INSTALL_DIR}/lib )
find_library ( ZcmToolsUtil_LIBRARY NAMES zcm_tools_util )

set ( Zcm_LIBRARIES ${Zcm_LIBRARY} ${ZcmToolsUtil_LIBRARY} )
set ( Zcm_INCLUDE_DIRS ${Zcm_INCLUDE_DIR} )

include ( FindPackageHandleStandardArgs )
# handle the QUIETLY and REQUIRED arguments and set Zcm_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args ( Zcm DEFAULT_MSG Zcm_LIBRARY Zcm_INCLUDE_DIR )
93 changes: 93 additions & 0 deletions plotjuggler_plugins/PluginsZcm/config_zcm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "config_zcm.h"
#include "ui_config_zcm.h"

#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QFileInfo>


ConfigZCM::ConfigZCM(QString prefix, QWidget *parent)
: QWidget(parent)
, ui(new Ui::ConfigZCM)
, _prefix(prefix)
{
ui->setupUi(this);

QSettings settings;
auto libs = settings.value(_prefix + "::manual_libs", {}).toStringList();
for (auto const &lib : libs) {
ui->listWidgetLibs->addItem(lib);
}

bool is_manual = settings.value(_prefix + "::is_manual", false).toBool();
ui->radioManualLibrary->setChecked(is_manual);
}

ConfigZCM::~ConfigZCM()
{
QSettings settings;

QStringList libs;
for (int row = 0; row < ui->listWidgetLibs->count(); row++) {
libs << ui->listWidgetLibs->item(row)->text();
}
settings.setValue(_prefix + "::manual_libs", libs);
settings.setValue(_prefix + "::is_manual", ui->radioManualLibrary->isChecked());
delete ui;
}

QString ConfigZCM::getLibraries() const
{
if (ui->radioEnvironmentLibrary->isChecked()) {
return getenv("PJ_ZCMTYPES_LIB_PATH");
} else {
QStringList libs;
for (int row = 0; row < ui->listWidgetLibs->count(); row++) {
libs << ui->listWidgetLibs->item(row)->text();
}
return libs.join(":");
}
}

void ConfigZCM::on_radioEnvironmentLibrary_toggled(bool checked)
{
if (checked) {
ui->radioManualLibrary->setChecked(false);
}
}

void ConfigZCM::on_radioManualLibrary_toggled(bool checked)
{
if (checked) {
ui->radioEnvironmentLibrary->setChecked(false);
}
ui->manualWidget->setEnabled(checked);
}

void ConfigZCM::on_pushButtonAdd_clicked()
{
QSettings settings;
auto dir = settings.value(_prefix + "::load_dir", QDir::currentPath()).toString();
auto files = QFileDialog::getOpenFileNames(this, "Zcm libraries", dir, "*.so *.dll");
for (auto filename : files) {
if (ui->listWidgetLibs->findItems(filename, Qt::MatchExactly).empty()) {
ui->listWidgetLibs->addItem(filename);
}
}
ui->listWidgetLibs->sortItems();
if(!files.empty()){
settings.setValue(_prefix + "::load_dir",
QFileInfo(files.front()).dir().absolutePath());
}
}

void ConfigZCM::on_pushButtonRemove_clicked()
{
auto items = ui->listWidgetLibs->selectedItems();
for(auto item: items) {
ui->listWidgetLibs->removeItemWidget(item);
delete item;
}
}

32 changes: 32 additions & 0 deletions plotjuggler_plugins/PluginsZcm/config_zcm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <QWidget>

namespace Ui {
class ConfigZCM;
}

class ConfigZCM : public QWidget
{
Q_OBJECT

public:
explicit ConfigZCM(QString prefix, QWidget *parent = nullptr);
~ConfigZCM();

QString getLibraries() const;

private slots:
void on_radioEnvironmentLibrary_toggled(bool checked);

void on_radioManualLibrary_toggled(bool checked);

void on_pushButtonAdd_clicked();

void on_pushButtonRemove_clicked();

private:
Ui::ConfigZCM *ui;
QString _prefix;
};

159 changes: 159 additions & 0 deletions plotjuggler_plugins/PluginsZcm/config_zcm.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigZCM</class>
<widget class="QWidget" name="ConfigZCM">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>553</width>
<height>264</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;Zcm types library:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioEnvironmentLibrary">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Read values from an environment variable &lt;span style=&quot; font-weight:700;&quot;&gt;PJ_ZCMTYPES_LIB_PATH&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Use PJ_ZCMTYPES_LIB_PATH</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioManualLibrary">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use the libraries in the list below&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Select manually</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="manualWidget" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidgetLibs">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="pushButtonAdd">
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add Libraries&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonRemove">
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Remove selected libraries&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading