ArvizProfileManagerWidget.h
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::ArVizProfileManagerWidget
17 * @author Andre Meixner ( andre dot meixner at kit dot edu )
18 * @date 2024
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22#pragma once
23
24#include <mutex>
25#include <string>
26#include <unordered_set>
27#include <utility>
28
29#include <QCheckBox>
30#include <QComboBox>
31#include <QDialog>
32#include <QLineEdit>
33#include <QPushButton>
34#include <QRadioButton>
35#include <QSettings>
36#include <QString>
37#include <QWidget>
38#include <qcheckbox.h>
39
41
42namespace armarx
43{
44 struct pair_hash
45 {
46 template <typename T1, typename T2>
47 std::size_t
48 operator()(const std::pair<T1, T2>& p) const
49 {
50 auto h1 = std::hash<T1>{}(p.first);
51 auto h2 = std::hash<T2>{}(p.second);
52 return h1 ^ (h2 << 1);
53 }
54 };
55
56 using Layers = std::unordered_set<viz::CoinLayerID, pair_hash>;
57
58 struct Profile
59 {
61 bool additive = false;
62 };
63
64 class ProfileDialog : public QDialog
65 {
66 Q_OBJECT
67
68 public:
69 explicit ProfileDialog(QWidget* parent = nullptr,
70 const QString& name = "",
71 bool additive = false,
72 bool addDialog = true,
73 bool isDefault = false);
75
76 QString getName() const;
77 bool isAdditive() const;
78 bool isDefaultProfile() const;
79
80 signals:
82
83 private slots:
84 void deleteProfile();
85
86 private:
87 QLineEdit* nameInput;
88 QRadioButton* additiveRadioButton;
89 QRadioButton* substractiveRadioButton;
90 QPushButton* deleteButton;
91 QCheckBox* defaultCheckBox;
92 };
93
94 class ArvizProfileManagerWidget : public QWidget
95 {
96 Q_OBJECT
97
98 public:
99 explicit ArvizProfileManagerWidget(QWidget* parent = nullptr);
100
101 inline void
102 update(const viz::CoinLayerID& layerID, bool visible)
103 {
104 std::scoped_lock lock(mtx);
105
106 if (currentProfile.additive == visible)
107 {
108 currentProfile.layers.insert(layerID);
109 }
110 else if (currentProfile.layers.count(layerID) > 0)
111 {
112 currentProfile.layers.erase(layerID);
113 currentProfile.layers.erase({layerID.first, "*"});
114 }
115 }
116
117 inline void
118 update(const std::string& componentName, bool visible)
119 {
120 update({componentName, "*"}, visible);
121 }
122
123 inline bool
124 isHidden(const viz::CoinLayerID& layerID) const
125 {
126 std::scoped_lock lock(mtx);
127
128 const bool result = currentProfile.layers.count(layerID) > 0 or
129 currentProfile.layers.count({layerID.first, "*"}) > 0;
130
131 if (currentProfile.additive)
132 {
133 return not result;
134 }
135 else
136 {
137 return result;
138 }
139 }
140
141 inline bool
142 isHidden(const std::string& componentName) const
143 {
144 std::scoped_lock lock(mtx);
145
146 return currentProfile.additive ==
147 (currentProfile.layers.count({componentName, "*"}) == 0);
148 }
149
150 signals:
153
154 public slots:
155 void onProfileSelected(int index);
156
157 private slots:
158 void saveCurrentProfile();
159 void deleteCurrentProfileSave();
160
161 void addProfile();
162 void editProfile();
163
164 private:
165 void loadLayerNames();
166 void loadProfile(const QString& name);
167 bool saveProfile(const QString& name, const Profile& profile);
168
169 ProfileDialog* dialog = nullptr;
170 QComboBox* layersComboBox;
171 QPushButton* addButton;
172 QPushButton* editButton;
173 QPushButton* saveButton;
174 QSettings settings;
175 mutable std::mutex mtx;
176
177 Profile currentProfile;
178
179 static const QString SETTINGS_DEFAULT_PROFILE_KEY;
180 };
181
182} // namespace armarx
uint8_t index
void update(const viz::CoinLayerID &layerID, bool visible)
void update(const std::string &componentName, bool visible)
bool isHidden(const std::string &componentName) const
bool isHidden(const viz::CoinLayerID &layerID) const
ProfileDialog(QWidget *parent=nullptr, const QString &name="", bool additive=false, bool addDialog=true, bool isDefault=false)
std::pair< std::string, std::string > CoinLayerID
Definition Visualizer.h:20
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::unordered_set< viz::CoinLayerID, pair_hash > Layers
std::size_t operator()(const std::pair< T1, T2 > &p) const