Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions src/frmmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions src/frmmain_heightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading