diff --git a/CMakeLists.txt b/CMakeLists.txt index 23b83bf..121e6ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,70 +1,69 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(atelier) find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) include(KDECompilerSettings) include(KDEInstallDirs) include(KDECMakeSettings) include(ECMInstallIcons) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(QT_MIN_VERSION "5.9.0") set(KF5_DEP_VERSION "5.30.0") set(KDE_APPLICATIONS_VERSION_MAJOR "1") set(KDE_APPLICATIONS_VERSION_MINOR "0") set(KDE_APPLICATIONS_VERSION_MICRO "0") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ") endif() #Atelier Dependencies find_package(AtCore REQUIRED COMPONENTS AtCore ) find_package(KF5 ${KF5_DEP_VERSION} REQUIRED COMPONENTS - Solid I18n XmlGui ConfigWidgets TextEditor ) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Core Widgets SerialPort Charts Quick Qml 3DCore 3DExtras 3DRender 3DInput Multimedia MultimediaWidgets ) if(BUILD_TESTING) find_package(Qt5Test ${QT_MIN_VERSION} CONFIG REQUIRED) endif() # config.h configure_file (config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) include(ECMPoQmTools) include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(src) add_subdirectory(deploy) if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8febbda..eb45319 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,17 +1,17 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTORCC ON) set(atelier_SRCS main.cpp mainwindow.cpp ) add_subdirectory(dialogs) add_subdirectory(widgets) add_executable(atelier ${atelier_SRCS} resources.qrc) ecm_create_qm_loader(atelier_SRCS atelier) -target_link_libraries(atelier AtelierWidgets AtelierDialogs Atelier3D AtCore::AtCore KF5::Solid KF5::XmlGui KF5::ConfigWidgets) +target_link_libraries(atelier AtelierWidgets AtelierDialogs Atelier3D AtCore::AtCore KF5::XmlGui KF5::ConfigWidgets) install(TARGETS atelier RUNTIME DESTINATION bin) diff --git a/src/dialogs/CMakeLists.txt b/src/dialogs/CMakeLists.txt index 43441c3..0c503d7 100644 --- a/src/dialogs/CMakeLists.txt +++ b/src/dialogs/CMakeLists.txt @@ -1,6 +1,6 @@ set(dialogs_SRCS profilesdialog.cpp connectsettingsdialog.cpp ) add_library(AtelierDialogs STATIC ${dialogs_SRCS}) -target_link_libraries(AtelierDialogs Qt5::Widgets Qt5::SerialPort KF5::Solid KF5::I18n) +target_link_libraries(AtelierDialogs Qt5::Widgets Qt5::SerialPort KF5::I18n) diff --git a/src/dialogs/connectsettingsdialog.cpp b/src/dialogs/connectsettingsdialog.cpp index a22c564..f0d537d 100644 --- a/src/dialogs/connectsettingsdialog.cpp +++ b/src/dialogs/connectsettingsdialog.cpp @@ -1,120 +1,110 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodrigues@gmail.com + Chris Rizzitello - rizzitello@kde.org 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 "connectsettingsdialog.h" -#include "ui_connectsettingsdialog.h" -#include -#include -#include #include +#include +#include +#include +#include ConnectSettingsDialog::ConnectSettingsDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::ConnectSettingsDialog), - deviceNotifier(Solid::DeviceNotifier::instance()) + atcore(new AtCore) { - ui->setupUi(this); - connect(deviceNotifier, &Solid::DeviceNotifier::deviceAdded, this, &ConnectSettingsDialog::locateSerialPort); - connect(deviceNotifier, &Solid::DeviceNotifier::deviceRemoved, this, &ConnectSettingsDialog::locateSerialPort); - locateSerialPort(); - - connect(ui->buttonBox, &QDialogButtonBox::clicked, [ = ](QAbstractButton * btn) { - if (ui->buttonBox->buttonRole(btn) == QDialogButtonBox::RejectRole) { - close(); - emit setConnectValue(false); - } - }); - - updateProfiles(); + initDisplay(); + initData(); + setWindowTitle(i18n("Connect to Printer")); + atcore->setSerialTimerInterval(100); + connect(atcore, &AtCore::portsChanged, this, &ConnectSettingsDialog::updateSerialPort); + connect(buttonBox, &QDialogButtonBox::accepted, this, &ConnectSettingsDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &ConnectSettingsDialog::close); } -ConnectSettingsDialog::~ConnectSettingsDialog() +void ConnectSettingsDialog::initDisplay() { - delete ui; -} + serialPortCB = new QComboBox; + serialPortCB->setEditable(true); + QLabel *deviceLabel = new QLabel(i18n("Device")); + QHBoxLayout *deviceLayout = new QHBoxLayout; + deviceLayout->addWidget(deviceLabel); + deviceLayout->addWidget(serialPortCB); -void ConnectSettingsDialog::locateSerialPort() -{ - QStringList ports; - QList serialPortInfoList = QSerialPortInfo::availablePorts(); - if (!serialPortInfoList.isEmpty()) { - foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList) { -#ifdef Q_OS_MAC - //Mac os has callout serial ports starting with cu. they can only recv data. filter them out - if (!serialPortInfo.portName().startsWith(QStringLiteral("cu."), Qt::CaseInsensitive)) { - ports.append(serialPortInfo.portName()); - } -#else - ports.append(serialPortInfo.portName()); -#endif - } - if (ports == serialPortList) { - return; - } else { - serialPortList.clear(); - serialPortList = ports; - ui->serialPortCB->clear(); - ui->serialPortCB->addItems(serialPortList); - } - } else { - serialPortList.clear(); - ui->serialPortCB->clear(); - } + deviceProfileCB = new QComboBox; + QHBoxLayout *profileLayout = new QHBoxLayout; + QLabel *profileLabel = new QLabel(i18n("Profile")); + profileLayout->addWidget(profileLabel); + profileLayout->addWidget(deviceProfileCB); + + buttonBox = new QDialogButtonBox(); + buttonBox->addButton(i18n("Connect"),QDialogButtonBox::AcceptRole); + buttonBox->addButton(QDialogButtonBox::Cancel); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(deviceLayout); + mainLayout->addLayout(profileLayout); + mainLayout->addWidget(buttonBox); + + setLayout(mainLayout); } -void ConnectSettingsDialog::updateProfiles() +void ConnectSettingsDialog::initData() { settings.beginGroup("GeneralSettings"); - QStringList groups = settings.childGroups(); + QStringList profiles = settings.childGroups(); settings.endGroup(); - ui->profileCB->clear(); - ui->profileCB->addItems(groups); + deviceProfileCB->addItems(profiles); } -void ConnectSettingsDialog::setFirmwareList(QStringList fw) +void ConnectSettingsDialog::updateSerialPort(const QStringList &ports) { - fw.prepend(i18n("Auto-Detect")); - ui->firmwareCB->clear(); - ui->firmwareCB->addItems(fw); + serialPortCB->clear(); + if(!ports.isEmpty()) { + serialPortCB->addItems(ports); + } } QMap ConnectSettingsDialog::profileData() { + QString profile = deviceProfileCB->currentText(); settings.beginGroup("GeneralSettings"); - settings.beginGroup(ui->profileCB->currentText()); + settings.beginGroup(profile); QMap data; data["bps"] = settings.value(QStringLiteral("bps"), QStringLiteral("115200")); - data["bedTemp"] = settings.value(QStringLiteral("temperatureBed"), QStringLiteral("0")); - data["hotendTemp"] = settings.value(QStringLiteral("temperatureExtrude"), QStringLiteral("0")); + data["bedTemp"] = settings.value(QStringLiteral("maximumTemperatureBed"), QStringLiteral("0")); + data["hotendTemp"] = settings.value(QStringLiteral("maximumTemperatureExtruder"), QStringLiteral("0")); + data["firmware"] = settings.value(QStringLiteral("firmware"),QStringLiteral("Auto-Detect")); + data["name"] = profile; settings.endGroup(); settings.endGroup(); return data; } void ConnectSettingsDialog::accept() { - if (ui->profileCB->currentText().isEmpty()) { - QMessageBox::warning(this, i18n("Warning"), i18n("Please, create a profile to connect on Settings!")); - emit setConnectValue(false); - } else if (ui->serialPortCB->currentText().isEmpty()) { - QMessageBox::warning(this, i18n("Warning"), i18n("Please, connect a serial device to continue!")); - emit setConnectValue(false); - } else { - emit startConnection(ui->serialPortCB->currentText(), profileData()); - this->close(); + if (deviceProfileCB->currentText().isEmpty()) { + QMessageBox::critical(this, i18n("Error"), i18n("Please, create a profile to connect on Settings!")); + return; + } + if (serialPortCB->currentText().isEmpty()) { + QMessageBox::critical(this, i18n("Error"), i18n("Please, connect a serial device to continue!")); + return; } + emit startConnection(serialPortCB->currentText(), profileData()); + close(); } diff --git a/src/dialogs/connectsettingsdialog.h b/src/dialogs/connectsettingsdialog.h index 13c0930..e29c3f9 100644 --- a/src/dialogs/connectsettingsdialog.h +++ b/src/dialogs/connectsettingsdialog.h @@ -1,51 +1,47 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodrigues@gmail.com + Chris Rizzitello - rizzitello@kde.org 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 . */ #pragma once +#include +#include #include -#include +#include #include -namespace Ui -{ -class ConnectSettingsDialog; -} - class ConnectSettingsDialog : public QDialog { Q_OBJECT public: explicit ConnectSettingsDialog(QWidget *parent = nullptr); - void updateProfiles(); - void setFirmwareList(const QStringList fw); - ~ConnectSettingsDialog(); private: - Ui::ConnectSettingsDialog *ui; - void locateSerialPort(); - QStringList serialPortList; - Solid::DeviceNotifier *deviceNotifier; + void initDisplay(); + void initData(); + void updateSerialPort(const QStringList &ports); + AtCore *atcore; QSettings settings; QMap profileData(); void accept(); - + QComboBox *serialPortCB; + QComboBox *deviceProfileCB; + QDialogButtonBox *buttonBox; signals: void startConnection(const QString port, const QMap data); - void setConnectValue(bool b); }; diff --git a/src/dialogs/connectsettingsdialog.ui b/src/dialogs/connectsettingsdialog.ui deleted file mode 100644 index e098384..0000000 --- a/src/dialogs/connectsettingsdialog.ui +++ /dev/null @@ -1,159 +0,0 @@ - - - ConnectSettingsDialog - - - - 0 - 0 - 290 - 191 - - - - Connect - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - - - - - - - * - - - - - - - Firmware name: - - - - - - - Serial Port: - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - Reset on Connect - - - - - - - true - - - - - - - Profile: - - - - - - - false - - - - - - - Save log - - - - - - - * - - - - - - - - - - - - - - - - buttonBox - accepted() - ConnectSettingsDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - ConnectSettingsDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1b7750f..ac74271 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,392 +1,384 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodrigues@gmail.com Chris Rizzitello - rizzitello@kde.org 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 "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent), ui(new Ui::MainWindow), - profilesDialog(new ProfilesDialog(this)), - connectSettingsDialog(new ConnectSettingsDialog(this)) + profilesDialog(new ProfilesDialog(this)) { ui->setupUi(this); logWidget = new LogWidget; setupActions(); initConnectsToAtCore(); initWidgets(); setCentralWidget(nullptr); } MainWindow::~MainWindow() { delete ui; } void MainWindow::initConnectsToAtCore() { - // Start Connection to the 3DPrinter - connect(connectSettingsDialog, &ConnectSettingsDialog::startConnection, [ = ](QString port, QMap data) { - core.initSerial(port, data["bps"].toInt()); - }); - // 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); - // When a new profile is added on the Profile Dialog it needs to update the profiles on connection dialog - connect(profilesDialog, &ProfilesDialog::updateProfiles, - connectSettingsDialog, &ConnectSettingsDialog::updateProfiles); - - connectSettingsDialog->setFirmwareList(core.availableFirmwarePlugins()); profilesDialog->setBaudRates(core.serial()->validBaudRates()); 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) { - connectSettingsDialog->show(); + std::unique_ptr csd(new ConnectSettingsDialog); + connect(csd.get(), &ConnectSettingsDialog::startConnection, [ & ](QString port, QMap data) { + core.initSerial(port, data["bps"].toInt()); + }); + csd->exec(); } else { core.closeConnection(); _connect->setText(i18n("&Connect")); ui->bedExtWidget->stopHeating(); core.setState(AtCore::DISCONNECTED); } }); - connect(connectSettingsDialog, &ConnectSettingsDialog::setConnectValue, _connect, &QAction::setChecked); - 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, profilesDialog, &ProfilesDialog::show); 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); 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; } 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) { 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()); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 30f8948..9faf3f0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,66 +1,64 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodrigues@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 . */ #pragma once #include #include #include #include -#include #include #include namespace Ui { class MainWindow; } class MainWindow : public KXmlGuiWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; AtCore core; QStringList firmwaresList; QUrl fileName; ProfilesDialog *profilesDialog; - ConnectSettingsDialog *connectSettingsDialog; LogWidget *logWidget; QAction *_connect; void initConnectsToAtCore(); void initWidgets(); 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); signals: void extruderCountChanged(int count); };