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 <fw/TransformProperty.h>
60 
61 class QMimeData;
62 class QDragEnterEvent;
63 class QDropEvent;
64 class QFocusEvent;
65 class QBoxLayout;
66 class QToolBar;
67 class QToolButton;
68 class QButtonGroup;
69 
70 namespace mira {
71 
73 
74 class Visualization;
75 class VisualizationTool;
76 class VisualizationControlPage;
77 
84 {
85  Q_OBJECT
87 
88 public:
89 
91  virtual ~VisualizationView();
92 
93 
94 public:
95 
96  template <typename Reflector>
97  void reflect(Reflector& r)
98  {
100  r.member("Visualizations", mVisualizations, "The assigned visualizations");
101 
102  r.property("Update",
103  mUpdateInterval,
105  "Update interval in ms",
106  40);
107 
108  r.property("WindowTitle",
109  getter(&VisualizationView::getWindowTitle,this),
110  setter(&VisualizationView::setWindowTitle,this),
111  "Title of window",
112  getClass().getMetaInfo("Name"));
113 
114  r.member("HideTools",
115  getter<bool>(boost::bind(actionGetter, mHideToolBar)),
116  setter<bool>(boost::bind(actionSetter, mHideToolBar, _1)),
117  "Hide tool bar with tools", false);
118 
119  r.property("Tools", mTools, "The used tools");
120  }
122  void reflect(XMLDeserializer& r);
124  void reflect(XMLSerializer& r);
125 
126 public:
127 
133  virtual void addVisualization(Visualization* vis);
134 
140  virtual void removeVisualization(Visualization* vis);
141 
148  virtual void moveUpVisualization(Visualization* vis);
149 
156  virtual void moveDownVisualization(Visualization* vis);
157 
158  const std::list<Visualization*>& getVisualizations() const;
159 
165  virtual void addTool(VisualizationTool* tool);
166 
167  const std::vector<VisualizationTool*>& getTools() const;
168 
169 public:
170 
176 
177 public:
178 
179  virtual Object* getAdapter(const Class& adapter);
180 
181 public:
182 
187  virtual const Class& supportedVisualizationClass() const = 0;
188 
196  virtual const Class& defaultVisualizationClass() const {
197  return NullClass::null();
198  }
199 
205  virtual const Class& supportedVisualizationToolClass() const {
206  return NullClass::null();
207  }
208 
209 protected:
210 
211  virtual QWidget* createPartControl();
212 
213  virtual QWidget* createVisualizationPart() = 0;
214 
215  virtual void resetView();
216  virtual void saveContentToFile();
217 
218 protected:
226  virtual void update(Duration dt) = 0;
227 
228 public:
229 
230  void setUpdateInterval(int interval);
231  int getUpdateInterval();
232 
233 public:
234 
236  VisualizationTool* getActiveTool() { return mActiveTool; }
237  void activateTool(VisualizationTool* tool);
238 
239 public:
240 
242  mOfferAuxiliaryVisualizations = on;
243  }
244 
245 protected:
246 
247  void startUpdateTimer();
248 
249  virtual void timerEvent(QTimerEvent*);
250  bool eventFilter(QObject *obj, QEvent *event);
251 
252  void keyPressEvent(QKeyEvent* event);
253  void keyReleaseEvent(QKeyEvent* event);
254 
255  void focusOutEvent(QFocusEvent* event);
256 
257 protected:
258 
259  std::string getChannelIDFromMimeData(const QMimeData* mimeData);
260  std::list<ClassProxy> getVisualizationsFor(const std::string& channelID);
261  void dragEnterEventImpl(QDragEnterEvent *event);
262  void dropEventImpl(QDropEvent* event, QWidget* widget);
263 
264 protected:
265  void destroyVisualizations();
266  void destroyTools();
267 
268 private:
269  void setToolbarArea(Qt::ToolBarArea area);
270  void addToolButton(VisualizationTool* tool, const QString& name, const QString& category, const QString& description);
271 
272  // Will enable this tool as the currently active one in its category
273  void switchToTool(VisualizationTool* tool, bool setChecked = false);
274 
275  // Returns the category of this tool, or the default category if none exists
276  QString getCategory(VisualizationTool* tool) {
277  return tool->getClass().getMetaInfo("Category").empty() ? DEFAULT_CATEGORY :
278  QString::fromLocal8Bit(tool->getClass().getMetaInfo("Category").c_str());
279  }
280 
281  void setWindowTitle( std::string const& title );
282  std::string getWindowTitle() const;
283 
284 private slots:
285  void onToolAction();
286  void onToolButton();
287  void onHideToolbar(bool);
288 
289 private:
290  VisualizationControlPage* mControl;
291  std::list<Visualization*> mVisualizations;
292 
293  std::vector<VisualizationTool*> mTools;
294  XMLDom mToolsState;
295 
296  // Convenience mapping from tool id (<category>_<toolname>) to its tool.
297  std::map<QString, VisualizationTool*> mIdToTool;
298 
299  // Stores the tool of each category that is currently in the top slot.
300  std::map<QString, VisualizationTool*> mCurrentTool;
301 
302  // Convenience mapping from category string to the corresponding tool button.
303  std::map<QString, QToolButton*> mCategoryToToolButton;
304 
305  // Currently active tool
306  VisualizationTool* mActiveTool;
307 
308  // When e.g. CTRL is pressed, this will store the old tool while the new one is active.
309  VisualizationTool* mDisplacedTool;
310 
311  // Manage our buttons, only one may be pressed at the same time
312  QButtonGroup* mButtonGroup;
313 
314 private:
315  QBasicTimer mUpdateTimer;
316  int mUpdateInterval;
317  Time mLastUpdateTime;
318 
319  QBoxLayout* mLayout;
320  QToolBar* mToolBar;
321  QAction* mHideToolBar;
322  QWidget* mVisualizationPart;
323  Qt::ToolBarArea mCurrentToolboxArea;
324 
325  const QString DEFAULT_CATEGORY;
326 
327  bool mOfferAuxiliaryVisualizations;
328 };
329 
331 
338 {
339  Q_OBJECT
341 
342 public:
343 
346 
347 public:
348 
349  template <typename Reflector>
350  void reflect(Reflector& r)
351  {
353  r.property("Fixed Frame", mFixedFrame, "The reference frame used to denote the world frame. Should not be moving (e.g. map frame, etc.)", "");
354  r.property("Camera Frame", mCameraFrame,
356  "The frame where all other frames are transformed to for displaying the data", TransformProperty());
357  }
358 
359 protected:
360 
361  virtual void setCameraFrame(const TransformProperty& frame) { mCameraFrame = frame; }
362 
363 protected:
364 
367 
368 private slots:
369 
370  void checkFrames();
371 
372 private:
373 
374  std::string mLastAskedFixedFrame; // the fixed frame value, we have asked to set the frame automatically
375  std::string mLastAskedCameraFrame; // the camera frame value, we have asked to set it automatically
376  QTimer* mFrameCheckTimer;
377 };
378 
380 
381 }
382 
383 #endif
virtual const Class & supportedVisualizationClass() const =0
Derived visualization views must return the base class of their supported visualizations.
void setOfferAuxiliaryVisualizations(bool on)
Definition: VisualizationView.h:241
void focusOutEvent(QFocusEvent *event)
static Class & null()
Returns the only single existing instance of a NullClass.
virtual QWidget * createVisualizationPart()=0
Provide marker class for marking an invalid "null" class.
virtual void addVisualization(Visualization *vis)
Adds an existing visualization to this view.
void activateTool(VisualizationTool *tool)
virtual void resetView()
Definition: VisualizationTool.h:59
Definition: XMLSerializer.h:122
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:88
std::list< ClassProxy > getVisualizationsFor(const std::string &channelID)
An editor is typically used to edit or browse data or objects.
Definition: EditorPart.h:69
virtual void saveContentToFile()
VisualizationTool * getActiveTool()
Returns the current active tool, or NULL of no tool is active.
Definition: VisualizationView.h:236
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
Time and Duration wrapper class.
Class object which supports some kind of class reflection.
Definition: Class.h:97
QWidget * widget() const
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:365
bool eventFilter(QObject *obj, QEvent *event)
virtual void moveUpVisualization(Visualization *vis)
Change order of visualizations in the view, move the specified visualization up.
Use this class instead of a string property whenever your module has a transform frame as property...
Definition: TransformProperty.h:70
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:235
void reflect(Reflector &r)
Definition: VisualizationView.h:350
Abstract base class for 2D, 3D, text and plot visualization views (namely Visualization2DView and Vis...
Definition: VisualizationView.h:83
Abstract base class for 2D, 3D, text and plot visualization views (namely Visualization2DView and Vis...
Definition: VisualizationView.h:337
void reflect(Reflector &r)
Definition: VisualizationView.h:97
Declaration of VisualizationTool.
VisualizationControlPage * getControl()
Returns pointer to VisualizationControlPage (or NULL, if no such page was created yet...
void keyPressEvent(QKeyEvent *event)
virtual void addTool(VisualizationTool *tool)
Adds an existing tool to this view.
void dropEventImpl(QDropEvent *event, QWidget *widget)
void dragEnterEventImpl(QDragEnterEvent *event)
Use this class to represent time durations.
Definition: Time.h:106
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:196
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)
const std::vector< VisualizationTool * > & getTools() const
VisualizationControl page.
Definition: VisualizationControlPage.h:81
void keyReleaseEvent(QKeyEvent *event)
TransformProperty mCameraFrame
Definition: VisualizationView.h:366
virtual void update(Duration dt)=0
Is called by this class within the update timer event to update the view.
Class const & getClass() const
call the virtual internalGetClass().
Definition: Object.h:159
const std::list< Visualization * > & getVisualizations() const
virtual void moveDownVisualization(Visualization *vis)
Change order of visualizations in the view, move the specified visualization down.
virtual void timerEvent(QTimerEvent *)
virtual Object * getAdapter(const Class &adapter)
Returns an object which is an instance of the given class associated with this object.
std::string getChannelIDFromMimeData(const QMimeData *mimeData)
virtual void setCameraFrame(const TransformProperty &frame)
Definition: VisualizationView.h:361
virtual QWidget * createPartControl()
Must be overloaded in subclasses to create the actual widget for this EditorPart. ...
virtual const Class & supportedVisualizationToolClass() const
Derived visualization views may return the base class of their supported tools.
Definition: VisualizationView.h:205
Declaration of the EditorPart class.
virtual void removeVisualization(Visualization *vis)
Remove the specified visualization from this view.
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:314