ObjectLocalizationRequesterWidgetController.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * \package VisionX::gui-plugins::ObjectLocalizationRequesterWidgetController
19 * \author Mirko Waechter ( mirko dot waechter at kit dot edu )
20 * \date 2015
21 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <string>
28
30
34
35namespace armarx
36{
38 customToolbar(NULL)
39 {
40 widget.setupUi(getWidget());
41 connect(widget.btnRequest,
42 SIGNAL(clicked()),
43 this,
44 SLOT(on_btnRequest_clicked()),
45 Qt::UniqueConnection);
46 connect(widget.btnRelease,
47 SIGNAL(clicked()),
48 this,
49 SLOT(on_btnRelease_clicked()),
50 Qt::UniqueConnection);
51 enableMainWidget(false);
52 }
53
57
58 void
62
63 void
67
68 void
70 {
71 usingProxy("ObjectMemoryObserver");
72 usingProxy("PriorKnowledge");
73 }
74
75 void
77 {
78 getProxy(omo, "ObjectMemoryObserver");
79 getProxy(prior, "PriorKnowledge");
81 on_toolButtonRefresh_clicked();
83 }
84
85 void
90
91 void
93 {
94 auto entities = prior->getObjectClassesSegment()->getAllEntities();
95 QString oldSelection = widget.comboBoxAvailableObjectClasses->currentText();
96 widget.comboBoxAvailableObjectClasses->clear();
97 QStringList objects;
98 for (memoryx::EntityBasePtr base : entities)
99 {
100 memoryx::EntityPtr entity = memoryx::EntityPtr::dynamicCast(base);
101 auto var = entity->getAttributeValue("recognitionMethod");
102 if (var && !var->getString().empty() && var->getString() != "<none>")
103 {
104 objects << (QString::fromStdString(entity->getName()));
105 }
106 }
107 objects.sort();
108 widget.comboBoxAvailableObjectClasses->addItems(objects);
109 int index = widget.comboBoxAvailableObjectClasses->findText(oldSelection);
110 if (index > 0)
111 {
112 widget.comboBoxAvailableObjectClasses->setCurrentIndex(index);
113 }
114 }
115
116 void
118 {
119 ARMARX_INFO << "refreshing channels";
120 channels = omo->getAvailableChannels(false);
121
122 widget.comboBoxRequestedObjectClasses->clear();
123 for (auto& channel : channels)
124 {
125 if (channel.first.find("_query_") != std::string::npos)
126 {
127 widget.comboBoxRequestedObjectClasses->addItem(
128 QString::fromStdString(channel.first));
129 }
130 }
131 }
132
133 void
134 armarx::ObjectLocalizationRequesterWidgetController::on_toolButtonRefresh_clicked()
135 {
136
137 updateAvailableChannels();
138 updateAvailableObjects();
139 }
140
141 void
142 armarx::ObjectLocalizationRequesterWidgetController::on_btnRequest_clicked()
143 {
144 ARMARX_INFO << "requesting";
145 if (!widget.comboBoxAvailableObjectClasses->currentText().isEmpty())
146 {
147 omo->requestObjectClassRepeated(
148 widget.comboBoxAvailableObjectClasses->currentText().toStdString(),
149 widget.spinBoxInterval->value(),
150 widget.spinBoxPriority->value());
151 }
152 updateAvailableChannels();
153 }
154
155 void
156 armarx::ObjectLocalizationRequesterWidgetController::on_btnRelease_clicked()
157 {
158 ARMARX_INFO << "releasing";
159 auto channelName =
160 channels[widget.comboBoxRequestedObjectClasses->currentText().toStdString()].name;
161 if (!channelName.empty())
162 {
163 armarx::ChannelRefPtr ref = new armarx::ChannelRef(omo, channelName);
164 omo->releaseObjectClass(ref);
165 }
166 updateAvailableChannels();
167 }
168
169 QPointer<QWidget>
171 {
172 if (customToolbar)
173 {
174 if (parent != customToolbar->parent())
175 {
176 customToolbar->setParent(parent);
177 }
178
179 return customToolbar;
180 }
181
182 customToolbar = new QToolBar(parent);
183 customToolbar->setIconSize(QSize(16, 16));
184 customToolbar->addAction(QIcon("://icons/view-refresh-7.png"),
185 "Refresh",
186 this,
187 SLOT(on_toolButtonRefresh_clicked()));
188
189 return customToolbar;
190 }
191} // namespace armarx
uint8_t index
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
void enableMainWidgetAsync(bool enable)
This function enables/disables the main widget asynchronously (if called from a non qt thread).
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)
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.
Definition Entity.h:45