Skip to content

Commit

Permalink
New scene manager GUI plugin that works with ign-gui's MinimalScene (g…
Browse files Browse the repository at this point in the history
…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
2 people authored and WilliamLewww committed Dec 7, 2021
1 parent b2c6134 commit 9b32d5a
Show file tree
Hide file tree
Showing 9 changed files with 690 additions and 0 deletions.
452 changes: 452 additions & 0 deletions examples/worlds/minimal_scene.sdf

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions include/ignition/gazebo/rendering/RenderUtil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
/// \return Name of the rendering scene.
public: std::string SceneName() const;

/// \brief Set the scene to use.
/// \param[in] _scene Pointer to the scene.
public: void SetScene(const rendering::ScenePtr &_scene);

/// \brief Set background color of render window
/// \param[in] _color Color of render window background
public: void SetBackgroundColor(const math::Color &_color);
Expand Down
1 change: 1 addition & 0 deletions src/gui/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ add_subdirectory(plot_3d)
add_subdirectory(plotting)
add_subdirectory(resource_spawner)
add_subdirectory(scene3d)
add_subdirectory(scene_manager)
add_subdirectory(shapes)
add_subdirectory(tape_measure)
add_subdirectory(transform_control)
Expand Down
7 changes: 7 additions & 0 deletions src/gui/plugins/scene_manager/CMakeLists.txt
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}
)
115 changes: 115 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.cc
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)
66 changes: 66 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.hh
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
28 changes: 28 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.qml
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
}
5 changes: 5 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.qrc
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>
12 changes: 12 additions & 0 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,10 @@ void RenderUtilPrivate::RemoveRenderingEntities(
/////////////////////////////////////////////////
void RenderUtil::Init()
{
// Already initialized
if (nullptr != this->dataPtr->scene)
return;

ignition::common::SystemPaths pluginPath;
pluginPath.SetPluginPathEnv(kRenderPluginPathEnv);
rendering::setPluginPaths(pluginPath.PluginPaths());
Expand Down Expand Up @@ -1776,6 +1780,14 @@ void RenderUtil::SetSceneName(const std::string &_name)
this->dataPtr->sceneName = _name;
}

/////////////////////////////////////////////////
void RenderUtil::SetScene(const rendering::ScenePtr &_scene)
{
this->dataPtr->scene = _scene;
this->dataPtr->sceneManager.SetScene(_scene);
this->dataPtr->engine = _scene == nullptr ? nullptr : _scene->Engine();
}

/////////////////////////////////////////////////
std::string RenderUtil::SceneName() const
{
Expand Down

0 comments on commit 9b32d5a

Please sign in to comment.