ObjectPoseClientWidget.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 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
23
24#include <memory>
25#include <string>
26#include <vector>
27
28#include <QLabel>
29#include <QPushButton>
30#include <qboxlayout.h>
31#include <qdialog.h>
32#include <qobject.h>
33#include <qobjectdefs.h>
34#include <qwidget.h>
35
38
42
43#include "ConnectDialog.h"
44
46{
47
49 _objectPoseStorageComponent(
50 std::make_unique<ObjectPoseStorageInterfacePrx>(objectPoseStorageComponent)),
51 _objectPoseClient(std::make_unique<objpose::ObjectPoseClient>(*_objectPoseStorageComponent))
52 {
53 ARMARX_CHECK_NOT_NULL(_objectPoseStorageComponent);
54 ARMARX_CHECK(_objectPoseClient->isConnected());
55 }
56
57 // destructor has to be defined here, because the content of the unique pointers was forward declared
59
62 {
63 ARMARX_CHECK_NOT_NULL(_objectPoseStorageComponent);
64 return *_objectPoseStorageComponent;
65 return nullptr;
66 }
67
68 std::string
70 {
71 return getObjectPoseStorageComponent()->ice_getIdentity().name;
72 }
73
76 {
77 return *_objectPoseClient;
78 }
79
82 {
83 return _objectPoseClient->fetchObjectPosesAsMap();
84 }
85
86 std::vector<ObjectInfo>
88 {
89 const auto& finder = _objectPoseClient->getObjectFinder();
90 return finder.findAllObjects();
91 }
92
94 QWidget(parent), _component(component)
95 {
96 _statusLabel = new QLabel("Not connected", this);
97 _connectButton = new QPushButton("Connect ...", this);
98
99 QBoxLayout* layout = new QVBoxLayout(this);
100 setLayout(layout);
101
102 layout->addWidget(_statusLabel);
103 layout->addWidget(_connectButton);
104
105
106 connect(_connectButton, &QPushButton::pressed, this, &This::connectToObjectPoseComponent);
107
108 connect(this,
110 this,
111 [this]()
112 {
113 QString name = QString::fromStdString(connection().getConnectedName());
114 _statusLabel->setText("Connected to '" + name + "'");
115 });
116 }
117
118 bool
120 {
121 return _connection.has_value();
122 }
123
126 {
127 return _connection.value();
128 }
129
130 void
132 {
133 ConnectDialog<ObjectPoseStorageInterfacePrx> dialog("*ObjectMemory", _component, this);
134 switch (dialog.exec())
135 {
136 case QDialog::Accepted:
137 break;
138 case QDialog::Rejected:
139 return;
140 }
141
142 auto objectPoseStorageComponent = dialog.getProxy();
143 if (objectPoseStorageComponent)
144 {
145 _connection.emplace(objectPoseStorageComponent);
146 emit connected();
147 }
148 }
149
150} // namespace armarx::navigation::qt_plugins::location_graph_editor
The ManagedIceObject is the base class for all ArmarX objects.
ObjectPoseClientWidget(ManagedIceObject &component, QWidget *parent=nullptr)
Provides access to the armarx::objpose::ObjectPoseStorageInterface (aka the object memory).
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
std::map< ObjectID, ObjectPose > ObjectPoseMap
::IceInternal::ProxyHandle<::IceProxy::armarx::objpose::ObjectPoseStorageInterface > ObjectPoseStorageInterfacePrx