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 FinishBuildingDialog;
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 
213  public: void SaveToSDF(const std::string &_savePath);
214 
217  public: void SaveToConfig(const std::string &_savePath);
218 
220  public: void Reset();
221 
222  // Documentation inherited
223  public: virtual void Start(const rendering::UserCameraPtr _camera);
224 
225  // Documentation inherited
226  public: virtual void Stop();
227 
229  public: void GenerateSDF();
230 
232  public: void GenerateConfig();
233 
234  // Documentation inherited
235  public: virtual bool IsActive() const;
236 
238  public: void BuildingChanged();
239 
240  // Documentation inherited
241  private: virtual void CreateTheEntity();
242 
244  private: bool Init();
245 
248  private: std::string CreateModel();
249 
251  private: void GenerateSDFWithCSG();
252 
254  private: std::string GetTemplateSDFString();
255 
257  private: std::string GetTemplateConfigString();
258 
261  private: static bool PointCompareY(const QPointF &_a, const QPointF &_b);
262 
265  private: static bool RectCompareX(const QRectF &_a, const QRectF &_b);
266 
269  private: static bool RectCompareY(const QRectF &_a, const QRectF &_b);
270 
277  private: void SubdivideRectSurface(const QRectF &_surface,
278  const std::vector<QRectF> &_holes, std::vector<QRectF> &_subdivisions);
279 
281  private: void SaveModelFiles();
282 
286  private: bool OnSave(const std::string &_saveName = "");
287 
291  private: bool OnSaveAs(const std::string &_saveName);
292 
295  private: void OnNameChanged(const std::string &_modelName);
296 
298  private: void OnNew();
299 
301  private: void OnExit();
302 
306  private: void OnChangeLevel(int _level);
307 
309  private: void StopMaterialModes();
310 
313  private: void ResetHoverVis();
314 
318  private: void OnColorSelected(QColor _color);
319 
323  private: void OnTextureSelected(QString _texture);
324 
328  private: bool On3dMouseMove(const common::MouseEvent &_event);
329 
333  private: bool On3dMousePress(const common::MouseEvent &_event);
334 
338  private: bool On3dMouseRelease(const common::MouseEvent &_event);
339 
343  private: bool On3dKeyPress(const common::KeyEvent &_event);
344 
346  public: static double conversionScale;
347 
350  private: std::map<std::string, BuildingModelManip *> allItems;
351 
353  private: sdf::SDFPtr modelSDF;
354 
356  private: sdf::SDFPtr modelTemplateSDF;
357 
359  private: TiXmlDocument modelConfig;
360 
362  private: std::string modelName;
363 
365  private: static const std::string previewName;
366 
368  private: rendering::VisualPtr previewVisual;
369 
371  private: int wallCounter;
372 
374  private: int windowCounter;
375 
377  private: int doorCounter;
378 
380  private: int stairsCounter;
381 
383  private: int floorCounter;
384 
386  private: enum SaveState currentSaveState;
387 
389  private: std::string defaultPath;
390 
392  private: std::string saveLocation;
393 
395  private: std::string authorName;
396 
398  private: std::string authorEmail;
399 
401  private: std::string description;
402 
404  private: std::string version;
405 
407  private: std::vector<event::ConnectionPtr> connections;
408 
410  private: static const std::string buildingDefaultName;
411 
413  private: FinishBuildingDialog *saveDialog;
414 
416  private: rendering::VisualPtr hoverVis;
417 
420  private: QColor selectedColor;
421 
424  private: QString selectedTexture;
425 
427  private: int currentLevel;
428  };
430  }
431 }
432 #endif
Generic description of a mouse event.
Definition: MouseEvent.hh:32
Base class of an item in the editor.
Definition: EditorItem.hh:34
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
GAZEBO_VISIBLE msgs::Vector3d Convert(const math::Vector3 &_v)
Convert a math::Vector3 to a msgs::Vector3d.
static double conversionScale
Conversion scale used by the Convert helper functions.
Definition: BuildingMaker.hh:346
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.
Dialog for saving the building model.
Definition: FinishBuildingDialog.hh:34
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:86
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48