forked from gazebosim/gz-sim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New scene manager GUI plugin that works with ign-gui's MinimalScene (g…
…azebosim#813) Signed-off-by: Louise Poubel <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]> Signed-off-by: William Lew <[email protected]>
- Loading branch information
1 parent
b2c6134
commit 9b32d5a
Showing
9 changed files
with
690 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
gz_add_gui_plugin(GzSceneManager | ||
SOURCES GzSceneManager.cc | ||
QT_HEADERS GzSceneManager.hh | ||
PRIVATE_LINK_LIBS | ||
${PROJECT_LIBRARY_TARGET_NAME}-rendering | ||
ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (C) 2021 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 "GzSceneManager.hh" | ||
|
||
#include <ignition/common/Profiler.hh> | ||
#include <ignition/gui/Application.hh> | ||
#include <ignition/gui/GuiEvents.hh> | ||
#include <ignition/gui/MainWindow.hh> | ||
#include <ignition/plugin/Register.hh> | ||
#include <ignition/rendering/RenderingIface.hh> | ||
#include <ignition/rendering/Scene.hh> | ||
|
||
#include "ignition/gazebo/EntityComponentManager.hh" | ||
#include "ignition/gazebo/components/Name.hh" | ||
#include "ignition/gazebo/components/World.hh" | ||
#include "ignition/gazebo/rendering/RenderUtil.hh" | ||
|
||
namespace ignition | ||
{ | ||
namespace gazebo | ||
{ | ||
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { | ||
/// \brief Private data class for GzSceneManager | ||
class GzSceneManagerPrivate | ||
{ | ||
/// \brief Update the 3D scene based on the latest state of the ECM. | ||
public: void OnRender(); | ||
|
||
//// \brief Pointer to the rendering scene | ||
public: rendering::ScenePtr scene; | ||
|
||
/// \brief Rendering utility | ||
public: RenderUtil renderUtil; | ||
}; | ||
} | ||
} | ||
} | ||
|
||
using namespace ignition; | ||
using namespace gazebo; | ||
|
||
///////////////////////////////////////////////// | ||
GzSceneManager::GzSceneManager() | ||
: GuiSystem(), dataPtr(std::make_unique<GzSceneManagerPrivate>()) | ||
{ | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
GzSceneManager::~GzSceneManager() = default; | ||
|
||
///////////////////////////////////////////////// | ||
void GzSceneManager::LoadConfig(const tinyxml2::XMLElement *) | ||
{ | ||
if (this->title.empty()) | ||
this->title = "Scene Manager"; | ||
|
||
ignition::gui::App()->findChild< | ||
ignition::gui::MainWindow *>()->installEventFilter(this); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void GzSceneManager::Update(const UpdateInfo &_info, | ||
EntityComponentManager &_ecm) | ||
{ | ||
IGN_PROFILE("GzSceneManager::Update"); | ||
|
||
this->dataPtr->renderUtil.UpdateECM(_info, _ecm); | ||
this->dataPtr->renderUtil.UpdateFromECM(_info, _ecm); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
bool GzSceneManager::eventFilter(QObject *_obj, QEvent *_event) | ||
{ | ||
if (_event->type() == gui::events::Render::kType) | ||
{ | ||
this->dataPtr->OnRender(); | ||
} | ||
|
||
// Standard event processing | ||
return QObject::eventFilter(_obj, _event); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void GzSceneManagerPrivate::OnRender() | ||
{ | ||
if (nullptr == this->scene) | ||
{ | ||
this->scene = rendering::sceneFromFirstRenderEngine(); | ||
if (nullptr == this->scene) | ||
return; | ||
|
||
this->renderUtil.SetScene(this->scene); | ||
} | ||
|
||
this->renderUtil.Update(); | ||
} | ||
|
||
// Register this plugin | ||
IGNITION_ADD_PLUGIN(ignition::gazebo::GzSceneManager, | ||
ignition::gui::Plugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2021 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. | ||
* | ||
*/ | ||
|
||
#ifndef IGNITION_GAZEBO_GUI_GZSCENEMANAGER_HH_ | ||
#define IGNITION_GAZEBO_GUI_GZSCENEMANAGER_HH_ | ||
|
||
#include <memory> | ||
|
||
#include <ignition/gazebo/gui/GuiSystem.hh> | ||
|
||
namespace ignition | ||
{ | ||
namespace gazebo | ||
{ | ||
// Inline bracket to help doxygen filtering. | ||
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { | ||
class GzSceneManagerPrivate; | ||
|
||
/// \brief Updates a 3D scene based on information coming from the ECM. | ||
/// This plugin doesn't instantiate a new 3D scene. Instead, it relies on | ||
/// another plugin being loaded alongside it that will create and paint the | ||
/// scene to the window, such as `ignition::gui::plugins::Scene3D`. | ||
class GzSceneManager : public GuiSystem | ||
{ | ||
Q_OBJECT | ||
|
||
/// \brief Constructor | ||
public: GzSceneManager(); | ||
|
||
/// \brief Destructor | ||
public: ~GzSceneManager() override; | ||
|
||
// Documentation inherited | ||
public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) | ||
override; | ||
|
||
// Documentation inherited | ||
public: void Update(const UpdateInfo &_info, | ||
EntityComponentManager &_ecm) override; | ||
|
||
// Documentation inherited | ||
private: bool eventFilter(QObject *_obj, QEvent *_event) override; | ||
|
||
/// \internal | ||
/// \brief Pointer to private data. | ||
private: std::unique_ptr<GzSceneManagerPrivate> dataPtr; | ||
}; | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) 2021 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. | ||
* | ||
*/ | ||
|
||
import QtQuick 2.0 | ||
import QtQuick.Controls 2.0 | ||
import QtQuick.Layouts 1.3 | ||
|
||
// TODO: remove invisible rectangle, see | ||
// https://github.com/ignitionrobotics/ign-gui/issues/220 | ||
Rectangle { | ||
visible: false | ||
Layout.minimumWidth: 100 | ||
Layout.minimumHeight: 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!DOCTYPE RCC><RCC version="1.0"> | ||
<qresource prefix="GzSceneManager/"> | ||
<file>GzSceneManager.qml</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters