ConfigWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 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 _CONFIG_WIDGET_HH_
19 #define _CONFIG_WIDGET_HH_
20 
21 #include <string>
22 #include <vector>
23 #include <map>
24 
25 #include "gazebo/math/Pose.hh"
26 #include "gazebo/common/Color.hh"
27 #include "gazebo/gui/qt.h"
28 
29 namespace google
30 {
31  namespace protobuf
32  {
33  class Message;
34  class Reflection;
35  class FieldDescriptor;
36  }
37 }
38 
39 namespace gazebo
40 {
41  namespace gui
42  {
43  class GroupWidget;
44 
47 
51  class GAZEBO_VISIBLE ConfigChildWidget : public QFrame
52  {
53  Q_OBJECT
54 
56  public: ConfigChildWidget() : groupWidget(NULL) {}
57 
59  public: std::string key;
60 
62  public: std::vector<QWidget *> widgets;
63 
65  public: std::map<QWidget *, QLabel *> mapWidgetToUnit;
66 
70  };
71 
75  {
76  Q_OBJECT
77 
80  public: QStackedWidget *geomDimensionWidget;
81 
83  public: QWidget *geomLengthSpinBox;
84 
86  public: QWidget *geomLengthLabel;
87 
89  public: QWidget *geomLengthUnitLabel;
90 
92  public: QWidget *geomFilenameLineEdit;
93 
95  public: QWidget *geomFilenameLabel;
96 
98  public: QWidget *geomFilenameButton;
99 
102  private slots: void GeometryChanged(const QString _text);
103 
105  private slots: void OnSelectFile();
106  };
107 
111  {
112  Q_OBJECT
113 
116  Q_SIGNALS: void EnumValueChanged(const QString &_value);
117 
120  private slots: void EnumChanged(const QString &_value);
121  };
122 
125  class GAZEBO_VISIBLE GroupWidget : public QWidget
126  {
127  Q_OBJECT
128 
130  public: QWidget *childWidget;
131 
134  private slots: void Toggle(bool _checked);
135  };
136 
139  class GAZEBO_VISIBLE ConfigWidget : public QWidget
140  {
141  Q_OBJECT
142 
144  public: ConfigWidget();
145 
147  public: ~ConfigWidget();
148 
151  public: void Load(const google::protobuf::Message *_msg);
152 
155  public: google::protobuf::Message *GetMsg();
156 
161  public: std::string GetHumanReadableKey(const std::string &_key);
162 
169  public: std::string GetUnitFromKey(const std::string &_key,
170  const std::string &_jointType = "");
171 
173  // "transparency" returns min == 0, max == 1.
177  public: void GetRangeFromKey(const std::string &_key,
178  double &_min, double &_max);
179 
183  public: void SetWidgetVisible(const std::string &_name, bool _visible);
184 
188  public: bool GetWidgetVisible(const std::string &_name) const;
189 
193  public: void SetWidgetReadOnly(const std::string &_name, bool _readOnly);
194 
198  public: bool GetWidgetReadOnly(const std::string &_name) const;
199 
202  public: void UpdateFromMsg(const google::protobuf::Message *_msg);
203 
208  public: bool SetIntWidgetValue(const std::string &_name, int _value);
209 
214  public: bool SetUIntWidgetValue(const std::string &_name, unsigned int
215  _value);
216 
221  public: bool SetDoubleWidgetValue(const std::string &_name,
222  double _value);
223 
228  public: bool SetBoolWidgetValue(const std::string &_name, bool _value);
229 
233  public: bool SetStringWidgetValue(const std::string &_name,
234  const std::string &_value);
235 
240  public: bool SetVector3WidgetValue(const std::string &_name,
241  const math::Vector3 &_value);
242 
247  public: bool SetColorWidgetValue(const std::string &_name,
248  const common::Color &_value);
249 
254  public: bool SetPoseWidgetValue(const std::string &_name,
255  const math::Pose &_value);
256 
262  public: bool SetGeometryWidgetValue(const std::string &_name,
263  const std::string &_value, const math::Vector3 &_dimensions,
264  const std::string &_uri = "");
265 
270  public: bool SetEnumWidgetValue(const std::string &_name,
271  const std::string &_value);
272 
276  public: int GetIntWidgetValue(const std::string &_name) const;
277 
281  public: unsigned int GetUIntWidgetValue(const std::string &_name) const;
282 
286  public: double GetDoubleWidgetValue(const std::string &_name) const;
287 
291  public: bool GetBoolWidgetValue(const std::string &_name) const;
292 
296  public: std::string GetStringWidgetValue(const std::string &_name) const;
297 
301  public: math::Vector3 GetVector3WidgetValue(const std::string &_name)
302  const;
303 
307  public: common::Color GetColorWidgetValue(const std::string &_name) const;
308 
312  public: math::Pose GetPoseWidgetValue(const std::string &_name) const;
313 
318  public: std::string GetGeometryWidgetValue(const std::string &_name,
319  math::Vector3 &_dimensions, std::string &_uri) const;
320 
324  public: std::string GetEnumWidgetValue(const std::string &_name) const;
325 
335  private: QWidget *Parse(google::protobuf::Message *_msg,
336  bool _update = false, const std::string &_name = "",
337  const int _level = 0);
338 
342  private: math::Vector3 ParseVector3(
343  const google::protobuf::Message *_msg);
344 
348  private: void UpdateMsg(google::protobuf::Message *_msg,
349  const std::string &_name = "");
350 
354  private: void UpdateVector3Msg(google::protobuf::Message *_msg,
355  const math::Vector3 &_value);
356 
361  private: ConfigChildWidget *CreateUIntWidget(const std::string &_key,
362  const int _level = 0);
363 
368  private: ConfigChildWidget *CreateIntWidget(const std::string &_key,
369  const int _level = 0);
370 
375  private: ConfigChildWidget *CreateDoubleWidget(const std::string &_key,
376  const int _level = 0);
377 
382  private: ConfigChildWidget *CreateStringWidget(const std::string &_key,
383  const int _level = 0);
384 
389  private: ConfigChildWidget *CreateBoolWidget(const std::string &_key,
390  const int _level = 0);
391 
396  private: ConfigChildWidget *CreateVector3dWidget(const std::string &_key,
397  const int _level = 0);
398 
403  private: ConfigChildWidget *CreateColorWidget(const std::string &_key,
404  const int _level = 0);
405 
410  private: ConfigChildWidget *CreatePoseWidget(const std::string &_key,
411  const int _level = 0);
412 
417  private: ConfigChildWidget *CreateGeometryWidget(const std::string &_key,
418  const int _level = 0);
419 
425  private: ConfigChildWidget *CreateEnumWidget(const std::string &_key,
426  const std::vector<std::string> &_values, const int _level = 0);
427 
432  private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
433  unsigned int _value);
434 
439  private: bool UpdateIntWidget(ConfigChildWidget *_widget, int _value);
440 
445  private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
446  double _value);
447 
452  private: bool UpdateStringWidget(ConfigChildWidget *_widget,
453  const std::string &_value);
454 
459  private: bool UpdateBoolWidget(ConfigChildWidget *_widget, bool _value);
460 
465  private: bool UpdateVector3Widget(ConfigChildWidget *_widget,
466  const math::Vector3 &_value);
467 
472  private: bool UpdateColorWidget(ConfigChildWidget *_widget,
473  const common::Color &_value);
474 
479  private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
480  const math::Pose &_value);
481 
488  private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
489  const std::string &_value, const math::Vector3 &_dimensions,
490  const std::string &_uri = "");
491 
496  private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
497  const std::string &_value);
498 
502  private: int GetIntWidgetValue(ConfigChildWidget *_widget) const;
503 
507  private: unsigned int GetUIntWidgetValue(ConfigChildWidget *_widget)
508  const;
509 
513  private: double GetDoubleWidgetValue(ConfigChildWidget *_widget) const;
514 
518  private: bool GetBoolWidgetValue(ConfigChildWidget *_widget) const;
519 
523  private: std::string GetStringWidgetValue(ConfigChildWidget *_widget)
524  const;
525 
529  private: math::Vector3 GetVector3WidgetValue(ConfigChildWidget *_widget)
530  const;
531 
535  private: common::Color GetColorWidgetValue(ConfigChildWidget *_widget)
536  const;
537 
541  private: math::Pose GetPoseWidgetValue(ConfigChildWidget *_widget) const;
542 
548  private: std::string GetGeometryWidgetValue(ConfigChildWidget *_widget,
549  math::Vector3 &_dimensions, std::string &_uri) const;
550 
554  private: std::string GetEnumWidgetValue(ConfigChildWidget *_widget) const;
555 
559  private slots: void OnItemSelection(QTreeWidgetItem *_item, int _column);
560 
563  private slots: void OnEnumValueChanged(const QString &_value);
564 
568  Q_SIGNALS: void EnumValueChanged(const QString &_name,
569  const QString &_value);
570 
575  private: bool eventFilter(QObject *_obj, QEvent *_event);
576 
578  private: std::map <std::string, ConfigChildWidget *> configWidgets;
579 
581  private: google::protobuf::Message *configMsg;
582 
584  private: static const QString level0BgColor;
585 
587  private: static const QString level1BgColor;
588 
590  private: static const QString level2BgColor;
591 
593  private: static const QString level3BgColor;
594 
596  private: static const QString level0WidgetColor;
597 
599  private: static const QString level1WidgetColor;
600 
602  private: static const QString level2WidgetColor;
603 
605  private: static const QString level3WidgetColor;
606 
608  private: static const QString redColor;
609 
611  private: static const QString greenColor;
612 
614  private: static const QString blueColor;
615  };
616  }
617 }
618 #endif
QWidget * geomLengthLabel
A label for the length widget.
Definition: ConfigWidget.hh:86
QWidget * geomFilenameLabel
A label for the mesh filename widget.
Definition: ConfigWidget.hh:95
A collapsible widget that holds child widgets.
Definition: ConfigWidget.hh:125
GroupWidget * groupWidget
Pointer to group widget.
Definition: ConfigWidget.hh:69
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
QWidget * childWidget
Child widget that can be collapsed or expanded.
Definition: ConfigWidget.hh:130
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
A widget generated from a google protobuf message.
Definition: ConfigWidget.hh:139
ConfigChildWidget()
Constructor;.
Definition: ConfigWidget.hh:56
QWidget * geomFilenameButton
A button for selecting the mesh filename.
Definition: ConfigWidget.hh:98
A convenience widget that also holds pointers to a list of its child widgets.
Definition: ConfigWidget.hh:51
QWidget * geomLengthSpinBox
A spin box for configuring the length of the geometry.
Definition: ConfigWidget.hh:83
QWidget * geomFilenameLineEdit
A line edit for editing the mesh filename.
Definition: ConfigWidget.hh:92
std::vector< QWidget * > widgets
List of widgets holding values, such as Spins and LineEdits.
Definition: ConfigWidget.hh:62
A widget for configuring enum values.
Definition: ConfigWidget.hh:110
std::map< QWidget *, QLabel * > mapWidgetToUnit
Map a widget to the label holding its unit value.
Definition: ConfigWidget.hh:65
A widget for configuring geometry properties.
Definition: ConfigWidget.hh:74
#define NULL
Definition: CommonTypes.hh:30
Defines a color.
Definition: Color.hh:36
QWidget * geomLengthUnitLabel
A label for the unit of the length widget.
Definition: ConfigWidget.hh:89
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:66
QStackedWidget * geomDimensionWidget
A stacked widget containing widgets for configuring geometry dimensions.
Definition: ConfigWidget.hh:80
std::string key
Widget's key value.
Definition: ConfigWidget.hh:59