diff options
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 265 |
1 files changed, 224 insertions, 41 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e73df5a..464beb4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4,11 +4,13 @@ #include <QComboBox> #include <QDoubleSpinBox> #include <QFormLayout> +#include <QGroupBox> #include <QHBoxLayout> #include <QLabel> #include <QOpenGLWidget> #include <QShortcut> #include <QStyle> +#include <QTimer> // optical design #include "graphicsscene.h" @@ -38,8 +40,9 @@ void MainWindow::initUi() const auto mainLayout = new QHBoxLayout{mainWidget}; mainWidget->setLayout(mainLayout); - // addLayout sets parent below - const auto leftLayout = new QFormLayout{}; + + const auto leftPanel = new QWidget{mainWidget}; + const auto leftLayout = new QFormLayout{mainWidget}; leftLayout->setLabelAlignment(Qt::AlignVCenter | Qt::AlignRight); mainLayout->addLayout(leftLayout); @@ -59,6 +62,22 @@ void MainWindow::initUi() using MinValue = double; using MaxValue = double; using SingleStep = double; + + const auto newGroup = [mainWidget, leftLayout](const QString&& title) { + const auto group = new QGroupBox{std::move(title), mainWidget}; + const auto layout = new QFormLayout{group}; + leftLayout->addRow(group); + + return group; + }; + + const auto lenseGroup = newGroup(tr("Lense")); + const auto sensorGroup = newGroup(tr("Sensor")); + const auto rangeGroup = newGroup(tr("Range")); + const auto laserGroup = newGroup(tr("Laser")); + const auto scannerBodyGroup = newGroup(tr("Scanner Body")); + const auto resultsGroup = newGroup(tr("Results")); + auto addFormPair = [this, leftLayout, connectWidgetToProperty]( const QString text, const auto propertySignal, @@ -66,7 +85,8 @@ void MainWindow::initUi() const auto propertySetter, const MinValue minValue, const MaxValue maxValue, - const SingleStep singleStep = 0.1 + const SingleStep singleStep = 0.1, + const QGroupBox* groupBox = nullptr ) { const auto spinBox = new QDoubleSpinBox{centralWidget()}; spinBox->setRange(minValue, maxValue); @@ -87,14 +107,25 @@ void MainWindow::initUi() std::bind(&GraphicsScene::update, m_scene, m_design) ); - leftLayout->addRow(text, spinBox); + if (groupBox) + { + const auto formLayout = + qobject_cast<QFormLayout*>(groupBox->layout()); + Q_ASSERT(formLayout); + formLayout->addRow(text, spinBox); + } + else + { + leftLayout->addRow(text, spinBox); + } }; using Decimals = int; auto addFormLabel = [this, leftLayout]( const QString text, const auto propertySignal, - const Decimals decimals = 2 + const Decimals decimals = 2, + const QGroupBox* groupBox = nullptr ) { const auto label = new QLabel{centralWidget()}; @@ -102,15 +133,28 @@ void MainWindow::initUi() m_design, propertySignal, label, - [label, decimals](const auto value) { + [label, decimals, text](const auto value) { + qDebug() << "AZAZA: changed:" << text << value; label->setText(QString::number(value, 'F', decimals)); } ); - leftLayout->addRow(text, label); + if (groupBox) + { + const auto formLayout = + qobject_cast<QFormLayout*>(groupBox->layout()); + Q_ASSERT(formLayout); + formLayout->addRow(text, label); + } + else + { + leftLayout->addRow(text, label); + } }; - const auto createLenseApertureComboBox = [this, leftLayout]() { + const auto createLenseApertureComboBox = [this](QFormLayout* formLayout) { + Q_ASSERT(formLayout); + const auto comboBox = new QComboBox{centralWidget()}; using namespace orphex; @@ -143,17 +187,20 @@ void MainWindow::initUi() ); // update combobox on property change + const auto onApertureChanged = [this, comboBox](const auto value) { + comboBox->setCurrentIndex( + comboBox->findData(QVariant::fromValue(value)) + ); + }; connect( m_design, qOverload<LenseAperture>(&OpticalDesign::lenseApertureChanged), comboBox, - [comboBox](const auto value) { - comboBox->setCurrentIndex( - comboBox->findData(QVariant::fromValue(value)) - ); - } + onApertureChanged ); + onApertureChanged(m_design->get_lenseAperture()); + connect( m_design, qOverload<>(&OpticalDesign::lenseApertureChanged), @@ -161,7 +208,7 @@ void MainWindow::initUi() std::bind(&GraphicsScene::update, m_scene, m_design) ); - leftLayout->addRow(tr("Lense A&perture:"), comboBox); + formLayout->addRow(tr("A&perture:"), comboBox); }; addFormPair( @@ -170,17 +217,20 @@ void MainWindow::initUi() &OpticalDesign::get_opticalAxisAngleDegrees, &OpticalDesign::set_opticalAxisAngleDegrees, MinValue{10.}, - MaxValue{85.} + MaxValue{85.}, + SingleStep{0.1}, + lenseGroup ); addFormPair( - tr("Lense &Y pos (mm):"), + tr("&Y pos (mm):"), qOverload<double>(&OpticalDesign::lenseYPosMmChanged), &OpticalDesign::get_lenseYPosMm, &OpticalDesign::set_lenseYPosMm, MinValue{10.}, MaxValue{500.}, - SingleStep{1.} + SingleStep{1.}, + lenseGroup ); addFormPair( @@ -189,7 +239,9 @@ void MainWindow::initUi() &OpticalDesign::get_focalDistanceMm, &OpticalDesign::set_focalDistanceMm, MinValue{1.}, - MaxValue{45.} + MaxValue{45.}, + SingleStep{0.1}, + lenseGroup ); addFormPair( tr("&Back Focal Distance (mm):"), @@ -197,55 +249,90 @@ void MainWindow::initUi() &OpticalDesign::get_backFocalDistanceMm, &OpticalDesign::set_backFocalDistanceMm, MinValue{1.}, - MaxValue{45.} + MaxValue{45.}, + SingleStep{0.1}, + lenseGroup + ); + + createLenseApertureComboBox( + qobject_cast<QFormLayout*>(lenseGroup->layout()) + ); + + addFormPair( + tr("Body Max Diameter (mm):"), + qOverload<double>(&OpticalDesign::lenseBodyMaxDiameterMmChanged), + &OpticalDesign::get_lenseBodyMaxDiameterMm, + &OpticalDesign::set_lenseBodyMaxDiameterMm, + MinValue{1.}, + MaxValue{100.}, + SingleStep{1.}, + lenseGroup ); - createLenseApertureComboBox(); + addFormPair( + tr("Body Length (mm):"), + qOverload<double>(&OpticalDesign::lenseBodyLengthMmChanged), + &OpticalDesign::get_lenseBodyLengthMm, + &OpticalDesign::set_lenseBodyLengthMm, + MinValue{1.}, + MaxValue{100.}, + SingleStep{1.}, + lenseGroup + ); addFormPair( - tr("Sensor &Width (mm):"), + tr("&Width (mm):"), qOverload<double>(&OpticalDesign::sensorWidthMmChanged), &OpticalDesign::get_sensorWidthMm, &OpticalDesign::set_sensorWidthMm, MinValue{1.}, - MaxValue{30.} + MaxValue{30.}, + SingleStep{0.1}, + sensorGroup ); addFormPair( - tr("Sensor &Height (mm):"), + tr("&Height (mm):"), qOverload<double>(&OpticalDesign::sensorHeightMmChanged), &OpticalDesign::get_sensorHeightMm, &OpticalDesign::set_sensorHeightMm, MinValue{1.}, - MaxValue{30.} + MaxValue{30.}, + SingleStep{0.1}, + sensorGroup ); addFormPair( - tr("Sensor Cell W&idth (mm):"), + tr("Cell W&idth (µm):"), qOverload<double>(&OpticalDesign::sensorCellWidthUmChanged), &OpticalDesign::get_sensorCellWidthUm, &OpticalDesign::set_sensorCellWidthUm, MinValue{1.}, - MaxValue{30.} + MaxValue{30.}, + SingleStep{0.1}, + sensorGroup ); addFormPair( - tr("Sensor Cell H&eight (mm):"), + tr("Cell H&eight (µm):"), qOverload<double>(&OpticalDesign::sensorCellHeightUmChanged), &OpticalDesign::get_sensorCellHeightUm, &OpticalDesign::set_sensorCellHeightUm, MinValue{1.}, - MaxValue{30.} + MaxValue{30.}, + SingleStep{0.1}, + sensorGroup ); addFormPair( - tr("Sensor Vertical &Offset (mm):"), + tr("Vertical &Offset (mm):"), qOverload<double>(&OpticalDesign::sensorVerticalOffsetMmChanged), &OpticalDesign::get_sensorVerticalOffsetMm, &OpticalDesign::set_sensorVerticalOffsetMm, MinValue{-50.}, MaxValue{50.}, - SingleStep{0.1} + SingleStep{0.1}, + sensorGroup ); addFormPair( @@ -255,7 +342,8 @@ void MainWindow::initUi() &OpticalDesign::set_zBaseMm, MinValue{1.}, MaxValue{10000.}, - SingleStep{1.} + SingleStep{1.}, + rangeGroup ); addFormPair( @@ -265,49 +353,144 @@ void MainWindow::initUi() &OpticalDesign::set_zRangeMm, MinValue{1.}, MaxValue{10000.}, - SingleStep{1.} + SingleStep{1.}, + rangeGroup + ); + + addFormPair( + tr("Body Diameter (mm):"), + qOverload<double>(&OpticalDesign::laserBodyDiameterMmChanged), + &OpticalDesign::get_laserBodyDiameterMm, + &OpticalDesign::set_laserBodyDiameterMm, + MinValue{1.}, + MaxValue{100.}, + SingleStep{1.}, + laserGroup + ); + + addFormPair( + tr("Body Length (mm):"), + qOverload<double>(&OpticalDesign::laserBodyLengthMmChanged), + &OpticalDesign::get_laserBodyLengthMm, + &OpticalDesign::set_laserBodyLengthMm, + MinValue{1.}, + MaxValue{100.}, + SingleStep{1.}, + laserGroup + ); + + addFormPair( + tr("Angle (°):"), + qOverload<double>(&OpticalDesign::laserAngleDegreesChanged), + &OpticalDesign::get_laserAngleDegrees, + &OpticalDesign::set_laserAngleDegrees, + MinValue{1.}, + MaxValue{180.}, + SingleStep{1.}, + laserGroup + ); + addFormPair( + tr("Z Offest (mm):"), + qOverload<double>(&OpticalDesign::laserZOffsetMmChanged), + &OpticalDesign::get_laserZOffsetMm, + &OpticalDesign::set_laserZOffsetMm, + MinValue{-100.}, + MaxValue{100.}, + SingleStep{1.}, + laserGroup + ); + + addFormPair( + tr("Wall Thickness (mm):"), + qOverload<double>(&OpticalDesign::scannerBodyWallThicknessMmChanged), + &OpticalDesign::get_scannerBodyWallThicknessMm, + &OpticalDesign::set_scannerBodyWallThicknessMm, + MinValue{1.}, + MaxValue{30.}, + SingleStep{1.}, + scannerBodyGroup + ); + + addFormPair( + tr("Front Wall Offset (mm):"), + qOverload<double>(&OpticalDesign::scannerBodyFrontWallOffsetMmChanged), + &OpticalDesign::get_scannerBodyFrontWallOffsetMm, + &OpticalDesign::set_scannerBodyFrontWallOffsetMm, + MinValue{-50.}, + MaxValue{50.}, + SingleStep{1.}, + scannerBodyGroup ); addFormLabel( tr("Sensor/Lense Angle (°):"), qOverload<double>(&OpticalDesign::sensorLenseAngleDegreesChanged), - Decimals{3} + Decimals{3}, + resultsGroup ); addFormLabel( - tr("Actual Z Base (mm):"), - qOverload<double>(&OpticalDesign::actualZBaseMmChanged), - Decimals{2} + tr("FoV (YZ, V) (°):"), + qOverload<double>(&OpticalDesign::vFoVDegreesChanged), + Decimals{3}, + resultsGroup ); + // addFormLabel( + // tr("Actual Z Base (mm):"), + // qOverload<double>(&OpticalDesign::actualZBaseMmChanged), + // Decimals{2}, + // resultsGroup + // ); + + { + const auto actualZBaseTextLabel = new QLabel{centralWidget()}; + + connect( + m_design, + &OpticalDesign::actualZBaseTextChanged, + actualZBaseTextLabel, + &QLabel::setText + ); + + auto formLayout = qobject_cast<QFormLayout*>(resultsGroup->layout()); + Q_ASSERT(formLayout); + formLayout->addRow(tr("Actual Z Base (mm):"), actualZBaseTextLabel); + } + addFormLabel( tr("Actual Z Range (mm):"), qOverload<double>(&OpticalDesign::actualZRangeMmChanged), - Decimals{2} + Decimals{2}, + resultsGroup ); addFormLabel( tr("Lense-Sensor Distance (mm):"), qOverload<double>(&OpticalDesign::lenseSensorDistanceMmChanged), - Decimals{2} + Decimals{2}, + resultsGroup ); addFormLabel( tr("Front Sharp Distance (mm):"), qOverload<double>(&OpticalDesign::frontSharpDistanceMmChanged), - Decimals{2} + Decimals{2}, + resultsGroup ); addFormLabel( tr("Back Sharp Distance (mm):"), qOverload<double>(&OpticalDesign::backSharpDistanceMmChanged), - Decimals{2} + Decimals{2}, + resultsGroup ); addFormLabel( tr("Depth Of Field (mm):"), qOverload<double>(&OpticalDesign::depthOfFieldMmChanged), - Decimals{2} + Decimals{2}, + resultsGroup ); // graphics view |
