EditorView.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 
18 #ifndef _EDITOR_VIEW_HH_
19 #define _EDITOR_VIEW_HH_
20 
21 #include <map>
22 #include <string>
23 #include <vector>
24 #include "gazebo/gui/qt.h"
25 #include "gazebo/common/Event.hh"
26 #include "gazebo/util/system.hh"
27 
28 namespace gazebo
29 {
30  namespace gui
31  {
32  class EditorItem;
33  class GrabberHandle;
34  class WindowItem;
35  class StairsItem;
36  class DoorItem;
37  class WallSegmentItem;
38  class FloorItem;
39  class BuildingMaker;
40  class LevelInspectorDialog;
41  class GridLines;
42 
45  class GZ_GUI_VISIBLE Level
46  {
48  public: Level() : level(0), name("level"), baseHeight(0),
49  // 2.4384m == 8ft, standard room height in US
50  height(2.4384),
51  backgroundPixmap(nullptr),
52  floorItem(nullptr) {}
53 
55  public: int level;
56 
58  public: std::string name;
59 
61  public: double baseHeight;
62 
64  public: double height;
65 
67  public: QGraphicsPixmapItem *backgroundPixmap;
68 
70  public: FloorItem *floorItem;
71  };
72 
75 
78  class GZ_GUI_VISIBLE EditorView : public QGraphicsView
79  {
80  Q_OBJECT
81 
84  public: enum DrawModes {
98  TEXTURE
99  };
100 
103  public: EditorView(QWidget *_parent = 0);
104 
106  public: ~EditorView();
107 
109  public: void Create3DVisual(EditorItem *_item);
110 
113  public: void DeleteItem(EditorItem *_item);
114 
118  public: void SetBackgroundImage(const std::string &_filename,
119  double _scale);
120 
123  private: void resizeEvent(QResizeEvent *_event);
124 
128  private: void scrollContentsBy(int _dx, int _dy);
129 
132  private: void contextMenuEvent(QContextMenuEvent *_event);
133 
136  private: void wheelEvent(QWheelEvent *_event);
137 
140  private: void mouseMoveEvent(QMouseEvent *_event);
141 
144  private: void mousePressEvent(QMouseEvent *_event);
145 
148  private: void mouseReleaseEvent(QMouseEvent *_event);
149 
152  private: void mouseDoubleClickEvent(QMouseEvent *_event);
153 
156  private: void leaveEvent(QEvent *_event);
157 
160  private: void keyPressEvent(QKeyEvent *_event);
161 
164  private: void DrawWall(const QPoint &_pos);
165 
169  private: void DrawWindow(const QPoint &_pos);
170 
174  private: void DrawDoor(const QPoint &_pos);
175 
179  private: void DrawStairs(const QPoint &_pos);
180 
184  private: void OnCreateEditorItem(const std::string &_type);
185 
189  private: void OnColorSelected(QColor _color);
190 
194  private: void OnTextureSelected(QString _texture);
195 
198  private: void OnFinishModel();
199 
201  private: void OnDiscardModel();
202 
204  private slots: void OnAddLevel();
205 
208  private slots: void OnDeleteLevel();
209 
211  private slots: void OnLevelApply();
212 
214  private slots: void OnOpenLevelInspector();
215 
219  private: void OnChangeLevel(int _level);
220 
223  private: void DeleteLevel(int _level);
224 
226  private: void CancelDrawMode();
227 
229  private: void OnShowFloorplan();
230 
232  private: void OnShowElements();
233 
235  private: void ShowCurrentLevelItems();
236 
240  private: void LinkGrabbers(GrabberHandle *_grabber1,
241  GrabberHandle *_grabber2);
242 
248  private: void UnlinkGrabbers(GrabberHandle *_grabber1,
249  GrabberHandle *_grabber2 = nullptr);
250 
252  private: int drawMode;
253 
255  private: bool drawInProgress;
256 
258  private: bool floorplanVisible;
259 
261  private: bool elementsVisible;
262 
264  private: std::vector<WallSegmentItem*> wallSegmentList;
265 
267  private: std::vector<WindowItem*> windowList;
268 
270  private: std::vector<DoorItem*> doorList;
271 
273  private: std::vector<StairsItem*> stairsList;
274 
276  private: std::vector<FloorItem*> floorList;
277 
279  private: std::map<EditorItem *, std::string> itemToVisualMap;
280 
282  private: std::vector<event::ConnectionPtr> connections;
283 
286  private: QGraphicsItem *currentMouseItem;
287 
289  private: QGraphicsItem *currentSelectedItem = nullptr;
290 
292  private: BuildingMaker *buildingMaker = nullptr;
293 
295  private: int currentLevel = 0;
296 
298  private: std::vector<Level *> levels;
299 
302  private: int levelCounter = 0;
303 
305  private: double levelDefaultHeight = 0.0;
306 
308  private: QAction *openLevelInspectorAct;
309 
311  private: QAction *addLevelAct;
312 
314  private: QAction *deleteLevelAct;
315 
318  private: double mousePressRotation;
319 
321  private: LevelInspectorDialog *levelInspector;
322 
324  private: GridLines *gridLines;
325 
327  private: double viewScale;
328 
331  private: bool snapToGrabber = false;
332 
334  private: GrabberHandle *snapGrabberOther = nullptr;
335 
337  private: GrabberHandle *snapGrabberCurrent = nullptr;
338 
340  private: QGraphicsTextItem *mouseTooltip;
341  };
343  }
344 }
345 
346 #endif
double baseHeight
Level height from ground.
Definition: EditorView.hh:61
None mode.
Definition: EditorView.hh:86
Base class of an item in the editor.
Definition: EditorItem.hh:43
Door mode.
Definition: EditorView.hh:92
int level
Level number.
Definition: EditorView.hh:55
Color mode.
Definition: EditorView.hh:96
double height
Level height.
Definition: EditorView.hh:64
Wall mode.
Definition: EditorView.hh:88
2D representation of a floor.
Definition: FloorItem.hh:43
DrawModes
Unique identifiers for all drawing modes within the editor.
Definition: EditorView.hh:84
Create and manage 3D visuals of a building.
Definition: BuildingMaker.hh:48
A convenient structure for storing level information.
Definition: EditorView.hh:45
Window mode.
Definition: EditorView.hh:90
Dialog for configuring a building level.
Definition: LevelInspectorDialog.hh:40
Control the editor view and manage contents in the editor scene.
Definition: EditorView.hh:78
Definition: GrabberHandle.hh:42
QGraphicsPixmapItem * backgroundPixmap
Background pixmap for a level.
Definition: EditorView.hh:67
std::string name
Level name.
Definition: EditorView.hh:58
FloorItem * floorItem
Level's floor item.
Definition: EditorView.hh:70
2D grid lines.
Definition: GridLines.hh:37
Level()
Constructor.
Definition: EditorView.hh:48
Stairs mode.
Definition: EditorView.hh:94