BuildingMaker.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 _BUILDING_MAKER_HH_
18 #define _BUILDING_MAKER_HH_
19 
20 #include <list>
21 #include <string>
22 #include <vector>
23 #include <map>
24 #include <sdf/sdf.hh>
25 
26 #include "gazebo/math/Pose.hh"
27 #include "gazebo/common/Events.hh"
30 #include "gazebo/gui/qt.h"
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace msgs
36  {
37  class Visual;
38  }
39 
40  namespace gui
41  {
42  class EntityMaker;
43  class EditorItem;
44  class BuildingModelManip;
45  class SaveDialog;
46 
49 
53  {
56  private: enum SaveState
57  {
58  // NEVER_SAVED: The building has never been saved.
59  NEVER_SAVED,
60 
61  // ALL_SAVED: All changes have been saved.
62  ALL_SAVED,
63 
64  // UNSAVED_CHANGES: Has been saved before, but has unsaved changes.
65  UNSAVED_CHANGES
66  };
67 
69  public: BuildingMaker();
70 
72  public: virtual ~BuildingMaker();
73 
76  public: void OnEdit(bool _checked);
77 
80  public: void SetModelName(const std::string &_modelName);
81 
83  public: void FinishModel();
84 
91  public: std::string AddPart(const std::string &_type,
92  const QVector3D &_size, const QVector3D &_pos, double _angle);
93 
99  public: std::string AddWall(const QVector3D &_size, const QVector3D &_pos,
100  double _angle);
101 
107  public: std::string AddWindow(const QVector3D &_size,
108  const QVector3D &_pos, double _angle);
109 
115  public: std::string AddDoor(const QVector3D &_size, const QVector3D &_pos,
116  double _angle);
117 
124  public: std::string AddStairs(const QVector3D &_size,
125  const QVector3D &_pos, double _angle, int _steps);
126 
132  public: std::string AddFloor(const QVector3D &_size,
133  const QVector3D &_pos, double _angle);
134 
137  public: void RemovePart(const std::string &_partName);
138 
141  public: void RemoveWall(const std::string &_wallName);
142 
146  public: void ConnectItem(const std::string &_partName,
147  const EditorItem *_item);
148 
153  public: void AttachManip(const std::string &_child,
154  const std::string &_parent);
155 
159  public: void DetachManip(const std::string &_child,
160  const std::string &_parent);
161 
164  public: void DetachAllChildren(const std::string &_manip);
165 
170  public: static math::Vector3 ConvertSize(const QVector3D &_size);
171 
178  public: static math::Vector3 ConvertSize(double _width, double _depth,
179  double _height);
180 
186  public: static math::Pose ConvertPose(const QVector3D &_pos,
187  const QVector3D &_rot);
188 
198  public: static math::Pose ConvertPose(double _x, double _y, double _z,
199  double _roll, double _pitch, double _yaw);
200 
204  public: static double Convert(double _value);
205 
209  public: static double ConvertAngle(double _angle);
210 
212  public: void Reset();
213 
214  // Documentation inherited
215  public: virtual void Start(const rendering::UserCameraPtr _camera);
216 
217  // Documentation inherited
218  public: virtual void Stop();
219 
221  public: void GenerateSDF();
222 
223  // Documentation inherited
224  public: virtual bool IsActive() const;
225 
227  public: void BuildingChanged();
228 
229  // Documentation inherited
230  private: virtual void CreateTheEntity();
231 
233  private: bool Init();
234 
237  private: std::string CreateModel();
238 
240  private: void GenerateSDFWithCSG();
241 
243  private: std::string GetTemplateSDFString();
244 
247  private: static bool PointCompareY(const QPointF &_a, const QPointF &_b);
248 
251  private: static bool RectCompareX(const QRectF &_a, const QRectF &_b);
252 
255  private: static bool RectCompareY(const QRectF &_a, const QRectF &_b);
256 
263  private: void SubdivideRectSurface(const QRectF &_surface,
264  const std::vector<QRectF> &_holes, std::vector<QRectF> &_subdivisions);
265 
267  private: void SaveModelFiles();
268 
271  private: bool OnSave();
272 
275  private: bool OnSaveAs();
276 
279  private: void OnNameChanged(const std::string &_modelName);
280 
282  private: void OnNew();
283 
285  private: void OnExit();
286 
290  private: void OnChangeLevel(int _level);
291 
293  private: void StopMaterialModes();
294 
297  private: void ResetHoverVis();
298 
302  private: void OnColorSelected(QColor _color);
303 
307  private: void OnTextureSelected(QString _texture);
308 
312  private: bool On3dMouseMove(const common::MouseEvent &_event);
313 
317  private: bool On3dMousePress(const common::MouseEvent &_event);
318 
322  private: bool On3dMouseRelease(const common::MouseEvent &_event);
323 
327  private: bool On3dKeyPress(const common::KeyEvent &_event);
328 
330  public: static double conversionScale;
331 
334  private: std::map<std::string, BuildingModelManip *> allItems;
335 
337  private: sdf::SDFPtr modelSDF;
338 
340  private: sdf::SDFPtr modelTemplateSDF;
341 
343  private: std::string modelName;
344 
346  private: std::string folderName;
347 
349  private: static const std::string previewName;
350 
352  private: rendering::VisualPtr previewVisual;
353 
355  private: int wallCounter;
356 
358  private: int windowCounter;
359 
361  private: int doorCounter;
362 
364  private: int stairsCounter;
365 
367  private: int floorCounter;
368 
370  private: enum SaveState currentSaveState;
371 
373  private: std::vector<event::ConnectionPtr> connections;
374 
376  private: static const std::string buildingDefaultName;
377 
379  private: SaveDialog *saveDialog;
380 
382  private: rendering::VisualPtr hoverVis;
383 
386  private: QColor selectedColor;
387 
390  private: QString selectedTexture;
391 
393  private: int currentLevel;
394  };
396  }
397 }
398 #endif
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Base class of an item in the editor.
Definition: EditorItem.hh:34
Dialog for saving to file.
Definition: SaveDialog.hh:37
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
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
GAZEBO_VISIBLE msgs::Vector3d Convert(const math::Vector3 &_v) GAZEBO_DEPRECATED(6.0)
Convert a math::Vector3 to a msgs::Vector3d.
static double conversionScale
Conversion scale used by the Convert helper functions.
Definition: BuildingMaker.hh:330
to make an entity base class
Definition: EntityMaker.hh:41
Create and manage 3D visuals of a building.
Definition: BuildingMaker.hh:52
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
#define GZ_GUI_BUILDING_VISIBLE
Definition: system.hh:393
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:107
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:91