Skip to content
Snippets Groups Projects

Feature/arviz profiles

Merged Andre Meixner requested to merge feature/arviz-profiles into master
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::gui-plugins::ArVizProfileManagerWidget
* @author Andre Meixner ( andre dot meixner at kit dot edu )
* @date 2024
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <QWidget>
#include <QDialog>
#include <QComboBox>
#include <QPushButton>
#include <QLineEdit>
#include <QSettings>
#include <QString>
#include <QCheckBox>
#include <QRadioButton>
#include <mutex>
#include <qcheckbox.h>
#include <unordered_set>
#include <string>
#include <utility>
#include <RobotAPI/components/ArViz/Coin/Visualizer.h>
namespace armarx
{
struct pair_hash
{
template <typename T1, typename T2>
std::size_t operator ()(const std::pair<T1, T2>& p) const
{
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ (h2 << 1);
}
};
using Layers = std::unordered_set<viz::CoinLayerID, pair_hash>;
struct Profile
{
Layers layers;
bool additive = false;
};
class ProfileDialog : public QDialog
{
Q_OBJECT
public:
explicit ProfileDialog(QWidget *parent = nullptr, const QString &name = "",
bool additive = false, bool addDialog = true, bool isDefault = false);
~ProfileDialog();
QString getName() const;
bool isAdditive() const;
bool isDefaultProfile() const;
signals:
void deleteProfileSignal();
private slots:
void deleteProfile();
private:
QLineEdit *nameInput;
QRadioButton *additiveRadioButton;
QRadioButton *substractiveRadioButton;
QPushButton *deleteButton;
QCheckBox *defaultCheckBox;
};
class ArvizProfileManagerWidget : public QWidget
{
Q_OBJECT
public:
explicit ArvizProfileManagerWidget(QWidget* parent = nullptr);
inline void update(const viz::CoinLayerID& layerID, bool visible)
{
std::scoped_lock lock(mtx);
if (currentProfile.additive == visible)
{
currentProfile.layers.insert(layerID);
}
else if (currentProfile.layers.count(layerID) > 0)
{
currentProfile.layers.erase(layerID);
currentProfile.layers.erase({layerID.first, "*"});
}
}
inline void update(const std::string& componentName, bool visible)
{
update({componentName, "*"}, visible);
}
inline bool isHidden(const viz::CoinLayerID& layerID) const
{
std::scoped_lock lock(mtx);
const bool result = currentProfile.layers.count(layerID) > 0 or currentProfile.layers.count({layerID.first, "*"}) > 0;
if (currentProfile.additive)
{
return not result;
}
else
{
return result;
}
}
inline bool isHidden(const std::string& componentName) const
{
std::scoped_lock lock(mtx);
return currentProfile.additive == (currentProfile.layers.count({componentName, "*"}) == 0);
}
signals:
void publishUpdate();
void fetchUpdate();
public slots:
void onProfileSelected(int index);
private slots:
void saveCurrentProfile();
void deleteCurrentProfileSave();
void addProfile();
void editProfile();
private:
void loadLayerNames();
void loadProfile(const QString& name);
bool saveProfile(const QString& name, const Profile& profile);
ProfileDialog* dialog = nullptr;
QComboBox* layersComboBox;
QPushButton* addButton;
QPushButton* editButton;
QPushButton* saveButton;
QSettings settings;
mutable std::mutex mtx;
Profile currentProfile;
static const QString SETTINGS_DEFAULT_PROFILE_KEY;
};
}
Loading