Skip to content
Open
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
166 changes: 163 additions & 3 deletions src/candle/frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ void frmMain::initUi()
ui->fraDropModification->setVisible(false);
ui->fraDropUser->setVisible(false);

// Default Speed Selection
ui->cboTraceSpeed->setCurrentIndex(1); // 0=Slow, 1=Medium, 2=Fast

// Dock widgets
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
Expand Down Expand Up @@ -3380,7 +3383,10 @@ void frmMain::saveSettings()

// Language
set.setValue("language", m_settings->language());


// Save Trace Z
set.setValue("heightmapTraceZ", ui->txtHeightMapTraceZ->value());

set.endGroup();
}

Expand Down Expand Up @@ -3570,7 +3576,10 @@ void frmMain::storeSettings()
void frmMain::restoreSettings()
{
auto set = m_storage.group("General");


// Restore Trace Z
ui->txtHeightMapTraceZ->setValue(set->value("heightmapTraceZ", 5.0).toDouble());

m_settingsLoading = true;

emit settingsAboutToLoad();
Expand Down Expand Up @@ -5995,4 +6004,155 @@ bool frmMain::actionTextLessThan(const QAction *a1, const QAction *a2)
QScriptValue frmMain::importExtension(QScriptContext *context, QScriptEngine *engine)
{
return engine->importExtension(context->argument(0).toString());
}
}

// =================================================================
// Emergency Stop Button
// =================================================================
void frmMain::on_cmdHeightMapStop_clicked()
{
// Immediate soft reset to halt all machine motion
grblReset();
}

// =================================================================
// Trace Border Function with Speed Control
// =================================================================
void frmMain::on_cmdHeightMapTrace_clicked()
{
if (!m_currentConnection || !m_currentConnection->isConnected()) return;

if (m_deviceState != DeviceIdle && m_deviceState != DeviceJog) {
QMessageBox::warning(this, tr("Safety Error"), tr("Device is busy. Please wait for IDLE state."));
return;
}

double x = ui->txtHeightMapBorderX->value();
double y = ui->txtHeightMapBorderY->value();
double w = ui->txtHeightMapBorderWidth->value();
double h = ui->txtHeightMapBorderHeight->value();
double safeZ = ui->txtHeightMapTraceZ->value();

// Validation: Ensure border area is defined
if (w <= 0 || h <= 0) {
QMessageBox::information(this, tr("HeightMap"), tr("Please define a valid border area first."));
return;
}

// Determine feed rate from UI selection (mm/min)
int speedIndex = ui->cboTraceSpeed->currentIndex();
double traceFeed;
switch (speedIndex) {
case 0: traceFeed = 300.0; break; // Slow
case 1: traceFeed = 800.0; break; // Medium
case 2: traceFeed = 2000.0; break; // Fast
default: traceFeed = 500.0;
}

QStringList cmds;
cmds << "G21 G90"; // Metric, Absolute Positioning
cmds << QString("G0 Z%1").arg(safeZ); // Retract to Safe Z
cmds << QString("G0 X%1 Y%2").arg(x).arg(y); // Move to starting corner

// Border tracing sequence
cmds << QString("G1 X%1 F%2").arg(x + w).arg(traceFeed);
cmds << QString("G1 Y%1").arg(y + h);
cmds << QString("G1 X%1").arg(x);
cmds << QString("G1 Y%1").arg(y);

sendCommands(cmds.join("\n"), -1);
}

// =================================================================
// Corner Navigation Helpers
// =================================================================

void frmMain::on_cmdCornerTL_clicked()
{
if (!m_currentConnection || !m_currentConnection->isConnected()) return;
if (m_deviceState != DeviceIdle && m_deviceState != DeviceJog) return;
if (ui->txtHeightMapBorderWidth->value() <= 0 || ui->txtHeightMapBorderHeight->value() <= 0) return;

double targetX = ui->txtHeightMapBorderX->value();
double targetY = ui->txtHeightMapBorderY->value() + ui->txtHeightMapBorderHeight->value();
double safeZ = ui->txtHeightMapTraceZ->value();

QStringList cmds;
cmds << "G21 G90" << QString("G0 Z%1").arg(safeZ) << QString("G0 X%1 Y%2").arg(targetX).arg(targetY);
sendCommands(cmds.join("\n"), -1);
}

