All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BuildingMaker.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 _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"
29 #include "gazebo/gui/qt.h"
30 #include "gazebo/util/system.hh"
31 
32 namespace gazebo
33 {
34  namespace msgs
35  {
36  class Visual;
37  }
38 
39  namespace gui
40  {
41  class EntityMaker;
42  class EditorItem;
43  class BuildingModelManip;
44  class FinishBuildingDialog;
45 
48 
52  {
54  public: BuildingMaker();
55 
57  public: virtual ~BuildingMaker();
58 
61  public: void SetModelName(const std::string &_modelName);
62 
64  public: void FinishModel();
65 
72  public: std::string AddPart(const std::string &_type,
73  const QVector3D &_size, const QVector3D &_pos, double _angle);
74 
80  public: std::string AddWall(const QVector3D &_size, const QVector3D &_pos,
81  double _angle);
82 
88  public: std::string AddWindow(const QVector3D &_size,
89  const QVector3D &_pos, double _angle);
90 
96  public: std::string AddDoor(const QVector3D &_size, const QVector3D &_pos,
97  double _angle);
98 
105  public: std::string AddStairs(const QVector3D &_size,
106  const QVector3D &_pos, double _angle, int _steps);
107 
113  public: std::string AddFloor(const QVector3D &_size,
114  const QVector3D &_pos, double _angle);
115 
118  public: void RemovePart(const std::string &_partName);
119 
122  public: void RemoveWall(const std::string &_wallName);
123 
127  public: void ConnectItem(const std::string &_partName,
128  const EditorItem *_item);
129 
134  public: void AttachManip(const std::string &_child,
135  const std::string &_parent);
136 
140  public: void DetachManip(const std::string &_child,
141  const std::string &_parent);
142 
147  public: static math::Vector3 ConvertSize(const QVector3D &_size);
148 
155  public: static math::Vector3 ConvertSize(double _width, double _depth,
156  double _height);
157 
163  public: static math::Pose ConvertPose(const QVector3D &_pos,
164  const QVector3D &_rot);
165 
175  public: static math::Pose ConvertPose(double _x, double _y, double _z,
176  double _roll, double _pitch, double _yaw);
177 
181  public: static double Convert(double _value);
182 
186  public: static double ConvertAngle(double _angle);
187 
190  public: void SaveToSDF(const std::string &_savePath);
191 
193  public: void Reset();
194 
195  // Documentation inherited
196  public: virtual void Start(const rendering::UserCameraPtr _camera);
197 
198  // Documentation inherited
199  public: virtual void Stop();
200 
202  public: void GenerateSDF();
203 
204  // Documentation inherited
205  public: virtual bool IsActive() const;
206 
207  // Documentation inherited
208  private: virtual void CreateTheEntity();
209 
211  private: bool Init();
212 
215  private: std::string CreateModel();
216 
218  private: void GenerateSDFWithCSG();
219 
221  private: std::string GetTemplateSDFString();
222 
225  private: static bool PointCompareY(const QPointF &_a, const QPointF &_b);
226 
229  private: static bool RectCompareX(const QRectF &_a, const QRectF &_b);
230 
233  private: static bool RectCompareY(const QRectF &_a, const QRectF &_b);
234 
241  private: void SubdivideRectSurface(const QRectF &_surface,
242  const std::vector<QRectF> &_holes, std::vector<QRectF> &_subdivisions);
243 
245  private: void OnSave();
246 
248  private: void OnDiscard();
249 
252  private: void OnDone();
253 
255  private: void OnExit();
256 
258  public: static double conversionScale;
259 
262  private: std::map<std::string, BuildingModelManip *> allItems;
263 
265  private: sdf::SDFPtr modelSDF;
266 
268  private: sdf::SDFPtr modelTemplateSDF;
269 
271  private: std::string modelName;
272 
274  private: rendering::VisualPtr modelVisual;
275 
277  private: math::Pose modelPose;
278 
280  private: int wallCounter;
281 
283  private: int windowCounter;
284 
286  private: int doorCounter;
287 
289  private: int stairsCounter;
290 
292  private: int floorCounter;
293 
295  private: bool saved;
296 
298  private: std::string saveLocation;
299 
301  private: std::vector<event::ConnectionPtr> connections;
302 
304  private: std::string buildingDefaultName;
305 
307  private: FinishBuildingDialog *saveDialog;
308 
311  private: FinishBuildingDialog *finishDialog;
312  };
314  }
315 }
316 #endif
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
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:258
to make an entity base class
Definition: EntityMaker.hh:41
Create and manage 3D visuals of a building.
Definition: BuildingMaker.hh:51
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:100
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:84
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48