mod_geo-tp/src/main_window.cpp

155 lines
5.1 KiB
C++
Raw Normal View History

2021-09-20 20:36:29 +02:00
#include "main_window.h"
2021-10-02 20:47:02 +02:00
#include "mesh_processor.h"
2021-09-20 20:36:29 +02:00
#include <QApplication>
#include <QFileDialog>
2021-11-25 14:59:13 +01:00
#include <QMenuBar>
#include <QGroupBox>
#include <QPushButton>
#include <QSlider>
#include <QLabel>
#include <QDoubleSpinBox>
2021-09-20 20:36:29 +02:00
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent),
2021-10-03 00:24:20 +02:00
toolbar(this),
2021-11-13 17:53:21 +01:00
mesh_viewer() {
2021-09-20 20:36:29 +02:00
setCentralWidget(&mesh_viewer);
2021-11-25 14:59:13 +01:00
// addToolBar(Qt::RightToolBarArea, &toolbar);
// open_action = toolbar.addAction("Ouvrir…", [&](){
// emit open(QFileDialog::getOpenFileName(this, "Ouvrir un maillage"));
// });
2021-09-20 20:36:29 +02:00
// toolbar_actions.append(toolbar.addAction("Fractionner", [&](){
// QVector<QPair<MyMesh::Point, MyMesh>> fragments = shatter(mesh);
// mesh_viewer.removeOpenGLMesh(glm);
// for (auto &[pos, fragment] : fragments) {
// fragment.triangulate();
// QMatrix4x4 mat;
// float scale = 1.2;
// mat.translate(pos[0] * scale, pos[1] * scale, pos[2] * scale);
// mesh_viewer.addOpenGLMeshFromOpenMesh(&fragment, mat);
// }
// }));
2021-11-25 14:59:13 +01:00
QMenuBar *menu_bar = new QMenuBar();
setMenuBar(menu_bar);
// File menu
QMenu *file_menu = new QMenu("Fichier");
open_action = file_menu->addAction("Ouvrir…", [&](){
emit open(QFileDialog::getOpenFileName(this, "Ouvrir un maillage"));
});
save_action = file_menu->addAction("Enregistrer sous…", [&]() {
emit save(QFileDialog::getSaveFileName(this,
"Enregistrer un maillage"));
});
menu_bar->addMenu(file_menu);
if (!mesh_viewer.isInitialized()) {
open_action->setEnabled(false);
connect(&mesh_viewer, &MeshViewer::initialized, [&]() {
open_action->setEnabled(true);
});
2021-09-20 20:36:29 +02:00
}
2021-11-25 14:59:13 +01:00
addToolBar(Qt::RightToolBarArea, &toolbar);
// Hole filling tools
QGroupBox *hole_box = new QGroupBox("Remplissage de trous");
QGridLayout *hole_layout = new QGridLayout();
hole_box->setLayout(hole_layout);
2021-11-25 14:59:13 +01:00
QPushButton *fill_holes_dumb = new QPushButton("Remplir bêtement");
connect(fill_holes_dumb, &QPushButton::clicked,
this, &MainWindow::fillHolesDumbClicked);
hole_layout->addWidget(fill_holes_dumb, 0, 0);
2021-11-27 11:20:08 +01:00
QPushButton *fill_holes_implicit =
new QPushButton("Remplir par une surface implicite");
2021-11-25 14:59:13 +01:00
connect(fill_holes_implicit, &QPushButton::clicked,
this, &MainWindow::fillHolesImplicitClicked);
hole_layout->addWidget(fill_holes_implicit, 1, 0);
const double implicit_scale_min = 0;
const double implicit_scale_max = 10;
QLabel *implicit_scale_text =
new QLabel("Échelle du remplissage implicite", this);
hole_layout->addWidget(implicit_scale_text, 2, 0);
QDoubleSpinBox *implicit_scale_sb = new QDoubleSpinBox(this);
implicit_scale_sb->setMinimum(implicit_scale_min);
implicit_scale_sb->setMaximum(implicit_scale_max);
hole_layout->addWidget(implicit_scale_sb, 3, 0);
QSlider *implicit_scale = new QSlider(Qt::Horizontal, this);
connect(implicit_scale, &QSlider::valueChanged,
[=](int v) {
double val = v / 100. * (implicit_scale_max
- implicit_scale_min)
+ implicit_scale_min;
fillHolesImplicitScaleChanged(val);
if (val != implicit_scale_sb->value()) {
implicit_scale_sb->setValue(val);
}
});
connect(implicit_scale_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[=](double v) {
if (v != implicit_scale_sb->value()) {
implicit_scale->setValue(v);
}
});
hole_layout->addWidget(implicit_scale, 3, 1);
const double implicit_discr_min = 0;
const double implicit_discr_max = .1;
QLabel *implicit_discr_text =
new QLabel("Taux de discrétisation du remplissage implicite", this);
hole_layout->addWidget(implicit_discr_text, 4, 0);
QDoubleSpinBox *implicit_discr_sb = new QDoubleSpinBox(this);
implicit_discr_sb->setMinimum(implicit_discr_min);
implicit_discr_sb->setMaximum(implicit_discr_max);
hole_layout->addWidget(implicit_discr_sb, 5, 0);
QSlider *implicit_discr = new QSlider(Qt::Horizontal, this);
connect(implicit_discr, &QSlider::valueChanged,
[=](int v) {
double val = v / 100. * (implicit_discr_max
- implicit_discr_min)
+ implicit_discr_min;
fillHolesImplicitDiscrChanged(val);
if (val != implicit_discr_sb->value()) {
implicit_discr_sb->setValue(val);
}
});
connect(implicit_discr_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[=](double v) {
if (v != implicit_discr_sb->value()) {
implicit_discr->setValue(v);
}
});
hole_layout->addWidget(implicit_discr, 5, 1);
2021-11-25 14:59:13 +01:00
toolbar.addWidget(hole_box);
2021-11-25 14:59:13 +01:00
// Smoothing tools
QGroupBox *smooth_box = new QGroupBox("Adoucissement");
QLayout *smooth_layout = new QVBoxLayout();
smooth_box->setLayout(smooth_layout);
2021-11-25 14:59:13 +01:00
QPushButton *smooth = new QPushButton("Adoucir");
connect(smooth, &QPushButton::clicked,
this, &MainWindow::smoothClicked);
smooth_layout->addWidget(smooth);
2021-11-25 14:59:13 +01:00
toolbar.addWidget(smooth_box);
2021-11-25 14:59:13 +01:00
// Curvature tools
QGroupBox *curvature_box = new QGroupBox("Analyse de courbure");
QLayout *curvature_layout = new QVBoxLayout();
curvature_box->setLayout(curvature_layout);
2021-11-25 14:59:13 +01:00
QPushButton *patch_mode = new QPushButton(
"Afficher le patch de la sélection");
patch_mode->setCheckable(true);
connect(patch_mode, &QPushButton::toggled,
this, &MainWindow::patchViewToggled);
curvature_layout->addWidget(patch_mode);
2021-11-25 14:59:13 +01:00
toolbar.addWidget(curvature_box);
2021-09-20 20:36:29 +02:00
}