void frmMain::on_cmdCornerTR_clicked()
{
if (!m_currentConnection || !m_currentConnection->isConnected()) return;
if (m_deviceState != DeviceIdle && m_deviceState != DeviceJog) return;
if (ui->txtHeightMapBorderWidth->value() <= 0 || ui->txtHeightMapBorderHeight->value() <= 0) return;

double targetX = ui->txtHeightMapBorderX->value() + ui->txtHeightMapBorderWidth->value();
double targetY = ui->txtHeightMapBorderY->value() + ui->txtHeightMapBorderHeight->value();
double safeZ = ui->txtHeightMapTraceZ->value();

QStringList cmds;
cmds << "G21 G90" << QString("G0 Z%1").arg(safeZ) << QString("G0 X%1 Y%2").arg(targetX).arg(targetY);
sendCommands(cmds.join("\n"), -1);
}

void frmMain::on_cmdCornerBL_clicked()
{
if (!m_currentConnection || !m_currentConnection->isConnected()) return;
if (m_deviceState != DeviceIdle && m_deviceState != DeviceJog) return;
// BL only needs X and Y, but we check width/height to ensure map is initialized
if (ui->txtHeightMapBorderWidth->value() <= 0 || ui->txtHeightMapBorderHeight->value() <= 0) return;

double targetX = ui->txtHeightMapBorderX->value();
double targetY = ui->txtHeightMapBorderY->value();
double safeZ = ui->txtHeightMapTraceZ->value();

QStringList cmds;
cmds << "G21 G90" << QString("G0 Z%1").arg(safeZ) << QString("G0 X%1 Y%2").arg(targetX).arg(targetY);
sendCommands(cmds.join("\n"), -1);
}

void frmMain::on_cmdCornerBR_clicked()
{
if (!m_currentConnection || !m_currentConnection->isConnected()) return;
if (m_deviceState != DeviceIdle && m_deviceState != DeviceJog) return;
if (ui->txtHeightMapBorderWidth->value() <= 0 || ui->txtHeightMapBorderHeight->value() <= 0) return;

double targetX = ui->txtHeightMapBorderX->value() + ui->txtHeightMapBorderWidth->value();
double targetY = ui->txtHeightMapBorderY->value();
double safeZ = ui->txtHeightMapTraceZ->value();

QStringList cmds;
cmds << "G21 G90" << QString("G0 Z%1").arg(safeZ) << QString("G0 X%1 Y%2").arg(targetX).arg(targetY);
sendCommands(cmds.join("\n"), -1);
}

// =================================================================
// Move to Center Function
// =================================================================
void frmMain::on_cmdHeightMapCenter_clicked()
{
if (!m_currentConnection || !m_currentConnection->isConnected()) return;
if (m_deviceState != DeviceIdle && m_deviceState != DeviceJog) return;

double x = ui->txtHeightMapBorderX->value();
double y = ui->txtHeightMapBorderY->value();
double w = ui->txtHeightMapBorderWidth->value();
double h = ui->txtHeightMapBorderHeight->value();
double safeZ = ui->txtHeightMapTraceZ->value();

if (w <= 0 || h <= 0) return;

double centerX = x + (w / 2.0);
double centerY = y + (h / 2.0);

QStringList cmds;
cmds << "G21 G90";
cmds << QString("G0 Z%1").arg(safeZ);
cmds << QString("G0 X%1 Y%2").arg(centerX).arg(centerY);

sendCommands(cmds.join("\n"), -1);
}

#include "frmmain.moc"
7 changes: 7 additions & 0 deletions src/candle/frmmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ private slots:
void on_cmdHeightMapLoad_clicked();
void on_cmdHeightMapOrigin_clicked();
void on_cmdHeightMapBorderAuto_clicked();
void on_cmdHeightMapTrace_clicked();
void on_cmdHeightMapOriginTool_clicked();
void on_cmdYPlus_pressed();
void on_cmdYPlus_released();
Expand All @@ -244,6 +245,12 @@ private slots:
void on_mnuViewPanels_aboutToShow();
void on_dockVisualizer_visibilityChanged(bool visible);
void on_sliProgram_valueChanged(int value);
void on_cmdCornerTL_clicked();
void on_cmdCornerTR_clicked();
void on_cmdCornerBL_clicked();
void on_cmdCornerBR_clicked();
void on_cmdHeightMapStop_clicked();
void on_cmdHeightMapCenter_clicked();

void onConnectionDataReceived(QString data);
void onConnectionErrorOccurred(QString error);
Expand Down
Loading