ViewFactory.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
18#ifndef _VIEWERFACTORY_HH_
19#define _VIEWERFACTORY_HH_
20
21#include <string>
22#include <map>
23#include <vector>
24
26#include "gazebo/util/system.hh"
27
28class QWidget;
29
30namespace gazebo
31{
32 namespace gui
33 {
36 typedef TopicView* (*ViewFactoryFn) (QWidget *_parent);
37
43 class GZ_GUI_VISIBLE ViewFactory
44 {
46 public: static void RegisterAll();
47
52 public: static void RegisterView(const std::string &_className,
53 ViewFactoryFn _factoryfn);
54
60 public: static TopicView *NewView(const std::string &_msgType,
61 const std::string &_topicName,
62 QWidget *_parent = NULL);
63
66 public: static void GetViewTypes(std::vector<std::string> &_types);
67
69 private: static std::map<std::string, ViewFactoryFn> viewMap;
70 };
71
72
78 #define GZ_REGISTER_STATIC_VIEWER(msgtype, classname) \
79 GZ_GUI_VISIBLE TopicView *New##classname(QWidget *_parent) \
80 { \
81 return new gazebo::gui::classname(_parent); \
82 } \
83 GZ_GUI_VISIBLE \
84 void Register##classname() \
85 {\
86 ViewFactory::RegisterView(msgtype, New##classname);\
87 }
89 }
90}
91
92#endif
#define NULL
Definition CommonTypes.hh:31
default namespace for gazebo
gui
Definition KeyEventHandler.hh:29
Base class for widgets that display topic data.
Definition TopicView.hh:79
The view factory creates GUI widgets to visualize data on a topic.
Definition ViewFactory.hh:44
static void RegisterView(const std::string &_className, ViewFactoryFn _factoryfn)
Register a view class (called by view registration function).
static void GetViewTypes(std::vector< std::string > &_types)
Get all the view types.
static TopicView * NewView(const std::string &_msgType, const std::string &_topicName, QWidget *_parent=NULL)
Create a new instance of a view.
static void RegisterAll()
Register all known views.
TopicView *(* ViewFactoryFn)(QWidget *_parent)
Definition ViewFactory.hh:36
Forward declarations for the common classes.
Definition Animation.hh:27