Mesh: Apply clang-format

This commit is contained in:
wmayer
2023-09-23 00:29:09 +02:00
committed by wwmayer
parent 23db389a76
commit 28ae0831cb
78 changed files with 4221 additions and 3294 deletions

View File

@@ -22,13 +22,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
#include <sstream>
# include <QDialog>
# include <QDoubleSpinBox>
# include <QMessageBox>
# include <QPointer>
# include <QVBoxLayout>
#include <QDialog>
#include <QDoubleSpinBox>
#include <QMessageBox>
#include <QPointer>
#include <QVBoxLayout>
#endif
#include <App/Application.h>
@@ -46,13 +46,15 @@
using namespace MeshGui;
namespace MeshGui {
class PlaneFitParameter : public FitParameter
namespace MeshGui
{
class PlaneFitParameter: public FitParameter
{
public:
PlaneFitParameter() = default;
~PlaneFitParameter() override = default;
std::vector<float> getParameter(FitParameter::Points pts) const override {
std::vector<float> getParameter(FitParameter::Points pts) const override
{
std::vector<float> values;
MeshCore::PlaneFit fit;
fit.AddPoints(pts.points);
@@ -70,12 +72,13 @@ public:
}
};
class CylinderFitParameter : public FitParameter
class CylinderFitParameter: public FitParameter
{
public:
CylinderFitParameter() = default;
~CylinderFitParameter() override = default;
std::vector<float> getParameter(FitParameter::Points pts) const override {
std::vector<float> getParameter(FitParameter::Points pts) const override
{
std::vector<float> values;
MeshCore::CylinderFit fit;
fit.AddPoints(pts.points);
@@ -106,16 +109,26 @@ public:
// Only for testing purposes
try {
float height = Base::Distance(base, top);
Gui::Command::doCommand(Gui::Command::App,
"cyl = App.ActiveDocument.addObject('Part::Cylinder', 'Cylinder')\n"
"cyl.Radius = %f\n"
"cyl.Height = %f\n"
"cyl.Placement = App.Placement(App.Vector(%f,%f,%f), App.Rotation(App.Vector(0,0,1), App.Vector(%f,%f,%f)))\n",
radius, height, base.x, base.y, base.z, axis.x, axis.y, axis.z);
Gui::Command::doCommand(
Gui::Command::App,
"cyl = App.ActiveDocument.addObject('Part::Cylinder', 'Cylinder')\n"
"cyl.Radius = %f\n"
"cyl.Height = %f\n"
"cyl.Placement = App.Placement(App.Vector(%f,%f,%f), "
"App.Rotation(App.Vector(0,0,1), App.Vector(%f,%f,%f)))\n",
radius,
height,
base.x,
base.y,
base.z,
axis.x,
axis.y,
axis.z);
Gui::Command::doCommand(Gui::Command::App,
"axis = cyl.Placement.Rotation.multVec(App.Vector(0,0,1))\n"
"print('Final axis: ({}, {}, {})'.format(axis.x, axis.y, axis.z))\n");
Gui::Command::doCommand(
Gui::Command::App,
"axis = cyl.Placement.Rotation.multVec(App.Vector(0,0,1))\n"
"print('Final axis: ({}, {}, {})'.format(axis.x, axis.y, axis.z))\n");
}
catch (...) {
}
@@ -125,12 +138,13 @@ public:
}
};
class SphereFitParameter : public FitParameter
class SphereFitParameter: public FitParameter
{
public:
SphereFitParameter() = default;
~SphereFitParameter() override = default;
std::vector<float> getParameter(FitParameter::Points pts) const override {
std::vector<float> getParameter(FitParameter::Points pts) const override
{
std::vector<float> values;
MeshCore::SphereFit fit;
fit.AddPoints(pts.points);
@@ -145,10 +159,12 @@ public:
return values;
}
};
}
} // namespace MeshGui
ParametersDialog::ParametersDialog(std::vector<float>& val, FitParameter* fitPar,
ParameterList par, Mesh::Feature* mesh,
ParametersDialog::ParametersDialog(std::vector<float>& val,
FitParameter* fitPar,
ParameterList par,
Mesh::Feature* mesh,
QWidget* parent)
: QDialog(parent)
, values(val)
@@ -158,54 +174,54 @@ ParametersDialog::ParametersDialog(std::vector<float>& val, FitParameter* fitPar
{
this->setWindowTitle(tr("Surface fit"));
QGridLayout *gridLayout;
QGridLayout* gridLayout;
gridLayout = new QGridLayout(this);
QGroupBox *groupBox;
QGroupBox* groupBox;
groupBox = new QGroupBox(this);
groupBox->setTitle(tr("Parameters"));
gridLayout->addWidget(groupBox, 0, 0, 1, 1);
QGroupBox *selectBox;
QGroupBox* selectBox;
selectBox = new QGroupBox(this);
selectBox->setTitle(tr("Selection"));
gridLayout->addWidget(selectBox, 1, 0, 1, 1);
QVBoxLayout *selectLayout;
QVBoxLayout* selectLayout;
selectLayout = new QVBoxLayout(selectBox);
QPushButton *regionButton;
QPushButton* regionButton;
regionButton = new QPushButton(this);
regionButton->setText(tr("Region"));
regionButton->setObjectName(QString::fromLatin1("region"));
selectLayout->addWidget(regionButton);
QPushButton *singleButton;
QPushButton* singleButton;
singleButton = new QPushButton(this);
singleButton->setText(tr("Triangle"));
singleButton->setObjectName(QString::fromLatin1("single"));
selectLayout->addWidget(singleButton);
QPushButton *clearButton;
QPushButton* clearButton;
clearButton = new QPushButton(this);
clearButton->setText(tr("Clear"));
clearButton->setObjectName(QString::fromLatin1("clear"));
selectLayout->addWidget(clearButton);
QPushButton *computeButton;
QPushButton* computeButton;
computeButton = new QPushButton(this);
computeButton->setText(tr("Compute"));
computeButton->setObjectName(QString::fromLatin1("compute"));
gridLayout->addWidget(computeButton, 2, 0, 1, 1);
QDialogButtonBox *buttonBox;
QDialogButtonBox* buttonBox;
buttonBox = new QDialogButtonBox(this);
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
gridLayout->addWidget(buttonBox, 3, 0, 1, 1);
int index = 0;
QGridLayout *layout;
QGridLayout* layout;
layout = new QGridLayout(groupBox);
for (const auto& it : parameter) {
QLabel* label = new QLabel(groupBox);
@@ -221,12 +237,14 @@ ParametersDialog::ParametersDialog(std::vector<float>& val, FitParameter* fitPar
++index;
}
// clang-format off
connect(buttonBox, &QDialogButtonBox::accepted, this, &ParametersDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ParametersDialog::reject);
connect(regionButton, &QPushButton::clicked, this, &ParametersDialog::onRegionClicked);
connect(singleButton, &QPushButton::clicked, this, &ParametersDialog::onSingleClicked);
connect(clearButton, &QPushButton::clicked, this, &ParametersDialog::onClearClicked);
connect(computeButton, &QPushButton::clicked, this, &ParametersDialog::onComputeClicked);
// clang-format on
Gui::SelectionObject obj(mesh);
std::vector<Gui::SelectionObject> sel;
@@ -277,7 +295,7 @@ void ParametersDialog::onComputeClicked()
values = fitParameter->getParameter(fitpts);
if (values.size() == spinBoxes.size()) {
for (std::size_t i=0; i<values.size(); i++) {
for (std::size_t i = 0; i < values.size(); i++) {
spinBoxes[i]->setValue(values[i]);
}
}
@@ -285,15 +303,18 @@ void ParametersDialog::onComputeClicked()
meshSel.clearSelection();
}
else {
QMessageBox::warning(this, tr("No selection"), tr("Before fitting the surface select an area."));
QMessageBox::warning(this,
tr("No selection"),
tr("Before fitting the surface select an area."));
}
}
void ParametersDialog::accept()
{
std::vector<float> v;
for (auto it : spinBoxes)
for (auto it : spinBoxes) {
v.push_back(it->value());
}
values = v;
QDialog::accept();
}
@@ -309,7 +330,8 @@ void ParametersDialog::reject()
/* TRANSLATOR MeshGui::SegmentationBestFit */
SegmentationBestFit::SegmentationBestFit(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags fl)
: QWidget(parent, fl), myMesh(mesh)
: QWidget(parent, fl)
, myMesh(mesh)
{
ui = new Ui_SegmentationBestFit;
ui->setupUi(this);
@@ -336,12 +358,14 @@ SegmentationBestFit::~SegmentationBestFit()
void SegmentationBestFit::setupConnections()
{
// clang-format off
connect(ui->planeParameters, &QPushButton::clicked,
this, &SegmentationBestFit::onPlaneParametersClicked);
connect(ui->cylinderParameters, &QPushButton::clicked,
this, &SegmentationBestFit::onCylinderParametersClicked);
connect(ui->sphereParameters, &QPushButton::clicked,
this, &SegmentationBestFit::onSphereParametersClicked);
// clang-format on
}
void SegmentationBestFit::onPlaneParametersClicked()
@@ -362,10 +386,9 @@ void SegmentationBestFit::onPlaneParametersClicked()
list.push_back(std::make_pair(axis + z, p[5]));
static QPointer<QDialog> dialog = nullptr;
if (!dialog)
dialog = new ParametersDialog(planeParameter,
new PlaneFitParameter,
list, myMesh, this);
if (!dialog) {
dialog = new ParametersDialog(planeParameter, new PlaneFitParameter, list, myMesh, this);
}
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}
@@ -387,13 +410,13 @@ void SegmentationBestFit::onCylinderParametersClicked()
list.push_back(std::make_pair(axis + x, p[3]));
list.push_back(std::make_pair(axis + y, p[4]));
list.push_back(std::make_pair(axis + z, p[5]));
list.push_back(std::make_pair(radius, p[6]));
list.push_back(std::make_pair(radius, p[6]));
static QPointer<QDialog> dialog = nullptr;
if (!dialog)
dialog = new ParametersDialog(cylinderParameter,
new CylinderFitParameter,
list, myMesh, this);
if (!dialog) {
dialog =
new ParametersDialog(cylinderParameter, new CylinderFitParameter, list, myMesh, this);
}
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}
@@ -411,13 +434,12 @@ void SegmentationBestFit::onSphereParametersClicked()
list.push_back(std::make_pair(base + x, p[0]));
list.push_back(std::make_pair(base + y, p[1]));
list.push_back(std::make_pair(base + z, p[2]));
list.push_back(std::make_pair(radius, p[3]));
list.push_back(std::make_pair(radius, p[3]));
static QPointer<QDialog> dialog = nullptr;
if (!dialog)
dialog = new ParametersDialog(sphereParameter,
new SphereFitParameter,
list, myMesh, this);
if (!dialog) {
dialog = new ParametersDialog(sphereParameter, new SphereFitParameter, list, myMesh, this);
}
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}
@@ -434,44 +456,49 @@ void SegmentationBestFit::accept()
MeshCore::AbstractSurfaceFit* fitter;
if (cylinderParameter.size() == 7) {
std::vector<float>& p = cylinderParameter;
fitter = new MeshCore::CylinderSurfaceFit(
Base::Vector3f(p[0],p[1],p[2]),
Base::Vector3f(p[3],p[4],p[5]),
p[6]);
fitter = new MeshCore::CylinderSurfaceFit(Base::Vector3f(p[0], p[1], p[2]),
Base::Vector3f(p[3], p[4], p[5]),
p[6]);
}
else {
fitter = new MeshCore::CylinderSurfaceFit;
}
segm.emplace_back(std::make_shared<MeshCore::MeshDistanceGenericSurfaceFitSegment>
(fitter, kernel, ui->numCyl->value(), ui->tolCyl->value()));
segm.emplace_back(
std::make_shared<MeshCore::MeshDistanceGenericSurfaceFitSegment>(fitter,
kernel,
ui->numCyl->value(),
ui->tolCyl->value()));
}
if (ui->groupBoxSph->isChecked()) {
MeshCore::AbstractSurfaceFit* fitter;
if (sphereParameter.size() == 4) {
std::vector<float>& p = sphereParameter;
fitter = new MeshCore::SphereSurfaceFit(
Base::Vector3f(p[0],p[1],p[2]),
p[3]);
fitter = new MeshCore::SphereSurfaceFit(Base::Vector3f(p[0], p[1], p[2]), p[3]);
}
else {
fitter = new MeshCore::SphereSurfaceFit;
}
segm.emplace_back(std::make_shared<MeshCore::MeshDistanceGenericSurfaceFitSegment>
(fitter, kernel, ui->numSph->value(), ui->tolSph->value()));
segm.emplace_back(
std::make_shared<MeshCore::MeshDistanceGenericSurfaceFitSegment>(fitter,
kernel,
ui->numSph->value(),
ui->tolSph->value()));
}
if (ui->groupBoxPln->isChecked()) {
MeshCore::AbstractSurfaceFit* fitter;
if (planeParameter.size() == 6) {
std::vector<float>& p = planeParameter;
fitter = new MeshCore::PlaneSurfaceFit(
Base::Vector3f(p[0],p[1],p[2]),
Base::Vector3f(p[3],p[4],p[5]));
fitter = new MeshCore::PlaneSurfaceFit(Base::Vector3f(p[0], p[1], p[2]),
Base::Vector3f(p[3], p[4], p[5]));
}
else {
fitter = new MeshCore::PlaneSurfaceFit;
}
segm.emplace_back(std::make_shared<MeshCore::MeshDistanceGenericSurfaceFitSegment>
(fitter, kernel, ui->numPln->value(), ui->tolPln->value()));
segm.emplace_back(
std::make_shared<MeshCore::MeshDistanceGenericSurfaceFitSegment>(fitter,
kernel,
ui->numPln->value(),
ui->tolPln->value()));
}
finder.FindSegments(segm);
@@ -480,16 +507,17 @@ void SegmentationBestFit::accept()
std::string internalname = "Segments_";
internalname += myMesh->getNameInDocument();
App::DocumentObjectGroup* group = static_cast<App::DocumentObjectGroup*>(document->addObject
("App::DocumentObjectGroup", internalname.c_str()));
App::DocumentObjectGroup* group = static_cast<App::DocumentObjectGroup*>(
document->addObject("App::DocumentObjectGroup", internalname.c_str()));
std::string labelname = "Segments ";
labelname += myMesh->Label.getValue();
group->Label.setValue(labelname);
for (const auto & it : segm) {
for (const auto& it : segm) {
const std::vector<MeshCore::MeshSegment>& data = it->GetSegments();
for (const auto & jt : data) {
for (const auto& jt : data) {
Mesh::MeshObject* segment = mesh->meshFromSegment(jt);
Mesh::Feature* feaSegm = static_cast<Mesh::Feature*>(group->addObject("Mesh::Feature", "Segment"));
Mesh::Feature* feaSegm =
static_cast<Mesh::Feature*>(group->addObject("Mesh::Feature", "Segment"));
Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing();
feaMesh->swap(*segment);
feaSegm->Mesh.finishEditing();
@@ -503,7 +531,7 @@ void SegmentationBestFit::accept()
document->commitTransaction();
}
void SegmentationBestFit::changeEvent(QEvent *e)
void SegmentationBestFit::changeEvent(QEvent* e)
{
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
@@ -518,8 +546,7 @@ void SegmentationBestFit::changeEvent(QEvent *e)
TaskSegmentationBestFit::TaskSegmentationBestFit(Mesh::Feature* mesh)
{
widget = new SegmentationBestFit(mesh);
taskbox = new Gui::TaskView::TaskBox(
QPixmap(), widget->windowTitle(), false, nullptr);
taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), false, nullptr);
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
}