Skip to content

Commit 9bcc35b

Browse files
PSIAltSchildkroet
authored andcommitted
Offer using heightmap when such data is loaded but not used
1 parent 249ed7f commit 9bcc35b

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎src/frmmain.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,17 @@ void frmMain::on_cmdFileSend_clicked()
949949
return;
950950
}
951951

952+
// Heightmap preflight
953+
switch (maybePromptEnableHeightmapBeforeRun())
954+
{
955+
case HmEnableButDoNotRun:
956+
return; // user chose to enable heightmap; do not start now
957+
case HmCancel:
958+
return; // user cancelled
959+
case HmProceedRun:
960+
break; // continue to run
961+
}
962+
952963
on_cmdFileReset_clicked();
953964

954965
m_startTime.start();
@@ -988,6 +999,17 @@ void frmMain::onActSendFromLineTriggered()
988999
if (m_currentModel->rowCount() == 1)
9891000
return;
9901001

1002+
// Heightmap preflight
1003+
switch (maybePromptEnableHeightmapBeforeRun())
1004+
{
1005+
case HmEnableButDoNotRun:
1006+
return; // user chose to enable heightmap; do not start now
1007+
case HmCancel:
1008+
return; // user cancelled
1009+
case HmProceedRun:
1010+
break; // continue
1011+
}
1012+
9911013
//Line to start from
9921014
int commandIndex = ui->tblProgram->currentIndex().row();
9931015

‎src/frmmain.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ private slots:
318318
void restoreParserState();
319319
void storeOffsets();
320320
void restoreOffsets();
321+
// Heightmap preflight: check before starting program
322+
bool hasHeightmapData();
323+
enum HeightmapPreflightResult { HmProceedRun, HmEnableButDoNotRun, HmCancel };
324+
HeightmapPreflightResult maybePromptEnableHeightmapBeforeRun();
321325
bool isGCodeFile(QString fileName);
322326
bool isHeightmapFile(QString fileName);
323327
bool compareCoordinates(double x, double y, double z);

‎src/frmmain_heightmap.cpp‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,50 @@ void frmMain::on_grpHeightMap_toggled(bool arg1)
5757
}
5858
}
5959

60+
bool frmMain::hasHeightmapData()
61+
{
62+
// Heightmap considered present if a heightmap file name is set or any cell contains non-NaN data
63+
if (!ui->txtHeightMap->text().isEmpty()) return true;
64+
for (int i = 0; i < m_heightMapModel.rowCount(); i++)
65+
for (int j = 0; j < m_heightMapModel.columnCount(); j++)
66+
if (!qIsNaN(m_heightMapModel.data(m_heightMapModel.index(i, j), Qt::UserRole).toDouble()))
67+
return true;
68+
return false;
69+
}
70+
71+
frmMain::HeightmapPreflightResult frmMain::maybePromptEnableHeightmapBeforeRun()
72+
{
73+
// Only applies when NOT in heightmap probing mode and when heightmap exists but is not enabled
74+
if (m_heightMapMode) return HmProceedRun;
75+
if (!hasHeightmapData()) return HmProceedRun;
76+
if (ui->chkHeightMapUse->isChecked()) return HmProceedRun;
77+
78+
QMessageBox box(this);
79+
box.setIcon(QMessageBox::Question);
80+
box.setText(tr("Heightmap is available but not enabled. Apply heightmap?"));
81+
box.setWindowTitle(qApp->applicationDisplayName());
82+
QPushButton* yesBtn = box.addButton(tr("Yes"), QMessageBox::AcceptRole);
83+
QPushButton* noBtn = box.addButton(tr("No"), QMessageBox::DestructiveRole);
84+
QPushButton* cancelBtn = box.addButton(tr("Cancel"), QMessageBox::RejectRole);
85+
box.setDefaultButton(yesBtn);
86+
box.exec();
87+
88+
if (box.clickedButton() == yesBtn)
89+
{
90+
ui->chkHeightMapUse->setChecked(true);
91+
on_chkHeightMapUse_clicked(true);
92+
return HmEnableButDoNotRun;
93+
}
94+
else if (box.clickedButton() == noBtn)
95+
{
96+
return HmProceedRun;
97+
}
98+
else
99+
{
100+
return HmCancel;
101+
}
102+
}
103+
60104
QRectF frmMain::borderRectFromTextboxes()
61105
{
62106
QRectF rect;

0 commit comments

Comments
 (0)