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 <QLabel>
25 #include <QPushButton>
26 
28 
30 
31 #include "ConnectDialog.h"
32 
34 {
35 
37  _objectPoseStorageComponent(
38  std::make_unique<ObjectPoseStorageInterfacePrx>(objectPoseStorageComponent)),
39  _objectPoseClient(std::make_unique<objpose::ObjectPoseClient>(*_objectPoseStorageComponent))
40  {
41  ARMARX_CHECK_NOT_NULL(_objectPoseStorageComponent);
42  ARMARX_CHECK(_objectPoseClient->isConnected());
43  }
44 
45  // destructor has to be defined here, because the content of the unique pointers was forward declared
47 
50  {
51  ARMARX_CHECK_NOT_NULL(_objectPoseStorageComponent);
52  return *_objectPoseStorageComponent;
53  return nullptr;
54  }
55 
56  std::string
58  {
59  return getObjectPoseStorageComponent()->ice_getIdentity().name;
60  }
61 
64  {
65  return *_objectPoseClient;
66  }
67 
70  {
71  return _objectPoseClient->fetchObjectPosesAsMap();
72  }
73 
74  std::vector<ObjectInfo>
76  {
77  const auto& finder = _objectPoseClient->getObjectFinder();
78  return finder.findAllObjects();
79  }
80 
82  QWidget(parent), _component(component)
83  {
84  _statusLabel = new QLabel("Not connected", this);
85  _connectButton = new QPushButton("Connect ...", this);
86 
87  QBoxLayout* layout = new QVBoxLayout(this);
88  setLayout(layout);
89 
90  layout->addWidget(_statusLabel);
91  layout->addWidget(_connectButton);
92 
93 
94  connect(_connectButton, &QPushButton::pressed, this, &This::connectToObjectPoseComponent);
95 
96  connect(this,
98  this,
99  [this]()
100  {
101  QString name = QString::fromStdString(connection().getConnectedName());
102  _statusLabel->setText("Connected to '" + name + "'");
103  });
104  }
105 
106  bool
108  {
109  return _connection.has_value();
110  }
111 
114  {
115  return _connection.value();
116  }
117 
118  void
120  {
121  ConnectDialog<ObjectPoseStorageInterfacePrx> dialog("*ObjectMemory", _component, this);
122  switch (dialog.exec())
123  {
124  case QDialog::Accepted:
125  break;
126  case QDialog::Rejected:
127  return;
128  }
129 
130  auto objectPoseStorageComponent = dialog.getProxy();
131  if (objectPoseStorageComponent)
132  {
133  _connection.emplace(objectPoseStorageComponent);
134  emit connected();
135  }
136  }
137 
138 } // namespace armarx::navigation::qt_plugins::location_graph_editor
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection
Definition: ObjectPoseClientWidget.h:57
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::getObjectPoseMap
objpose::ObjectPoseMap getObjectPoseMap()
Definition: ObjectPoseClientWidget.cpp:69
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:75
ConnectDialog.h
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::getObjectClient
objpose::ObjectPoseClient & getObjectClient()
Definition: ObjectPoseClientWidget.cpp:63
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::connection
objectposes::Connection & connection()
Definition: ObjectPoseClientWidget.cpp:113
ObjectPoseClientWidget.h
armarx::objpose::ObjectPoseClient
Provides access to the armarx::objpose::ObjectPoseStorageInterface (aka the object memory).
Definition: ObjectPoseClient.h:18
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:57
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::ObjectPoseClientWidget
ObjectPoseClientWidget(ManagedIceObject &component, QWidget *parent=nullptr)
Definition: ObjectPoseClientWidget.cpp:81
ObjectPoseClient.h
armarx::navigation::qt_plugins::location_graph_editor::ConnectDialog
Definition: ConnectDialog.h:36
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:119
armarx::navigation::qt_plugins::location_graph_editor
Definition: GuiGraph.cpp:29
armarx::navigation::qt_plugins::location_graph_editor::ConnectDialog::getProxy
ProxyT getProxy()
Definition: ConnectDialog.h:63
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
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:49
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::isConnected
bool isConnected() const
Definition: ObjectPoseClientWidget.cpp:107
armarx::navigation::qt_plugins::location_graph_editor::objectposes::Connection::Connection
Connection(ObjectPoseStorageInterfacePrx objectPoseStorageComponent)
Definition: ObjectPoseClientWidget.cpp:36
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget::connected
void connected()
armarx::objpose::ObjectPoseMap
std::map< ObjectID, ObjectPose > ObjectPoseMap
Definition: forward_declarations.h:21