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

Add FixedFrame tf status in GlobalOptions #69

Merged
merged 6 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions ign_rviz_plugins/include/ignition/rviz/plugins/GlobalOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>
#include <memory>
#include <utility>
#include <vector>

#include "ignition/rviz/plugins/message_display_base.hpp"

Expand All @@ -37,6 +38,98 @@ namespace rviz
{
namespace plugins
{
/**
* @brief TF status and message
*
* Displays tf status and message under GlobalOptions
*/
class TFStatus : public QObject
{
Q_OBJECT

/**
* @brief TF status
*/
Q_PROPERTY(
QString status
READ getStatus
NOTIFY statusChanged
)

/**
* @brief TF status message
*/
Q_PROPERTY(
QString message
READ getMessage
NOTIFY messageChanged
)

/**
* @brief TF status color
*/
Q_PROPERTY(
QString color
READ getColor
NOTIFY colorChanged
)

public:
// Constructor
TFStatus();

// Destructor
~TFStatus() {}

/**
* @brief Update tf status and message
* @param[in] _fixedFrame FixedFrame name
* @param[in] _allFrames List of all frames
*/
void update(std::string & _fixedFrame, std::vector<std::string> & _allFrames);

/**
* @brief Get the TF status as a string
* @return TF status
*/
Q_INVOKABLE QString getStatus() const;

/**
* @brief Get the TF status message as a string
* @return TF status message
*/
Q_INVOKABLE QString getMessage() const;

/**
* @brief Get the TF status color as a string
* @return TF status color
*/
Q_INVOKABLE QString getColor() const;

signals:
/**
* @brief Notify that TF status has changed
*/
void statusChanged();

signals:
/**
* @brief Notify that TF message has changed
*/
void messageChanged();

signals:
/**
* @brief Notify that TF color has changed
*/
void colorChanged();

private:
QString status;
QString message;
QString color;
};

/**
* @brief Configure global option of ignition rviz
*
Expand All @@ -56,6 +149,15 @@ class GlobalOptions : public MessageDisplayBase
NOTIFY frameListChanged
)

/**
* @brief TF status
*/
Q_PROPERTY(
TFStatus * tfStatus
READ getTfStatus
NOTIFY tfStatusChanged
)

public:
// Constructor
GlobalOptions();
Expand Down Expand Up @@ -93,6 +195,12 @@ class GlobalOptions : public MessageDisplayBase
*/
Q_INVOKABLE QStringList getFrameList() const;

/**
* @brief Get the TF status as a TFStatus object
* @return TFStatus object
*/
Q_INVOKABLE TFStatus * getTfStatus() const;

/**
* @brief Set the frame list from a string
* @param[in] _frameList List of frames
Expand All @@ -105,6 +213,12 @@ class GlobalOptions : public MessageDisplayBase
*/
void frameListChanged();

signals:
/**
* @brief Notify that TF status has changed
*/
void tfStatusChanged();

signals:
/**
* @brief Set combo box index
Expand All @@ -127,6 +241,7 @@ public slots:
bool initialized;
bool populated;
QColor color;
TFStatus * tfStatus;
};

} // namespace plugins
Expand Down
23 changes: 22 additions & 1 deletion ign_rviz_plugins/res/qml/GlobalOptions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import QtQuick.Dialogs 1.0

Item {
Layout.minimumWidth: 280
Layout.minimumHeight: 200
Layout.minimumHeight: 220
anchors.fill: parent
anchors.margins: 10

Expand Down Expand Up @@ -104,6 +104,27 @@ Item {
}
}
}

RowLayout {
width: parent.width
spacing: 10

Label {
id: "status"
text: GlobalOptions.tfStatus.status
color: GlobalOptions.tfStatus.color
font.pointSize: 11
}

Label {
id: "message"
text: GlobalOptions.tfStatus.message
color: GlobalOptions.tfStatus.color
font.pointSize: 11
Layout.fillWidth: true
elide: Label.ElideRight
}
}
}

ColorDialog {
Expand Down
65 changes: 64 additions & 1 deletion ign_rviz_plugins/src/rviz/plugins/GlobalOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,56 @@ namespace rviz
{
namespace plugins
{
////////////////////////////////////////////////////////////////////////////////
TFStatus::TFStatus()
: status(" "), message(" "), color("green")
{}

////////////////////////////////////////////////////////////////////////////////
void TFStatus::update(std::string & _fixedFrame, std::vector<std::string> & _allFrames)
{
// Check for tf data
auto framePosition = std::find(_allFrames.begin(), _allFrames.end(), _fixedFrame);

if (_allFrames.empty()) {
std::string msg = "No tf data. Frame [" + _fixedFrame + "] does not exist";

this->status = QString::fromStdString("Fixed Frame [Warn]");
this->message = QString::fromStdString(msg);
this->color = QString::fromStdString("orange");
} else if (framePosition == _allFrames.end()) {
std::string msg = "Frame [" + _fixedFrame + "] does not exist";

this->status = QString::fromStdString("Fixed Frame [Error]");
this->message = QString::fromStdString(msg);
this->color = QString::fromStdString("red");
} else {
std::string msg = "OK";

this->status = QString::fromStdString("Fixed Frame");
this->message = QString::fromStdString(msg);
this->color = QString::fromStdString("green");
}
}

////////////////////////////////////////////////////////////////////////////////
QString TFStatus::getStatus() const
{
return this->status;
}

////////////////////////////////////////////////////////////////////////////////
QString TFStatus::getMessage() const
{
return this->message;
}

////////////////////////////////////////////////////////////////////////////////
QString TFStatus::getColor() const
{
return this->color;
}

////////////////////////////////////////////////////////////////////////////////
GlobalOptions::GlobalOptions()
: dirty(false), initialized(false), populated(false), color("#303030")
Expand All @@ -42,7 +92,7 @@ GlobalOptions::GlobalOptions()
igndbg << "Engine '" << "ogre" << "' is not supported" << std::endl;
return;
}

this->tfStatus = new TFStatus();
this->frameList.push_back("world");
}

Expand Down Expand Up @@ -97,6 +147,13 @@ bool GlobalOptions::eventFilter(QObject * _object, QEvent * _event)
this->scene->SetBackgroundColor(math::Color(color.redF(), color.greenF(), color.blue()));
this->dirty = false;
}

// Update tf status and message
std::vector<std::string> allFrames;
this->frameManager->getFrames(allFrames);
std::string fixedFrame = this->frameManager->getFixedFrame();
this->tfStatus->update(fixedFrame, allFrames);
emit tfStatusChanged();
}

// Update combo-box on frame list change
Expand All @@ -120,6 +177,12 @@ QStringList GlobalOptions::getFrameList() const
return this->frameList;
}

////////////////////////////////////////////////////////////////////////////////
TFStatus * GlobalOptions::getTfStatus() const
{
return this->tfStatus;
}

////////////////////////////////////////////////////////////////////////////////
void GlobalOptions::onRefresh()
{
Expand Down