-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy pathGzSceneManager.cc
141 lines (119 loc) · 3.88 KB
/
GzSceneManager.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* 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 <set>
#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/gui/GuiEvents.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);
// Emit entities created / removed event for gui::Plugins which don't have
// direct access to the ECM.
std::set<Entity> created;
_ecm.EachNew<components::Name>(
[&](const Entity &_entity, const components::Name *)->bool
{
created.insert(_entity);
return true;
});
std::set<Entity> removed;
_ecm.EachRemoved<components::Name>(
[&](const Entity &_entity, const components::Name *)->bool
{
removed.insert(_entity);
return true;
});
ignition::gazebo::gui::events::NewRemovedEntities removedEvent(
created, removed);
ignition::gui::App()->sendEvent(
ignition::gui::App()->findChild<ignition::gui::MainWindow *>(),
&removedEvent);
}
/////////////////////////////////////////////////
bool GzSceneManager::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == ignition::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)