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 
24 
25 #include <string>
26 
28 #include "Elements/PoseWidget.h"
29 #include "Elements/RobotWidget.h"
30 
31 namespace armarx
32 {
34  {
35  _ui.setupUi(getWidget());
36  connect(_ui.pushButtonElementAdd,
37  &QPushButton::clicked,
38  this,
39  &ArVizDrawerGuiWidgetController::on_pushButtonElementAdd_clicked);
40  //setup factories
41  {
42  _factory["Robot"] = [] { return new RobotWidget; };
43  _factory["Pose"] = [] { return new PoseWidget; };
44 
45  for (const auto& [key, _] : _factory)
46  {
47  _ui.comboBoxElement->addItem(QString::fromStdString(key));
48  }
49  }
50  startTimer(20);
51  }
52 
53  void
55  {
56  _connected = true;
57  }
58 
59  void
61  {
62  _connected = false;
63  }
64 
65  void
66  ArVizDrawerGuiWidgetController::on_pushButtonElementAdd_clicked()
67  {
68  const auto name = _ui.comboBoxElement->currentText().toStdString();
69  auto* ptr = _factory.at(name)();
70  _ui.verticalLayoutElements->addWidget(ptr);
71  _elements.emplace(ptr);
72  }
73 
74  void
76  {
77  if (!_connected)
78  {
79  return;
80  }
81  auto layer = getArvizClient().layer("elements");
82  for (auto* elem : _elements)
83  {
84  if (elem->toDelete())
85  {
86  _ui.verticalLayoutElements->removeWidget(elem);
87  elem->deleteLater();
88  _elements.erase(elem);
89  }
90  else
91  {
92  elem->addTo(layer);
93  }
94  }
95  getArvizClient().commit({layer});
96  }
97 } // namespace armarx
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:89
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:33
armarx::ArVizDrawerGuiWidgetController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ArVizDrawerGuiWidgetController.cpp:54
ArVizDrawerGuiWidgetController.h
armarx::RobotWidget
Definition: RobotWidget.h:9
armarx::ArVizDrawerGuiWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ArVizDrawerGuiWidgetController.cpp:60
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:80
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ArVizDrawerGuiWidgetController::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: ArVizDrawerGuiWidgetController.cpp:75