Skip to content

Commit

Permalink
Saving of transformed file added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denvi committed Dec 1, 2015
1 parent e99edc0 commit 01ebf33
Show file tree
Hide file tree
Showing 9 changed files with 642 additions and 604 deletions.
Binary file modified bin/grblControl
Binary file not shown.
Binary file modified bin/grblControl.exe
Binary file not shown.
41 changes: 26 additions & 15 deletions frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ void frmMain::updateControlsState() {
ui->cmdFileAbort->ensurePolished();

// Heightmap

m_heightMapBorderDrawer.setVisible(ui->chkHeightMapBorderShow->isChecked() && m_heightMapMode);
m_heightMapGridDrawer.setVisible(ui->chkHeightMapGridShow->isChecked() && m_heightMapMode);
m_heightMapInterpolationDrawer.setVisible(ui->chkHeightMapInterpolationShow->isChecked() && m_heightMapMode);
Expand All @@ -520,6 +519,8 @@ void frmMain::updateControlsState() {
ui->cmdFileSend->setText(m_heightMapMode ? tr("Probe") : tr("Send"));

ui->chkHeightMapUse->setEnabled(!m_heightMapMode && !ui->txtHeightMap->text().isEmpty());

ui->actFileSaveTransformedAs->setVisible(ui->chkHeightMapUse->isChecked());
}

void frmMain::openPort()
Expand Down Expand Up @@ -2134,36 +2135,44 @@ void frmMain::on_cmdClearConsole_clicked()
ui->txtConsole->clear();
}

bool frmMain::saveProgramToFile(QString fileName)
bool frmMain::saveProgramToFile(QString fileName, GCodeTableModel *model)
{
QFile file(fileName);
QDir dir;

qDebug() << "Saving program";

m_fileChanged = false;

if (file.exists()) dir.remove(file.fileName());

if (!file.open(QIODevice::WriteOnly)) return false;

QTextStream textStream(&file);

for (int i = 0; i < m_programModel.rowCount() - 1; i++) {
textStream << m_programModel.data(m_programModel.index(i, 1)).toString() << "\r\n";
for (int i = 0; i < model->rowCount() - 1; i++) {
textStream << model->data(model->index(i, 1)).toString() << "\r\n";
}

file.close();

return true;
}

void frmMain::on_actFileSaveTransformedAs_triggered()
{
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), "", tr("G-Code files (*.nc *.ncc *.tap *.txt)")));

if (!fileName.isEmpty()) {
saveProgramToFile(fileName, &m_programHeightmapModel);
}
}

void frmMain::on_actFileSaveAs_triggered()
{
if (!m_heightMapMode) {

QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), "", tr("G-Code files (*.nc *.ncc *.tap *.txt)")));

if (!fileName.isEmpty()) if (saveProgramToFile(fileName)) {
if (!fileName.isEmpty()) if (saveProgramToFile(fileName, &m_programModel)) {
m_programFileName = fileName;
m_fileChanged = false;

addRecentFile(fileName);
updateRecentFilesMenu();
Expand All @@ -2181,9 +2190,6 @@ void frmMain::on_actFileSaveAs_triggered()
addRecentHeightmap(fileName);
updateRecentFilesMenu();

// addRecentFile(fileName);
// updateRecentFilesMenu();

updateControlsState();
}
}
Expand All @@ -2193,7 +2199,10 @@ void frmMain::on_actFileSave_triggered()
{
if (!m_heightMapMode) {
// G-code saving
if (m_programFileName.isEmpty()) on_actFileSaveAs_triggered(); else saveProgramToFile(m_programFileName);
if (m_programFileName.isEmpty()) on_actFileSaveAs_triggered(); else {
saveProgramToFile(m_programFileName, &m_programModel);
m_fileChanged = false;
}
} else {
// Height map saving
if (m_heightMapFileName.isEmpty()) on_actFileSaveAs_triggered(); else saveHeightMap(m_heightMapFileName);
Expand Down Expand Up @@ -3230,8 +3239,7 @@ void frmMain::on_chkHeightMapUse_clicked(bool checked)

// Update parser
m_currentDrawer = m_codeDrawer;
updateParser();

updateParser();
} else {
QByteArray headerState = ui->tblProgram->horizontalHeader()->saveState();
ui->tblProgram->setModel(NULL);
Expand All @@ -3249,6 +3257,9 @@ void frmMain::on_chkHeightMapUse_clicked(bool checked)
updateParser();
m_fileChanged = fileChanged;
}

// Update menu
ui->actFileSaveTransformedAs->setVisible(checked);
}

QList<LineSegment*> frmMain::subdivideSegment(LineSegment* segment)
Expand Down
4 changes: 2 additions & 2 deletions frmmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private slots:
void on_cmdClearConsole_clicked();
void on_actFileSaveAs_triggered();
void on_actFileSave_triggered();
void on_actFileSaveTransformedAs_triggered();
void on_cmdTop_clicked();
void on_cmdFront_clicked();
void on_cmdLeft_clicked();
Expand Down Expand Up @@ -148,7 +149,6 @@ private slots:
void on_chkHeightMapUse_clicked(bool checked);
void on_cmdHeightMapCreate_clicked();
void on_cmdHeightMapBorderAuto_clicked();

void on_cmdFileAbort_clicked();

protected:
Expand Down Expand Up @@ -291,7 +291,7 @@ private slots:
bool dataIsReset(QString data);

QTime updateProgramEstimatedTime(QList<LineSegment *> lines);
bool saveProgramToFile(QString fileName);
bool saveProgramToFile(QString fileName, GCodeTableModel *model);
QString feedOverride(QString command);

bool eventFilter(QObject *obj, QEvent *event);
Expand Down
14 changes: 10 additions & 4 deletions frmmain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1592,9 +1592,9 @@ QToolButton:checked { /* all types of tool button */
<property name="geometry">
<rect>
<x>0</x>
<y>-305</y>
<width>228</width>
<height>603</height>
<y>0</y>
<width>231</width>
<height>638</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -2686,7 +2686,7 @@ padding-right: 8;</string>
<x>0</x>
<y>0</y>
<width>913</width>
<height>21</height>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="mnuFile">
Expand All @@ -2706,6 +2706,7 @@ padding-right: 8;</string>
<addaction name="separator"/>
<addaction name="actFileSave"/>
<addaction name="actFileSaveAs"/>
<addaction name="actFileSaveTransformedAs"/>
<addaction name="separator"/>
<addaction name="actFileExit"/>
</widget>
Expand Down Expand Up @@ -2765,6 +2766,11 @@ padding-right: 8;</string>
<string>&amp;Clear</string>
</property>
</action>
<action name="actFileSaveTransformedAs">
<property name="text">
<string>Save &amp;transformed as...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
Loading

0 comments on commit 01ebf33

Please sign in to comment.