From 9f8eeda9e974eaba6ad66c7991d8e773d93b7a47 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Thu, 19 Nov 2020 17:44:35 -0800 Subject: [PATCH 1/3] add gazebo gui events Signed-off-by: John Shepherd --- include/ignition/gui/GuiEvents.hh | 152 ++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index 0f8b6fbee..7e72319b7 100644 --- a/include/ignition/gui/GuiEvents.hh +++ b/include/ignition/gui/GuiEvents.hh @@ -43,6 +43,158 @@ namespace ignition /// \brief Unique type for this event. static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser); }; + + /// \brief The class for sending and receiving custom snap value events. + class SnapIntervals : public QEvent + { + /// \brief Constructor + /// \param[in] _xyz XYZ snapping values. + /// \param[in] _rpy RPY snapping values. + /// \param[in] _scale Scale snapping values. + public: SnapIntervals( + const math::Vector3d &_xyz, + const math::Vector3d &_rpy, + const math::Vector3d &_scale) + : QEvent(kType), xyz(_xyz), rpy(_rpy), scale(_scale) + { + } + + /// \brief Get the XYZ snapping values. + /// \return The XYZ snapping values. + public: math::Vector3d XYZ() const + { + return this->xyz; + } + + /// \brief Get the RPY snapping values. + /// \return The RPY snapping values. + public: math::Vector3d RPY() const + { + return this->rpy; + } + + /// \brief Get the scale snapping values. + /// \return The scale snapping values. + public: math::Vector3d Scale() const + { + return this->scale; + } + + /// \brief The QEvent representing a snap event occurrence. + static const QEvent::Type kType = QEvent::Type(QEvent::User); + + /// \brief XYZ snapping values in meters, these values must be positive. + private: math::Vector3d xyz; + + /// \brief RPY snapping values in degrees, these values must be positive. + private: math::Vector3d rpy; + + /// \brief Scale snapping values - a multiplier of the current size, + /// these values must be positive. + private: math::Vector3d scale; + }; + + /// \brief Event called to spawn a preview model. + /// Used by plugins that spawn models. + class SpawnPreviewModel : public QEvent + { + /// \brief Constructor + /// \param[in] _modelSdfString The model's SDF file as a string. + public: explicit SpawnPreviewModel(std::string &_modelSdfString) + : QEvent(kType), modelSdfString(_modelSdfString) + { + } + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::User + 4); + + /// \brief Get the sdf string of the model. + /// \return The model sdf string + public: std::string ModelSdfString() const + { + return this->modelSdfString; + } + + /// \brief The sdf string of the model to be previewed. + std::string modelSdfString; + }; + + /// \brief Event called to spawn a preview resource, which takes the path + /// to the SDF file. Used by plugins that spawn resources. + class SpawnPreviewPath : public QEvent + { + /// \brief Constructor + /// \param[in] _filePath The path to an SDF file. + public: explicit SpawnPreviewPath(const std::string &_filePath) + : QEvent(kType), filePath(_filePath) + { + } + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::User + 5); + + /// \brief Get the path of the SDF file. + /// \return The file path. + public: std::string FilePath() const + { + return this->filePath; + } + + /// \brief The path of SDF file to be previewed. + std::string filePath; + }; + + /// \brief Event which is called to broadcast the 3D coordinates of a user's + /// mouse hover within the scene. + class HoverToScene : public QEvent + { + /// \brief Constructor + /// \param[in] _point The point at which the mouse is hovering within the + /// scene + public: explicit HoverToScene(const math::Vector3d &_point) + : QEvent(kType), point(_point) + { + } + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::User + 6); + + /// \brief Get the point within the scene over which the user is hovering. + /// \return The 3D point + public: math::Vector3d Point() const + { + return this->point; + } + + /// \brief The 3D point over which the user is hovering. + private: math::Vector3d point; + }; + + /// \brief Event which is called to broadcast the 3D coordinates of a user's + /// left click within the scene. + class LeftClickToScene : public QEvent + { + /// \brief Constructor + /// \param[in] _point The point which the user has left clicked within the + /// scene + public: explicit LeftClickToScene(const math::Vector3d &_point) + : QEvent(kType), point(_point) + { + } + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::User + 7); + + /// \brief Get the point within the scene that the user clicked. + /// \return The 3D point. + public: math::Vector3d Point() const + { + return this->point; + } + + /// \brief The 3D point that the user clicked within the scene. + private: math::Vector3d point; + }; } } } From be5a482d8da3da972dff28a187723c805378d367 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Fri, 20 Nov 2020 12:33:34 -0800 Subject: [PATCH 2/3] suggested fixes Signed-off-by: John Shepherd --- include/ignition/gui/GuiEvents.hh | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index 7e72319b7..3a24f5345 100644 --- a/include/ignition/gui/GuiEvents.hh +++ b/include/ignition/gui/GuiEvents.hh @@ -45,6 +45,8 @@ namespace ignition }; /// \brief The class for sending and receiving custom snap value events. + /// This event is used in the Transform Control plugin tool when the + /// user manually alters their snapping values. class SnapIntervals : public QEvent { /// \brief Constructor @@ -81,7 +83,7 @@ namespace ignition } /// \brief The QEvent representing a snap event occurrence. - static const QEvent::Type kType = QEvent::Type(QEvent::User); + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 1); /// \brief XYZ snapping values in meters, these values must be positive. private: math::Vector3d xyz; @@ -99,48 +101,48 @@ namespace ignition class SpawnPreviewModel : public QEvent { /// \brief Constructor - /// \param[in] _modelSdfString The model's SDF file as a string. - public: explicit SpawnPreviewModel(std::string &_modelSdfString) - : QEvent(kType), modelSdfString(_modelSdfString) + /// \param[in] _modelString The model's description as a string. + public: explicit SpawnPreviewModel(std::string &_modelString) + : QEvent(kType), modelString(_modelString) { } /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::User + 4); + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 2); - /// \brief Get the sdf string of the model. - /// \return The model sdf string - public: std::string ModelSdfString() const + /// \brief Get the string of the model. + /// \return The model string + public: std::string ModelString() const { - return this->modelSdfString; + return this->modelString; } - /// \brief The sdf string of the model to be previewed. - std::string modelSdfString; + /// \brief The string of the model to be previewed. + std::string modelString; }; /// \brief Event called to spawn a preview resource, which takes the path - /// to the SDF file. Used by plugins that spawn resources. + /// to s file. Used by plugins that spawn resources. class SpawnPreviewPath : public QEvent { /// \brief Constructor - /// \param[in] _filePath The path to an SDF file. + /// \param[in] _filePath The path to a file. public: explicit SpawnPreviewPath(const std::string &_filePath) : QEvent(kType), filePath(_filePath) { } /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::User + 5); + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 3); - /// \brief Get the path of the SDF file. + /// \brief Get the path of the file. /// \return The file path. public: std::string FilePath() const { return this->filePath; } - /// \brief The path of SDF file to be previewed. + /// \brief The path of file to be previewed. std::string filePath; }; @@ -157,7 +159,7 @@ namespace ignition } /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::User + 6); + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 4); /// \brief Get the point within the scene over which the user is hovering. /// \return The 3D point @@ -183,7 +185,7 @@ namespace ignition } /// \brief Unique type for this event. - static const QEvent::Type kType = QEvent::Type(QEvent::User + 7); + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 5); /// \brief Get the point within the scene that the user clicked. /// \return The 3D point. From e4e60121178b33cd9fa54f6dabc8bb49973064de Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 10 Dec 2020 11:23:20 -0800 Subject: [PATCH 3/3] Suggestions to #148 (#150) * Suggestions to #148 * more codecheck Signed-off-by: Louise Poubel --- include/ignition/gui/GuiEvents.hh | 106 ++++++++++++++++-------------- src/CMakeLists.txt | 1 + src/GuiEvents_TEST.cc | 80 ++++++++++++++++++++++ 3 files changed, 136 insertions(+), 51 deletions(-) create mode 100644 src/GuiEvents_TEST.cc diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index 3a24f5345..08d776a54 100644 --- a/include/ignition/gui/GuiEvents.hh +++ b/include/ignition/gui/GuiEvents.hh @@ -18,6 +18,7 @@ #define IGNITION_GUI_GUIEVENTS_HH_ #include +#include #include #include #include @@ -60,140 +61,143 @@ namespace ignition : QEvent(kType), xyz(_xyz), rpy(_rpy), scale(_scale) { } - + /// \brief Get the XYZ snapping values. /// \return The XYZ snapping values. - public: math::Vector3d XYZ() const + public: math::Vector3d Position() const { return this->xyz; } - + /// \brief Get the RPY snapping values. /// \return The RPY snapping values. - public: math::Vector3d RPY() const + public: math::Vector3d Rotation() const { return this->rpy; } - + /// \brief Get the scale snapping values. /// \return The scale snapping values. public: math::Vector3d Scale() const { return this->scale; } - + /// \brief The QEvent representing a snap event occurrence. static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 1); - + /// \brief XYZ snapping values in meters, these values must be positive. private: math::Vector3d xyz; - - /// \brief RPY snapping values in degrees, these values must be positive. + + /// \brief RPY snapping values in degrees, these values must be + /// positive. private: math::Vector3d rpy; - + /// \brief Scale snapping values - a multiplier of the current size, /// these values must be positive. private: math::Vector3d scale; }; - /// \brief Event called to spawn a preview model. - /// Used by plugins that spawn models. - class SpawnPreviewModel : public QEvent + /// \brief Event called to spawn a resource, given its description as a + /// string. + class SpawnFromDescription : public QEvent { /// \brief Constructor - /// \param[in] _modelString The model's description as a string. - public: explicit SpawnPreviewModel(std::string &_modelString) - : QEvent(kType), modelString(_modelString) + /// \param[in] _string The resource's description as a string, such + /// as an SDF file. + public: explicit SpawnFromDescription(const std::string &_description) + : QEvent(kType), description(_description) { } - + /// \brief Unique type for this event. static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 2); - - /// \brief Get the string of the model. - /// \return The model string - public: std::string ModelString() const + + /// \brief Get the string description of the resource. + /// \return The resource string + public: const std::string &Description() const { - return this->modelString; + return this->description; } - - /// \brief The string of the model to be previewed. - std::string modelString; + + /// \brief The string of the resource to be spawned. + std::string description; }; - - /// \brief Event called to spawn a preview resource, which takes the path - /// to s file. Used by plugins that spawn resources. - class SpawnPreviewPath : public QEvent + + /// \brief Event called to spawn a resource, which takes the path + /// to its file. + class SpawnFromPath : public QEvent { /// \brief Constructor /// \param[in] _filePath The path to a file. - public: explicit SpawnPreviewPath(const std::string &_filePath) + public: explicit SpawnFromPath(const std::string &_filePath) : QEvent(kType), filePath(_filePath) { } - + /// \brief Unique type for this event. static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 3); - + /// \brief Get the path of the file. /// \return The file path. - public: std::string FilePath() const + public: const std::string &FilePath() const { return this->filePath; } - + /// \brief The path of file to be previewed. std::string filePath; }; - - /// \brief Event which is called to broadcast the 3D coordinates of a user's - /// mouse hover within the scene. + + /// \brief Event which is called to broadcast the 3D coordinates of a + /// user's mouse hover within the scene. class HoverToScene : public QEvent { /// \brief Constructor - /// \param[in] _point The point at which the mouse is hovering within the - /// scene + /// \param[in] _point The point at which the mouse is hovering within + /// the scene public: explicit HoverToScene(const math::Vector3d &_point) : QEvent(kType), point(_point) { } - + /// \brief Unique type for this event. static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 4); - - /// \brief Get the point within the scene over which the user is hovering. + + /// \brief Get the point within the scene over which the user is + /// hovering. /// \return The 3D point public: math::Vector3d Point() const { return this->point; } - + /// \brief The 3D point over which the user is hovering. private: math::Vector3d point; }; - - /// \brief Event which is called to broadcast the 3D coordinates of a user's - /// left click within the scene. + + /// \brief Event which is called to broadcast the 3D coordinates of a + /// user's left click within the scene. class LeftClickToScene : public QEvent { /// \brief Constructor - /// \param[in] _point The point which the user has left clicked within the - /// scene + /// \param[in] _point The point which the user has left clicked within + /// the scene public: explicit LeftClickToScene(const math::Vector3d &_point) : QEvent(kType), point(_point) { } - + /// \brief Unique type for this event. static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 5); - + /// \brief Get the point within the scene that the user clicked. /// \return The 3D point. public: math::Vector3d Point() const { return this->point; } - + /// \brief The 3D point that the user clicked within the scene. private: math::Vector3d point; }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a5b3f1302..61f278399 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,7 @@ set (gtest_sources Conversions_TEST DragDropModel_TEST Helpers_TEST + GuiEvents_TEST ign_TEST MainWindow_TEST Plugin_TEST diff --git a/src/GuiEvents_TEST.cc b/src/GuiEvents_TEST.cc new file mode 100644 index 000000000..0bdb24d74 --- /dev/null +++ b/src/GuiEvents_TEST.cc @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#include + +#include "test_config.h" // NOLINT(build/include) +#include "ignition/gui/GuiEvents.hh" + +using namespace ignition; +using namespace gui; + +///////////////////////////////////////////////// +TEST(GuiEventsTest, Render) +{ + events::Render event; + + EXPECT_LT(QEvent::User, event.type()); +} + +///////////////////////////////////////////////// +TEST(GuiEventsTest, SnapIntervals) +{ + events::SnapIntervals event({1, 2, 3}, {4, 5, 6}, {7, 8, 9}); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ(math::Vector3d(1, 2, 3), event.Position()); + EXPECT_EQ(math::Vector3d(4, 5, 6), event.Rotation()); + EXPECT_EQ(math::Vector3d(7, 8, 9), event.Scale()); +} + +///////////////////////////////////////////////// +TEST(GuiEventsTest, SpawnFromDescription) +{ + events::SpawnFromDescription event("banana"); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ("banana", event.Description()); +} + +///////////////////////////////////////////////// +TEST(GuiEventsTest, SpawnFromPath) +{ + events::SpawnFromPath event("banana"); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ("banana", event.FilePath()); +} + +///////////////////////////////////////////////// +TEST(GuiEventsTest, HoverToScene) +{ + events::HoverToScene event({1, 2, 3}); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ(math::Vector3d(1, 2, 3), event.Point()); +} + +///////////////////////////////////////////////// +TEST(GuiEventsTest, LeftClickToScene) +{ + events::LeftClickToScene event({1, 2, 3}); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ(math::Vector3d(1, 2, 3), event.Point()); +} +