From 22501566812aaa30d6dcafe197e99619303e469b Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Wed, 28 Jul 2021 18:38:32 -0400 Subject: [PATCH 1/7] drag and drop mesh Signed-off-by: Jenn Nguyen --- src/gui/plugins/scene3d/Scene3D.cc | 53 +++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 66c31073c3..0bb96fcf42 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -2811,7 +2812,57 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) math::Vector3d pos = renderWindow->ScreenToScene({_mouseX, _mouseY}); msgs::EntityFactory req; - req.set_sdf_filename(_drop.toStdString()); + std::string dropStr = _drop.toStdString(); + if (QUrl(_drop).isLocalFile()) + { + // mesh to sdf model + common::rtrim(dropStr); + std::string lowerStr = common::lowercase(dropStr); + + if (!common::EndsWith(lowerStr, ".dae") + && !common::EndsWith(lowerStr, ".stl")) + { + ignwarn << "Only DAE and STL meshes are supported." + << std::endl; + return; + } + + // Fixes whitespace + dropStr = common::replaceAll(dropStr, "%20", " "); + + std::string filename = common::basename(dropStr); + std::vector splitName = common::split(filename, "."); + + std::string sdf = "" + "" + "" + "" + "" + "" + "" + "" + dropStr + "" + "" + "" + "" + "" + "" + "" + "" + dropStr + "" + "" + "" + "" + "" + "" + ""; + + req.set_sdf(sdf); + } + else + { + // model from fuel + req.set_sdf_filename(dropStr); + } + req.set_allow_renaming(true); msgs::Set(req.mutable_pose(), math::Pose3d(pos.X(), pos.Y(), pos.Z(), 1, 0, 0, 0)); From bf7731282f9e13485fbf6f6a360d0997fac861fb Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Fri, 30 Jul 2021 16:06:53 -0700 Subject: [PATCH 2/7] pop error for invalid mesh Signed-off-by: Jenn Nguyen --- src/gui/plugins/scene3d/GzScene3D.qml | 21 +++++++++++++++++++++ src/gui/plugins/scene3d/Scene3D.cc | 7 ++----- src/gui/plugins/scene3d/Scene3D.hh | 3 +++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/gui/plugins/scene3d/GzScene3D.qml b/src/gui/plugins/scene3d/GzScene3D.qml index 1f8289465f..38c986a1d4 100644 --- a/src/gui/plugins/scene3d/GzScene3D.qml +++ b/src/gui/plugins/scene3d/GzScene3D.qml @@ -98,4 +98,25 @@ Rectangle { GzScene3D.OnDropped(drop.text, drag.x, drag.y) } } + + // pop error for Scene3D::OnDropped + Connections { + target: GzScene3D + onPopupError: errorPopup.open() + } + + Popup { + id: errorPopup + parent: ApplicationWindow.overlay + dim: true + anchors.centerIn: parent + background: Rectangle { + border.width: 3 + border.color: "red" + } + Text { + text: "Unable to load mesh: only DAE, OBJ, and STL meshes are supported." + } + } + } diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 3fe03d3b33..3e349ca175 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2814,13 +2814,10 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) { // mesh to sdf model common::rtrim(dropStr); - std::string lowerStr = common::lowercase(dropStr); - if (!common::EndsWith(lowerStr, ".dae") - && !common::EndsWith(lowerStr, ".stl")) + if (!common::MeshManager::Instance()->IsValidFilename(dropStr)) { - ignwarn << "Only DAE and STL meshes are supported." - << std::endl; + this->popupError(); return; } diff --git a/src/gui/plugins/scene3d/Scene3D.hh b/src/gui/plugins/scene3d/Scene3D.hh index 97289bd412..56684e2189 100644 --- a/src/gui/plugins/scene3d/Scene3D.hh +++ b/src/gui/plugins/scene3d/Scene3D.hh @@ -161,6 +161,9 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { private: bool OnViewCollisions(const msgs::StringMsg &_msg, msgs::Boolean &_res); + /// \brief Notify that an error has occurred during OnDrop (opens popup) + signals: void popupError(); + /// \internal /// \brief Pointer to private data. private: std::unique_ptr dataPtr; From 7717bac063cf7940e38c6afff8cb440a5887d524 Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Fri, 30 Jul 2021 16:36:39 -0700 Subject: [PATCH 3/7] modifiable error popup Signed-off-by: Jenn Nguyen --- src/gui/plugins/scene3d/GzScene3D.qml | 4 ++-- src/gui/plugins/scene3d/Scene3D.cc | 19 ++++++++++++++++++- src/gui/plugins/scene3d/Scene3D.hh | 21 ++++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/gui/plugins/scene3d/GzScene3D.qml b/src/gui/plugins/scene3d/GzScene3D.qml index 38c986a1d4..7195c373e7 100644 --- a/src/gui/plugins/scene3d/GzScene3D.qml +++ b/src/gui/plugins/scene3d/GzScene3D.qml @@ -99,7 +99,7 @@ Rectangle { } } - // pop error for Scene3D::OnDropped + // pop error Connections { target: GzScene3D onPopupError: errorPopup.open() @@ -115,7 +115,7 @@ Rectangle { border.color: "red" } Text { - text: "Unable to load mesh: only DAE, OBJ, and STL meshes are supported." + text: GzScene3D.errorPopupText } } diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 3e349ca175..955602ced2 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -374,6 +374,9 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \brief View collisions service public: std::string viewCollisionsService; + + /// \brief Text for popup error message + public: QString errorPopupText; }; } } @@ -2817,7 +2820,7 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) if (!common::MeshManager::Instance()->IsValidFilename(dropStr)) { - this->popupError(); + this->SetErrorPopupText("Only DAE, OBJ, and STL meshes are supported."); return; } @@ -2865,6 +2868,20 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) req, cb); } +///////////////////////////////////////////////// +QString Scene3D::ErrorPopupText() const +{ + return this->dataPtr->errorPopupText; +} + +///////////////////////////////////////////////// +void Scene3D::SetErrorPopupText(const QString &_errorTxt) +{ + this->dataPtr->errorPopupText = _errorTxt; + this->ErrorPopupTextChanged(); + this->popupError(); +} + ///////////////////////////////////////////////// void Scene3D::OnFocusWindow() { diff --git a/src/gui/plugins/scene3d/Scene3D.hh b/src/gui/plugins/scene3d/Scene3D.hh index 56684e2189..7be0035d92 100644 --- a/src/gui/plugins/scene3d/Scene3D.hh +++ b/src/gui/plugins/scene3d/Scene3D.hh @@ -80,6 +80,14 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { { Q_OBJECT + /// \brief Text for popup error + Q_PROPERTY( + QString errorPopupText + READ ErrorPopupText + WRITE SetErrorPopupText + NOTIFY ErrorPopupTextChanged + ) + /// \brief Constructor public: Scene3D(); @@ -161,7 +169,18 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { private: bool OnViewCollisions(const msgs::StringMsg &_msg, msgs::Boolean &_res); - /// \brief Notify that an error has occurred during OnDrop (opens popup) + /// \brief Get the text for the popup error message + /// \return The error text + public: Q_INVOKABLE QString ErrorPopupText() const; + + /// \brief Set the text for the popup error message + /// \param[in] _errorTxt The error text + public: Q_INVOKABLE void SetErrorPopupText(const QString &_errorTxt); + + /// \brief Notify the popup error text has changed + signals: void ErrorPopupTextChanged(); + + /// \brief Notify that an error has occurred (opens popup) signals: void popupError(); /// \internal From 805bd9bc21b596b655ede1fcc4fc1288366c96dc Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Mon, 2 Aug 2021 14:22:02 -0700 Subject: [PATCH 4/7] added comment Signed-off-by: Jenn Nguyen --- src/gui/plugins/scene3d/Scene3D.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/plugins/scene3d/Scene3D.hh b/src/gui/plugins/scene3d/Scene3D.hh index 7be0035d92..918ab9af05 100644 --- a/src/gui/plugins/scene3d/Scene3D.hh +++ b/src/gui/plugins/scene3d/Scene3D.hh @@ -181,6 +181,8 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { signals: void ErrorPopupTextChanged(); /// \brief Notify that an error has occurred (opens popup) + /// Note that the function name needs to start with lowercase in order for + /// the connection to work on the QML side signals: void popupError(); /// \internal From 38893b969b0a300f548a68f19e9437e2328d9125 Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Mon, 2 Aug 2021 16:31:56 -0700 Subject: [PATCH 5/7] popup to dialog Signed-off-by: Jenn Nguyen --- src/gui/plugins/scene3d/GzScene3D.qml | 12 ++++++++---- src/gui/plugins/scene3d/Scene3D.cc | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/gui/plugins/scene3d/GzScene3D.qml b/src/gui/plugins/scene3d/GzScene3D.qml index 7195c373e7..5b36a40429 100644 --- a/src/gui/plugins/scene3d/GzScene3D.qml +++ b/src/gui/plugins/scene3d/GzScene3D.qml @@ -15,7 +15,8 @@ * */ import QtQuick 2.9 -import QtQuick.Controls 2.0 +import QtQuick.Controls 2.2 +import QtQuick.Dialogs 1.0 import RenderWindow 1.0 import QtGraphicalEffects 1.0 import IgnGazebo 1.0 as IgnGazebo @@ -105,18 +106,21 @@ Rectangle { onPopupError: errorPopup.open() } - Popup { + Dialog { id: errorPopup parent: ApplicationWindow.overlay - dim: true + modal: true + focus: true anchors.centerIn: parent background: Rectangle { - border.width: 3 + border.width: 5 border.color: "red" } + title: "Error" Text { text: GzScene3D.errorPopupText } + standardButtons: Dialog.Ok } } diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 955602ced2..80de372a24 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2831,7 +2831,7 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) std::vector splitName = common::split(filename, "."); std::string sdf = "" - "" + "" "" "" "" From 2d6a9301443ab06d3fb217ee22be9254781389b6 Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Wed, 4 Aug 2021 11:54:49 -0700 Subject: [PATCH 6/7] qml fix for bionic Signed-off-by: Jenn Nguyen --- src/gui/plugins/scene3d/GzScene3D.qml | 3 ++- src/gui/plugins/scene3d/Scene3D.hh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/plugins/scene3d/GzScene3D.qml b/src/gui/plugins/scene3d/GzScene3D.qml index 5b36a40429..e0fc582579 100644 --- a/src/gui/plugins/scene3d/GzScene3D.qml +++ b/src/gui/plugins/scene3d/GzScene3D.qml @@ -111,7 +111,8 @@ Rectangle { parent: ApplicationWindow.overlay modal: true focus: true - anchors.centerIn: parent + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 background: Rectangle { border.width: 5 border.color: "red" diff --git a/src/gui/plugins/scene3d/Scene3D.hh b/src/gui/plugins/scene3d/Scene3D.hh index 918ab9af05..89a5dbef26 100644 --- a/src/gui/plugins/scene3d/Scene3D.hh +++ b/src/gui/plugins/scene3d/Scene3D.hh @@ -182,7 +182,7 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \brief Notify that an error has occurred (opens popup) /// Note that the function name needs to start with lowercase in order for - /// the connection to work on the QML side + /// the connection to work on the QML side signals: void popupError(); /// \internal From 0fd716f68afe0a4691e42b43956b40880e9de545 Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Tue, 10 Aug 2021 11:19:39 -0700 Subject: [PATCH 7/7] updated popup error Signed-off-by: Jenn Nguyen --- src/gui/plugins/scene3d/GzScene3D.qml | 4 ---- src/gui/plugins/scene3d/Scene3D.cc | 6 ++++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gui/plugins/scene3d/GzScene3D.qml b/src/gui/plugins/scene3d/GzScene3D.qml index e0fc582579..4411fb5d7e 100644 --- a/src/gui/plugins/scene3d/GzScene3D.qml +++ b/src/gui/plugins/scene3d/GzScene3D.qml @@ -113,10 +113,6 @@ Rectangle { focus: true x: (parent.width - width) / 2 y: (parent.height - height) / 2 - background: Rectangle { - border.width: 5 - border.color: "red" - } title: "Error" Text { text: GzScene3D.errorPopupText diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 80de372a24..09ae8c5919 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2797,7 +2797,7 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) { if (_drop.toStdString().empty()) { - ignwarn << "Dropped empty entity URI." << std::endl; + this->SetErrorPopupText("Dropped empty entity URI."); return; } @@ -2820,7 +2820,9 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) if (!common::MeshManager::Instance()->IsValidFilename(dropStr)) { - this->SetErrorPopupText("Only DAE, OBJ, and STL meshes are supported."); + QString errTxt = QString::fromStdString("Invalid URI: " + dropStr + + "\nOnly Fuel URLs or mesh file types DAE, OBJ, and STL are supported."); + this->SetErrorPopupText(errTxt); return; }