NJointControllerGuiPluginBase.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::NJointControllerGuiPluginUtility
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
26 
27 namespace armarx
28 {
29  template <class Derived, class Proxy>
31  {
32  public:
33  NJointControllerGuiPluginBase(const std::string& ctrlClass) :
34  detail::_NJointControllerGuiPluginBase::Base(), _ctrlClass{ctrlClass}
35  {
36  }
37 
39  {
41  }
42 
43  public:
44  QString
45  getWidgetName() const final override
46  {
47  return Derived::GetWidgetName();
48  }
49 
50  QIcon
51  getWidgetIcon() const final override
52  {
53  return Derived::GetWidgetIcon();
54  }
55 
56  QIcon
57  getWidgetCategoryIcon() const final override
58  {
59  return Derived::GetWidgetCategoryIcon();
60  }
61 
62  public:
63  void
64  createController() override
65  {
67  std::lock_guard g{_allMutex};
68  if (_controller || !getRobotUnit())
69  {
70  ARMARX_IMPORTANT << "No RobotUnit or controller already created";
71  return;
72  }
73  ARMARX_IMPORTANT << "Creating " << _ctrlClass << " '" << getControllerName() << "'";
74  _controller = Proxy::checkedCast(getRobotUnit()->createNJointController(
77  }
78 
79  void
80  activateController() override
81  {
83  std::lock_guard g{_allMutex};
84  if (!_controller)
85  {
86  ARMARX_IMPORTANT << "No controller";
87  return;
88  }
89  ARMARX_IMPORTANT << "activating controller";
90  _controller->activateController();
91  }
92 
93  void
95  {
97  std::lock_guard g{_allMutex};
98  if (!_controller)
99  {
100  ARMARX_IMPORTANT << "No controller";
101  return;
102  }
103  ARMARX_IMPORTANT << "deactivating controller";
104  _controller->deactivateController();
105  }
106 
107  void
108  deleteController() override
109  {
110  ARMARX_TRACE;
111  std::lock_guard g{_allMutex};
112  if (!_controller || !getRobotUnit())
113  {
114  ARMARX_IMPORTANT << "No controller";
115  return;
116  }
117  ARMARX_IMPORTANT << "deleting old controller '" << getControllerName() << "'";
118  try
119  {
120  _controller->deactivateAndDeleteController();
121  }
122  catch (...)
123  {
124  }
125  _controller = nullptr;
126  }
127 
128  protected:
129  Proxy _controller;
130  std::string _ctrlClass;
131  };
132 } // namespace armarx
NJointControllerGuiPluginBase.h
armarx::detail::_NJointControllerGuiPluginBase::Base::getControllerName
std::string getControllerName() const
Definition: NJointControllerGuiPluginBase.cpp:10
armarx::detail::_NJointControllerGuiPluginBase::Base::readFullCFG
virtual NJointControllerConfigPtr readFullCFG() const =0
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::NJointControllerGuiPluginBase::~NJointControllerGuiPluginBase
~NJointControllerGuiPluginBase()
Definition: NJointControllerGuiPluginBase.h:38
armarx::NJointControllerGuiPluginBase::deactivateController
void deactivateController() override
Definition: NJointControllerGuiPluginBase.h:94
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::NJointControllerGuiPluginBase::_ctrlClass
std::string _ctrlClass
Definition: NJointControllerGuiPluginBase.h:130
detail
Definition: OpenCVUtil.cpp:128
armarx::NJointControllerGuiPluginBase::getWidgetCategoryIcon
QIcon getWidgetCategoryIcon() const final override
Implement this function to supply an icon for the category.
Definition: NJointControllerGuiPluginBase.h:57
armarx::detail::_NJointControllerGuiPluginBase::Base::_allMutex
std::recursive_mutex _allMutex
Definition: NJointControllerGuiPluginBase.h:106
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::NJointControllerGuiPluginBase::getWidgetName
QString getWidgetName() const final override
Implement this function to specify the default name of your Widget.
Definition: NJointControllerGuiPluginBase.h:45
armarx::detail::_NJointControllerGuiPluginBase::Base::Base
Base()
Definition: NJointControllerGuiPluginBase.cpp:35
armarx::NJointControllerGuiPluginBase::activateController
void activateController() override
Definition: NJointControllerGuiPluginBase.h:80
armarx::detail::_NJointControllerGuiPluginBase::Base
Definition: NJointControllerGuiPluginBase.h:42
armarx::NJointControllerGuiPluginBase::createController
void createController() override
Definition: NJointControllerGuiPluginBase.h:64
armarx::NJointControllerGuiPluginBase::NJointControllerGuiPluginBase
NJointControllerGuiPluginBase(const std::string &ctrlClass)
Definition: NJointControllerGuiPluginBase.h:33
armarx::NJointControllerGuiPluginBase::_controller
Proxy _controller
Definition: NJointControllerGuiPluginBase.h:129
armarx::NJointControllerGuiPluginBase::deleteController
void deleteController() override
Definition: NJointControllerGuiPluginBase.h:108
armarx::NJointControllerGuiPluginBase::getWidgetIcon
QIcon getWidgetIcon() const final override
Implement this function to supply an icon for the menu.
Definition: NJointControllerGuiPluginBase.h:51
armarx::NJointControllerGuiPluginBase
Definition: NJointControllerGuiPluginBase.h:30
armarx::RobotUnitComponentPluginUser::getRobotUnit
RobotUnitInterfacePrx getRobotUnit() const
Definition: RobotUnitComponentPlugin.cpp:185
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27