Skip to content

Commit

Permalink
Allow outputing GCode with CRLF Windows line endings. #286
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoffland committed Feb 9, 2019
1 parent f01f15a commit 0554b96
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
2 changes: 1 addition & 1 deletion qt/donate_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</size>
</property>
<property name="windowTitle">
<string>Donate</string>
<string>Welcome</string>
</property>
<property name="windowIcon">
<iconset resource="camotics.qrc">
Expand Down
48 changes: 43 additions & 5 deletions qt/export_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>225</width>
<height>346</height>
<height>435</height>
</rect>
</property>
<property name="minimumSize">
Expand All @@ -21,8 +21,8 @@
</property>
<property name="maximumSize">
<size>
<width>225</width>
<height>346</height>
<width>227</width>
<height>435</height>
</size>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -80,6 +80,31 @@
</attribute>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<item>
<widget class="QCheckBox" name="crlfCheckBox">
<property name="text">
<string>Windows line endings</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QRadioButton" name="surfaceRadioButton">
<property name="text">
Expand All @@ -106,7 +131,7 @@
<number>4</number>
</property>
<property name="leftMargin">
<number>30</number>
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_3">
Expand Down Expand Up @@ -163,7 +188,7 @@
<number>4</number>
</property>
<property name="leftMargin">
<number>30</number>
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_2">
Expand Down Expand Up @@ -220,6 +245,19 @@
</property>
</spacer>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
22 changes: 21 additions & 1 deletion src/camotics/qt/ExportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@

#include "ui_export_dialog.h"

#include <QSettings>

using namespace CAMotics;


ExportDialog::ExportDialog(QWidget *parent) :
QDialog(parent), ui(new Ui::ExportDialog) {
ui->setupUi(this);
#ifdef _WIN32
bool crlf = true;
#else
bool crlf = false;
#endif

crlf = QSettings().value("Settings/GCode/CRLF", crlf).toBool();
ui->crlfCheckBox->setChecked(crlf);
}


Expand All @@ -53,7 +63,12 @@ int ExportDialog::exec() {
}
}

return QDialog::exec();
int ret = QDialog::exec();

if (ret == QDialog::Accepted)
QSettings().setValue("Settings/GCode/CRLF", crlfSelected());

return ret;
}


Expand All @@ -76,6 +91,11 @@ void ExportDialog::enableSimData(bool enable) {
}


bool ExportDialog::crlfSelected() const {
return ui->crlfCheckBox->isChecked();
}


bool ExportDialog::surfaceSelected() const {
return ui->surfaceRadioButton->isChecked();
}
Expand Down
1 change: 1 addition & 0 deletions src/camotics/qt/ExportDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace CAMotics {
bool gcodeSelected() const;
bool simDataSelected() const;

bool crlfSelected() const;
bool binarySTLSelected() const;
bool compactJSONSelected() const;
bool withCutSurfaceSelected() const;
Expand Down
8 changes: 7 additions & 1 deletion src/camotics/qt/QtWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,13 @@ void QtWin::exportData() {
surface->writeSTL(*stream, binary, "CAMotics Surface", hash);

} else if (exportDialog.gcodeSelected()) {
stream->write(&gcode->front(), gcode->size());
if (exportDialog.crlfSelected()) {
for (unsigned i = 0; i < gcode->size(); i++) {
if ((*gcode)[i] == '\n') stream->put('\r');
stream->put((*gcode)[i]);
}

} else stream->write(&gcode->front(), gcode->size());

} else {
JSON::Writer writer(*stream, 0, exportDialog.compactJSONSelected());
Expand Down

0 comments on commit 0554b96

Please sign in to comment.