Gazebo Gazebo

API Reference

6.16.0
ComponentInspector.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GZ_GAZEBO_GUI_COMPONENTINSPECTOR_HH_
19 #define GZ_GAZEBO_GUI_COMPONENTINSPECTOR_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 
25 #include <sdf/Material.hh>
26 #include <sdf/Physics.hh>
27 
28 #include <gz/math/Vector3.hh>
29 #include <gz/transport/Node.hh>
30 
32 #include <gz/sim/gui/GuiSystem.hh>
33 #include <gz/sim/Types.hh>
34 
35 #include "Types.hh"
36 
37 #include <gz/msgs/light.pb.h>
38 
40 
41 namespace ignition
42 {
43 namespace gazebo
44 {
45  class ComponentInspectorPrivate;
46 
50  template <class DataType>
51  void setData(QStandardItem *_item, const DataType &_data)
52  {
53  // cppcheck-suppress syntaxError
54  // cppcheck-suppress unmatchedSuppression
56  {
58  ss << _data;
59  setData(_item, ss.str());
60  }
61  else
62  {
63  ignwarn << "Attempting to set unsupported data type to item ["
64  << _item->text().toStdString() << "]" << std::endl;
65  }
66  }
67 
71  template<>
72  void setData(QStandardItem *_item, const std::string &_data);
73 
77  template<>
78  void setData(QStandardItem *_item, const msgs::Light &_data);
79 
83  template<>
84  void setData(QStandardItem *_item, const math::Vector3d &_data);
85 
89  template<>
90  void setData(QStandardItem *_item, const sdf::Physics &_data);
91 
95  template<>
96  void setData(QStandardItem *_item, const math::SphericalCoordinates &_data);
97 
101  template<>
102  void setData(QStandardItem *_item, const bool &_data);
103 
107  template<>
108  void setData(QStandardItem *_item, const int &_data);
109 
113  template<>
114  void setData(QStandardItem *_item, const double &_data);
115 
119  template<>
120  void setData(QStandardItem *_item, const std::ostream &_data);
121 
125  template<>
126  void setData(QStandardItem *_item, const sdf::Material &_data);
127 
128 
132  void setUnit(QStandardItem *_item, const std::string &_unit);
133 
136  class ComponentsModel : public QStandardItemModel
137  {
138  Q_OBJECT
139 
141  public: explicit ComponentsModel();
142 
144  public: ~ComponentsModel() override = default;
145 
146  // Documentation inherited
147  public: QHash<int, QByteArray> roleNames() const override;
148 
151  public: static QHash<int, QByteArray> RoleNames();
152 
156  public slots: QStandardItem *AddComponentType(
158 
161  public slots: void RemoveComponentType(
163 
166  };
167 
172  class ComponentInspector : public ignition::gazebo::GuiSystem
173  {
174  Q_OBJECT
175 
177  Q_PROPERTY(
178  Entity entity
179  READ GetEntity
180  WRITE SetEntity
181  NOTIFY EntityChanged
182  )
183 
184 
185  Q_PROPERTY(
186  QString type
187  READ Type
188  WRITE SetType
189  NOTIFY TypeChanged
190  )
191 
192 
193  Q_PROPERTY(
194  bool locked
195  READ Locked
196  WRITE SetLocked
197  NOTIFY LockedChanged
198  )
199 
200 
201  Q_PROPERTY(
202  bool paused
203  READ Paused
204  WRITE SetPaused
205  NOTIFY PausedChanged
206  )
207 
208 
209  Q_PROPERTY(
210  bool nestedModel
211  READ NestedModel
212  NOTIFY NestedModelChanged
213  )
214 
215 
216  Q_PROPERTY(
217  QStringList systemNameList
218  READ SystemNameList
219  WRITE SetSystemNameList
220  NOTIFY SystemNameListChanged
221  )
222 
223 
224  public: ComponentInspector();
225 
227  public: ~ComponentInspector() override;
228 
229  // Documentation inherited
230  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
231 
232  // Documentation inherited
233  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
234 
239  public: void AddUpdateViewCb(ComponentTypeId _id,
241 
266  public: Q_INVOKABLE void OnLight(
267  double _rSpecular, double _gSpecular, double _bSpecular,
268  double _aSpecular, double _rDiffuse, double _gDiffuse,
269  double _bDiffuse, double _aDiffuse, double _attRange,
270  double _attLinear, double _attConstant, double _attQuadratic,
271  bool _castShadows, double _directionX, double _directionY,
272  double _directionZ, double _innerAngle, double _outerAngle,
273  double _falloff, double _intensity, int _type, bool _isLightOn,
274  bool _visualizeVisual);
275 
279  public: Q_INVOKABLE void OnPhysics(double _stepSize,
280  double _realTimeFactor);
281 
282  // \brief Callback in Qt thread when material color changes for a visual
303  public: Q_INVOKABLE void OnMaterialColor(
304  double _rAmbient, double _gAmbient, double _bAmbient,
305  double _aAmbient, double _rDiffuse, double _gDiffuse,
306  double _bDiffuse, double _aDiffuse, double _rSpecular,
307  double _gSpecular, double _bSpecular, double _aSpecular,
308  double _rEmissive, double _gEmissive, double _bEmissive,
309  double _aEmissive, QString _type, QColor _currColor);
310 
317  public: Q_INVOKABLE void OnSphericalCoordinates(QString _surface,
318  double _latitude, double _longitude, double _elevation,
319  double _heading);
320 
323  public: Q_INVOKABLE bool NestedModel() const;
324 
326  signals: void NestedModelChanged();
327 
328  // Documentation inherited
329  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
330 
333  public: Q_INVOKABLE Entity GetEntity() const;
334 
337  public: Q_INVOKABLE void SetEntity(const Entity &_entity);
338 
340  signals: void EntityChanged();
341 
344  public: Q_INVOKABLE QString Type() const;
345 
348  public: Q_INVOKABLE void SetType(const QString &_entity);
349 
351  signals: void TypeChanged();
352 
355  public: Q_INVOKABLE bool Locked() const;
356 
359  public: Q_INVOKABLE void SetLocked(bool _locked);
360 
362  signals: void LockedChanged();
363 
366  public: Q_INVOKABLE bool Paused() const;
367 
370  public: Q_INVOKABLE void SetPaused(bool _paused);
371 
373  signals: void PausedChanged();
374 
377  public: const std::string &WorldName() const;
378 
381  public: transport::Node &TransportNode();
382 
384  public: Q_INVOKABLE void QuerySystems();
385 
388  public: Q_INVOKABLE QStringList SystemNameList() const;
389 
392  public: Q_INVOKABLE void SetSystemNameList(
393  const QStringList &_systemNameList);
394 
396  signals: void SystemNameListChanged();
397 
402  public: Q_INVOKABLE void OnAddSystem(const QString &_name,
403  const QString &_filename, const QString &_innerxml);
404 
408  };
409 }
410 }
411 
412 #endif
Base class for a GUI System.
Definition: gz/sim/gui/GuiSystem.hh:44
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light....
Definition: gz/sim/Entity.hh:58
This library is part of the Gazebo project.
STL class.
std::function< void(const EntityComponentManager &_ecm, QStandardItem *_item)> UpdateViewCb
Function definition that a component can use to update its UI elements based on changes from the ECM.
Definition: src/gui/plugins/component_inspector/Types.hh:37
Component< math::SphericalCoordinates, class SphericalCoordinatesTag, serializers::SphericalCoordinatesSerializer > SphericalCoordinates
This component holds the spherical coordinates of the world origin.
Definition: gz/sim/components/SphericalCoordinates.hh:45
STL class.
Component< sdf::Light, class LightTag, serializers::LightSerializer > Light
This component contains light source information. For more information on lights, see SDF's Light ele...
Definition: gz/sim/components/Light.hh:48
Q_DECLARE_METATYPE(ignition::gazebo::ComponentTypeId) namespace ignition
Definition: ComponentInspector.hh:39
#define ignwarn
static constexpr bool value
Definition: gz/sim/components/Component.hh:72
STL class.
T endl(T... args)
T str(T... args)
uint64_t ComponentTypeId
A unique identifier for a component type. A component type must be derived from components::BaseCompo...
Definition: include/gz/sim/Types.hh:90
Component< sdf::Material, class MaterialTag, serializers::MaterialSerializer > Material
This component holds an entity's material.
Definition: gz/sim/components/Material.hh:44
STL class.
Component< sdf::Physics, class PhysicsTag, serializers::PhysicsSerializer > Physics
A component type that contains the physics properties of the World entity.
Definition: include/gz/sim/components/Physics.hh:50
Vector3< double > Vector3d