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/common/Color.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 
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 
302  public: bool SetColorWidgetValue(const std::string &_name,
303  const common::Color &_value) GAZEBO_DEPRECATED(9);
304 
309  public: bool SetColorWidgetValue(const std::string &_name,
310  const ignition::math::Color &_value);
311 
316  public: bool SetPoseWidgetValue(const std::string &_name,
317  const ignition::math::Pose3d &_value);
318 
324  public: bool SetGeometryWidgetValue(const std::string &_name,
325  const std::string &_value,
326  const ignition::math::Vector3d &_dimensions,
327  const std::string &_uri = "");
328 
333  public: bool SetDensityWidgetValue(const std::string &_name,
334  const double _value);
335 
340  public: bool SetEnumWidgetValue(const std::string &_name,
341  const std::string &_value);
342 
347  public: bool AddItemEnumWidget(const std::string &_name,
348  const std::string &_itemText);
349 
354  public: bool RemoveItemEnumWidget(const std::string &_name,
355  const std::string &_itemText);
356 
360  public: bool ClearEnumWidget(const std::string &_name);
361 
365  public: int IntWidgetValue(const std::string &_name) const;
366 
370  public: unsigned int UIntWidgetValue(const std::string &_name) const;
371 
375  public: double DoubleWidgetValue(const std::string &_name) const;
376 
380  public: bool BoolWidgetValue(const std::string &_name) const;
381 
385  public: std::string StringWidgetValue(const std::string &_name) const;
386 
390  public: ignition::math::Vector3d Vector3dWidgetValue(
391  const std::string &_name) const;
392 
396  public: ignition::math::Color ColorWidgetValue(
397  const std::string &_name) const;
398 
402  public: ignition::math::Pose3d PoseWidgetValue(
403  const std::string &_name) const;
404 
410  public: std::string GeometryWidgetValue(const std::string &_name,
411  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
412 
416  public: double DensityWidgetValue(const std::string &_name) const;
417 
421  public: std::string EnumWidgetValue(const std::string &_name) const;
422 
429  public: GroupWidget *CreateGroupWidget(const std::string &_name,
430  ConfigChildWidget *_childWidget, const int _level = 0);
431 
436  public: ConfigChildWidget *CreateUIntWidget(const std::string &_key,
437  const int _level = 0);
438 
443  public: ConfigChildWidget *CreateIntWidget(const std::string &_key,
444  const int _level = 0);
445 
450  public: ConfigChildWidget *CreateDoubleWidget(const std::string &_key,
451  const int _level = 0);
452 
458  public: ConfigChildWidget *CreateStringWidget(const std::string &_key,
459  const int _level = 0, const std::string &_type = "line");
460 
465  public: ConfigChildWidget *CreateBoolWidget(const std::string &_key,
466  const int _level = 0);
467 
472  public: ConfigChildWidget *CreateVector3dWidget(const std::string &_key,
473  const int _level = 0);
474 
479  public: ConfigChildWidget *CreateColorWidget(const std::string &_key,
480  const int _level = 0);
481 
486  public: ConfigChildWidget *CreatePoseWidget(const std::string &_key,
487  const int _level = 0);
488 
493  public: ConfigChildWidget *CreateGeometryWidget(const std::string &_key,
494  const int _level = 0);
495 
501  public: ConfigChildWidget *CreateEnumWidget(const std::string &_key,
502  const std::vector<std::string> &_values, const int _level = 0);
503 
508  public: ConfigChildWidget *CreateDensityWidget(const std::string &_key,
509  const int _level = 0);
510 
518  public: bool AddConfigChildWidget(const std::string &_name,
519  ConfigChildWidget *_child);
520 
525  public: void InsertLayout(QLayout *_layout, int _pos);
526 
531  public: ConfigChildWidget *ConfigChildWidgetByName(
532  const std::string &_name) const;
533 
536  public: unsigned int ConfigChildWidgetCount() const;
537 
545  public: static QString StyleSheet(const std::string &_type,
546  const int _level = 0);
547 
550  public: static const std::vector<QString> bgColors;
551 
553  public: static const std::vector<QString> widgetColors;
554 
556  public: static const QString redColor;
557 
559  public: static const QString greenColor;
560 
562  public: static const QString blueColor;
563 
573  private: QWidget *Parse(google::protobuf::Message *_msg,
574  bool _update = false, const std::string &_name = "",
575  const int _level = 0);
576 
580  private: ignition::math::Vector3d ParseVector3d(
581  const google::protobuf::Message *_msg) const;
582 
586  private: void UpdateMsg(google::protobuf::Message *_msg,
587  const std::string &_name = "");
588 
593  private: void UpdateVector3dMsg(google::protobuf::Message *_msg,
594  const ignition::math::Vector3d &_value);
595 
600  private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
601  const unsigned int _value);
602 
607  private: bool UpdateIntWidget(ConfigChildWidget *_widget,
608  const int _value);
609 
614  private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
615  const double _value);
616 
621  private: bool UpdateStringWidget(ConfigChildWidget *_widget,
622  const std::string &_value);
623 
628  private: bool UpdateBoolWidget(ConfigChildWidget *_widget,
629  const bool _value);
630 
635  private: bool UpdateVector3dWidget(ConfigChildWidget *_widget,
636  const ignition::math::Vector3d &_value);
637 
642  private: bool UpdateColorWidget(ConfigChildWidget *_widget,
643  const ignition::math::Color &_value);
644 
649  private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
650  const ignition::math::Pose3d &_value);
651 
658  private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
659  const std::string &_value,
660  const ignition::math::Vector3d &_dimensions,
661  const std::string &_uri = "");
662 
667  private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
668  const std::string &_value);
669 
674  private: bool UpdateDensityWidget(ConfigChildWidget *_widget,
675  const double _value);
676 
680  private: int IntWidgetValue(ConfigChildWidget *_widget) const;
681 
685  private: unsigned int UIntWidgetValue(ConfigChildWidget *_widget) const;
686 
690  private: double DoubleWidgetValue(ConfigChildWidget *_widget) const;
691 
695  private: bool BoolWidgetValue(ConfigChildWidget *_widget) const;
696 
700  private: std::string StringWidgetValue(ConfigChildWidget *_widget) const;
701 
705  private: ignition::math::Vector3d Vector3dWidgetValue(
706  ConfigChildWidget *_widget) const;
707 
711  private: ignition::math::Color ColorWidgetValue(
712  ConfigChildWidget *_widget) const;
713 
717  private: ignition::math::Pose3d PoseWidgetValue(
718  ConfigChildWidget *_widget) const;
719 
725  private: std::string GeometryWidgetValue(ConfigChildWidget *_widget,
726  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
727 
731  private: std::string EnumWidgetValue(ConfigChildWidget *_widget) const;
732 
736  private slots: void OnItemSelection(QTreeWidgetItem *_item,
737  const int _column);
738 
740  private slots: void OnUIntValueChanged();
741 
743  private slots: void OnIntValueChanged();
744 
746  private slots: void OnDoubleValueChanged();
747 
749  private slots: void OnBoolValueChanged();
750 
752  private slots: void OnStringValueChanged();
753 
755  private slots: void OnVector3dValueChanged();
756 
759  private slots: void OnVector3dPresetChanged(const int _index);
760 
762  private slots: void OnColorValueChanged();
763 
767  private slots: void OnColorValueChanged(const QColor _value);
768 
770  private slots: void OnPoseValueChanged();
771 
773  private slots: void OnGeometryValueChanged();
774 
777  private slots: void OnGeometryValueChanged(const int _value);
778 
781  private slots: void OnEnumValueChanged(const QString &_value);
782 
785  private slots: void OnCustomColorDialog();
786 
790  Q_SIGNALS: void UIntValueChanged(const QString &_name,
791  const unsigned int _value);
792 
796  Q_SIGNALS: void IntValueChanged(const QString &_name, const int _value);
797 
801  Q_SIGNALS: void DoubleValueChanged(const QString &_name,
802  const double _value);
803 
807  Q_SIGNALS: void BoolValueChanged(const QString &_name,
808  const bool _value);
809 
815  Q_SIGNALS: void StringValueChanged(const QString &_name,
816  const std::string &_value);
817 
821  Q_SIGNALS: void Vector3dValueChanged(const QString &_name,
822  const ignition::math::Vector3d &_value);
823 
827  Q_SIGNALS: void ColorValueChanged(const QString &_name,
828  const ignition::math::Color &_value);
829 
833  Q_SIGNALS: void PoseValueChanged(const QString &_name,
834  const ignition::math::Pose3d &_pose);
835 
841  Q_SIGNALS: void GeometryValueChanged(const std::string &_name,
842  const std::string &_value,
843  const ignition::math::Vector3d &_dimensions,
844  const std::string &_uri);
845 
849  Q_SIGNALS: void EnumValueChanged(const QString &_name,
850  const QString &_value);
851 
854  Q_SIGNALS: void DensityValueChanged(const double &_value);
855 
858  Q_SIGNALS: void MassValueChanged(const double &_value);
859 
862  private slots: void OnDensityValueChanged(const double _value);
863 
866  private slots: void OnMassValueChanged(const double _value);
867 
869  private slots: void OnGeometryChanged();
870 
872  Q_SIGNALS: void GeometryChanged();
873 
878  private: bool eventFilter(QObject *_obj, QEvent *_event);
879 
882  private: std::unique_ptr<ConfigWidgetPrivate> dataPtr;
883  };
884  }
885 }
886 #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
static const std::vector< QString > widgetColors
List of colors used for widget areas according to their level.
Definition: ConfigWidget.hh:553
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:559
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:562
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:550
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:556
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
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
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