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  }
38  {
40  }
41 
42  public:
43  QString
44  getWidgetName() const final override
45  {
46  return Derived::GetWidgetName();
47  }
48  QIcon
49  getWidgetIcon() const final override
50  {
51  return Derived::GetWidgetIcon();
52  }
53  QIcon
54  getWidgetCategoryIcon() const final override
55  {
56  return Derived::GetWidgetCategoryIcon();
57  }
58 
59  public:
60  void
61  createController() override
62  {
64  std::lock_guard g{_allMutex};
65  if (_controller || !getRobotUnit())
66  {
67  ARMARX_IMPORTANT << "No RobotUnit or controller already created";
68  return;
69  }
70  ARMARX_IMPORTANT << "Creating " << _ctrlClass << " '" << getControllerName() << "'";
71  _controller = Proxy::checkedCast(getRobotUnit()->createNJointController(
74  }
75  void
76  activateController() override
77  {
79  std::lock_guard g{_allMutex};
80  if (!_controller)
81  {
82  ARMARX_IMPORTANT << "No controller";
83  return;
84  }
85  ARMARX_IMPORTANT << "activating controller";
86  _controller->activateController();
87  }
88  void
90  {
92  std::lock_guard g{_allMutex};
93  if (!_controller)
94  {
95  ARMARX_IMPORTANT << "No controller";
96  return;
97  }
98  ARMARX_IMPORTANT << "deactivating controller";
99  _controller->deactivateController();
100  }
101  void
102  deleteController() override
103  {
104  ARMARX_TRACE;
105  std::lock_guard g{_allMutex};
106  if (!_controller || !getRobotUnit())
107  {
108  ARMARX_IMPORTANT << "No controller";
109  return;
110  }
111  ARMARX_IMPORTANT << "deleting old controller '" << getControllerName() << "'";
112  try
113  {
114  _controller->deactivateAndDeleteController();
115  }
116  catch (...)
117  {
118  }
119  _controller = nullptr;
120  }
121 
122  protected:
123  Proxy _controller;
124  std::string _ctrlClass;
125  };
126 } // 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:183
armarx::NJointControllerGuiPluginBase::~NJointControllerGuiPluginBase
~NJointControllerGuiPluginBase()
Definition: NJointControllerGuiPluginBase.h:37
armarx::NJointControllerGuiPluginBase::deactivateController
void deactivateController() override
Definition: NJointControllerGuiPluginBase.h:89
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:124
detail
Definition: OpenCVUtil.cpp:127
armarx::NJointControllerGuiPluginBase::getWidgetCategoryIcon
QIcon getWidgetCategoryIcon() const final override
Implement this function to supply an icon for the category.
Definition: NJointControllerGuiPluginBase.h:54
armarx::detail::_NJointControllerGuiPluginBase::Base::_allMutex
std::recursive_mutex _allMutex
Definition: NJointControllerGuiPluginBase.h:104
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::NJointControllerGuiPluginBase::getWidgetName
QString getWidgetName() const final override
Implement this function to specify the default name of your Widget.
Definition: NJointControllerGuiPluginBase.h:44
armarx::detail::_NJointControllerGuiPluginBase::Base::Base
Base()
Definition: NJointControllerGuiPluginBase.cpp:32
armarx::NJointControllerGuiPluginBase::activateController
void activateController() override
Definition: NJointControllerGuiPluginBase.h:76
armarx::detail::_NJointControllerGuiPluginBase::Base
Definition: NJointControllerGuiPluginBase.h:43
armarx::NJointControllerGuiPluginBase::createController
void createController() override
Definition: NJointControllerGuiPluginBase.h:61
armarx::NJointControllerGuiPluginBase::NJointControllerGuiPluginBase
NJointControllerGuiPluginBase(const std::string &ctrlClass)
Definition: NJointControllerGuiPluginBase.h:33
armarx::NJointControllerGuiPluginBase::_controller
Proxy _controller
Definition: NJointControllerGuiPluginBase.h:123
armarx::NJointControllerGuiPluginBase::deleteController
void deleteController() override
Definition: NJointControllerGuiPluginBase.h:102
armarx::NJointControllerGuiPluginBase::getWidgetIcon
QIcon getWidgetIcon() const final override
Implement this function to supply an icon for the menu.
Definition: NJointControllerGuiPluginBase.h:49
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:28