Ignition Gazebo

API Reference

6.9.0
ComponentInspectorEditor.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 IGNITION_GAZEBO_GUI_COMPONENTINSPECTOREDITOR_HH_
19 #define IGNITION_GAZEBO_GUI_COMPONENTINSPECTOREDITOR_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 
25 #include <sdf/Material.hh>
26 #include <sdf/Physics.hh>
27 #include <sdf/Joint.hh>
28 
29 #include <ignition/math/Vector3.hh>
30 
33 #include <ignition/gazebo/Types.hh>
34 
35 #include <ignition/msgs/light.pb.h>
36 
37 #include "Types.hh"
39 
40 namespace ignition
41 {
42 namespace gazebo
43 {
44  class ComponentInspectorEditorPrivate;
45 
49  template <class DataType>
50  void setData(QStandardItem *_item, const DataType &_data)
51  {
52  // cppcheck-suppress syntaxError
53  // cppcheck-suppress unmatchedSuppression
55  {
57  ss << _data;
58  setData(_item, ss.str());
59  }
60  else
61  {
62  ignwarn << "Attempting to set unsupported data type to item ["
63  << _item->text().toStdString() << "]" << std::endl;
64  }
65  }
69  template<>
70  void setData(QStandardItem *_item, const std::string &_data);
71 
75  template<>
76  void setData(QStandardItem *_item, const msgs::Light &_data);
77 
81  template<>
82  void setData(QStandardItem *_item, const math::Vector3d &_data);
83 
87  template<>
88  void setData(QStandardItem *_item, const sdf::Physics &_data);
89 
93  template<>
94  void setData(QStandardItem *_item, const math::SphericalCoordinates &_data);
95 
99  template<>
100  void setData(QStandardItem *_item, const bool &_data);
101 
105  template<>
106  void setData(QStandardItem *_item, const int &_data);
107 
111  template<>
112  void setData(QStandardItem *_item, const double &_data);
113 
117  template<>
118  void setData(QStandardItem *_item, const std::ostream &_data);
119 
123  template<>
124  void setData(QStandardItem *_item, const sdf::Material &_data);
125 
126 
130  void setUnit(QStandardItem *_item, const std::string &_unit);
131 
134  class ComponentsModel : public QStandardItemModel
135  {
136  Q_OBJECT
137 
139  public: explicit ComponentsModel();
140 
142  public: ~ComponentsModel() override = default;
143 
144  // Documentation inherited
145  public: QHash<int, QByteArray> roleNames() const override;
146 
149  public: static QHash<int, QByteArray> RoleNames();
150 
154  public slots: QStandardItem *AddComponentType(
156 
159  public slots: void RemoveComponentType(
161 
164  };
165 
170  class ComponentInspectorEditor : public gazebo::GuiSystem
171  {
172  Q_OBJECT
173 
175  Q_PROPERTY(
176  Entity entity
177  READ GetEntity
178  WRITE SetEntity
179  NOTIFY EntityChanged
180  )
181 
182 
183  Q_PROPERTY(
184  QString type
185  READ Type
186  WRITE SetType
187  NOTIFY TypeChanged
188  )
189 
190 
191  Q_PROPERTY(
192  QStringList modelParentLinks
193  READ ModelParentLinks
194  NOTIFY ModelLinksChanged
195  )
196 
197 
198  Q_PROPERTY(
199  QStringList modelChildLinks
200  READ ModelChildLinks
201  NOTIFY ModelLinksChanged
202  )
203 
204 
205  Q_PROPERTY(
206  bool locked
207  READ Locked
208  WRITE SetLocked
209  NOTIFY LockedChanged
210  )
211 
212 
213  Q_PROPERTY(
214  bool paused
215  READ Paused
216  WRITE SetPaused
217  NOTIFY PausedChanged
218  )
219 
220 
221  Q_PROPERTY(
222  bool simPaused
223  READ SimPaused
224  NOTIFY SimPausedChanged
225  )
226 
227 
228  Q_PROPERTY(
229  bool nestedModel
230  READ NestedModel
231  NOTIFY NestedModelChanged
232  )
233 
234 
235  public: ComponentInspectorEditor();
236 
238  public: ~ComponentInspectorEditor() override;
239 
240  // Documentation inherited
241  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
242 
243  // Documentation inherited
244  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
245 
268  public: Q_INVOKABLE void OnLight(
269  double _rSpecular, double _gSpecular, double _bSpecular,
270  double _aSpecular, double _rDiffuse, double _gDiffuse,
271  double _bDiffuse, double _aDiffuse, double _attRange,
272  double _attLinear, double _attConstant, double _attQuadratic,
273  bool _castShadows, double _directionX, double _directionY,
274  double _directionZ, double _innerAngle, double _outerAngle,
275  double _falloff, double _intensity, int _type);
276 
280  public: Q_INVOKABLE void OnPhysics(double _stepSize,
281  double _realTimeFactor);
282 
283  // \brief Callback in Qt thread when material color changes for a visual
304  public: Q_INVOKABLE void OnMaterialColor(
305  double _rAmbient, double _gAmbient, double _bAmbient,
306  double _aAmbient, double _rDiffuse, double _gDiffuse,
307  double _bDiffuse, double _aDiffuse, double _rSpecular,
308  double _gSpecular, double _bSpecular, double _aSpecular,
309  double _rEmissive, double _gEmissive, double _bEmissive,
310  double _aEmissive, QString _type, QColor _currColor);
311 
318  public: Q_INVOKABLE void OnSphericalCoordinates(QString _surface,
319  double _latitude, double _longitude, double _elevation,
320  double _heading);
321 
324  public: Q_INVOKABLE bool NestedModel() const;
325 
327  signals: void NestedModelChanged();
328 
329  // Documentation inherited
330  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
331 
334  public: Q_INVOKABLE Entity GetEntity() const;
335 
338  public: Q_INVOKABLE void SetEntity(const gazebo::Entity &_entity);
339 
341  signals: void EntityChanged();
342 
345  public: Q_INVOKABLE QString Type() const;
346 
349  public: Q_INVOKABLE void SetType(const QString &_entity);
350 
352  signals: void TypeChanged();
353 
356  public: Q_INVOKABLE bool Locked() const;
357 
360  public: Q_INVOKABLE void SetLocked(bool _locked);
361 
363  signals: void LockedChanged();
364 
367  public: Q_INVOKABLE bool SimPaused() const;
368 
370  signals: void SimPausedChanged();
371 
374  public: void SetSimPaused(bool _paused);
375 
378  public: Q_INVOKABLE bool Paused() const;
379 
382  public: Q_INVOKABLE void SetPaused(bool _paused);
383 
385  signals: void PausedChanged();
386 
390  public: Q_INVOKABLE void OnAddEntity(const QString &_entity,
391  const QString &_type);
392 
397  public: Q_INVOKABLE void OnAddJoint(const QString &_jointType,
398  const QString &_parentLink,
399  const QString &_childLink);
400 
404  public: Q_INVOKABLE QStringList ModelParentLinks() const;
405 
409  public: Q_INVOKABLE QStringList ModelChildLinks() const;
410 
413  public: Q_INVOKABLE void SetModelLinks(const QStringList &_modelLinks);
414 
416  signals: void ModelLinksChanged();
417 
422  public: Q_INVOKABLE void OnLoadMesh(const QString &_entity,
423  const QString &_type, const QString &_mesh);
424 
425 
428  public: void AddUpdateCallback(UpdateCallback _cb);
429 
437  public: void RegisterComponentCreator(ComponentTypeId _id,
438  ComponentCreator _creatorFn);
439 
443  };
444 }
445 }
446 
447 #endif
Q_DECLARE_METATYPE(ComponentTypeId) namespace ignition
Definition: ComponentInspectorEditor.hh:38
std::function< void(EntityComponentManager &)> UpdateCallback
UpdateCallback is a function defition that is used by a component to manage ECM changes.
Definition: src/gui/plugins/component_inspector_editor/Types.hh:35
T endl(T... args)
STL class.
STL class.
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/ignition/gazebo/Types.hh:90
Component< math::SphericalCoordinates, class SphericalCoordinatesTag, serializers::SphericalCoordinatesSerializer > SphericalCoordinates
This component holds the spherical coordinates of the world origin.
Definition: SphericalCoordinates.hh:45
Component< sdf::Material, class MaterialTag, serializers::MaterialSerializer > Material
This component holds an entity&#39;s material.
Definition: Material.hh:44
Component< sdf::Light, class LightTag, serializers::LightSerializer > Light
This component contains light source information. For more information on lights, see SDF&#39;s Light ele...
Definition: Light.hh:48
STL class.
Vector3< double > Vector3d
std::function< void(EntityComponentManager &, Entity, QStandardItem *)> ComponentCreator
Definition: src/gui/plugins/component_inspector_editor/Types.hh:43
This library is part of the Ignition Robotics project.
static constexpr bool value
Definition: Component.hh:72
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light. At its core, an Entity is just an identifier.
Definition: Entity.hh:59
STL class.
Component< sdf::Physics, class PhysicsTag, serializers::PhysicsSerializer > Physics
A component type that contains the physics properties of the World entity.
Definition: include/ignition/gazebo/components/Physics.hh:50
#define ignwarn