ArmarXGuiPlugin.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <type_traits>
27
30
32#include "ArmarXGuiInterface.h"
33
34namespace armarx
35{
36 /**
37 \defgroup ArmarXGuiBase ArmarXGui
38
39 The ArmarXGuiBase library is used to build custom ArmarXGui plugins.
40 See \ref ArmarXGui-Tutorials-CreateGuiPlugin andf \ref ArmarXGui-HowTos-Build-Gui-Plugin for detailed instructions on custom gui plugin creation.
41
42 \class ArmarXGuiPlugin
43
44 \ingroup ArmarXGuiBase
45 */
46 class ArmarXGuiPlugin : public QObject, public ArmarXGuiInterface
47 {
48 Q_OBJECT
49 Q_INTERFACES(ArmarXGuiInterface)
50
51 public:
52 ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(HasGetWidgetName, GetWidgetName, QString (*)());
53
54 template <typename ArmarXWidgetType>
55 typename std::enable_if<!HasGetWidgetName<ArmarXWidgetType>::value>::type
57 {
58 static_assert(std::is_base_of_v<ArmarXWidgetController, ArmarXWidgetType>,
59 "The template parameter of addWidget, must be a class that derives from "
60 "ArmarXWidget");
61
62 try
63 {
64 ArmarXWidgetControllerPtr creatorInstance(new ArmarXWidgetType());
65
66 if (__availableWidgets.find(creatorInstance->getWidgetName()) !=
67 __availableWidgets.end())
68 {
69 throw LocalException(QString("A widget with the name '" +
70 creatorInstance->getWidgetName() +
71 "' already exists in a loaded plugin!")
72 .toStdString());
73 }
74
75 if (ArmarXComponentWidgetControllerPtr::dynamicCast(creatorInstance))
76 {
79 creatorInstance->getWidgetIcon(),
80 creatorInstance->getWidgetCategoryIcon()));
81 __availableWidgets[creatorInstance->getWidgetName()] = widgetInfo;
82 }
83 else
84 {
87 creatorInstance->getWidgetIcon(),
88 creatorInstance->getWidgetCategoryIcon()));
89 __availableWidgets[creatorInstance->getWidgetName()] = widgetInfo;
90 }
91 }
92 catch (...)
93 {
94 ARMARX_ERROR_S << "Could not add widget!\n" << GetHandledExceptionString();
95 }
96
97 // ARMARX_VERBOSE_S << "Added new widget named " + creatorInstance->getWidgetName().toStdString() << std::endl;
98 }
99
100 template <typename ArmarXWidgetType>
101 typename std::enable_if<HasGetWidgetName<ArmarXWidgetType>::value>::type
103 {
104 static_assert(std::is_base_of_v<ArmarXWidgetController, ArmarXWidgetType>,
105 "The template parameter of addWidget, must be a class that derives from "
106 "ArmarXWidget");
107
108 try
109 {
110 if (__availableWidgets.find(ArmarXWidgetType::GetWidgetName()) !=
111 __availableWidgets.end())
112 {
113 throw LocalException(QString("A widget with the name '" +
114 ArmarXWidgetType::GetWidgetName() +
115 "' already exists in a loaded plugin!")
116 .toStdString());
117 }
118
119 if (std::is_base_of_v<ArmarXComponentWidgetController, ArmarXWidgetType>)
120 {
123 ArmarXWidgetType::GetWidgetIcon(),
124 ArmarXWidgetType::GetWidgetCategoryIcon()));
125 __availableWidgets[ArmarXWidgetType::GetWidgetName()] = widgetInfo;
126 }
127 else
128 {
131 ArmarXWidgetType::GetWidgetIcon(),
132 ArmarXWidgetType::GetWidgetCategoryIcon()));
133 __availableWidgets[ArmarXWidgetType::GetWidgetName()] = widgetInfo;
134 }
135 }
136 catch (...)
137 {
138 ARMARX_ERROR_S << "Could not add widget!\n" << GetHandledExceptionString();
139 }
140 }
141
144 {
145 return __availableWidgets;
146 }
147
148 private:
149 WidgetCreatorMap __availableWidgets;
150 };
151} // namespace armarx
std::shared_ptr< ArmarXWidgetInfo > ArmarXWidgetInfoPtr
std::map< QString, ArmarXWidgetInfoPtr > WidgetCreatorMap
The main gui interface.
The ArmarXWidgetInfo class.
WidgetCreatorMap getProvidedWidgets() override
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
std::enable_if< HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(HasGetWidgetName, GetWidgetName, QString(*)())
static ArmarXWidgetControllerPtr createInstance()
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:216
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::string GetHandledExceptionString()
IceUtil::Handle< ArmarXWidgetController > ArmarXWidgetControllerPtr