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 
22 #include "ObjectPoseClientWidget.h"
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
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection
Definition: ObjectPoseClientWidget.h:63
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::getObjectPoseMap
objpose::ObjectPoseMap getObjectPoseMap()
Definition: ObjectPoseClientWidget.cpp:81
armarx::ProxyType::component
@ component
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::getObjectInfo
std::vector< ObjectInfo > getObjectInfo()
Definition: ObjectPoseClientWidget.cpp:87
ConnectDialog.h
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::getObjectClient
objpose::ObjectPoseClient & getObjectClient()
Definition: ObjectPoseClientWidget.cpp:75
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::connection
objectposes::Connection & connection()
Definition: ObjectPoseClientWidget.cpp:125
ObjectPoseClientWidget.h
armarx::objpose::ObjectPoseClient
Provides access to the armarx::objpose::ObjectPoseStorageInterface (aka the object memory).
Definition: ObjectPoseClient.h:17
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
ManagedIceObject.h
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::getConnectedName
std::string getConnectedName() const
Definition: ObjectPoseClientWidget.cpp:69
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::ObjectPoseClientWidget
ObjectPoseClientWidget(ManagedIceObject &component, QWidget *parent=nullptr)
Definition: ObjectPoseClientWidget.cpp:93
ObjectPoseClient.h
armarx::navigation::qt_plugins::location_graph_editor::ConnectDialog
Definition: ConnectDialog.h:40
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::~Connection
~Connection()
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::connectToObjectPoseComponent
void connectToObjectPoseComponent()
Definition: ObjectPoseClientWidget.cpp:131
armarx::navigation::qt_plugins::location_graph_editor
Definition: GuiGraph.cpp:34
ObjectInfo.h
ExpressionException.h
armarx::navigation::qt_plugins::location_graph_editor::ConnectDialog::getProxy
ProxyT getProxy()
Definition: ConnectDialog.h:66
forward_declarations.h
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:162
std
Definition: Application.h:66
IceInternal::ProxyHandle<::IceProxy::armarx::objpose::ObjectPoseStorageInterface >
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::getObjectPoseStorageComponent
ObjectPoseStorageInterfacePrx getObjectPoseStorageComponent() const
Definition: ObjectPoseClientWidget.cpp:61
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::isConnected
bool isConnected() const
Definition: ObjectPoseClientWidget.cpp:119
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::Connection
Connection(ObjectPoseStorageInterfacePrx objectPoseStorageComponent)
Definition: ObjectPoseClientWidget.cpp:48
httplib::detail::make_unique
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Definition: httplib.h:333
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::connected
void connected()
armarx::objpose::ObjectPoseMap
std::map< ObjectID, ObjectPose > ObjectPoseMap
Definition: forward_declarations.h:21