MIRA
VisualizationView.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_VISUALIZATIONVIEW_H_
48 #define _MIRA_VISUALIZATIONVIEW_H_
49 
50 #include <QBasicTimer>
51 
52 #include <factory/NullClass.h>
53 #include <utils/Time.h>
54 #include <serialization/adapters/std/list>
55 #include <serialization/adapters/Qt/QAction>
56 #include <rcp/EditorPart.h>
57 
58 #include <views/GuiViewsExports.h>
59 #include <fw/TransformProperty.h>
61 
62 class QMimeData;
63 class QDragEnterEvent;
64 class QDropEvent;
65 class QFocusEvent;
66 class QBoxLayout;
67 class QToolBar;
68 class QToolButton;
69 class QButtonGroup;
70 
71 namespace mira {
72 
74 
75 class Visualization;
76 class VisualizationTool;
77 class VisualizationControlPage;
78 
85 {
86  Q_OBJECT
88 
89 public:
90 
92  virtual ~VisualizationView();
93 
94 
95 public:
96 
97  template <typename Reflector>
98  void reflect(Reflector& r)
99  {
101  r.member("Visualizations", mVisualizations, "The assigned visualizations");
102 
103  r.property("Update",
104  mUpdateInterval,
106  "Update interval in ms",
107  40);
108 
109  r.property("WindowTitle",
110  getter(&VisualizationView::getWindowTitle,this),
111  setter(&VisualizationView::setWindowTitle,this),
112  "Title of window",
113  getClass().getMetaInfo("Name"));
114 
115  r.member("HideTools",
116  getter<bool>(boost::bind(actionGetter, mHideToolBar)),
117  setter<bool>(boost::bind(actionSetter, mHideToolBar, _1)),
118  "Hide tool bar with tools", false);
119 
120  r.property("Tools", mTools, "The used tools");
121  }
123  void reflect(XMLDeserializer& r);
125  void reflect(XMLSerializer& r);
126 
127 public:
128 
134  virtual void addVisualization(Visualization* vis);
135 
141  virtual void removeVisualization(Visualization* vis);
142 
149  virtual void moveUpVisualization(Visualization* vis);
150 
157  virtual void moveDownVisualization(Visualization* vis);
158 
159  const std::list<Visualization*>& getVisualizations() const;
160 
166  virtual void addTool(VisualizationTool* tool);
167 
168  const std::vector<VisualizationTool*>& getTools() const;
169 
170 public:
171 
176  VisualizationControlPage* getControl();
177 
178 public:
179 
180  virtual Object* getAdapter(const Class& adapter);
181 
182 public:
183 
188  virtual const Class& supportedVisualizationClass() const = 0;
189 
197  virtual const Class& defaultVisualizationClass() const {
198  return NullClass::null();
199  }
200 
206  virtual const Class& supportedVisualizationToolClass() const {
207  return NullClass::null();
208  }
209 
210 protected:
211 
212  virtual QWidget* createPartControl();
213 
214  virtual QWidget* createVisualizationPart() = 0;
215 
216  virtual void resetView();
217  virtual void saveContentToFile();
218 
219 protected:
227  virtual void update(Duration dt) = 0;
228 
229 public:
230 
231  void setUpdateInterval(int interval);
232  int getUpdateInterval();
233 
234 public:
235 
237  VisualizationTool* getActiveTool() { return mActiveTool; }
238  void activateTool(VisualizationTool* tool);
239 
240 public:
241 
243  mOfferAuxiliaryVisualizations = on;
244  }
245 
246 protected:
247 
248  void startUpdateTimer();
249 
250  virtual void timerEvent(QTimerEvent*);
251  bool eventFilter(QObject *obj, QEvent *event);
252 
253  void keyPressEvent(QKeyEvent* event);
254  void keyReleaseEvent(QKeyEvent* event);
255 
256  void focusOutEvent(QFocusEvent* event);
257 
258 protected:
259 
260  std::string getChannelIDFromMimeData(const QMimeData* mimeData);
261  std::list<ClassProxy> getVisualizationsFor(const std::string& channelID);
262  void dragEnterEventImpl(QDragEnterEvent *event);
263  void dropEventImpl(QDropEvent* event, QWidget* widget);
264 
265 protected:
266  void destroyVisualizations();
267  void destroyTools();
268 
269 private:
270  void setToolbarArea(Qt::ToolBarArea area);
271  void addToolButton(VisualizationTool* tool, const QString& name, const QString& category, const QString& description);
272 
273  // Will enable this tool as the currently active one in its category
274  void switchToTool(VisualizationTool* tool, bool setChecked = false);
275 
276  // Returns the category of this tool, or the default category if none exists
277  QString getCategory(VisualizationTool* tool) {
278  return tool->getClass().getMetaInfo("Category").empty() ? DEFAULT_CATEGORY :
279  QString::fromLocal8Bit(tool->getClass().getMetaInfo("Category").c_str());
280  }
281 
282  void setWindowTitle( std::string const& title );
283  std::string getWindowTitle() const;
284 
285 private slots:
286  void onToolAction();
287  void onToolButton();
288  void onHideToolbar(bool);
289 
290 private:
291  VisualizationControlPage* mControl;
292  std::list<Visualization*> mVisualizations;
293 
294  std::vector<VisualizationTool*> mTools;
295  XMLDom mToolsState;
296 
297  // Convenience mapping from tool id (<category>_<toolname>) to its tool.
298  std::map<QString, VisualizationTool*> mIdToTool;
299 
300  // Stores the tool of each category that is currently in the top slot.
301  std::map<QString, VisualizationTool*> mCurrentTool;
302 
303  // Convenience mapping from category string to the corresponding tool button.
304  std::map<QString, QToolButton*> mCategoryToToolButton;
305 
306  // Currently active tool
307  VisualizationTool* mActiveTool;
308 
309  // When e.g. CTRL is pressed, this will store the old tool while the new one is active.
310  VisualizationTool* mDisplacedTool;
311 
312  // Manage our buttons, only one may be pressed at the same time
313  QButtonGroup* mButtonGroup;
314 
315 private:
316  QBasicTimer mUpdateTimer;
317  int mUpdateInterval;
318  Time mLastUpdateTime;
319 
320  QBoxLayout* mLayout;
321  QToolBar* mToolBar;
322  QAction* mHideToolBar;
323  QWidget* mVisualizationPart;
324  Qt::ToolBarArea mCurrentToolboxArea;
325 
326  const QString DEFAULT_CATEGORY;
327 
328  bool mOfferAuxiliaryVisualizations;
329 };
330 
332 
339 {
340  Q_OBJECT
342 
343 public:
344 
347 
348 public:
349 
350  template <typename Reflector>
351  void reflect(Reflector& r)
352  {
354  r.property("Fixed Frame", mFixedFrame, "The reference frame used to denote the world frame. Should not be moving (e.g. map frame, etc.)", "");
355  r.property("Camera Frame", mCameraFrame,
357  "The frame where all other frames are transformed to for displaying the data", TransformProperty());
358  }
359 
360 protected:
361 
362  virtual void setCameraFrame(const TransformProperty& frame) { mCameraFrame = frame; }
363 
364 protected:
365 
368 
369 private slots:
370 
371  void checkFrames();
372 
373 private:
374 
375  std::string mLastAskedFixedFrame; // the fixed frame value, we have asked to set the frame automatically
376  std::string mLastAskedCameraFrame; // the camera frame value, we have asked to set it automatically
377  QTimer* mFrameCheckTimer;
378 };
379 
381 
382 }
383 
384 #endif
void setOfferAuxiliaryVisualizations(bool on)
Definition: VisualizationView.h:242
static Class & null()
Returns the only single existing instance of a NullClass.
Provide marker class for marking an invalid "null" class.
Definition: VisualizationTool.h:59
Definition: XMLSerializer.h:121
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Abstract base class for all derived visualizations, namely Visualization3D and Visualization2D.
Definition: Visualization.h:90
An editor is typically used to edit or browse data or objects.
Definition: EditorPart.h:69
VisualizationTool * getActiveTool()
Returns the current active tool, or NULL of no tool is active.
Definition: VisualizationView.h:237
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:956
Time and Duration wrapper class.
Class object which supports some kind of class reflection.
Definition: Class.h:97
Gui export macro declaration.
Setter< T > setter(void(*f)(const T &))
Creates a Setter for global or static class methods taking the argument by const reference.
Definition: GetterSetter.h:443
TransformProperty mFixedFrame
Definition: VisualizationView.h:366
Use this class instead of a string property whenever your module has a transform frame as property...
Definition: TransformProperty.h:72
std::map< std::string, std::string > const & getMetaInfo() const
Return map with meta information.
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
Use this MACRO instead of MIRA_OBJECT to declare the class as abstract.
Definition: FactoryMacros.h:239
void reflect(Reflector &r)
Definition: VisualizationView.h:351
Abstract base class for 2D, 3D, text and plot visualization views (namely Visualization2DView and Vis...
Definition: VisualizationView.h:84
Abstract base class for 2D, 3D, text and plot visualization views (namely Visualization2DView and Vis...
Definition: VisualizationView.h:338
void reflect(Reflector &r)
Definition: VisualizationView.h:98
Declaration of VisualizationTool.
MIRA_GUI_VISUALIZATION_EXPORT std::list< ClassPtr > getVisualizationsFor(const std::string &channelID, const Class &visualizationType)
Use this class to represent time durations.
Definition: Time.h:104
Property that can be used whenever a unit has a transform frame as property.
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
virtual const Class & defaultVisualizationClass() const
If a default visualization class is provided, this class is used to instantiate a default visualizati...
Definition: VisualizationView.h:197
Getter< T > getter(T(*f)())
Creates a Getter for global or static class methods returning the result by value.
Definition: GetterSetter.h:136
void setUpdateInterval(int interval)
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:136
MIRA_GUI_VISUALIZATION_EXPORT std::string getChannelIDFromMimeData(const QMimeData *mimeData)
VisualizationControl page.
Definition: VisualizationControlPage.h:82
TransformProperty mCameraFrame
Definition: VisualizationView.h:367
Class const & getClass() const
call the virtual internalGetClass().
Definition: Object.h:159
#define MIRA_GUI_VIEWS_EXPORT
Definition: GuiViewsExports.h:61
virtual void setCameraFrame(const TransformProperty &frame)
Definition: VisualizationView.h:362
virtual const Class & supportedVisualizationToolClass() const
Derived visualization views may return the base class of their supported tools.
Definition: VisualizationView.h:206
Declaration of the EditorPart class.
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:313