ConfigWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2016 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/Pose3.hh>
27 #include <ignition/math/Vector3.hh>
28 
29 #include "gazebo/common/Color.hh"
30 #include "gazebo/math/Pose.hh"
31 #include "gazebo/gui/qt.h"
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 
210  public: google::protobuf::Message *GetMsg() GAZEBO_DEPRECATED(7.0);
211 
214  public: google::protobuf::Message *Msg();
215 
221  public: std::string GetHumanReadableKey(const std::string &_key)
222  GAZEBO_DEPRECATED(7.0);
223 
228  public: std::string HumanReadableKey(const std::string &_key) const;
229 
238  public: std::string GetUnitFromKey(const std::string &_key,
239  const std::string &_jointType = "") GAZEBO_DEPRECATED(7.0);
240 
247  public: std::string UnitFromKey(const std::string &_key,
248  const std::string &_jointType = "") const;
249 
258  public: void GetRangeFromKey(const std::string &_key,
259  double &_min, double &_max) GAZEBO_DEPRECATED(7.0);
260 
266  public: void RangeFromKey(const std::string &_key,
267  double &_min, double &_max) const;
268 
272  public: void SetWidgetVisible(const std::string &_name, bool _visible);
273 
278  public: bool GetWidgetVisible(const std::string &_name) const
279  GAZEBO_DEPRECATED(7.0);
280 
284  public: bool WidgetVisible(const std::string &_name) const;
285 
289  public: void SetWidgetReadOnly(const std::string &_name, bool _readOnly);
290 
295  public: bool GetWidgetReadOnly(const std::string &_name) const
296  GAZEBO_DEPRECATED(7.0);
297 
301  public: bool WidgetReadOnly(const std::string &_name) const;
302 
305  public: void UpdateFromMsg(const google::protobuf::Message *_msg);
306 
311  public: bool SetIntWidgetValue(const std::string &_name, int _value);
312 
317  public: bool SetUIntWidgetValue(const std::string &_name, unsigned int
318  _value);
319 
324  public: bool SetDoubleWidgetValue(const std::string &_name,
325  double _value);
326 
331  public: bool SetBoolWidgetValue(const std::string &_name, bool _value);
332 
336  public: bool SetStringWidgetValue(const std::string &_name,
337  const std::string &_value);
338 
345  public: bool SetVector3WidgetValue(const std::string &_name,
346  const math::Vector3 &_value) GAZEBO_DEPRECATED(7.0);
347 
352  public: bool SetVector3dWidgetValue(const std::string &_name,
353  const ignition::math::Vector3d &_value);
354 
359  public: bool SetColorWidgetValue(const std::string &_name,
360  const common::Color &_value);
361 
368  public: bool SetPoseWidgetValue(const std::string &_name,
369  const math::Pose &_value) GAZEBO_DEPRECATED(7.0);
370 
375  public: bool SetPoseWidgetValue(const std::string &_name,
376  const ignition::math::Pose3d &_value);
377 
387  public: bool SetGeometryWidgetValue(const std::string &_name,
388  const std::string &_value, const math::Vector3 &_dimensions,
389  const std::string &_uri = "") GAZEBO_DEPRECATED(7.0);
390 
396  public: bool SetGeometryWidgetValue(const std::string &_name,
397  const std::string &_value,
398  const ignition::math::Vector3d &_dimensions,
399  const std::string &_uri = "");
400 
405  public: bool SetDensityWidgetValue(const std::string &_name,
406  const double _value);
407 
412  public: bool SetEnumWidgetValue(const std::string &_name,
413  const std::string &_value);
414 
419  public: bool AddItemEnumWidget(const std::string &_name,
420  const std::string &_itemText);
421 
426  public: bool RemoveItemEnumWidget(const std::string &_name,
427  const std::string &_itemText);
428 
432  public: bool ClearEnumWidget(const std::string &_name);
433 
438  public: int GetIntWidgetValue(const std::string &_name) const
439  GAZEBO_DEPRECATED(7.0);
440 
444  public: int IntWidgetValue(const std::string &_name) const;
445 
450  public: unsigned int GetUIntWidgetValue(const std::string &_name) const
451  GAZEBO_DEPRECATED(7.0);
452 
456  public: unsigned int UIntWidgetValue(const std::string &_name) const;
457 
462  public: double GetDoubleWidgetValue(const std::string &_name) const
463  GAZEBO_DEPRECATED(7.0);
464 
468  public: double DoubleWidgetValue(const std::string &_name) const;
469 
474  public: bool GetBoolWidgetValue(const std::string &_name) const
475  GAZEBO_DEPRECATED(7.0);
476 
480  public: bool BoolWidgetValue(const std::string &_name) const;
481 
486  public: std::string GetStringWidgetValue(const std::string &_name) const
487  GAZEBO_DEPRECATED(7.0);
488 
492  public: std::string StringWidgetValue(const std::string &_name) const;
493 
498  public: math::Vector3 GetVector3WidgetValue(const std::string &_name)
499  const GAZEBO_DEPRECATED(7.0);
500 
504  public: ignition::math::Vector3d Vector3dWidgetValue(
505  const std::string &_name) const;
506 
511  public: common::Color GetColorWidgetValue(const std::string &_name) const
512  GAZEBO_DEPRECATED(7.0);
513 
517  public: common::Color ColorWidgetValue(const std::string &_name) const;
518 
523  public: math::Pose GetPoseWidgetValue(const std::string &_name) const
524  GAZEBO_DEPRECATED(7.0);
525 
529  public: ignition::math::Pose3d PoseWidgetValue(
530  const std::string &_name) const;
531 
539  public: std::string GetGeometryWidgetValue(const std::string &_name,
540  math::Vector3 &_dimensions, std::string &_uri) const
541  GAZEBO_DEPRECATED(7.0);
542 
548  public: std::string GeometryWidgetValue(const std::string &_name,
549  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
550 
554  public: double DensityWidgetValue(const std::string &_name) const;
555 
560  public: std::string GetEnumWidgetValue(const std::string &_name) const
561  GAZEBO_DEPRECATED(7.0);
562 
566  public: std::string EnumWidgetValue(const std::string &_name) const;
567 
574  public: GroupWidget *CreateGroupWidget(const std::string &_name,
575  ConfigChildWidget *_childWidget, const int _level = 0);
576 
581  public: ConfigChildWidget *CreateUIntWidget(const std::string &_key,
582  const int _level = 0);
583 
588  public: ConfigChildWidget *CreateIntWidget(const std::string &_key,
589  const int _level = 0);
590 
595  public: ConfigChildWidget *CreateDoubleWidget(const std::string &_key,
596  const int _level = 0);
597 
603  public: ConfigChildWidget *CreateStringWidget(const std::string &_key,
604  const int _level = 0, const std::string &_type = "line");
605 
610  public: ConfigChildWidget *CreateBoolWidget(const std::string &_key,
611  const int _level = 0);
612 
617  public: ConfigChildWidget *CreateVector3dWidget(const std::string &_key,
618  const int _level = 0);
619 
624  public: ConfigChildWidget *CreateColorWidget(const std::string &_key,
625  const int _level = 0);
626 
631  public: ConfigChildWidget *CreatePoseWidget(const std::string &_key,
632  const int _level = 0);
633 
638  public: ConfigChildWidget *CreateGeometryWidget(const std::string &_key,
639  const int _level = 0);
640 
646  public: ConfigChildWidget *CreateEnumWidget(const std::string &_key,
647  const std::vector<std::string> &_values, const int _level = 0);
648 
653  public: ConfigChildWidget *CreateDensityWidget(const std::string &_key,
654  const int _level = 0);
655 
663  public: bool AddConfigChildWidget(const std::string &_name,
664  ConfigChildWidget *_child);
665 
670  public: void InsertLayout(QLayout *_layout, int _pos);
671 
676  public: ConfigChildWidget *ConfigChildWidgetByName(
677  const std::string &_name) const;
678 
681  public: unsigned int ConfigChildWidgetCount() const;
682 
690  public: static QString StyleSheet(const std::string &_type,
691  const int _level = 0);
692 
695  public: static const std::vector<QString> bgColors;
696 
698  public: static const std::vector<QString> widgetColors;
699 
701  public: static const QString redColor;
702 
704  public: static const QString greenColor;
705 
707  public: static const QString blueColor;
708 
718  private: QWidget *Parse(google::protobuf::Message *_msg,
719  bool _update = false, const std::string &_name = "",
720  const int _level = 0);
721 
725  private: ignition::math::Vector3d ParseVector3d(
726  const google::protobuf::Message *_msg) const;
727 
731  private: void UpdateMsg(google::protobuf::Message *_msg,
732  const std::string &_name = "");
733 
737  private: void UpdateVector3dMsg(google::protobuf::Message *_msg,
738  const ignition::math::Vector3d &_value);
739 
744  private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
745  const unsigned int _value);
746 
751  private: bool UpdateIntWidget(ConfigChildWidget *_widget,
752  const int _value);
753 
758  private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
759  const double _value);
760 
765  private: bool UpdateStringWidget(ConfigChildWidget *_widget,
766  const std::string &_value);
767 
772  private: bool UpdateBoolWidget(ConfigChildWidget *_widget,
773  const bool _value);
774 
779  private: bool UpdateVector3dWidget(ConfigChildWidget *_widget,
780  const ignition::math::Vector3d &_value);
781 
786  private: bool UpdateColorWidget(ConfigChildWidget *_widget,
787  const common::Color &_value);
788 
793  private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
794  const ignition::math::Pose3d &_value);
795 
802  private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
803  const std::string &_value,
804  const ignition::math::Vector3d &_dimensions,
805  const std::string &_uri = "");
806 
811  private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
812  const std::string &_value);
813 
818  private: bool UpdateDensityWidget(ConfigChildWidget *_widget,
819  const double _value);
820 
824  private: int IntWidgetValue(ConfigChildWidget *_widget) const;
825 
829  private: unsigned int UIntWidgetValue(ConfigChildWidget *_widget) const;
830 
834  private: double DoubleWidgetValue(ConfigChildWidget *_widget) const;
835 
839  private: bool BoolWidgetValue(ConfigChildWidget *_widget) const;
840 
844  private: std::string StringWidgetValue(ConfigChildWidget *_widget) const;
845 
849  private: ignition::math::Vector3d Vector3dWidgetValue(
850  ConfigChildWidget *_widget) const;
851 
855  private: common::Color ColorWidgetValue(ConfigChildWidget *_widget) const;
856 
860  private: ignition::math::Pose3d PoseWidgetValue(
861  ConfigChildWidget *_widget) const;
862 
868  private: std::string GeometryWidgetValue(ConfigChildWidget *_widget,
869  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
870 
874  private: std::string EnumWidgetValue(ConfigChildWidget *_widget) const;
875 
879  private slots: void OnItemSelection(QTreeWidgetItem *_item,
880  const int _column);
881 
883  private slots: void OnUIntValueChanged();
884 
886  private slots: void OnIntValueChanged();
887 
889  private slots: void OnDoubleValueChanged();
890 
892  private slots: void OnBoolValueChanged();
893 
895  private slots: void OnStringValueChanged();
896 
898  private slots: void OnVector3dValueChanged();
899 
902  private slots: void OnVector3dPresetChanged(const int _index);
903 
905  private slots: void OnColorValueChanged();
906 
908  private slots: void OnPoseValueChanged();
909 
911  private slots: void OnGeometryValueChanged();
912 
915  private slots: void OnGeometryValueChanged(const int _value);
916 
919  private slots: void OnEnumValueChanged(const QString &_value);
920 
924  Q_SIGNALS: void UIntValueChanged(const QString &_name,
925  const unsigned int _value);
926 
930  Q_SIGNALS: void IntValueChanged(const QString &_name, const int _value);
931 
935  Q_SIGNALS: void DoubleValueChanged(const QString &_name,
936  const double _value);
937 
941  Q_SIGNALS: void BoolValueChanged(const QString &_name,
942  const bool _value);
943 
949  Q_SIGNALS: void StringValueChanged(const QString &_name,
950  const std::string &_value);
951 
955  Q_SIGNALS: void Vector3dValueChanged(const QString &_name,
956  const ignition::math::Vector3d &_value);
957 
961  Q_SIGNALS: void ColorValueChanged(const QString &_name,
962  const gazebo::common::Color &_value);
963 
967  Q_SIGNALS: void PoseValueChanged(const QString &_name,
968  const ignition::math::Pose3d &_pose);
969 
975  Q_SIGNALS: void GeometryValueChanged(const std::string &_name,
976  const std::string &_value,
977  const ignition::math::Vector3d &_dimensions,
978  const std::string &_uri);
979 
983  Q_SIGNALS: void EnumValueChanged(const QString &_name,
984  const QString &_value);
985 
988  Q_SIGNALS: void DensityValueChanged(const double &_value);
989 
992  Q_SIGNALS: void MassValueChanged(const double &_value);
993 
996  private slots: void OnDensityValueChanged(const double _value);
997 
1000  private slots: void OnMassValueChanged(const double _value);
1001 
1003  private slots: void OnGeometryChanged();
1004 
1006  Q_SIGNALS: void GeometryChanged();
1007 
1012  private: bool eventFilter(QObject *_obj, QEvent *_event);
1013 
1016  private: std::unique_ptr<ConfigWidgetPrivate> dataPtr;
1017  };
1018  }
1019 }
1020 #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
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
static const std::vector< QString > widgetColors
List of colors used for widget areas according to their level.
Definition: ConfigWidget.hh:698
A widget generated from a google protobuf message.
Definition: ConfigWidget.hh:193
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
static const QString greenColor
Green color used for "green" or "y" fields.
Definition: ConfigWidget.hh:704
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:707
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:695
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:701
A widget for configuring enum values.
Definition: ConfigWidget.hh:164
std::string scopedName
Widget'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
Defines a color.
Definition: Color.hh:36
QWidget * geomLengthUnitLabel
A label for the unit of the length widget.
Definition: ConfigWidget.hh:97
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'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