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 
30 namespace armarx
31 {
33  {
34  }
35 
36  void
38  {
39  getWidget()->show();
40  usingProxy("ConditionHandler");
41  }
42 
43  void
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 
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 
160 QPointer<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 }
armarx::ConditionViewerWidgetController::getWidget
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
Definition: ConditionViewerWidgetController.cpp:80
armarx::ConditionViewerWidgetController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: ConditionViewerWidgetController.cpp:37
armarx::ConditionViewerWidgetController::ConditionViewerWidgetController
ConditionViewerWidgetController()
Definition: ConditionViewerWidgetController.cpp:32
armarx::ConditionViewerWidgetController::removeConditions
void removeConditions()
Definition: ConditionViewerWidgetController.cpp:124
armarx::ConditionViewerWidgetController::getActiveConditions
ConditionRegistry getActiveConditions()
Definition: ConditionViewerWidgetController.cpp:91
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:161
ConditionViewerWidgetController.h
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::ConditionViewerWidget
Definition: ConditionViewerWidget.h:48
armarx::ConditionViewerWidgetController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ConditionViewerWidgetController.cpp:71
armarx::ConditionViewerWidgetController::refresh
void refresh(bool enableRefreshing)
Definition: ConditionViewerWidgetController.cpp:105
armarx::ConditionViewerWidgetController::handler
ConditionHandlerInterfacePrx handler
Definition: ConditionViewerWidgetController.h:93
armarx::ConditionViewerWidgetController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ConditionViewerWidgetController.cpp:44
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ConditionViewerWidgetController::getPastConditions
ConditionRegistry getPastConditions()
Definition: ConditionViewerWidgetController.cpp:98
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:202
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:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ConditionViewerWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ConditionViewerWidgetController.cpp:62