All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ModelListWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-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 #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 *_parentItem);
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 
174  private: void ProcessModelMsgs();
175  private: void ProcessLightMsgs();
176  private: void ProcessRemoveEntity();
177 
178  public: void InitTransport(const std::string &_name ="");
179  private: void ResetTree();
180  private: void ResetScene();
181 
184  private: void ModelPropertyChanged(QtProperty *_item);
185 
188  private: void ScenePropertyChanged(QtProperty *_item);
189 
190  private: void LightPropertyChanged(QtProperty *_item);
191 
194  private: void PhysicsPropertyChanged(QtProperty *_item);
195 
196  private: QTreeWidget *modelTreeWidget;
197  private: QtTreePropertyBrowser *propTreeBrowser;
198 
199  private: transport::NodePtr node;
200  private: transport::PublisherPtr requestPub;
201  private: transport::PublisherPtr modelPub;
202  private: transport::PublisherPtr scenePub;
203  private: transport::PublisherPtr physicsPub;
204  private: transport::PublisherPtr lightPub;
205 
206  private: transport::SubscriberPtr responseSub;
207  private: transport::SubscriberPtr requestSub;
208 
209  private: QTreeWidgetItem *sceneItem;
210  private: QTreeWidgetItem *physicsItem;
211  private: QTreeWidgetItem *modelsItem;
212  private: QTreeWidgetItem *lightsItem;
213  private: QTreeWidgetItem *sphericalCoordItem;
214 
215  private: QtVariantPropertyManager *variantManager;
216  private: QtVariantEditorFactory *variantFactory;
217  private: boost::mutex *propMutex, *receiveMutex;
218  private: sdf::ElementPtr sdfElement;
219  private: std::string selectedEntityName;
220  private: bool fillingPropertyTree;
221  private: QtProperty *selectedProperty;
222 
223  private: msgs::Request *requestMsg;
224 
225  private: std::vector<event::ConnectionPtr> connections;
226 
227  typedef std::list<msgs::Model> ModelMsgs_L;
228  private: ModelMsgs_L modelMsgs;
229 
230  typedef std::list<msgs::Light> LightMsgs_L;
231  private: LightMsgs_L lightMsgs;
232 
233  typedef std::list<std::string> RemoveEntity_L;
234  private: RemoveEntity_L removeEntityList;
235 
236  private: msgs::Model modelMsg;
237  private: msgs::Link linkMsg;
238  private: msgs::Scene sceneMsg;
239  private: msgs::Joint jointMsg;
240  private: msgs::Physics physicsMsg;
241  private: msgs::Light lightMsg;
242  private: msgs::SphericalCoordinates sphericalCoordMsg;
243 
244  private: bool fillPropertyTree;
245  private: std::deque<std::string> fillTypes;
246 
247  private: msgs::Light::LightType lightType;
248 
250  private: msgs::Physics_Type physicsType;
251  };
252 
253  class GAZEBO_VISIBLE ModelListSheetDelegate: public QItemDelegate
254  {
255  Q_OBJECT
256  public: ModelListSheetDelegate(QTreeView *view, QWidget *parent);
257 
258  public: virtual void paint(QPainter *painter,
259  const QStyleOptionViewItem &option,
260  const QModelIndex &index) const;
261 
262  public: virtual QSize sizeHint(const QStyleOptionViewItem &opt,
263  const QModelIndex &index) const;
264 
265  private: QTreeView *m_view;
266  };
267  }
268 }
269 #endif
Definition: ModelListWidget.hh:253
Definition: qtpropertybrowser.h:311
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:48
Definition: qtvariantproperty.h:92
Forward declarations for transport.
Definition: qttreepropertybrowser.h:142
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:52
Definition: ModelListWidget.hh:54
Definition: qtpropertybrowser.h:77
Definition: qtvariantproperty.h:302
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:44
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48