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
27namespace 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
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
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
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
109 {
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:
130 std::string _ctrlClass;
131 };
132} // namespace armarx
QString getWidgetName() const final override
Implement this function to specify the default name of your Widget.
QIcon getWidgetIcon() const final override
Implement this function to supply an icon for the menu.
QIcon getWidgetCategoryIcon() const final override
Implement this function to supply an icon for the category.
NJointControllerGuiPluginBase(const std::string &ctrlClass)
virtual NJointControllerConfigPtr readFullCFG() const =0
#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...
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
This file offers overloads of toIce() and fromIce() functions for STL container types.
#define ARMARX_TRACE
Definition trace.h:77