Skip to content

Commit

Permalink
Adds visibility control.
Browse files Browse the repository at this point in the history
  • Loading branch information
agalbachicar committed Apr 6, 2021
1 parent 40f1b95 commit 5049e95
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
15 changes: 14 additions & 1 deletion delphyne_gui/visualizer/display_plugins/OriginDisplay.qml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3


Rectangle {
id: originDisplay
color: "transparent"
Layout.minimumWidth: 290
Layout.minimumHeight: 110
Layout.fillWidth: true

// Checkbox to toggle axes visibility.
RowLayout {
CheckBox {
id: visibilityCheckbox
text: qsTr("Visible")
checked: OriginDisplay.isVisible
onClicked : {
visibilityCheckbox.checked = !OriginDisplay.isVisible;
OriginDisplay.isVisible = !OriginDisplay.isVisible;
}
}
}
}
21 changes: 18 additions & 3 deletions delphyne_gui/visualizer/display_plugins/origin_display.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2021 Toyota Research Institute
#include "origin_display.hh"

#include <array>
#include <cmath>

#include <ignition/common/Console.hh>
Expand All @@ -24,6 +23,11 @@ void OriginDisplay::LoadConfig(const tinyxml2::XMLElement* _pluginElem) {
if (auto elem = _pluginElem->FirstChildElement("scene")) {
sceneName = elem->GetText();
}
// Similarly with the visibility flag.
if (auto elem = _pluginElem->FirstChildElement("visible")) {
elem->QueryBoolText(&isVisible);
IsVisibleChanged();
}
}

// Get the render engine.
Expand Down Expand Up @@ -62,7 +66,7 @@ void OriginDisplay::timerEvent(QTimerEvent* _event) {
DrawAxes(scene);
}

void OriginDisplay::DrawAxes(ignition::rendering::ScenePtr scene) const {
void OriginDisplay::DrawAxes(ignition::rendering::ScenePtr scene) {
constexpr double kAxisRadius{0.02};
constexpr double kAxisLength{10000.0};
constexpr double kAxisHalfLength{kAxisLength / 2.0};
Expand All @@ -72,7 +76,6 @@ void OriginDisplay::DrawAxes(ignition::rendering::ScenePtr scene) const {
scene->RootVisual()->AddChild(visual);

// Create the visual axes.
std::array<ignition::rendering::VisualPtr, 3> axes;
for (auto& axis : axes) {
axis = scene->CreateVisual();
if (!axis) {
Expand Down Expand Up @@ -105,6 +108,18 @@ void OriginDisplay::DrawAxes(ignition::rendering::ScenePtr scene) const {
for (auto& axis : axes) {
visual->AddChild(axis);
}

// Set the visibility of the visuals
ChangeAxesVisibility();
}

void OriginDisplay::ChangeAxesVisibility() {
bool newIsVisibleValue = isVisible;
if (axes[0] != nullptr) {
for (auto& axis : axes) {
axis->SetVisible(newIsVisibleValue);
}
}
}

} // namespace gui
Expand Down
30 changes: 29 additions & 1 deletion delphyne_gui/visualizer/display_plugins/origin_display.hh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright 2021 Toyota Research Institute
#pragma once

#include <array>
#include <string>

#include <ignition/gui/Plugin.hh>
#include <ignition/rendering/RenderTypes.hh>
#include <ignition/rendering/Visual.hh>

namespace delphyne {
namespace gui {
Expand All @@ -17,9 +19,13 @@ namespace gui {
/// available, then it starts a timer and tries periodically to
/// retrieve the scene.
/// Typically, this plugin goes hand in hand with the Scene3D plugin.
/// The plugin UI has a checkbox to toggle visibility. It is paired
/// with `isVisible`
class OriginDisplay : public ignition::gui::Plugin {
Q_OBJECT

Q_PROPERTY(bool isVisible READ IsVisible WRITE SetIsVisible NOTIFY IsVisibleChanged)

public:
OriginDisplay() = default;

Expand All @@ -30,6 +36,19 @@ class OriginDisplay : public ignition::gui::Plugin {
/// It only works with ogre rendering engine.
void LoadConfig(const tinyxml2::XMLElement* _pluginElem) override;

/// @{ isVisible accessors.
Q_INVOKABLE bool IsVisible() const { return isVisible; }

Q_INVOKABLE void SetIsVisible(bool _isVisible) {
isVisible = _isVisible;
IsVisibleChanged();
ChangeAxesVisibility();
}
/// @}

signals:
void IsVisibleChanged();

protected:
/// @brief Timer event callback which handles the logic to draw the axes when
/// the scene is not ready yet.
Expand All @@ -44,13 +63,22 @@ class OriginDisplay : public ignition::gui::Plugin {

/// @brief Draws the axes in the scene.
/// @param scene The scene to draw the axes into.
void DrawAxes(ignition::rendering::ScenePtr scene) const;
void DrawAxes(ignition::rendering::ScenePtr scene);

/// @brief Toggles the visibility of the axes.
void ChangeAxesVisibility();

/// @brief Triggers an event every `kTimerPeriodInMs` to try to draw the axes.
QBasicTimer timer;

/// @brief The scene name.
std::string sceneName{"scene"};

/// @brief Holds the visibility status of the axes.
bool isVisible{true};

/// @brief Pointers to the visual axes
std::array<ignition::rendering::VisualPtr, 3> axes{nullptr, nullptr, nullptr};
};

} // namespace gui
Expand Down

0 comments on commit 5049e95

Please sign in to comment.