diff --git a/src/atelierui.rc b/src/atelierui.rc --- a/src/atelierui.rc +++ b/src/atelierui.rc @@ -12,21 +12,13 @@ - - - - - Run - - - @@ -37,11 +29,6 @@ - - - - - diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -19,9 +19,8 @@ #include #include -#include #include -#include + namespace Ui { class MainWindow; @@ -37,24 +36,10 @@ private: Ui::MainWindow *ui; - AtCore core; - QStringList firmwaresList; - QUrl fileName; - LogWidget *logWidget; - QAction *_connect; - void initConnectsToAtCore(); - void initWidgets(); + QUrl m_fileName; void setupActions(); void openFile(); - void printFile(); - void pausePrint(); - void stopPrint(); - void checkReceivedCommand(const QByteArray &message); - void checkPushedCommands(QByteArray bmsg); - void handlePrinterStatusChanged(AtCore::STATES newState); - void checkTemperature(uint sensorType, uint number, uint temp); - void axisControlClicked(QChar axis, int value); - void toggleDockTitles(bool checked); + void newConnection(const QString& port, const QMap& profile); signals: void extruderCountChanged(int count); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -23,363 +23,82 @@ #include #include #include -#include -#include #include #include - +#include MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); - logWidget = new LogWidget; setupActions(); - initConnectsToAtCore(); - initWidgets(); - setCentralWidget(nullptr); } MainWindow::~MainWindow() { delete ui; } -void MainWindow::initConnectsToAtCore() -{ - // Handle AtCore status change - connect(&core, &AtCore::stateChanged, this, &MainWindow::handlePrinterStatusChanged); - - // If the number of extruders from the printer change, we need to update the radiobuttons on the widget - connect(this, &MainWindow::extruderCountChanged, ui->bedExtWidget, &BedExtruderWidget::setExtruderCount); - - // Bed and Extruder temperatures management - connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &core, &AtCore::setBedTemp); - connect(ui->bedExtWidget, &BedExtruderWidget::extTemperatureChanged, &core, &AtCore::setExtruderTemp); - - // Connect AtCore temperatures changes on Atelier Plot - connect(&core.temperature(), &Temperature::bedTemperatureChanged, [ = ](float temp) { - checkTemperature(0x00, 0, temp); - ui->plotWidget->appendPoint(i18n("Actual Bed"), temp); - ui->plotWidget->update(); - ui->bedExtWidget->updateBedTemp(temp); - }); - connect(&core.temperature(), &Temperature::bedTargetTemperatureChanged, [ = ](float temp) { - checkTemperature(0x01, 0, temp); - ui->plotWidget->appendPoint(i18n("Target Bed"), temp); - ui->plotWidget->update(); - ui->bedExtWidget->updateBedTargetTemp(temp); - }); - connect(&core.temperature(), &Temperature::extruderTemperatureChanged, [ = ](float temp) { - checkTemperature(0x02, 0, temp); - ui->plotWidget->appendPoint(i18n("Actual Ext.1"), temp); - ui->plotWidget->update(); - ui->bedExtWidget->updateExtTemp(temp); - }); - connect(&core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ = ](float temp) { - checkTemperature(0x03, 0, temp); - ui->plotWidget->appendPoint(i18n("Target Ext.1"), temp); - ui->plotWidget->update(); - ui->bedExtWidget->updateExtTargetTemp(temp); - }); - - connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ = ](QString command) { - logWidget->addLog("Push " + command); - core.pushCommand(command); - }); - - // Fan, Flow and Speed management - connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &core, &AtCore::setFanSpeed); - connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &core, &AtCore::setFlowRate); - connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &core, &AtCore::setPrinterSpeed); - connect(ui->axisViewWidget, &AxisControl::clicked, this, &MainWindow::axisControlClicked); - -} - -void MainWindow::initWidgets() -{ - // Disable Toolbox to prevent the user to mess up without a printer being connected - ui->controlDockWidget->setDisabled(true); - ui->axisDockWidget->setDisabled(true); - - // This dock is of Printing Progress. It only need to be show while printing - ui->printProgressDockWidget->setVisible(false); - - ui->logDockWidget->setWidget(logWidget); - ui->statusBar->addWidget(ui->statusBarWidget); - - ui->homeAllPB->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon)); - ui->homeXPB->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon)); - ui->homeYPB->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon)); - ui->homeZPB->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon)); - - tabifyDockWidget(ui->axisDockWidget, ui->controlDockWidget); - tabifyDockWidget(ui->view3DdockWidget, ui->gcodeDockWidget); - tabifyDockWidget(ui->view3DdockWidget, ui->videoDockWidget); -} - void MainWindow::setupActions() { // Actions for the Toolbar QAction *action; action = actionCollection()->addAction(QStringLiteral("open_gcode")); action->setText(i18n("&Open GCode")); connect(action, &QAction::triggered, this, &MainWindow::openFile); - _connect = actionCollection()->addAction(QStringLiteral("connect")); - _connect->setText(i18n("&Connect")); - _connect->setCheckable(true); - connect(_connect, &QAction::toggled, [ = ](bool checked) { - if (checked) { + action = actionCollection()->addAction(QStringLiteral("connect")); + action->setText(i18n("&Connect")); + connect(action, &QAction::triggered, [ & ]{ std::unique_ptr csd(new ConnectSettingsDialog); connect(csd.get(), &ConnectSettingsDialog::startConnection, [ & ](QString port, QMap data) { - core.initSerial(port, data["bps"].toInt()); + newConnection(port, data); }); csd->exec(); - } else { - core.closeConnection(); - _connect->setText(i18n("&Connect")); - ui->bedExtWidget->stopHeating(); - core.setState(AtCore::DISCONNECTED); - } - }); - - connect(ui->homeAllPB, &QPushButton::clicked, [=]{ - core.home(); - }); - - connect(ui->homeXPB, &QPushButton::clicked, [=]{ - core.home(AtCore::X); - }); - - connect(ui->homeYPB, &QPushButton::clicked, [=]{ - core.home(AtCore::Y); - }); - - connect(ui->homeZPB, &QPushButton::clicked, [=]{ - core.home(AtCore::Z); }); action = actionCollection()->addAction(QStringLiteral("profiles")); action->setText(i18n("&Profiles")); connect(action, &QAction::triggered, [ & ] { - std::unique_ptr pd(new ProfilesDialog(core.availableFirmwarePlugins(),core.portSpeeds())); + std::unique_ptr pd(new ProfilesDialog(QStringList(),QStringList())); pd->exec(); }); - action = actionCollection()->addAction(QStringLiteral("print")); - action->setText(i18n("&Print")); - connect(action, &QAction::triggered, this, &MainWindow::printFile); - - action = actionCollection()->addAction(QStringLiteral("pause")); - action->setText(i18n("&Pause")); - connect(action, &QAction::triggered, this, &MainWindow::pausePrint); - - action = actionCollection()->addAction(QStringLiteral("stop")); - action->setText(i18n("&Stop")); - connect(action, &QAction::triggered, this, &MainWindow::stopPrint); - #ifdef Q_OS_LINUX //only set icons from theme on linux actionCollection()->action(QStringLiteral("profiles"))->setIcon(QIcon::fromTheme("emblem-favorite")); #endif //use style's standardIcon for the icons we can. actionCollection()->action(QStringLiteral("open_gcode"))->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)); - actionCollection()->action(QStringLiteral("print"))->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - actionCollection()->action(QStringLiteral("pause"))->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); - actionCollection()->action(QStringLiteral("stop"))->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); - - // Actions for the Docks - action = actionCollection()->addAction(QStringLiteral("dock_labels")); - action->setText(i18n("&Show Dock Labels")); - action->setCheckable(true); - action->setChecked(true); - connect(action, &QAction::triggered, [=](bool checked){ - toggleDockTitles(checked); - }); - - action = actionCollection()->addAction(QStringLiteral("3d"), ui->view3DdockWidget->toggleViewAction()); - action->setText(i18n("&3DView")); - - action = actionCollection()->addAction(QStringLiteral("gcode"), ui->gcodeDockWidget->toggleViewAction()); - action->setText(i18n("&GCode")); action = KStandardAction::quit(qApp, SLOT(quit()), actionCollection()); - // Plot - action = actionCollection()->addAction(QStringLiteral("plot"), ui->plotDockWidget->toggleViewAction()); - action->setText(i18n("Temperature Timeline")); - - action = actionCollection()->addAction(QStringLiteral("controller"), ui->controlDockWidget->toggleViewAction()); - action->setText(i18n("Controller")); - - action = actionCollection()->addAction(QStringLiteral("axis"), ui->axisDockWidget->toggleViewAction()); - action->setText(i18n("Axis")); - - action = actionCollection()->addAction(QStringLiteral("video"), ui->videoDockWidget->toggleViewAction()); - action->setText(i18n("Video Monitor")); - - action = actionCollection()->addAction(QStringLiteral("log"), ui->logDockWidget->toggleViewAction()); - action->setText(i18n("Log")); - setupGUI(Default, ":/atelierui"); } void MainWindow::openFile() { QUrl fileNameFromDialog = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"), QDir::homePath(), i18n("GCode (*.gco *.gcode)")); if (!fileNameFromDialog.isEmpty()) { - fileName = fileNameFromDialog; - ui->gcodeEditorWidget->loadFile(fileName); + m_fileName = fileNameFromDialog; + ui->gcodeEditorWidget->loadFile(m_fileName); guiFactory()->addClient(ui->gcodeEditorWidget->gcodeView()); - ui->view3DWidget->drawModel(fileName.toString()); - } -} - -void MainWindow::printFile() -{ - if (!fileName.isEmpty() && (core.state() == AtCore::IDLE)) { - QString f = fileName.toLocalFile(); - core.print(f); - } -} - -void MainWindow::pausePrint() -{ - core.pause(QString()); -} - -void MainWindow::stopPrint() -{ - core.stop(); -} - -void MainWindow::handlePrinterStatusChanged(AtCore::STATES newState) -{ - QString stateString; - switch (newState) { - case AtCore::CONNECTING: { - stateString = i18n("Connecting..."); - connect(&core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); - connect(core.serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); - } break; - case AtCore::IDLE: { - stateString = i18n("Connected to ") + core.serial()->portName(); - ui->controlDockWidget->setEnabled(true); - ui->axisDockWidget->setEnabled(true); - emit extruderCountChanged(core.extruderCount()); - logWidget->addLog(i18n("Serial connected")); - _connect->setText(i18n("&Disconnect")); - } break; - case AtCore::DISCONNECTED: { - stateString = i18n("Not Connected"); - ui->controlDockWidget->setEnabled(false); - ui->axisDockWidget->setEnabled(false); - disconnect(&core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); - disconnect(core.serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); - logWidget->addLog(i18n("Serial disconnected")); - - } break; - case AtCore::STARTPRINT: { - stateString = i18n("Starting Print"); - ui->printProgressDockWidget->setVisible(true); - connect(&core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); - } break; - case AtCore::FINISHEDPRINT: { - stateString = i18n("Finished Print"); - ui->printProgressDockWidget->setVisible(false); - disconnect(&core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); - } break; - case AtCore::BUSY: { - stateString = i18n("Printing"); - } break; - case AtCore::PAUSE: { - stateString = i18n("Paused"); - } break; - case AtCore::STOP: { - stateString = i18n("Stoping Print"); - } break; - case AtCore::ERRORSTATE: { - stateString = i18n("Error"); - } break; - } - ui->lblState->setText(stateString); -} - -void MainWindow::checkTemperature(uint sensorType, uint number, uint temp) -{ - QString msg; - switch (sensorType) { - case 0x00: // bed - msg = QString::fromLatin1("Bed Temperature "); - break; - - case 0x01: // bed target - msg = QString::fromLatin1("Bed Target Temperature "); - break; - - case 0x02: // extruder - msg = QString::fromLatin1("Extruder Temperature "); - break; - - case 0x03: // extruder target - msg = QString::fromLatin1("Extruder Target Temperature "); - break; - - case 0x04: // enclosure - msg = QString::fromLatin1("Enclosure Temperature "); - break; - - case 0x05: // enclosure target - msg = QString::fromLatin1("Enclosure Target Temperature "); - break; + ui->view3DWidget->drawModel(m_fileName.toString()); } - - msg.append(QString::fromLatin1("[%1] : %2")); - msg = msg.arg(QString::number(number)) - .arg(QString::number(temp)); - - logWidget->addRLog(msg); } -void MainWindow::checkReceivedCommand(const QByteArray &message) +void MainWindow::newConnection(const QString& port, const QMap& profile) { - logWidget->addRLog(QString::fromUtf8(message)); -} - -void MainWindow::checkPushedCommands(QByteArray bmsg) -{ - QString msg = QString::fromUtf8(bmsg); - QRegExp _newLine(QChar::fromLatin1('\n')); - QRegExp _return(QChar::fromLatin1('\r')); - msg.replace(_newLine, QStringLiteral("\\n")); - msg.replace(_return, QStringLiteral("\\r")); - logWidget->addSLog(msg); -} - -void MainWindow::axisControlClicked(QChar axis, int value) -{ - core.setRelativePosition(); - core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); - core.setAbsolutePosition(); -} - -void MainWindow::toggleDockTitles(bool checked) -{ - if(checked){ - delete ui->axisDockWidget->titleBarWidget(); - delete ui->view3DdockWidget->titleBarWidget(); - delete ui->plotDockWidget->titleBarWidget(); - delete ui->logDockWidget->titleBarWidget(); - delete ui->controlDockWidget->titleBarWidget(); - delete ui->gcodeDockWidget->titleBarWidget(); - }else{ - ui->axisDockWidget->setTitleBarWidget(new QWidget()); - ui->view3DdockWidget->setTitleBarWidget(new QWidget()); - ui->plotDockWidget->setTitleBarWidget(new QWidget()); - ui->logDockWidget->setTitleBarWidget(new QWidget()); - ui->controlDockWidget->setTitleBarWidget(new QWidget()); - ui->gcodeDockWidget->setTitleBarWidget(new QWidget()); + const int tabs = ui->tabWidget->count(); + if(tabs == 1){ + auto instance = qobject_cast(ui->tabWidget->currentWidget()); + if(!instance->connected()){ + instance->startConnection(port, profile); + return; + } } + auto newInstance = new AtCoreInstanceWidget(); + ui->tabWidget->addTab(newInstance, QString::number(tabs+1)); + newInstance->startConnection(port, profile); } diff --git a/src/mainwindow.ui b/src/mainwindow.ui --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -14,7 +14,58 @@ Atelier - + + + + + 0 + + + + + 0 + 0 + 233 + 285 + + + + Page 1 + + + + + Page + + + + + + 0 + 0 + 233 + 285 + + + + Page 2 + + + + + + + + 0 + + + + Tab 1 + + + + + @@ -98,197 +149,22 @@ - - - Edit &GCode - - - 1 - - - - - - Cont&roller - - - 2 - - - - - - - 0 - - - - Temperatures - - - - - Advanced - - - - - - - - - - - - - - - - - - Te&mperatures Timeline - - - 2 - - - - - - Pri&nt Progress - - - 2 - - - - - - true - - - &Log - - - true - - - 1 - - - Qt::NoContextMenu false - - - A&xis - - - 2 - - - - - - - All - - - - - - - X - - - - - - - Y - - - - - - - Z - - - - - - - - - - - - &3DView - - - 1 - - - - - - &Video Monitor - - - 1 - - - GCodeEditorWidget QWidget
widgets/gcodeeditorwidget.h
1
- - PlotWidget - QWidget -
widgets/plotwidget.h
- 1 -
- - RatesControlWidget - QWidget -
widgets/ratescontrolwidget.h
- 1 -
- - PrintProgressWidget - QWidget -
widgets/printprogresswidget.h
- 1 -
- - AxisControl - QGraphicsView -
widgets/axiscontrol.h
-
- - BedExtruderWidget - QWidget -
widgets/bedextruderwidget.h
- 1 -
- - PushGCodeWidget - QWidget -
widgets/pushgcodewidget.h
- 1 -
Viewer3D QWidget @@ -301,6 +177,12 @@
widgets/videomonitorwidget.h
1
+ + AtCoreInstanceWidget + QWidget +
widgets/atcoreinstancewidget.h
+ 1 +
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -8,6 +8,7 @@ printprogresswidget.cpp logwidget.cpp videomonitorwidget.cpp + atcoreinstancewidget.cpp ) add_library(AtelierWidgets STATIC ${widgets_SRCS}) @@ -21,6 +22,7 @@ KF5::TextEditor Qt5::Charts Qt5::Multimedia - Qt5::MultimediaWidgets) + Qt5::MultimediaWidgets + AtCore::AtCore) add_subdirectory(3dview) diff --git a/src/mainwindow.h b/src/widgets/atcoreinstancewidget.h copy from src/mainwindow.h copy to src/widgets/atcoreinstancewidget.h --- a/src/mainwindow.h +++ b/src/widgets/atcoreinstancewidget.h @@ -1,6 +1,6 @@ /* Atelier KDE Printer Host for 3D Printing - Copyright (C) <2016> - Author: Lays Rodrigues - laysrodrigues@gmail.com + Copyright (C) <2017> + Author: Lays Rodrigues - laysrodriguessilva@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,48 +15,56 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#pragma once -#include +#pragma once +#include #include +#include #include -#include -#include + namespace Ui { -class MainWindow; +class AtCoreInstanceWidget; } -class MainWindow : public KXmlGuiWindow +/** + * @todo write docs + */ +class AtCoreInstanceWidget : public QWidget { Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + /** + * Default constructor + */ + AtCoreInstanceWidget(QWidget* parent = nullptr); + + /** + * Destructor + */ + ~AtCoreInstanceWidget(); + void startConnection(const QString& serialPort, const QMap& profiles); + bool connected(); private: - Ui::MainWindow *ui; - AtCore core; - QStringList firmwaresList; - QUrl fileName; - LogWidget *logWidget; - QAction *_connect; + Ui::AtCoreInstanceWidget* ui; + AtCore m_core; + QToolBar *toolBar; void initConnectsToAtCore(); - void initWidgets(); - void setupActions(); - void openFile(); - void printFile(); + void printFile(const QUrl& fileName); void pausePrint(); void stopPrint(); + void disableMotors(); void checkReceivedCommand(const QByteArray &message); - void checkPushedCommands(QByteArray bmsg); + void checkPushedCommands(const QByteArray &bmsg); void handlePrinterStatusChanged(AtCore::STATES newState); void checkTemperature(uint sensorType, uint number, uint temp); void axisControlClicked(QChar axis, int value); - void toggleDockTitles(bool checked); + void enableControls(bool b); + void buildToolbar(); + void setupConnections(); signals: void extruderCountChanged(int count); - }; diff --git a/src/widgets/atcoreinstancewidget.cpp b/src/widgets/atcoreinstancewidget.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/atcoreinstancewidget.cpp @@ -0,0 +1,285 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Lays Rodrigues - laysrodriguessilva@gmail.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "atcoreinstancewidget.h" +#include "ui_atcoreinstancewidget.h" +#include +#include +#include +#include + +AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): + QWidget(parent) +{ + ui = new Ui::AtCoreInstanceWidget; + ui->setupUi(this); + ui->printPB->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + ui->pausePB->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); + ui->stopPB->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); + ui->disableMotorsPB->setIcon(style()->standardIcon(QStyle::SP_DockWidgetCloseButton)); + ui->printProgressWidget->setVisible(false); + + setupConnections(); + enableControls(false); +} + +void AtCoreInstanceWidget::setupConnections(){ + connect(ui->pausePB, &QPushButton::clicked, this, &AtCoreInstanceWidget::pausePrint); + connect(ui->stopPB, &QPushButton::clicked, this, &AtCoreInstanceWidget::stopPrint); + connect(ui->disableMotorsPB, &QPushButton::clicked, this, &AtCoreInstanceWidget::disableMotors); + + buildToolbar(); + connect(ui->disconnectPB, &QPushButton::clicked, [ & ]{ + m_core.setState(AtCore::DISCONNECTED); + }); +} + +AtCoreInstanceWidget::~AtCoreInstanceWidget() +{ + delete ui; +} + +void AtCoreInstanceWidget::buildToolbar() +{ + toolBar = new QToolBar(); + + auto axis = new QAction("Axis"); + axis->setCheckable(true); + axis->setChecked(true); + connect(axis, &QAction::toggled, ui->axisViewWidget, &AxisControl::setVisible); + + auto controls = new QAction("Controls"); + controls->setCheckable(true); + controls->setChecked(true); + connect(controls, &QAction::toggled, ui->bedExtWidget, &BedExtruderWidget::setVisible); + + auto plot = new QAction("Temperature Plot"); + plot->setCheckable(true); + plot->setChecked(true); + connect(plot, &QAction::toggled, ui->plotWidget, &PlotWidget::setVisible); + + toolBar->addAction(axis); + toolBar->addAction(controls); + toolBar->addAction(plot); + ui->toolBarLayout->addWidget(new QLabel(i18n("Show/Hide: "))); + ui->toolBarLayout->addWidget(toolBar); + ui->toolBarLayout->addStretch(); +} +void AtCoreInstanceWidget::startConnection(const QString& serialPort, const QMap& profiles){ + m_core.initSerial(serialPort, profiles["bps"].toInt()); + initConnectsToAtCore(); +} + +void AtCoreInstanceWidget::initConnectsToAtCore() +{ + // Handle AtCore status change + connect(&m_core, &AtCore::stateChanged, this, &AtCoreInstanceWidget::handlePrinterStatusChanged); + + // If the number of extruders from the printer change, we need to update the radiobuttons on the widget + connect(this, &AtCoreInstanceWidget::extruderCountChanged, ui->bedExtWidget, &BedExtruderWidget::setExtruderCount); + + // Bed and Extruder temperatures management + connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &m_core, &AtCore::setBedTemp); + connect(ui->bedExtWidget, &BedExtruderWidget::extTemperatureChanged, &m_core, &AtCore::setExtruderTemp); + + // Connect AtCore temperatures changes on Atelier Plot + connect(&m_core.temperature(), &Temperature::bedTemperatureChanged, [ & ](const float& temp) { + checkTemperature(0x00, 0, temp); + ui->plotWidget->appendPoint(i18n("Actual Bed"), temp); + ui->plotWidget->update(); + ui->bedExtWidget->updateBedTemp(temp); + }); + connect(&m_core.temperature(), &Temperature::bedTargetTemperatureChanged, [ & ](const float& temp) { + checkTemperature(0x01, 0, temp); + ui->plotWidget->appendPoint(i18n("Target Bed"), temp); + ui->plotWidget->update(); + ui->bedExtWidget->updateBedTargetTemp(temp); + }); + connect(&m_core.temperature(), &Temperature::extruderTemperatureChanged, [ & ](const float& temp) { + checkTemperature(0x02, 0, temp); + ui->plotWidget->appendPoint(i18n("Actual Ext.1"), temp); + ui->plotWidget->update(); + ui->bedExtWidget->updateExtTemp(temp); + }); + connect(&m_core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ & ](const float& temp) { + checkTemperature(0x03, 0, temp); + ui->plotWidget->appendPoint(i18n("Target Ext.1"), temp); + ui->plotWidget->update(); + ui->bedExtWidget->updateExtTargetTemp(temp); + }); + + connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ & ](QString command) { + ui->logWidget->addLog("Push " + command); + m_core.pushCommand(command); + }); + + // Fan, Flow and Speed management + connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &m_core, &AtCore::setFanSpeed); + connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &m_core, &AtCore::setFlowRate); + connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &m_core, &AtCore::setPrinterSpeed); + connect(ui->axisViewWidget, &AxisControl::clicked, this, &AtCoreInstanceWidget::axisControlClicked); +} + +void AtCoreInstanceWidget::printFile(const QUrl& fileName) +{ + if (!fileName.isEmpty() && (m_core.state() == AtCore::IDLE)) { + m_core.print(fileName.toLocalFile()); + } +} + +void AtCoreInstanceWidget::pausePrint() +{ + m_core.pause(QString()); +} + +void AtCoreInstanceWidget::stopPrint() +{ + m_core.stop(); +} + +void AtCoreInstanceWidget::disableMotors() +{ + m_core.setIdleHold(0); +} + +void AtCoreInstanceWidget::handlePrinterStatusChanged(AtCore::STATES newState) +{ + static QString stateString; + switch (newState) { + case AtCore::CONNECTING: { + stateString = i18n("Connecting..."); + connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); + connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); + } break; + case AtCore::IDLE: { + stateString = i18n("Connected to ") + m_core.serial()->portName(); + emit extruderCountChanged(m_core.extruderCount()); + ui->logWidget->addLog(i18n("Serial connected")); + ui->disconnectPB->setEnabled(true); + enableControls(true); + } break; + case AtCore::DISCONNECTED: { + stateString = i18n("Not Connected"); + disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); + disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); + ui->logWidget->addLog(i18n("Serial disconnected")); + enableControls(false); + } break; + case AtCore::STARTPRINT: { + stateString = i18n("Starting Print"); + ui->printProgressWidget->setVisible(true); + connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); + } break; + case AtCore::FINISHEDPRINT: { + stateString = i18n("Finished Print"); + ui->printProgressWidget->setVisible(false); + disconnect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); + } break; + case AtCore::BUSY: { + stateString = i18n("Printing"); + ui->disconnectPB->setDisabled(true); + } break; + case AtCore::PAUSE: { + stateString = i18n("Paused"); + } break; + case AtCore::STOP: { + stateString = i18n("Stoping Print"); + } break; + case AtCore::ERRORSTATE: { + stateString = i18n("Error"); + } break; + default: + qWarning("AtCore State not Recognized."); + break; + } + ui->lblState->setText(stateString); +} + +void AtCoreInstanceWidget::checkTemperature(uint sensorType, uint number, uint temp) +{ + static QString msg; + switch (sensorType) { + case 0x00: // bed + msg = QString::fromLatin1("Bed Temperature "); + break; + + case 0x01: // bed target + msg = QString::fromLatin1("Bed Target Temperature "); + break; + + case 0x02: // extruder + msg = QString::fromLatin1("Extruder Temperature "); + break; + + case 0x03: // extruder target + msg = QString::fromLatin1("Extruder Target Temperature "); + break; + + case 0x04: // enclosure + msg = QString::fromLatin1("Enclosure Temperature "); + break; + + case 0x05: // enclosure target + msg = QString::fromLatin1("Enclosure Target Temperature "); + break; + } + + msg.append(QString::fromLatin1("[%1] : %2")); + msg = msg.arg(QString::number(number)) + .arg(QString::number(temp)); + + ui->logWidget->addRLog(msg); +} + +void AtCoreInstanceWidget::checkReceivedCommand(const QByteArray &message) +{ + ui->logWidget->addRLog(QString::fromUtf8(message)); +} + +void AtCoreInstanceWidget::checkPushedCommands(const QByteArray &bmsg) +{ + QString msg = QString::fromUtf8(bmsg); + QRegExp _newLine(QChar::fromLatin1('\n')); + QRegExp _return(QChar::fromLatin1('\r')); + msg.replace(_newLine, QStringLiteral("\\n")); + msg.replace(_return, QStringLiteral("\\r")); + ui->logWidget->addSLog(msg); +} + +void AtCoreInstanceWidget::axisControlClicked(QChar axis, int value) +{ + m_core.setRelativePosition(); + m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); + m_core.setAbsolutePosition(); +} + +void AtCoreInstanceWidget::enableControls(bool b) +{ + ui->mainTab->setEnabled(b); + ui->printPB->setEnabled(b); + ui->pausePB->setEnabled(b); + ui->stopPB->setEnabled(b); + ui->disconnectPB->setEnabled(b); + ui->disableMotorsPB->setEnabled(b); + toolBar->setEnabled(b); +} + +bool AtCoreInstanceWidget::connected() +{ + return (m_core.state() != AtCore::DISCONNECTED); +} diff --git a/src/widgets/atcoreinstancewidget.ui b/src/widgets/atcoreinstancewidget.ui new file mode 100644 --- /dev/null +++ b/src/widgets/atcoreinstancewidget.ui @@ -0,0 +1,179 @@ + + + AtCoreInstanceWidget + + + + 0 + 0 + 483 + 362 + + + + + + + + + Disconnect + + + true + + + + + + + Print + + + + + + + Pause + + + + + + + Stop + + + + + + + Disable Motors + + + + + + + + + + + + 0 + + + + Controllers + + + + + + + + + + + + + + + + + + + Advanced + + + + + + + + + + + + + + + + + + + + + Printer Status: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + PlotWidget + QWidget +
plotwidget.h
+ 1 +
+ + PrintProgressWidget + QWidget +
printprogresswidget.h
+ 1 +
+ + AxisControl + QGraphicsView +
axiscontrol.h
+
+ + BedExtruderWidget + QWidget +
bedextruderwidget.h
+ 1 +
+ + LogWidget + QWidget +
logwidget.h
+ 1 +
+ + PushGCodeWidget + QWidget +
pushgcodewidget.h
+ 1 +
+ + RatesControlWidget + QWidget +
ratescontrolwidget.h
+ 1 +
+
+ + +