From 7bf3a9f0af35e8339ad821e05c3b64a29b6cf303 Mon Sep 17 00:00:00 2001 From: Albert Galimov Date: Tue, 7 Oct 2025 22:19:11 +0300 Subject: [PATCH] Offer using heightmap when such data is loaded but not used --- src/frmmain.cpp | 22 ++++++++++++++++++++ src/frmmain.h | 4 ++++ src/frmmain_heightmap.cpp | 44 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/src/frmmain.cpp b/src/frmmain.cpp index 6a934e9..27a1895 100644 --- a/src/frmmain.cpp +++ b/src/frmmain.cpp @@ -949,6 +949,17 @@ void frmMain::on_cmdFileSend_clicked() return; } + // Heightmap preflight + switch (maybePromptEnableHeightmapBeforeRun()) + { + case HmEnableButDoNotRun: + return; // user chose to enable heightmap; do not start now + case HmCancel: + return; // user cancelled + case HmProceedRun: + break; // continue to run + } + on_cmdFileReset_clicked(); m_startTime.start(); @@ -988,6 +999,17 @@ void frmMain::onActSendFromLineTriggered() if (m_currentModel->rowCount() == 1) return; + // Heightmap preflight + switch (maybePromptEnableHeightmapBeforeRun()) + { + case HmEnableButDoNotRun: + return; // user chose to enable heightmap; do not start now + case HmCancel: + return; // user cancelled + case HmProceedRun: + break; // continue + } + //Line to start from int commandIndex = ui->tblProgram->currentIndex().row(); diff --git a/src/frmmain.h b/src/frmmain.h index fea0281..5c3d799 100644 --- a/src/frmmain.h +++ b/src/frmmain.h @@ -318,6 +318,10 @@ private slots: void restoreParserState(); void storeOffsets(); void restoreOffsets(); + // Heightmap preflight: check before starting program + bool hasHeightmapData(); + enum HeightmapPreflightResult { HmProceedRun, HmEnableButDoNotRun, HmCancel }; + HeightmapPreflightResult maybePromptEnableHeightmapBeforeRun(); bool isGCodeFile(QString fileName); bool isHeightmapFile(QString fileName); bool compareCoordinates(double x, double y, double z); diff --git a/src/frmmain_heightmap.cpp b/src/frmmain_heightmap.cpp index 1d11f42..fa53a1e 100644 --- a/src/frmmain_heightmap.cpp +++ b/src/frmmain_heightmap.cpp @@ -52,6 +52,50 @@ void frmMain::on_grpHeightMap_toggled(bool arg1) ui->widgetHeightMap->setVisible(arg1); } +bool frmMain::hasHeightmapData() +{ + // Heightmap considered present if a heightmap file name is set or any cell contains non-NaN data + if (!ui->txtHeightMap->text().isEmpty()) return true; + for (int i = 0; i < m_heightMapModel.rowCount(); i++) + for (int j = 0; j < m_heightMapModel.columnCount(); j++) + if (!qIsNaN(m_heightMapModel.data(m_heightMapModel.index(i, j), Qt::UserRole).toDouble())) + return true; + return false; +} + +frmMain::HeightmapPreflightResult frmMain::maybePromptEnableHeightmapBeforeRun() +{ + // Only applies when NOT in heightmap probing mode and when heightmap exists but is not enabled + if (m_heightMapMode) return HmProceedRun; + if (!hasHeightmapData()) return HmProceedRun; + if (ui->chkHeightMapUse->isChecked()) return HmProceedRun; + + QMessageBox box(this); + box.setIcon(QMessageBox::Question); + box.setText(tr("Heightmap is available but not enabled. Apply heightmap?")); + box.setWindowTitle(qApp->applicationDisplayName()); + QPushButton* yesBtn = box.addButton(tr("Yes"), QMessageBox::AcceptRole); + QPushButton* noBtn = box.addButton(tr("No"), QMessageBox::DestructiveRole); + QPushButton* cancelBtn = box.addButton(tr("Cancel"), QMessageBox::RejectRole); + box.setDefaultButton(yesBtn); + box.exec(); + + if (box.clickedButton() == yesBtn) + { + ui->chkHeightMapUse->setChecked(true); + on_chkHeightMapUse_clicked(true); + return HmEnableButDoNotRun; + } + else if (box.clickedButton() == noBtn) + { + return HmProceedRun; + } + else + { + return HmCancel; + } +} + QRectF frmMain::borderRectFromTextboxes() { QRectF rect;