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