BuildingMaker.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 _GAZEBO_GUI_BUILDING_BUILDINGMAKER_HH_
18 #define _GAZEBO_GUI_BUILDING_BUILDINGMAKER_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <memory>
23 
24 #include <ignition/math/Pose3.hh>
25 #include <ignition/math/Vector3.hh>
26 
29 
30 #include "gazebo/gui/qt.h"
31 
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace gui
37  {
38  class BuildingModelManip;
39  class EditorItem;
40 
41  // Forward declare provate data.
42  class BuildingMakerPrivate;
43 
46 
48  class GZ_GUI_VISIBLE BuildingMaker
49  {
51  public: BuildingMaker();
52 
54  public: ~BuildingMaker();
55 
58  public: void OnEdit(bool _checked);
59 
62  public: void SetModelName(const std::string &_modelName);
63 
65  public: void FinishModel();
66 
73  public: std::string AddPart(const std::string &_type,
74  const QVector3D &_size, const QVector3D &_pos, double _angle);
75 
81  public: std::string AddWall(const QVector3D &_size, const QVector3D &_pos,
82  double _angle);
83 
89  public: std::string AddWindow(const QVector3D &_size,
90  const QVector3D &_pos, double _angle);
91 
97  public: std::string AddDoor(const QVector3D &_size, const QVector3D &_pos,
98  double _angle);
99 
106  public: std::string AddStairs(const QVector3D &_size,
107  const QVector3D &_pos, double _angle, int _steps);
108 
114  public: std::string AddFloor(const QVector3D &_size,
115  const QVector3D &_pos, double _angle);
116 
119  public: void RemovePart(const std::string &_partName);
120 
123  public: void RemoveWall(const std::string &_wallName);
124 
128  public: void ConnectItem(const std::string &_partName,
129  const EditorItem *_item);
130 
136  public: void AttachManip(const std::string &_child,
137  const std::string &_parent);
138 
141  public: void DetachFromParent(const std::string &_child);
142 
145  public: void DetachAllChildren(const std::string &_parent);
146 
150  public: bool IsAttached(const std::string &_child) const;
151 
154  public: BuildingModelManip *ManipByName(const std::string &_name);
155 
162  public: static ignition::math::Vector3d ConvertSize(
163  const double _width, const double _depth, const double _height);
164 
174  public: static ignition::math::Pose3d ConvertPose(const double _x,
175  const double _y, const double _z, const double _roll,
176  const double _pitch, const double _yaw);
177 
181  public: static double Convert(double _value);
182 
186  public: static double ConvertAngle(double _angle);
187 
189  public: void Reset();
190 
192  public: void GenerateSDF();
193 
195  public: void BuildingChanged();
196 
199  public: std::string ModelSDF() const;
200 
202  private: void CreateTheEntity();
203 
205  private: bool Init();
206 
209  private: std::string CreateModel();
210 
212  private: void GenerateSDFWithCSG();
213 
216  private: std::string TemplateSDFString() const;
217 
220  private: static bool PointCompareY(const QPointF &_a, const QPointF &_b);
221 
224  private: static bool RectCompareX(const QRectF &_a, const QRectF &_b);
225 
228  private: static bool RectCompareY(const QRectF &_a, const QRectF &_b);
229 
236  private: void SubdivideRectSurface(const QRectF &_surface,
237  const std::vector<QRectF> &_holes, std::vector<QRectF> &_subdivisions);
238 
240  private: void SaveModelFiles();
241 
244  private: bool OnSave();
245 
248  private: bool OnSaveAs();
249 
252  private: void OnNameChanged(const std::string &_modelName);
253 
255  private: void OnNew();
256 
258  private: void OnExit();
259 
263  private: void OnChangeLevel(int _level);
264 
266  private: void StopMaterialModes();
267 
270  private: void ResetHoverVis();
271 
275  private: void OnColorSelected(QColor _color);
276 
280  private: void OnTextureSelected(QString _texture);
281 
285  private: bool On3dMouseMove(const common::MouseEvent &_event);
286 
290  private: bool On3dMousePress(const common::MouseEvent &_event);
291 
295  private: bool On3dMouseRelease(const common::MouseEvent &_event);
296 
300  private: bool On3dKeyPress(const common::KeyEvent &_event);
301 
303  public: static const double conversionScale;
304 
307  private: std::unique_ptr<BuildingMakerPrivate> dataPtr;
308  };
310  }
311 }
312 #endif
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Base class of an item in the editor.
Definition: EditorItem.hh:43
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
GAZEBO_VISIBLE msgs::Vector3d Convert(const ignition::math::Vector3d &_v)
Convert a ignition::math::Vector3 to a msgs::Vector3d.
Create and manage 3D visuals of a building.
Definition: BuildingMaker.hh:48
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
static const double conversionScale
Conversion scale used by the Convert helper functions.
Definition: BuildingMaker.hh:303
bool const T & _b
Definition: Helpers.hh:258
Manipulate a 3D visual associated to a 2D editor item.
Definition: BuildingModelManip.hh:47