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 "ArmarXGuiInterface.h"
28 
31 
32 #include <type_traits>
33 
34 namespace 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  */
47  public QObject,
48  public ArmarXGuiInterface
49  {
50  Q_OBJECT
51  Q_INTERFACES(ArmarXGuiInterface)
52 
53  public:
54 
55  ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(HasGetWidgetName, GetWidgetName, QString(*)());
56 
57  template < typename ArmarXWidgetType>
59  {
60  static_assert(std::is_base_of_v<ArmarXWidgetController, ArmarXWidgetType>,
61  "The template parameter of addWidget, must be a class that derives from ArmarXWidget");
62 
63  try
64  {
65  ArmarXWidgetControllerPtr creatorInstance(new ArmarXWidgetType());
66 
67  if (__availableWidgets.find(creatorInstance->getWidgetName()) != __availableWidgets.end())
68  {
69  throw LocalException(QString("A widget with the name '"
70  + creatorInstance->getWidgetName()
71  + "' already exists in a loaded plugin!").toStdString());
72  }
73 
74  if (ArmarXComponentWidgetControllerPtr::dynamicCast(creatorInstance))
75  {
76  ArmarXWidgetInfoPtr widgetInfo(new ArmarXWidgetInfo(ArmarXComponentWidgetController::createInstance<ArmarXWidgetType>,
77  creatorInstance->getWidgetIcon(),
78  creatorInstance->getWidgetCategoryIcon()));
79  __availableWidgets[creatorInstance->getWidgetName()] = widgetInfo;
80  }
81  else
82  {
83  ArmarXWidgetInfoPtr widgetInfo(new ArmarXWidgetInfo(ArmarXWidgetController::createInstance<ArmarXWidgetType>,
84  creatorInstance->getWidgetIcon(),
85  creatorInstance->getWidgetCategoryIcon()));
86  __availableWidgets[creatorInstance->getWidgetName()] = widgetInfo;
87  }
88  }
89  catch (...)
90  {
91  ARMARX_ERROR_S << "Could not add widget!\n" << GetHandledExceptionString();
92  }
93 
94  // ARMARX_VERBOSE_S << "Added new widget named " + creatorInstance->getWidgetName().toStdString() << std::endl;
95  }
96 
97  template <typename ArmarXWidgetType>
99  {
100  static_assert(std::is_base_of_v<ArmarXWidgetController, ArmarXWidgetType>,
101  "The template parameter of addWidget, must be a class that derives from ArmarXWidget");
102 
103  try
104  {
105  if (__availableWidgets.find(ArmarXWidgetType::GetWidgetName()) != __availableWidgets.end())
106  {
107  throw LocalException(QString("A widget with the name '"
108  + ArmarXWidgetType::GetWidgetName()
109  + "' already exists in a loaded plugin!").toStdString());
110  }
111 
112  if (std::is_base_of_v<ArmarXComponentWidgetController, ArmarXWidgetType>)
113  {
114  ArmarXWidgetInfoPtr widgetInfo(new ArmarXWidgetInfo(ArmarXComponentWidgetController::createInstance<ArmarXWidgetType>,
115  ArmarXWidgetType::GetWidgetIcon(),
116  ArmarXWidgetType::GetWidgetCategoryIcon()));
117  __availableWidgets[ArmarXWidgetType::GetWidgetName()] = widgetInfo;
118  }
119  else
120  {
121  ArmarXWidgetInfoPtr widgetInfo(new ArmarXWidgetInfo(ArmarXWidgetController::createInstance<ArmarXWidgetType>,
122  ArmarXWidgetType::GetWidgetIcon(),
123  ArmarXWidgetType::GetWidgetCategoryIcon()));
124  __availableWidgets[ArmarXWidgetType::GetWidgetName()] = widgetInfo;
125  }
126  }
127  catch (...)
128  {
129  ARMARX_ERROR_S << "Could not add widget!\n" << GetHandledExceptionString();
130  }
131  }
132 
134  {
135  return __availableWidgets;
136  }
137 
138  private:
139  WidgetCreatorMap __availableWidgets;
140  };
141 }
142 
ArmarXWidgetInfo
The ArmarXWidgetInfo class.
Definition: ArmarXGuiInterface.h:42
armarx::ArmarXGuiPlugin::getProvidedWidgets
WidgetCreatorMap getProvidedWidgets() override
Definition: ArmarXGuiPlugin.h:133
ArmarXGuiInterface.h
LocalException.h
armarx::ArmarXGuiPlugin
Definition: ArmarXGuiPlugin.h:46
TemplateMetaProgramming.h
ArmarXWidgetInfoPtr
std::shared_ptr< ArmarXWidgetInfo > ArmarXWidgetInfoPtr
Definition: ArmarXGuiInterface.h:32
armarx::ArmarXGuiPlugin::addWidget
std::enable_if< !HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
Definition: ArmarXGuiPlugin.h:58
ArmarXGuiInterface
The main gui interface.
Definition: ArmarXGuiInterface.h:74
armarx::GetHandledExceptionString
std::string GetHandledExceptionString()
Definition: Exception.cpp:147
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
ArmarXComponentWidgetController.h
armarx::ArmarXGuiPlugin::ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK
ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(HasGetWidgetName, GetWidgetName, QString(*)())
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
WidgetCreatorMap
std::map< QString, ArmarXWidgetInfoPtr > WidgetCreatorMap
Definition: ArmarXGuiInterface.h:35
IceUtil::Handle< ArmarXWidgetController >
armarx::ArmarXGuiPlugin::addWidget
std::enable_if< HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
Definition: ArmarXGuiPlugin.h:98
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28