Gazebo Sim

API Reference

7.7.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_SIM_GUI_COMPONENTINSPECTOR_HH_
19 #define GZ_SIM_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/SphericalCoordinates.hh>
29 #include <gz/math/Vector3.hh>
30 #include <gz/transport/Node.hh>
31 
33 #include <gz/sim/gui/GuiSystem.hh>
34 #include <gz/sim/Types.hh>
35 
36 #include "Types.hh"
37 
38 #include <gz/msgs/light.pb.h>
39 
41 
42 namespace gz
43 {
44 namespace sim
45 {
46  class ComponentInspectorPrivate;
47 
51  template <class DataType>
52  void setData(QStandardItem *_item, const DataType &_data)
53  {
54  // cppcheck-suppress syntaxError
55  // cppcheck-suppress unmatchedSuppression
57  {
59  ss << _data;
60  setData(_item, ss.str());
61  }
62  else
63  {
64  gzwarn << "Attempting to set unsupported data type to item ["
65  << _item->text().toStdString() << "]" << std::endl;
66  }
67  }
68 
72  template<>
73  void setData(QStandardItem *_item, const std::string &_data);
74 
78  template<>
79  void setData(QStandardItem *_item, const msgs::Light &_data);
80 
84  template<>
85  void setData(QStandardItem *_item, const math::Vector3d &_data);
86 
90  template<>
91  void setData(QStandardItem *_item, const sdf::Physics &_data);
92 
96  template<>
97  void setData(QStandardItem *_item, const math::SphericalCoordinates &_data);
98 
102  template<>
103  void setData(QStandardItem *_item, const bool &_data);
104 
108  template<>
109  void setData(QStandardItem *_item, const int &_data);
110 
114  template<>
115  void setData(QStandardItem *_item, const double &_data);
116 
120  template<>
121  void setData(QStandardItem *_item, const std::ostream &_data);
122 
126  template<>
127  void setData(QStandardItem *_item, const sdf::Material &_data);
128 
129 
133  void setUnit(QStandardItem *_item, const std::string &_unit);
134 
137  class ComponentsModel : public QStandardItemModel
138  {
139  Q_OBJECT
140 
142  public: explicit ComponentsModel();
143 
145  public: ~ComponentsModel() override = default;
146 
147  // Documentation inherited
148  public: QHash<int, QByteArray> roleNames() const override;
149 
152  public: static QHash<int, QByteArray> RoleNames();
153 
157  public slots: QStandardItem *AddComponentType(
158  gz::sim::ComponentTypeId _typeId);
159 
162  public slots: void RemoveComponentType(
163  gz::sim::ComponentTypeId _typeId);
164 
167  };
168 
173  class ComponentInspector : public sim::GuiSystem
174  {
175  Q_OBJECT
176 
178  Q_PROPERTY(
179  Entity entity
180  READ GetEntity
181  WRITE SetEntity
182  NOTIFY EntityChanged
183  )
184 
185 
186  Q_PROPERTY(
187  QString type
188  READ Type
189  WRITE SetType
190  NOTIFY TypeChanged
191  )
192 
193 
194  Q_PROPERTY(
195  bool locked
196  READ Locked
197  WRITE SetLocked
198  NOTIFY LockedChanged
199  )
200 
201 
202  Q_PROPERTY(
203  bool paused
204  READ Paused
205  WRITE SetPaused
206  NOTIFY PausedChanged
207  )
208 
209 
210  Q_PROPERTY(
211  bool nestedModel
212  READ NestedModel
213  NOTIFY NestedModelChanged
214  )
215 
216 
217  Q_PROPERTY(
218  QStringList systemNameList
219  READ SystemNameList
220  WRITE SetSystemNameList
221  NOTIFY SystemNameListChanged
222  )
223 
224 
225  public: ComponentInspector();
226 
228  public: ~ComponentInspector() override;
229 
230  // Documentation inherited
231  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
232 
233  // Documentation inherited
234  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
235 
240  public: void AddUpdateViewCb(ComponentTypeId _id,
242 
267  public: Q_INVOKABLE void OnLight(
268  double _rSpecular, double _gSpecular, double _bSpecular,
269  double _aSpecular, double _rDiffuse, double _gDiffuse,
270  double _bDiffuse, double _aDiffuse, double _attRange,
271  double _attLinear, double _attConstant, double _attQuadratic,
272  bool _castShadows, double _directionX, double _directionY,
273  double _directionZ, double _innerAngle, double _outerAngle,
274  double _falloff, double _intensity, int _type, bool _isLightOn,
275  bool _visualizeVisual);
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 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 Paused() const;
368 
371  public: Q_INVOKABLE void SetPaused(bool _paused);
372 
374  signals: void PausedChanged();
375 
378  public: const std::string &WorldName() const;
379 
382  public: transport::Node &TransportNode();
383 
385  public: Q_INVOKABLE void QuerySystems();
386 
389  public: Q_INVOKABLE QStringList SystemNameList() const;
390 
393  public: Q_INVOKABLE void SetSystemNameList(
394  const QStringList &_systemNameList);
395 
397  signals: void SystemNameListChanged();
398 
403  public: Q_INVOKABLE void OnAddSystem(const QString &_name,
404  const QString &_filename, const QString &_innerxml);
405 
409  };
410 }
411 }
412 
413 #endif