ConditionViewerWidgetController.cpp
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 ArmarX::Gui::ConditionViewerWidgetController
17* @author Kai Welke ( welke at kit dot edu)
18* @date
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
24
25#include <QAction>
26#include <QToolBar>
27
29
30namespace armarx
31{
35
36 void
38 {
39 getWidget()->show();
40 usingProxy("ConditionHandler");
41 }
42
43 void
45 {
46
47 // get proxy of conditionhandler
49 if (handler)
50 {
51 std::unique_lock lock(dataMutex);
52 QMetaObject::invokeMethod(__widget, "onConnect");
53 }
54 refreshAction->setChecked(true);
55
56 qRegisterMetaType<Qt::Orientation>("Qt::Orientation");
57
58 ARMARX_INFO << "Starting ConditionViewerGuiPlugin" << flush;
59 }
60
61 void
63 {
64 ARMARX_INFO_S << "Stopping ConditionViewer";
65
66 refreshAction->setChecked(false);
67 __widget->onDisconnect();
68 }
69
70 void
72 {
73 if (updateTask)
74 {
75 updateTask->stop();
76 }
77 }
78
79 QPointer<QWidget>
81 {
82 if (!__widget)
83 {
84 __widget = new ConditionViewerWidget(this);
85 }
86
87 return qobject_cast<ConditionViewerWidget*>(__widget);
88 }
89
90 ConditionRegistry
92 {
93 std::unique_lock lock(dataMutex);
94 return currentConditions;
95 }
96
97 ConditionRegistry
99 {
100 std::unique_lock lock(dataMutex);
101 return pastConditions;
102 }
103
104 void
106 {
107 if (enableRefreshing)
108 {
110 this,
111 &ConditionViewerWidgetController::updateConditions,
112 2000,
113 false,
114 "ConditionsUpdateTask");
115 updateTask->start();
116 }
117 else if (updateTask)
118 {
119 updateTask->stop();
120 }
121 }
122
123 void
125 {
126 try
127 {
128 if (handler)
129 {
130 auto removeResult = handler->begin_removeAllConditions();
131 std::unique_lock lock(dataMutex);
132 handler->end_removeAllConditions(removeResult);
133 }
134 }
135 catch (Ice::NotRegisteredException&)
136 {
137 }
138 }
139
140 void
141 ConditionViewerWidgetController::updateConditions()
142 {
143 try
144 {
145 if (handler)
146 {
147 auto pastResult = handler->begin_getPastConditions();
148 auto activeResult = handler->begin_getActiveConditions();
149 std::unique_lock lock(dataMutex);
150 pastConditions = handler->end_getPastConditions(pastResult);
151 currentConditions = handler->end_getActiveConditions(activeResult);
152 }
153 }
154 catch (Ice::NotRegisteredException&)
155 {
156 }
157 }
158} // namespace armarx
159
160QPointer<QWidget>
162{
163 if (customToolbar)
164 {
165 if (parent != customToolbar->parent())
166 {
167 customToolbar->setParent(parent);
168 }
169
170 return qobject_cast<QToolBar*>(customToolbar);
171 }
172
173 customToolbar = new QToolBar(parent);
174 customToolbar->setIconSize(QSize(16, 16));
175 refreshAction =
176 customToolbar->addAction(QIcon(":/icons/view-refresh-7.png"), "Refresh conditions");
177 refreshAction->setCheckable(true);
178 connect(refreshAction, SIGNAL(toggled(bool)), this, SLOT(refresh(bool)));
179
180 QAction* removeAction =
181 customToolbar->addAction(QIcon(":/icons/dialog-close.ico"), "Remove conditions");
182 connect(removeAction, SIGNAL(triggered()), this, SLOT(removeConditions()));
183
184 return qobject_cast<QToolBar*>(customToolbar);
185}
void onInitComponent() override
Pure virtual hook for the subclass.
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
void onConnectComponent() override
Pure virtual hook for the subclass.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_INFO_S
Definition Logging.h:202
This file offers overloads of toIce() and fromIce() functions for STL container types.
const LogSender::manipulator flush
Definition LogSender.h:251