ConfigWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 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 _GAZEBO_GUI_CONFIGWIDGET_HH_
19 #define _GAZEBO_GUI_CONFIGWIDGET_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <ignition/math/Color.hh>
27 #include <ignition/math/Pose3.hh>
28 #include <ignition/math/Vector3.hh>
29 
30 #include "gazebo/gui/qt.h"
31 #include "gazebo/util/system.hh"
32 
33 namespace google
34 {
35  namespace protobuf
36  {
37  class Message;
38  class Reflection;
39  class FieldDescriptor;
40  }
41 }
42 
43 namespace gazebo
44 {
45  namespace gui
46  {
47  class ConfigWidgetPrivate;
48  class GroupWidget;
49 
52 
56  class GZ_GUI_VISIBLE ConfigChildWidget : public QFrame
57  {
58  Q_OBJECT
59 
61  public: ConfigChildWidget() : groupWidget(NULL) {}
62 
64  public: std::string key;
65 
67  public: std::string scopedName;
68 
70  public: std::vector<QWidget *> widgets;
71 
73  public: std::map<QWidget *, QLabel *> mapWidgetToUnit;
74 
78  };
79 
82  class GZ_GUI_VISIBLE GeometryConfigWidget : public ConfigChildWidget
83  {
84  Q_OBJECT
85 
88  public: QStackedWidget *geomDimensionWidget;
89 
91  public: QWidget *geomLengthSpinBox;
92 
94  public: QWidget *geomLengthLabel;
95 
97  public: QWidget *geomLengthUnitLabel;
98 
100  public: QWidget *geomFilenameLineEdit;
101 
103  public: QWidget *geomFilenameLabel;
104 
106  public: QWidget *geomFilenameButton;
107 
110  private slots: void OnGeometryTypeChanged(const QString &_text);
111 
114  private slots: void OnGeometrySizeChanged(const double _value);
115 
117  private slots: void OnSelectFile();
118 
120  Q_SIGNALS: void GeometryChanged();
121  };
122 
125  class GZ_GUI_VISIBLE DensityConfigWidget : public ConfigChildWidget
126  {
127  Q_OBJECT
128 
130  public: DensityConfigWidget();
131 
134  public: void SetDensity(const double _density);
135 
138  public: double Density() const;
139 
142  private slots: void OnComboBoxChanged(const QString &_text);
143 
146  private slots: void OnSpinBoxChanged(const QString &_text);
147 
150  Q_SIGNALS: void DensityValueChanged(const double &_value);
151 
153  public: QComboBox *comboBox;
154 
156  public: QDoubleSpinBox *spinBox;
157 
159  private: double density;
160  };
161 
164  class GZ_GUI_VISIBLE EnumConfigWidget : public ConfigChildWidget
165  {
166  Q_OBJECT
167 
170  Q_SIGNALS: void EnumValueChanged(const QString &_value);
171 
174  private slots: void EnumChanged(const QString &_value);
175  };
176 
179  class GZ_GUI_VISIBLE GroupWidget : public QWidget
180  {
181  Q_OBJECT
182 
184  public: QWidget *childWidget;
185 
188  private slots: void Toggle(bool _checked);
189  };
190 
193  class GZ_GUI_VISIBLE ConfigWidget : public QWidget
194  {
195  Q_OBJECT
196 
198  public: ConfigWidget();
199 
201  public: ~ConfigWidget();
202 
205  public: void Load(const google::protobuf::Message *_msg);
206 
209  public: google::protobuf::Message *Msg();
210 
215  public: static std::string HumanReadableKey(const std::string &_key);
216 
223  public: std::string UnitFromKey(const std::string &_key,
224  const std::string &_jointType = "") const;
225 
231  public: void RangeFromKey(const std::string &_key,
232  double &_min, double &_max) const;
233 
237  public: void SetWidgetVisible(const std::string &_name, bool _visible);
238 
242  public: bool WidgetVisible(const std::string &_name) const;
243 
247  public: void SetWidgetReadOnly(const std::string &_name, bool _readOnly);
248 
252  public: bool WidgetReadOnly(const std::string &_name) const;
253 
256  public: void UpdateFromMsg(const google::protobuf::Message *_msg);
257 
262  public: bool SetIntWidgetValue(const std::string &_name, int _value);
263 
268  public: bool SetUIntWidgetValue(const std::string &_name, unsigned int
269  _value);
270 
275  public: bool SetDoubleWidgetValue(const std::string &_name,
276  double _value);
277 
282  public: bool SetBoolWidgetValue(const std::string &_name, bool _value);
283 
287  public: bool SetStringWidgetValue(const std::string &_name,
288  const std::string &_value);
289 
294  public: bool SetVector3dWidgetValue(const std::string &_name,
295  const ignition::math::Vector3d &_value);
296 
301  public: bool SetColorWidgetValue(const std::string &_name,
302  const ignition::math::Color &_value);
303 
308  public: bool SetPoseWidgetValue(const std::string &_name,
309  const ignition::math::Pose3d &_value);
310 
316  public: bool SetGeometryWidgetValue(const std::string &_name,
317  const std::string &_value,
318  const ignition::math::Vector3d &_dimensions,
319  const std::string &_uri = "");
320 
325  public: bool SetDensityWidgetValue(const std::string &_name,
326  const double _value);
327 
332  public: bool SetEnumWidgetValue(const std::string &_name,
333  const std::string &_value);
334 
339  public: bool AddItemEnumWidget(const std::string &_name,
340  const std::string &_itemText);
341 
346  public: bool RemoveItemEnumWidget(const std::string &_name,
347  const std::string &_itemText);
348 
352  public: bool ClearEnumWidget(const std::string &_name);
353 
357  public: int IntWidgetValue(const std::string &_name) const;
358 
362  public: unsigned int UIntWidgetValue(const std::string &_name) const;
363 
367  public: double DoubleWidgetValue(const std::string &_name) const;
368 
372  public: bool BoolWidgetValue(const std::string &_name) const;
373 
377  public: std::string StringWidgetValue(const std::string &_name) const;
378 
382  public: ignition::math::Vector3d Vector3dWidgetValue(
383  const std::string &_name) const;
384 
388  public: ignition::math::Color ColorWidgetValue(
389  const std::string &_name) const;
390 
394  public: ignition::math::Pose3d PoseWidgetValue(
395  const std::string &_name) const;
396 
402  public: std::string GeometryWidgetValue(const std::string &_name,
403  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
404 
408  public: double DensityWidgetValue(const std::string &_name) const;
409 
413  public: std::string EnumWidgetValue(const std::string &_name) const;
414 
421  public: GroupWidget *CreateGroupWidget(const std::string &_name,
422  ConfigChildWidget *_childWidget, const int _level = 0);
423 
428  public: ConfigChildWidget *CreateUIntWidget(const std::string &_key,
429  const int _level = 0);
430 
435  public: ConfigChildWidget *CreateIntWidget(const std::string &_key,
436  const int _level = 0);
437 
442  public: ConfigChildWidget *CreateDoubleWidget(const std::string &_key,
443  const int _level = 0);
444 
450  public: ConfigChildWidget *CreateStringWidget(const std::string &_key,
451  const int _level = 0, const std::string &_type = "line");
452 
457  public: ConfigChildWidget *CreateBoolWidget(const std::string &_key,
458  const int _level = 0);
459 
464  public: ConfigChildWidget *CreateVector3dWidget(const std::string &_key,
465  const int _level = 0);
466 
471  public: ConfigChildWidget *CreateColorWidget(const std::string &_key,
472  const int _level = 0);
473 
478  public: ConfigChildWidget *CreatePoseWidget(const std::string &_key,
479  const int _level = 0);
480 
485  public: ConfigChildWidget *CreateGeometryWidget(const std::string &_key,
486  const int _level = 0);
487 
493  public: ConfigChildWidget *CreateEnumWidget(const std::string &_key,
494  const std::vector<std::string> &_values, const int _level = 0);
495 
500  public: ConfigChildWidget *CreateDensityWidget(const std::string &_key,
501  const int _level = 0);
502 
510  public: bool AddConfigChildWidget(const std::string &_name,
511  ConfigChildWidget *_child);
512 
517  public: void InsertLayout(QLayout *_layout, int _pos);
518 
523  public: ConfigChildWidget *ConfigChildWidgetByName(
524  const std::string &_name) const;
525 
528  public: unsigned int ConfigChildWidgetCount() const;
529 
537  public: static QString StyleSheet(const std::string &_type,
538  const int _level = 0);
539 
542  public: static const std::vector<QString> bgColors;
543 
545  public: static const std::vector<QString> widgetColors;
546 
548  public: static const QString redColor;
549 
551  public: static const QString greenColor;
552 
554  public: static const QString blueColor;
555 
565  private: QWidget *Parse(google::protobuf::Message *_msg,
566  bool _update = false, const std::string &_name = "",
567  const int _level = 0);
568 
572  private: ignition::math::Vector3d ParseVector3d(
573  const google::protobuf::Message *_msg) const;
574 
578  private: void UpdateMsg(google::protobuf::Message *_msg,
579  const std::string &_name = "");
580 
585  private: void UpdateVector3dMsg(google::protobuf::Message *_msg,
586  const ignition::math::Vector3d &_value);
587 
592  private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
593  const unsigned int _value);
594 
599  private: bool UpdateIntWidget(ConfigChildWidget *_widget,
600  const int _value);
601 
606  private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
607  const double _value);
608 
613  private: bool UpdateStringWidget(ConfigChildWidget *_widget,
614  const std::string &_value);
615 
620  private: bool UpdateBoolWidget(ConfigChildWidget *_widget,
621  const bool _value);
622 
627  private: bool UpdateVector3dWidget(ConfigChildWidget *_widget,
628  const ignition::math::Vector3d &_value);
629 
634  private: bool UpdateColorWidget(ConfigChildWidget *_widget,
635  const ignition::math::Color &_value);
636 
641  private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
642  const ignition::math::Pose3d &_value);
643 
650  private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
651  const std::string &_value,
652  const ignition::math::Vector3d &_dimensions,
653  const std::string &_uri = "");
654 
659  private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
660  const std::string &_value);
661 
666  private: bool UpdateDensityWidget(ConfigChildWidget *_widget,
667  const double _value);
668 
672  private: int IntWidgetValue(ConfigChildWidget *_widget) const;
673 
677  private: unsigned int UIntWidgetValue(ConfigChildWidget *_widget) const;
678 
682  private: double DoubleWidgetValue(ConfigChildWidget *_widget) const;
683 
687  private: bool BoolWidgetValue(ConfigChildWidget *_widget) const;
688 
692  private: std::string StringWidgetValue(ConfigChildWidget *_widget) const;
693 
697  private: ignition::math::Vector3d Vector3dWidgetValue(
698  ConfigChildWidget *_widget) const;
699 
703  private: ignition::math::Color ColorWidgetValue(
704  ConfigChildWidget *_widget) const;
705 
709  private: ignition::math::Pose3d PoseWidgetValue(
710  ConfigChildWidget *_widget) const;
711 
717  private: std::string GeometryWidgetValue(ConfigChildWidget *_widget,
718  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
719 
723  private: std::string EnumWidgetValue(ConfigChildWidget *_widget) const;
724 
728  private slots: void OnItemSelection(QTreeWidgetItem *_item,
729  const int _column);
730 
732  private slots: void OnUIntValueChanged();
733 
735  private slots: void OnIntValueChanged();
736 
738  private slots: void OnDoubleValueChanged();
739 
741  private slots: void OnBoolValueChanged();
742 
744  private slots: void OnStringValueChanged();
745 
747  private slots: void OnVector3dValueChanged();
748 
751  private slots: void OnVector3dPresetChanged(const int _index);
752 
754  private slots: void OnColorValueChanged();
755 
759  private slots: void OnColorValueChanged(const QColor _value);
760 
762  private slots: void OnPoseValueChanged();
763 
765  private slots: void OnGeometryValueChanged();
766 
769  private slots: void OnGeometryValueChanged(const int _value);
770 
773  private slots: void OnEnumValueChanged(const QString &_value);
774 
777  private slots: void OnCustomColorDialog();
778 
782  Q_SIGNALS: void UIntValueChanged(const QString &_name,
783  const unsigned int _value);
784 
788  Q_SIGNALS: void IntValueChanged(const QString &_name, const int _value);
789 
793  Q_SIGNALS: void DoubleValueChanged(const QString &_name,
794  const double _value);
795 
799  Q_SIGNALS: void BoolValueChanged(const QString &_name,
800  const bool _value);
801 
807  Q_SIGNALS: void StringValueChanged(const QString &_name,
808  const std::string &_value);
809 
813  Q_SIGNALS: void Vector3dValueChanged(const QString &_name,
814  const ignition::math::Vector3d &_value);
815 
819  Q_SIGNALS: void ColorValueChanged(const QString &_name,
820  const ignition::math::Color &_value);
821 
825  Q_SIGNALS: void PoseValueChanged(const QString &_name,
826  const ignition::math::Pose3d &_pose);
827 
833  Q_SIGNALS: void GeometryValueChanged(const std::string &_name,
834  const std::string &_value,
835  const ignition::math::Vector3d &_dimensions,
836  const std::string &_uri);
837 
841  Q_SIGNALS: void EnumValueChanged(const QString &_name,
842  const QString &_value);
843 
846  Q_SIGNALS: void DensityValueChanged(const double &_value);
847 
850  Q_SIGNALS: void MassValueChanged(const double &_value);
851 
854  private slots: void OnDensityValueChanged(const double _value);
855 
858  private slots: void OnMassValueChanged(const double _value);
859 
861  private slots: void OnGeometryChanged();
862 
864  Q_SIGNALS: void GeometryChanged();
865 
870  private: bool eventFilter(QObject *_obj, QEvent *_event);
871 
874  private: std::unique_ptr<ConfigWidgetPrivate> dataPtr;
875  };
876  }
877 }
878 #endif
A collapsible widget that holds child widgets.
Definition: ConfigWidget.hh:179
QComboBox * comboBox
A combo box for selecting a material density.
Definition: ConfigWidget.hh:153
GroupWidget * groupWidget
Pointer to group widget.
Definition: ConfigWidget.hh:77
Forward declarations for the common classes.
Definition: Animation.hh:26
static const std::vector< QString > widgetColors
List of colors used for widget areas according to their level.
Definition: ConfigWidget.hh:545
A widget generated from a google protobuf message.
Definition: ConfigWidget.hh:193
static const QString greenColor
Green color used for "green" or "y" fields.
Definition: ConfigWidget.hh:551
QWidget * geomFilenameLineEdit
A line edit for editing the mesh filename.
Definition: ConfigWidget.hh:100
static const QString blueColor
Blue color used for "blue" or "z" fields.
Definition: ConfigWidget.hh:554
QWidget * geomLengthSpinBox
A spin box for configuring the length of the geometry.
Definition: ConfigWidget.hh:91
QWidget * geomFilenameButton
A button for selecting the mesh filename.
Definition: ConfigWidget.hh:106
static const std::vector< QString > bgColors
List of colors used for the background of widgets according to their level.
Definition: ConfigWidget.hh:542
A convenience widget that also holds pointers to a list of its child widgets.
Definition: ConfigWidget.hh:56
QWidget * childWidget
Child widget that can be collapsed or expanded.
Definition: ConfigWidget.hh:184
static const QString redColor
Red color used for "red" or "x" fields.
Definition: ConfigWidget.hh:548
A widget for configuring enum values.
Definition: ConfigWidget.hh:164
std::string scopedName
Widget&#39;s scoped name within parent config widget.
Definition: ConfigWidget.hh:67
QDoubleSpinBox * spinBox
A spin box for entering a density value.
Definition: ConfigWidget.hh:156
A widget for configuring geometry properties.
Definition: ConfigWidget.hh:82
#define NULL
Definition: CommonTypes.hh:31
QStackedWidget * geomDimensionWidget
A stacked widget containing widgets for configuring geometry dimensions.
Definition: ConfigWidget.hh:88
QWidget * geomLengthUnitLabel
A label for the unit of the length widget.
Definition: ConfigWidget.hh:97
Definition: ConfigWidget.hh:33
std::map< QWidget *, QLabel * > mapWidgetToUnit
Map a widget to the label holding its unit value.
Definition: ConfigWidget.hh:73
QWidget * geomLengthLabel
A label for the length widget.
Definition: ConfigWidget.hh:94
ConfigChildWidget()
Constructor;.
Definition: ConfigWidget.hh:61
A widget for configuring density properties.
Definition: ConfigWidget.hh:125
QWidget * geomFilenameLabel
A label for the mesh filename widget.
Definition: ConfigWidget.hh:103
std::string key
Widget&#39;s key value.
Definition: ConfigWidget.hh:64
std::vector< QWidget * > widgets
List of widgets holding values, such as Spins and LineEdits.
Definition: ConfigWidget.hh:70