ModelListWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-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 #ifndef _MODEL_LIST_WIDGET_HH_
18 #define _MODEL_LIST_WIDGET_HH_
19 
20 #include <string>
21 #include <list>
22 #include <vector>
23 #include <deque>
24 #include <sdf/sdf.hh>
25 
26 #include "gazebo/gui/qt.h"
27 #include "gazebo/msgs/msgs.hh"
30 #include "gazebo/util/system.hh"
31 
32 class QTreeWidget;
33 class QTreeWidgetItem;
34 class QPushButton;
37 class QtProperty;
38 class QtTreePropertyItem;
39 class QtBrowserItem;
41 
42 namespace boost
43 {
44  class recursive_mutex;
45  class mutex;
46 }
47 
48 namespace gazebo
49 {
50  namespace gui
51  {
52  class ModelEditWidget;
53 
54  class GAZEBO_VISIBLE ModelListWidget : public QWidget
55  {
56  Q_OBJECT
57  public: ModelListWidget(QWidget *_parent = 0);
58  public: virtual ~ModelListWidget();
59 
60  private slots: void OnModelSelection(QTreeWidgetItem *item, int column);
61  private slots: void Update();
62  private slots: void OnPropertyChanged(QtProperty *_item);
63  private slots: void OnCustomContextMenu(const QPoint &_pt);
64  private slots: void OnCurrentPropertyChanged(QtBrowserItem *_item);
65  private: void OnSetSelectedEntity(const std::string &_name,
66  const std::string &_mode);
67  private: void OnResponse(ConstResponsePtr &_msg);
68 
69  private: void OnModelUpdate(const msgs::Model &_msg);
70 
73  private: void OnLightUpdate(const msgs::Light &_msg);
74 
75  private: void OnRequest(ConstRequestPtr &_msg);
76 
77  private: void OnRemoveScene(const std::string &_name);
78  private: void OnCreateScene(const std::string &_name);
79 
80  private: void AddModelToList(const msgs::Model &_msg);
81 
82  private: void FillMsgField(QtProperty *_item,
83  google::protobuf::Message *_message,
84  const google::protobuf::Reflection *_reflection,
85  const google::protobuf::FieldDescriptor *_field);
86 
87  private: void FillMsg(QtProperty *_item,
88  google::protobuf::Message *_message,
89  const google::protobuf::Descriptor *_descriptor,
90  QtProperty *_changedItem);
91 
92  private: void FillGeometryMsg(QtProperty *_item,
93  google::protobuf::Message *_message,
94  const google::protobuf::Descriptor *_descriptor,
95  QtProperty *_changedItem);
96 
97  private: void FillPoseMsg(QtProperty *_item,
98  google::protobuf::Message *_message,
99  const google::protobuf::Descriptor *_descriptor);
100 
101  private: void FillColorMsg(QtProperty *_item, msgs::Color *_msg);
102 
103  private: void FillVector3Msg(QtProperty *_item, msgs::Vector3d *_msg);
104 
105  private: QtProperty *PopChildItem(QList<QtProperty*> &_list,
106  const std::string &_name);
107 
108  private: QtProperty *GetParentItemValue(const std::string &_name);
109  private: QtProperty *GetParentItemValue(QtProperty *_item,
110  const std::string &_name);
111 
112  private: QtProperty *GetParentItem(const std::string &_name);
113  private: QtProperty *GetParentItem(QtProperty *_item,
114  const std::string &_name);
115 
116  private: QtProperty *GetChildItemValue(const std::string &_name);
117  private: QtProperty *GetChildItemValue(QtProperty *_item,
118  const std::string &_name);
119 
120  private: QtProperty *GetChildItem(const std::string &_name);
121  private: QtProperty *GetChildItem(QtProperty *_item,
122  const std::string &_name);
123 
124  private: bool HasChildItem(QtProperty *_parent, QtProperty *_child);
125 
126  private: void RemoveEntity(const std::string &_name);
127 
128  private: QTreeWidgetItem *GetListItem(const std::string &_name,
129  QTreeWidgetItem *_parent);
130 
131  private: void FillPropertyTree(const msgs::Model &_msg,
132  QtProperty *_parent);
133 
134  private: void FillPropertyTree(const msgs::Link &_msg,
135  QtProperty *_parent);
136 
137  private: void FillPropertyTree(const msgs::Collision &_msg,
138  QtProperty *_parent);
139 
140  private: void FillPropertyTree(const msgs::Joint &_msg,
141  QtProperty *_parent);
142 
143  private: void FillPropertyTree(const msgs::Surface &_msg,
144  QtProperty *_parent);
145 
146  private: void FillPropertyTree(const msgs::Visual &_msg,
147  QtProperty *_parent);
148 
149  private: void FillPropertyTree(const msgs::Geometry &_msg,
150  QtProperty *_parent);
151 
152  private: void FillPropertyTree(const msgs::Scene &_msg,
153  QtProperty *_parent);
154 
155  private: void FillPropertyTree(const msgs::Physics &_msg,
156  QtProperty *_parent);
157 
158  private: void FillPropertyTree(const msgs::Light &_msg,
159  QtProperty *_parent);
160 
161  private: void FillVector3dProperty(const msgs::Vector3d &_msg,
162  QtProperty *_parent);
163 
164  private: void FillPoseProperty(const msgs::Pose &_msg,
165  QtProperty *_parent);
166 
171  private: void FillPropertyTree(const msgs::SphericalCoordinates &_msg,
172  QtProperty *_parent);
173 
177  private: void AddProperty(QtProperty *_item, QtProperty *_parent);
178 
179  private: void ProcessModelMsgs();
180  private: void ProcessLightMsgs();
181  private: void ProcessRemoveEntity();
182 
183  public: void InitTransport(const std::string &_name ="");
184  private: void ResetTree();
185  private: void ResetScene();
186 
189  private: void ModelPropertyChanged(QtProperty *_item);
190 
193  private: void ScenePropertyChanged(QtProperty *_item);
194 
195  private: void LightPropertyChanged(QtProperty *_item);
196 
199  private: void PhysicsPropertyChanged(QtProperty *_item);
200 
203  private: void GUIPropertyChanged(QtProperty *_item);
204 
205  private: QTreeWidget *modelTreeWidget;
206  private: QtTreePropertyBrowser *propTreeBrowser;
207 
208  private: transport::NodePtr node;
209  private: transport::PublisherPtr requestPub;
210  private: transport::PublisherPtr modelPub;
211  private: transport::PublisherPtr scenePub;
212  private: transport::PublisherPtr physicsPub;
213  private: transport::PublisherPtr lightPub;
214 
215  private: transport::SubscriberPtr responseSub;
216  private: transport::SubscriberPtr requestSub;
217 
219  private: QTreeWidgetItem *guiItem;
220 
222  private: QTreeWidgetItem *sceneItem;
223 
225  private: QTreeWidgetItem *physicsItem;
226 
228  private: QTreeWidgetItem *modelsItem;
229 
231  private: QTreeWidgetItem *lightsItem;
232 
234  private: QTreeWidgetItem *sphericalCoordItem;
235 
236  private: QtVariantPropertyManager *variantManager;
237  private: QtVariantEditorFactory *variantFactory;
238  private: boost::mutex *propMutex, *receiveMutex;
239  private: sdf::ElementPtr sdfElement;
240  private: std::string selectedEntityName;
241  private: bool fillingPropertyTree;
242  private: QtProperty *selectedProperty;
243 
244  private: msgs::Request *requestMsg;
245 
246  private: std::vector<event::ConnectionPtr> connections;
247 
248  typedef std::list<msgs::Model> ModelMsgs_L;
249  private: ModelMsgs_L modelMsgs;
250 
251  typedef std::list<msgs::Light> LightMsgs_L;
252  private: LightMsgs_L lightMsgs;
253 
254  typedef std::list<std::string> RemoveEntity_L;
255  private: RemoveEntity_L removeEntityList;
256 
257  private: msgs::Model modelMsg;
258  private: msgs::Link linkMsg;
259  private: msgs::Scene sceneMsg;
260  private: msgs::Joint jointMsg;
261  private: msgs::Physics physicsMsg;
262  private: msgs::Light lightMsg;
263  private: msgs::SphericalCoordinates sphericalCoordMsg;
264 
265  private: bool fillPropertyTree;
266  private: std::deque<std::string> fillTypes;
267 
268  private: msgs::Light::LightType lightType;
269 
271  private: msgs::Physics_Type physicsType;
272  };
273 
274  class GAZEBO_VISIBLE ModelListSheetDelegate: public QItemDelegate
275  {
276  Q_OBJECT
277  public: ModelListSheetDelegate(QTreeView *view, QWidget *parent);
278 
279  public: virtual void paint(QPainter *painter,
280  const QStyleOptionViewItem &option,
281  const QModelIndex &index) const;
282 
283  public: virtual QSize sizeHint(const QStyleOptionViewItem &opt,
284  const QModelIndex &index) const;
285 
286  private: QTreeView *m_view;
287  };
288  }
289 }
290 #endif
Definition: ModelListWidget.hh:274
Definition: qtpropertybrowser.h:311
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Definition: qtvariantproperty.h:92
Forward declarations for transport.
Definition: qttreepropertybrowser.h:142
std::list< boost::shared_ptr< msgs::Model const > > ModelMsgs_L
Definition: ScenePrivate.hh:92
std::list< boost::shared_ptr< msgs::Light const > > LightMsgs_L
Definition: ScenePrivate.hh:72
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
Definition: ModelListWidget.hh:54
Definition: qtpropertybrowser.h:77
Definition: qtvariantproperty.h:302
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:66