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 
25 
26 #include <QAction>
27 #include <QToolBar>
28 
29 namespace armarx
30 {
32  customToolbar(NULL)
33  {
34 
35  }
36 
38  {
39  getWidget()->show();
40  usingProxy("ConditionHandler");
41 
42  }
43 
45  {
46 
47  // get proxy of conditionhandler
48  handler = getProxy<ConditionHandlerInterfacePrx>("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 
62  {
63  ARMARX_INFO_S << "Stopping ConditionViewer";
64 
65  refreshAction->setChecked(false);
66  __widget->onDisconnect();
67  }
68 
70  {
71  if (updateTask)
72  {
73  updateTask->stop();
74  }
75  }
76 
78  {
79  if (!__widget)
80  {
81  __widget = new ConditionViewerWidget(this);
82  }
83 
84  return qobject_cast<ConditionViewerWidget*>(__widget);
85  }
86 
88  {
89  std::unique_lock lock(dataMutex);
90  return currentConditions;
91  }
92 
94  {
95  std::unique_lock lock(dataMutex);
96  return pastConditions;
97  }
98 
99  void ConditionViewerWidgetController::refresh(bool enableRefreshing)
100  {
101  if (enableRefreshing)
102  {
103  updateTask = new armarx::PeriodicTask<ConditionViewerWidgetController>(this, &ConditionViewerWidgetController::updateConditions, 2000, false, "ConditionsUpdateTask");
104  updateTask->start();
105  }
106  else if (updateTask)
107  {
108  updateTask->stop();
109  }
110  }
111 
113  {
114  try
115  {
116  if (handler)
117  {
118  auto removeResult = handler->begin_removeAllConditions();
119  std::unique_lock lock(dataMutex);
120  handler->end_removeAllConditions(removeResult);
121  }
122  }
123  catch (Ice::NotRegisteredException&)
124  {
125 
126  }
127  }
128 
129  void ConditionViewerWidgetController::updateConditions()
130  {
131  try
132  {
133  if (handler)
134  {
135  auto pastResult = handler->begin_getPastConditions();
136  auto activeResult = handler->begin_getActiveConditions();
137  std::unique_lock lock(dataMutex);
138  pastConditions = handler->end_getPastConditions(pastResult);
139  currentConditions = handler->end_getActiveConditions(activeResult);
140  }
141  }
142  catch (Ice::NotRegisteredException&)
143  {
144 
145  }
146 
147  }
148 }
149 
150 
152 {
153  if (customToolbar)
154  {
155  if (parent != customToolbar->parent())
156  {
157  customToolbar->setParent(parent);
158  }
159 
160  return qobject_cast<QToolBar*>(customToolbar);
161  }
162 
163  customToolbar = new QToolBar(parent);
164  customToolbar->setIconSize(QSize(16, 16));
165  refreshAction = customToolbar->addAction(QIcon(":/icons/view-refresh-7.png"), "Refresh conditions");
166  refreshAction->setCheckable(true);
167  connect(refreshAction, SIGNAL(toggled(bool)), this, SLOT(refresh(bool)));
168 
169  QAction* removeAction = customToolbar->addAction(QIcon(":/icons/dialog-close.ico"), "Remove conditions");
170  connect(removeAction, SIGNAL(triggered()), this, SLOT(removeConditions()));
171 
172  return qobject_cast<QToolBar*>(customToolbar);
173 }
armarx::ConditionViewerWidgetController::getWidget
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
Definition: ConditionViewerWidgetController.cpp:77
armarx::ConditionViewerWidgetController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: ConditionViewerWidgetController.cpp:37
armarx::ConditionViewerWidgetController::ConditionViewerWidgetController
ConditionViewerWidgetController()
Definition: ConditionViewerWidgetController.cpp:31
armarx::ConditionViewerWidgetController::removeConditions
void removeConditions()
Definition: ConditionViewerWidgetController.cpp:112
armarx::ConditionViewerWidgetController::getActiveConditions
ConditionRegistry getActiveConditions()
Definition: ConditionViewerWidgetController.cpp:87
ObserverObjectFactories.h
armarx::ConditionViewerWidgetController::getCustomTitlebarWidget
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
Definition: ConditionViewerWidgetController.cpp:151
ConditionViewerWidgetController.h
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::ConditionViewerWidget
Definition: ConditionViewerWidget.h:49
armarx::ConditionViewerWidgetController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ConditionViewerWidgetController.cpp:69
armarx::ConditionViewerWidgetController::refresh
void refresh(bool enableRefreshing)
Definition: ConditionViewerWidgetController.cpp:99
armarx::ConditionViewerWidgetController::handler
ConditionHandlerInterfacePrx handler
Definition: ConditionViewerWidgetController.h:82
armarx::ConditionViewerWidgetController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ConditionViewerWidgetController.cpp:44
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ConditionViewerWidgetController::getPastConditions
ConditionRegistry getPastConditions()
Definition: ConditionViewerWidgetController.cpp:93
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ConditionViewerWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ConditionViewerWidgetController.cpp:61