Gazebo Sim

API Reference

7.7.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 GZ_SIM_GUI_COMPONENTINSPECTOREDITOR_HH_
19 #define GZ_SIM_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 <gz/math/SphericalCoordinates.hh>
30 #include <gz/math/Vector3.hh>
31 
33 #include <gz/sim/gui/GuiSystem.hh>
34 #include <gz/sim/Types.hh>
35 
36 #include <gz/msgs/light.pb.h>
37 
38 #include "Types.hh"
40 
41 namespace gz
42 {
43 namespace sim
44 {
45  class ComponentInspectorEditorPrivate;
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  gzwarn << "Attempting to set unsupported data type to item ["
64  << _item->text().toStdString() << "]" << std::endl;
65  }
66  }
70  template<>
71  void setData(QStandardItem *_item, const std::string &_data);
72 
76  template<>
77  void setData(QStandardItem *_item, const msgs::Light &_data);
78 
82  template<>
83  void setData(QStandardItem *_item, const math::Vector3d &_data);
84 
88  template<>
89  void setData(QStandardItem *_item, const sdf::Physics &_data);
90 
94  template<>
95  void setData(QStandardItem *_item, const math::SphericalCoordinates &_data);
96 
100  template<>
101  void setData(QStandardItem *_item, const bool &_data);
102 
106  template<>
107  void setData(QStandardItem *_item, const int &_data);
108 
112  template<>
113  void setData(QStandardItem *_item, const double &_data);
114 
118  template<>
119  void setData(QStandardItem *_item, const std::ostream &_data);
120 
124  template<>
125  void setData(QStandardItem *_item, const sdf::Material &_data);
126 
127 
131  void setUnit(QStandardItem *_item, const std::string &_unit);
132 
135  class ComponentsModel : public QStandardItemModel
136  {
137  Q_OBJECT
138 
140  public: explicit ComponentsModel();
141 
143  public: ~ComponentsModel() override = default;
144 
145  // Documentation inherited
146  public: QHash<int, QByteArray> roleNames() const override;
147 
150  public: static QHash<int, QByteArray> RoleNames();
151 
155  public slots: QStandardItem *AddComponentType(
156  gz::sim::ComponentTypeId _typeId);
157 
160  public slots: void RemoveComponentType(
161  gz::sim::ComponentTypeId _typeId);
162 
165  };
166 
171  class ComponentInspectorEditor : public sim::GuiSystem
172  {
173  Q_OBJECT
174 
176  Q_PROPERTY(
177  Entity entity
178  READ GetEntity
179  WRITE SetEntity
180  NOTIFY EntityChanged
181  )
182 
183 
184  Q_PROPERTY(
185  QString type
186  READ Type
187  WRITE SetType
188  NOTIFY TypeChanged
189  )
190 
191 
192  Q_PROPERTY(
193  QStringList modelParentLinks
194  READ ModelParentLinks
195  NOTIFY ModelLinksChanged
196  )
197 
198 
199  Q_PROPERTY(
200  QStringList modelChildLinks
201  READ ModelChildLinks
202  NOTIFY ModelLinksChanged
203  )
204 
205 
206  Q_PROPERTY(
207  bool locked
208  READ Locked
209  WRITE SetLocked
210  NOTIFY LockedChanged
211  )
212 
213 
214  Q_PROPERTY(
215  bool paused
216  READ Paused
217  WRITE SetPaused
218  NOTIFY PausedChanged
219  )
220 
221 
222  Q_PROPERTY(
223  bool simPaused
224  READ SimPaused
225  NOTIFY SimPausedChanged
226  )
227 
228 
229  Q_PROPERTY(
230  bool nestedModel
231  READ NestedModel
232  NOTIFY NestedModelChanged
233  )
234 
235 
236  public: ComponentInspectorEditor();
237 
239  public: ~ComponentInspectorEditor() override;
240 
241  // Documentation inherited
242  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
243 
244  // Documentation inherited
245  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
246 
269  public: Q_INVOKABLE void OnLight(
270  double _rSpecular, double _gSpecular, double _bSpecular,
271  double _aSpecular, double _rDiffuse, double _gDiffuse,
272  double _bDiffuse, double _aDiffuse, double _attRange,
273  double _attLinear, double _attConstant, double _attQuadratic,
274  bool _castShadows, double _directionX, double _directionY,
275  double _directionZ, double _innerAngle, double _outerAngle,
276  double _falloff, double _intensity, int _type);
277 
281  public: Q_INVOKABLE void OnPhysics(double _stepSize,
282  double _realTimeFactor);
283 
284  // \brief Callback in Qt thread when material color changes for a visual
305  public: Q_INVOKABLE void OnMaterialColor(
306  double _rAmbient, double _gAmbient, double _bAmbient,
307  double _aAmbient, double _rDiffuse, double _gDiffuse,
308  double _bDiffuse, double _aDiffuse, double _rSpecular,
309  double _gSpecular, double _bSpecular, double _aSpecular,
310  double _rEmissive, double _gEmissive, double _bEmissive,
311  double _aEmissive, QString _type, QColor _currColor);
312 
319  public: Q_INVOKABLE void OnSphericalCoordinates(QString _surface,
320  double _latitude, double _longitude, double _elevation,
321  double _heading);
322 
325  public: Q_INVOKABLE bool NestedModel() const;
326 
328  signals: void NestedModelChanged();
329 
330  // Documentation inherited
331  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
332 
335  public: Q_INVOKABLE Entity GetEntity() const;
336 
339  public: Q_INVOKABLE void SetEntity(const sim::Entity &_entity);
340 
342  signals: void EntityChanged();
343 
346  public: Q_INVOKABLE QString Type() const;
347 
350  public: Q_INVOKABLE void SetType(const QString &_entity);
351 
353  signals: void TypeChanged();
354 
357  public: Q_INVOKABLE bool Locked() const;
358 
361  public: Q_INVOKABLE void SetLocked(bool _locked);
362 
364  signals: void LockedChanged();
365 
368  public: Q_INVOKABLE bool SimPaused() const;
369 
371  signals: void SimPausedChanged();
372 
375  public: void SetSimPaused(bool _paused);
376 
379  public: Q_INVOKABLE bool Paused() const;
380 
383  public: Q_INVOKABLE void SetPaused(bool _paused);
384 
386  signals: void PausedChanged();
387 
391  public: Q_INVOKABLE void OnAddEntity(const QString &_entity,
392  const QString &_type);
393 
398  public: Q_INVOKABLE void OnAddJoint(const QString &_jointType,
399  const QString &_parentLink,
400  const QString &_childLink);
401 
405  public: Q_INVOKABLE QStringList ModelParentLinks() const;
406 
410  public: Q_INVOKABLE QStringList ModelChildLinks() const;
411 
414  public: Q_INVOKABLE void SetModelLinks(const QStringList &_modelLinks);
415 
417  signals: void ModelLinksChanged();
418 
423  public: Q_INVOKABLE void OnLoadMesh(const QString &_entity,
424  const QString &_type, const QString &_mesh);
425 
426 
429  public: void AddUpdateCallback(UpdateCallback _cb);
430 
438  public: void RegisterComponentCreator(ComponentTypeId _id,
439  ComponentCreator _creatorFn);
440 
444  };
445 }
446 }
447 
448 #endif