ArVizDrawerGuiWidgetController.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  * \package RobotAPI::gui-plugins::ArVizDrawerGuiWidgetController
17  * \author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * \date 2020
19  * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include <string>
24 
27 #include "Elements/RobotWidget.h"
28 #include "Elements/PoseWidget.h"
29 
30 namespace armarx
31 {
33  {
34  _ui.setupUi(getWidget());
35  connect(_ui.pushButtonElementAdd, &QPushButton::clicked, this,
36  &ArVizDrawerGuiWidgetController::on_pushButtonElementAdd_clicked);
37  //setup factories
38  {
39  _factory["Robot"] = [] { return new RobotWidget; };
40  _factory["Pose" ] = [] { return new PoseWidget ; };
41 
42  for (const auto& [key, _] : _factory)
43  {
44  _ui.comboBoxElement->addItem(QString::fromStdString(key));
45  }
46  }
47  startTimer(20);
48  }
49 
51  {
52  _connected = true;
53  }
55  {
56  _connected = false;
57  }
58 
59  void ArVizDrawerGuiWidgetController::on_pushButtonElementAdd_clicked()
60  {
61  const auto name = _ui.comboBoxElement->currentText().toStdString();
62  auto* ptr = _factory.at(name)();
63  _ui.verticalLayoutElements->addWidget(ptr);
64  _elements.emplace(ptr);
65  }
66 
68  {
69  if (!_connected)
70  {
71  return;
72  }
73  auto layer = getArvizClient().layer("elements");
74  for (auto* elem : _elements)
75  {
76  if (elem->toDelete())
77  {
78  _ui.verticalLayoutElements->removeWidget(elem);
79  elem->deleteLater();
80  _elements.erase(elem);
81  }
82  else
83  {
84  elem->addTo(layer);
85  }
86  }
87  getArvizClient().commit({layer});
88  }
89 }
90 
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:80
armarx::ArVizComponentPluginUser::getArvizClient
armarx::viz::Client & getArvizClient()
Definition: ArVizComponentPlugin.h:45
ElementWidgetBase.h
armarx::RemoteGui::Client::PoseWidget
Definition: EigenWidgets.h:32
armarx::ArVizDrawerGuiWidgetController::ArVizDrawerGuiWidgetController
ArVizDrawerGuiWidgetController()
Definition: ArVizDrawerGuiWidgetController.cpp:32
armarx::ArVizDrawerGuiWidgetController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ArVizDrawerGuiWidgetController.cpp:50
ArVizDrawerGuiWidgetController.h
armarx::RobotWidget
Definition: RobotWidget.h:9
armarx::ArVizDrawerGuiWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ArVizDrawerGuiWidgetController.cpp:54
RobotWidget.h
PoseWidget.h
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:73
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ArVizDrawerGuiWidgetController::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: ArVizDrawerGuiWidgetController.cpp:67