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 
30 #include <string>
31 
32 namespace armarx
33 {
35  customToolbar(NULL)
36  {
37  widget.setupUi(getWidget());
38  connect(widget.btnRequest, SIGNAL(clicked()), this, SLOT(on_btnRequest_clicked()), Qt::UniqueConnection);
39  connect(widget.btnRelease, SIGNAL(clicked()), this, SLOT(on_btnRelease_clicked()), Qt::UniqueConnection);
40  enableMainWidget(false);
41  }
42 
43 
45  {
46 
47  }
48 
49 
51  {
52 
53  }
54 
56  {
57 
58  }
59 
60 
62  {
63  usingProxy("ObjectMemoryObserver");
64  usingProxy("PriorKnowledge");
65  }
66 
67 
69  {
70  getProxy(omo, "ObjectMemoryObserver");
71  getProxy(prior, "PriorKnowledge");
73  on_toolButtonRefresh_clicked();
75 
76  }
77 
79  {
80  enableMainWidgetAsync(false);
81  }
82 
84  {
85  auto entities = prior->getObjectClassesSegment()->getAllEntities();
86  QString oldSelection = widget.comboBoxAvailableObjectClasses->currentText();
87  widget.comboBoxAvailableObjectClasses->clear();
88  QStringList objects;
89  for (memoryx::EntityBasePtr base : entities)
90  {
91  memoryx::EntityPtr entity = memoryx::EntityPtr::dynamicCast(base);
92  auto var = entity->getAttributeValue("recognitionMethod");
93  if (var && !var->getString().empty() && var->getString() != "<none>")
94  {
95  objects << (QString::fromStdString(entity->getName()));
96  }
97  }
98  objects.sort();
99  widget.comboBoxAvailableObjectClasses->addItems(objects);
100  int index = widget.comboBoxAvailableObjectClasses->findText(oldSelection);
101  if (index > 0)
102  {
103  widget.comboBoxAvailableObjectClasses->setCurrentIndex(index);
104  }
105  }
106 
108  {
109  ARMARX_INFO << "refreshing channels";
110  channels = omo->getAvailableChannels(false);
111 
112  widget.comboBoxRequestedObjectClasses->clear();
113  for (auto& channel : channels)
114  {
115  if (channel.first.find("_query_") != std::string::npos)
116  {
117  widget.comboBoxRequestedObjectClasses->addItem(QString::fromStdString(channel.first));
118  }
119  }
120  }
121 
122 
123 
124  void armarx::ObjectLocalizationRequesterWidgetController::on_toolButtonRefresh_clicked()
125  {
126 
127  updateAvailableChannels();
128  updateAvailableObjects();
129  }
130 
131  void armarx::ObjectLocalizationRequesterWidgetController::on_btnRequest_clicked()
132  {
133  ARMARX_INFO << "requesting";
134  if (!widget.comboBoxAvailableObjectClasses->currentText().isEmpty())
135  {
136  omo->requestObjectClassRepeated(widget.comboBoxAvailableObjectClasses->currentText().toStdString(),
137  widget.spinBoxInterval->value(), widget.spinBoxPriority->value());
138  }
139  updateAvailableChannels();
140  }
141 
142  void armarx::ObjectLocalizationRequesterWidgetController::on_btnRelease_clicked()
143  {
144  ARMARX_INFO << "releasing";
145  auto channelName = channels[widget.comboBoxRequestedObjectClasses->currentText().toStdString()].name;
146  if (!channelName.empty())
147  {
148  armarx::ChannelRefPtr ref = new armarx::ChannelRef(omo, channelName);
149  omo->releaseObjectClass(ref);
150  }
151  updateAvailableChannels();
152  }
153 
155  {
156  if (customToolbar)
157  {
158  if (parent != customToolbar->parent())
159  {
160  customToolbar->setParent(parent);
161  }
162 
163  return customToolbar;
164  }
165 
166  customToolbar = new QToolBar(parent);
167  customToolbar->setIconSize(QSize(16, 16));
168  customToolbar->addAction(QIcon("://icons/view-refresh-7.png"), "Refresh", this, SLOT(on_toolButtonRefresh_clicked()));
169 
170  return customToolbar;
171  }
172 }
armarx::ObjectLocalizationRequesterWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Definition: ObjectLocalizationRequesterWidgetController.cpp:55
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::ObjectLocalizationRequesterWidgetController::updateAvailableChannels
void updateAvailableChannels()
Definition: ObjectLocalizationRequesterWidgetController.cpp:107
armarx::ObjectLocalizationRequesterWidgetController::~ObjectLocalizationRequesterWidgetController
virtual ~ObjectLocalizationRequesterWidgetController()
Controller destructor.
Definition: ObjectLocalizationRequesterWidgetController.cpp:44
armarx::ObjectLocalizationRequesterWidgetController::onInitComponent
void onInitComponent() override
Definition: ObjectLocalizationRequesterWidgetController.cpp:61
armarx::ObjectLocalizationRequesterWidgetController::ObjectLocalizationRequesterWidgetController
ObjectLocalizationRequesterWidgetController()
Controller Constructor.
Definition: ObjectLocalizationRequesterWidgetController.cpp:34
armarx::ObjectLocalizationRequesterWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ObjectLocalizationRequesterWidgetController.cpp:78
armarx::ArmarXWidgetController::enableMainWidget
void enableMainWidget(bool enable)
Definition: ArmarXWidgetController.cpp:157
armarx::ObjectLocalizationRequesterWidgetController::updateAvailableObjects
void updateAvailableObjects()
Definition: ObjectLocalizationRequesterWidgetController.cpp:83
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::VariantType::ChannelRef
const VariantTypeId ChannelRef
Definition: ChannelRef.h:162
armarx::ObjectLocalizationRequesterWidgetController::onConnectComponent
void onConnectComponent() override
Definition: ObjectLocalizationRequesterWidgetController.cpp:68
MemoryXCoreObjectFactories.h
armarx::ObjectLocalizationRequesterWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Definition: ObjectLocalizationRequesterWidgetController.cpp:50
armarx::ObjectLocalizationRequesterWidgetController::getCustomTitlebarWidget
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
Definition: ObjectLocalizationRequesterWidgetController.cpp:154
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ArmarXWidgetController::enableMainWidgetAsync
void enableMainWidgetAsync(bool enable)
This function enables/disables the main widget asynchronously (if called from a non qt thread).
Definition: ArmarXWidgetController.cpp:174
Entity.h
MemoryXTypesObjectFactories.h
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
ObjectLocalizationRequesterWidgetController.h
armarx::ManagedIceObject::getProxy
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Definition: ManagedIceObject.cpp:393
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
ChannelRef.h