mirror of
https://github.com/leozide/leocad.git
synced 2026-10-26 22:10:32 +00:00
Rename the localized float parser to lcParseFloatValueLocalized and return std::optional<float> so conversion failures and nonfinite values cannot silently become zero. Return std::optional<lcVector3> from GetTransformAmount and apply transforms only when every nonempty axis is valid, preserving blank axes as zero. Validate all Array offsets and rotations before updating dialog results, and show an informational message with focus on invalid input. Verified with a macOS Qt debug build and actual Array/transform checks in US English, German, and Arabic locales, including blank input, overflow, NaN, and infinity.
120 lines
4.4 KiB
C++
120 lines
4.4 KiB
C++
#include "lc_global.h"
|
|
#include "lc_arraydialog.h"
|
|
#include "ui_lc_arraydialog.h"
|
|
#include "lc_qutils.h"
|
|
|
|
lcArrayDialog::lcArrayDialog(QWidget* Parent)
|
|
: QDialog(Parent), ui(new Ui::lcArrayDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
lcSetupDialogHelp(this, ui->buttonBox);
|
|
|
|
ui->offset1x->setValidator(new QDoubleValidator(ui->offset1x));
|
|
ui->offset1y->setValidator(new QDoubleValidator(ui->offset1y));
|
|
ui->offset1z->setValidator(new QDoubleValidator(ui->offset1z));
|
|
ui->offset2x->setValidator(new QDoubleValidator(ui->offset2x));
|
|
ui->offset2y->setValidator(new QDoubleValidator(ui->offset2y));
|
|
ui->offset2z->setValidator(new QDoubleValidator(ui->offset2z));
|
|
ui->offset3x->setValidator(new QDoubleValidator(ui->offset3x));
|
|
ui->offset3y->setValidator(new QDoubleValidator(ui->offset3y));
|
|
ui->offset3z->setValidator(new QDoubleValidator(ui->offset3z));
|
|
ui->rotation1x->setValidator(new QDoubleValidator(ui->rotation1x));
|
|
ui->rotation1y->setValidator(new QDoubleValidator(ui->rotation1y));
|
|
ui->rotation1z->setValidator(new QDoubleValidator(ui->rotation1z));
|
|
ui->rotation2x->setValidator(new QDoubleValidator(ui->rotation2x));
|
|
ui->rotation2y->setValidator(new QDoubleValidator(ui->rotation2y));
|
|
ui->rotation2z->setValidator(new QDoubleValidator(ui->rotation2z));
|
|
ui->rotation3x->setValidator(new QDoubleValidator(ui->rotation3x));
|
|
ui->rotation3y->setValidator(new QDoubleValidator(ui->rotation3y));
|
|
ui->rotation3z->setValidator(new QDoubleValidator(ui->rotation3z));
|
|
|
|
mCounts[0] = 10;
|
|
mCounts[1] = 1;
|
|
mCounts[2] = 1;
|
|
mOffsets[0] = mOffsets[1] = mOffsets[2] = lcVector3(0.0f, 0.0f, 0.0f);
|
|
mRotations[0] = mRotations[1] = mRotations[2] = lcVector3(0.0f, 0.0f, 0.0f);
|
|
|
|
ui->count1->setValue(mCounts[0]);
|
|
ui->count2->setValue(mCounts[1]);
|
|
ui->count3->setValue(mCounts[2]);
|
|
ui->offset1x->setText(lcFormatValueLocalized(mOffsets[0].x));
|
|
ui->offset1y->setText(lcFormatValueLocalized(mOffsets[0].y));
|
|
ui->offset1z->setText(lcFormatValueLocalized(mOffsets[0].z));
|
|
ui->offset2x->setText(lcFormatValueLocalized(mOffsets[1].x));
|
|
ui->offset2y->setText(lcFormatValueLocalized(mOffsets[1].y));
|
|
ui->offset2z->setText(lcFormatValueLocalized(mOffsets[1].z));
|
|
ui->offset3x->setText(lcFormatValueLocalized(mOffsets[2].x));
|
|
ui->offset3y->setText(lcFormatValueLocalized(mOffsets[2].y));
|
|
ui->offset3z->setText(lcFormatValueLocalized(mOffsets[2].z));
|
|
ui->rotation1x->setText(lcFormatValueLocalized(mRotations[0].x));
|
|
ui->rotation1y->setText(lcFormatValueLocalized(mRotations[0].y));
|
|
ui->rotation1z->setText(lcFormatValueLocalized(mRotations[0].z));
|
|
ui->rotation2x->setText(lcFormatValueLocalized(mRotations[1].x));
|
|
ui->rotation2y->setText(lcFormatValueLocalized(mRotations[1].y));
|
|
ui->rotation2z->setText(lcFormatValueLocalized(mRotations[1].z));
|
|
ui->rotation3x->setText(lcFormatValueLocalized(mRotations[2].x));
|
|
ui->rotation3y->setText(lcFormatValueLocalized(mRotations[2].y));
|
|
ui->rotation3z->setText(lcFormatValueLocalized(mRotations[2].z));
|
|
}
|
|
|
|
lcArrayDialog::~lcArrayDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void lcArrayDialog::accept()
|
|
{
|
|
int Counts[3];
|
|
|
|
Counts[0] = ui->count1->value();
|
|
Counts[1] = ui->count2->value();
|
|
Counts[2] = ui->count3->value();
|
|
|
|
if (Counts[0] * Counts[1] * Counts[2] < 2)
|
|
{
|
|
QMessageBox::information(this, windowTitle(), tr("Array is empty."));
|
|
return;
|
|
}
|
|
|
|
QLineEdit* Edits[2][3][3] =
|
|
{
|
|
{
|
|
{ ui->offset1x, ui->offset1y, ui->offset1z },
|
|
{ ui->offset2x, ui->offset2y, ui->offset2z },
|
|
{ ui->offset3x, ui->offset3y, ui->offset3z }
|
|
},
|
|
{
|
|
{ ui->rotation1x, ui->rotation1y, ui->rotation1z },
|
|
{ ui->rotation2x, ui->rotation2y, ui->rotation2z },
|
|
{ ui->rotation3x, ui->rotation3y, ui->rotation3z }
|
|
}
|
|
};
|
|
lcVector3 Values[2][3];
|
|
|
|
for (int Type = 0; Type < 2; Type++)
|
|
for (int Dimension = 0; Dimension < 3; Dimension++)
|
|
for (int Axis = 0; Axis < 3; Axis++)
|
|
{
|
|
QLineEdit* Edit = Edits[Type][Dimension][Axis];
|
|
const std::optional<float> Value = lcParseFloatValueLocalized(Edit->text(), Edit->validator()->locale());
|
|
|
|
if (!Value || !Edit->hasAcceptableInput())
|
|
{
|
|
QMessageBox::information(this, windowTitle(), tr("Please enter a valid value for '%1'.").arg(Edit->accessibleName()));
|
|
Edit->setFocus();
|
|
return;
|
|
}
|
|
|
|
Values[Type][Dimension][Axis] = *Value;
|
|
}
|
|
|
|
for (int Dimension = 0; Dimension < 3; Dimension++)
|
|
{
|
|
mCounts[Dimension] = Counts[Dimension];
|
|
mOffsets[Dimension] = Values[0][Dimension];
|
|
mRotations[Dimension] = Values[1][Dimension];
|
|
}
|
|
|
|
QDialog::accept();
|
|
}
|