BuildingMaker.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
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 
198  private: void CreateTheEntity();
199 
201  private: bool Init();
202 
205  private: std::string CreateModel();
206 
208  private: void GenerateSDFWithCSG();
209 
212  private: std::string TemplateSDFString() const;
213 
216  private: static bool PointCompareY(const QPointF &_a, const QPointF &_b);
217 
220  private: static bool RectCompareX(const QRectF &_a, const QRectF &_b);
221 
224  private: static bool RectCompareY(const QRectF &_a, const QRectF &_b);
225 
232  private: void SubdivideRectSurface(const QRectF &_surface,
233  const std::vector<QRectF> &_holes, std::vector<QRectF> &_subdivisions);
234 
236  private: void SaveModelFiles();
237 
240  private: bool OnSave();
241 
244  private: bool OnSaveAs();
245 
248  private: void OnNameChanged(const std::string &_modelName);
249 
251  private: void OnNew();
252 
254  private: void OnExit();
255 
259  private: void OnChangeLevel(int _level);
260 
262  private: void StopMaterialModes();
263 
266  private: void ResetHoverVis();
267 
271  private: void OnColorSelected(QColor _color);
272 
276  private: void OnTextureSelected(QString _texture);
277 
281  private: bool On3dMouseMove(const common::MouseEvent &_event);
282 
286  private: bool On3dMousePress(const common::MouseEvent &_event);
287 
291  private: bool On3dMouseRelease(const common::MouseEvent &_event);
292 
296  private: bool On3dKeyPress(const common::KeyEvent &_event);
297 
299  public: static const double conversionScale;
300 
303  private: std::unique_ptr<BuildingMakerPrivate> dataPtr;
304  };
306  }
307 }
308 #endif
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Base class of an item in the editor.
Definition: EditorItem.hh:40
#define GZ_GUI_VISIBLE
Definition: system.hh:284
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:299
Manipulate a 3D visual associated to a 2D editor item.
Definition: BuildingModelManip.hh:47