diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp index 3d6c215..ec4662c 100644 --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -1,808 +1,744 @@ /* AtCore Test Client Copyright (C) <2016> Authors: Patrick José Pereira Lays Rodrigues Chris Rizzitello Tomaz Canabrava 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 #include #include #include #include #include "mainwindow.h" #include "seriallayer.h" #include "gcodecommands.h" #include "widgets/axiscontrol.h" #include "widgets/about.h" Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core") int MainWindow::fanCount = 4; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), core(new AtCore(this)) { setWindowTitle(tr("AtCore - Test Client")); setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); QCoreApplication::setApplicationVersion(core->version()); initMenu(); initStatusBar(); initWidgets(); logWidget->appendLog(tr("Attempting to locate Serial Ports")); core->setSerialTimerInterval(1000); - printTime = new QTime(); - printTimer = new QTimer(); - printTimer->setInterval(1000); - printTimer->setSingleShot(false); - connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); - connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); - connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); - connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { listSdFiles->clear(); listSdFiles->addItems(fileList); }); connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { checkTemperature(0x00, 0, temp); plotWidget->appendPoint(tr("Actual Bed"), temp); plotWidget->update(); }); connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { checkTemperature(0x01, 0, temp); plotWidget->appendPoint(tr("Target Bed"), temp); plotWidget->update(); }); connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { checkTemperature(0x02, 0, temp); plotWidget->appendPoint(tr("Actual Ext.1"), temp); plotWidget->update(); }); connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { checkTemperature(0x03, 0, temp); plotWidget->appendPoint(tr("Target Ext.1"), temp); plotWidget->update(); }); } void MainWindow::initMenu() { QMenu *menuFile = new QMenu(tr("File")); QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Quit")); connect(actionQuit, &QAction::triggered, this, &MainWindow::close); menuFile->addAction(actionQuit); menuView = new QMenu(tr("View")); QAction *actionShowDockTitles = new QAction(tr("Show Dock Titles")); actionShowDockTitles->setCheckable(true); actionShowDockTitles->setChecked(true); connect(actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); menuView->addAction(actionShowDockTitles); QMenu *menuHelp = new QMenu(tr("Help")); QAction *actionAbout = new QAction(tr("About")); actionAbout->setShortcut(QKeySequence(Qt::Key_F1)); connect(actionAbout, &QAction::triggered, [] { auto *dialog = new About; dialog->exec(); }); menuHelp->addAction(actionAbout); menuBar()->addMenu(menuFile); menuBar()->addMenu(menuView); menuBar()->addMenu(menuHelp); } void MainWindow::initStatusBar() { - //first create the item for the print Progress. - printingProgress = new QProgressBar; - auto *newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); - connect(newButton, &QPushButton::clicked, core, &AtCore::stop); - lblTime = new QLabel(QStringLiteral("00:00:00")); - lblTime->setAlignment(Qt::AlignHCenter); - auto *newLabel = new QLabel(QStringLiteral(" / ")); - lblTimeLeft = new QLabel(QStringLiteral("00:00:00")); - lblTimeLeft->setAlignment(Qt::AlignHCenter); - - auto *hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(printingProgress); - hBoxLayout->addWidget(newButton); - hBoxLayout->addWidget(lblTime); - hBoxLayout->addWidget(newLabel); - hBoxLayout->addWidget(lblTimeLeft); - printProgressWidget = new QWidget(); - printProgressWidget->setLayout(hBoxLayout); - - //Then Create the full bar. - newLabel = new QLabel(tr("AtCore State:")); - lblState = new QLabel(tr("Not Connected")); - lblSd = new QLabel(); - - hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(newLabel); - hBoxLayout->addWidget(lblState); - hBoxLayout->addSpacerItem(new QSpacerItem(10, 20, QSizePolicy::Fixed)); - hBoxLayout->addWidget(lblSd); - hBoxLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); - hBoxLayout->addWidget(printProgressWidget); - - //Then put it all into a widget on the bar. - QWidget *sBar = new QWidget(); - sBar->setLayout(hBoxLayout); - statusBar()->addPermanentWidget(sBar, 100); + statusWidget = new StatusWidget; + connect(statusWidget, &StatusWidget::stopPressed, core, &AtCore::stop); + connect(core, &AtCore::printProgressChanged, statusWidget, &StatusWidget::updatePrintProgress); + connect(core, &AtCore::sdMountChanged, statusWidget, &StatusWidget::setSD); + statusBar()->addPermanentWidget(statusWidget, 100); } void MainWindow::initWidgets() { //Make the Docks makeCommandDock(); makePrintDock(); makeTempTimelineDock(); makeLogDock(); makeConnectDock(); makeMoveDock(); makeTempControlsDock(); makeSdDock(); setDangeriousDocksDisabled(true); setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); tabifyDockWidget(moveDock, tempControlsDock); tabifyDockWidget(moveDock, sdDock); moveDock->raise(); tabifyDockWidget(connectDock, printDock); tabifyDockWidget(connectDock, commandDock); connectDock->raise(); setCentralWidget(nullptr); //More Gui stuff populateCBs(); //hide the printing progress bar. - printProgressWidget->setVisible(false); + statusWidget->showPrintArea(false); } void MainWindow::makeCommandDock() { commandWidget = new CommandWidget; //Connect the commandPressed signal connect(commandWidget, &CommandWidget::commandPressed, [this](const QString & command) { core->pushCommand(command.toUpper()); }); //Connect the messagePressed signal connect(commandWidget, &CommandWidget::messagePressed, [this](const QString & message) { core->showMessage(message); }); //Create the dock, and set the Widget. commandDock = new QDockWidget(tr("Commands"), this); commandDock->setWidget(commandWidget); //Push the toggle view action into our view menu menuView->insertAction(nullptr, commandDock->toggleViewAction()); //Place the Dock into a DockWidget Area. //Failure todo this will create some odd side effects at runtime addDockWidget(Qt::LeftDockWidgetArea, commandDock); } void MainWindow::makePrintDock() { printWidget = new PrintWidget; connect(printWidget, &PrintWidget::printPressed, this, &MainWindow::printPBClicked); connect(printWidget, &PrintWidget::emergencyStopPressed, core, &AtCore::emergencyStop); connect(printWidget, &PrintWidget::printSpeedChanged, [this](const int speed) { core->setPrinterSpeed(speed); }); connect(printWidget, &PrintWidget::flowRateChanged, [this](const int rate) { core->setFlowRate(rate); }); printDock = new QDockWidget(tr("Print"), this); printDock->setWidget(printWidget); menuView->insertAction(nullptr, printDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, printDock); } void MainWindow::makeTempTimelineDock() { plotWidget = new PlotWidget; tempTimelineDock = new QDockWidget(tr("Temperature Timeline"), this); tempTimelineDock->setWidget(plotWidget); menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); } void MainWindow::makeLogDock() { logWidget = new LogWidget(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))); logDock = new QDockWidget(tr("Session Log"), this); logDock->setWidget(logWidget); menuView->insertAction(nullptr, logDock->toggleViewAction()); addDockWidget(Qt::RightDockWidgetArea, logDock); } void MainWindow::makeConnectDock() { auto *mainLayout = new QVBoxLayout; auto *newLabel = new QLabel(tr("Port:")); comboPort = new QComboBox; comboPort->setEditable(true); auto *hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(comboPort, 75); mainLayout->addLayout(hBoxLayout); newLabel = new QLabel(tr("Baud Rate:")); comboBAUD = new QComboBox; comboBAUD->addItems(core->portSpeeds()); comboBAUD->setCurrentIndex(9); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(comboBAUD, 75); mainLayout->addLayout(hBoxLayout); newLabel = new QLabel(tr("Use Plugin:")); comboPlugin = new QComboBox; comboPlugin->addItem(tr("Autodetect")); comboPlugin->addItems(core->availableFirmwarePlugins()); connect(comboPlugin, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(comboPlugin, 75); mainLayout->addLayout(hBoxLayout); buttonConnect = new QPushButton(tr("Connect")); connect(buttonConnect, &QPushButton::clicked, this, &MainWindow::connectPBClicked); mainLayout->addWidget(buttonConnect); auto *dockContents = new QWidget; dockContents->setLayout(mainLayout); connectDock = new QDockWidget(tr("Connect"), this); connectDock->setWidget(dockContents); menuView->insertAction(nullptr, connectDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, connectDock); } void MainWindow::makeMoveDock() { auto *mainLayout = new QVBoxLayout; auto *hBoxLayout = new QHBoxLayout; auto *newButton = new QPushButton(tr("Home All")); connect(newButton, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); hBoxLayout->addWidget(newButton); newButton = new QPushButton(tr("Home X")); connect(newButton, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); hBoxLayout->addWidget(newButton); newButton = new QPushButton(tr("Home Y")); connect(newButton, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); hBoxLayout->addWidget(newButton); newButton = new QPushButton(tr("Home Z")); connect(newButton, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); hBoxLayout->addWidget(newButton); mainLayout->addLayout(hBoxLayout); comboMoveAxis = new QComboBox; comboMoveAxis->addItem(tr("Move X Axis to")); comboMoveAxis->addItem(tr("Move Y Axis to")); comboMoveAxis->addItem(tr("Move Z Axis to")); sbMoveAxis = new QDoubleSpinBox; sbMoveAxis->setRange(0, 200); newButton = new QPushButton(tr("Go")); connect(newButton, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(comboMoveAxis); hBoxLayout->addWidget(sbMoveAxis); hBoxLayout->addWidget(newButton); mainLayout->addLayout(hBoxLayout); newButton = new QPushButton(tr("Disable Motors")); connect(newButton, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); mainLayout->addWidget(newButton); auto *axisControl = new AxisControl; connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); mainLayout->addWidget(axisControl); auto *dockContents = new QWidget; dockContents->setLayout(mainLayout); moveDock = new QDockWidget(tr("Movement"), this); moveDock->setWidget(dockContents); menuView->insertAction(nullptr, moveDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, moveDock); } void MainWindow::makeTempControlsDock() { auto *mainLayout = new QVBoxLayout; checkAndWait = new QCheckBox(tr("Wait Until Temperature Stabilizes")); mainLayout->addWidget(checkAndWait); auto label = new QLabel(tr("Bed Temp")); sbBedTemp = new QSpinBox; sbBedTemp->setRange(0, 120); sbBedTemp->setSuffix(QStringLiteral("°C")); auto *newButton = new QPushButton(tr("Set")); connect(newButton, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); auto *hboxLayout = new QHBoxLayout; hboxLayout->addWidget(label, 80); hboxLayout->addWidget(sbBedTemp); hboxLayout->addWidget(newButton); mainLayout->addItem(hboxLayout); comboExtruderSelect = new QComboBox; sbExtruderTemp = new QSpinBox; sbExtruderTemp->setRange(0, 275); sbExtruderTemp->setSuffix(QStringLiteral("°C")); newButton = new QPushButton(tr("Set")); connect(newButton, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); hboxLayout = new QHBoxLayout; hboxLayout->addWidget(comboExtruderSelect, 80); hboxLayout->addWidget(sbExtruderTemp); hboxLayout->addWidget(newButton); mainLayout->addItem(hboxLayout); comboFanSelect = new QComboBox; sbFanSpeed = new QSpinBox; sbFanSpeed->setRange(0, 100); sbFanSpeed->setSuffix(QStringLiteral("%")); newButton = new QPushButton(tr("Set")); connect(newButton, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); hboxLayout = new QHBoxLayout; hboxLayout->addWidget(comboFanSelect, 80); hboxLayout->addWidget(sbFanSpeed); hboxLayout->addWidget(newButton); mainLayout->addItem(hboxLayout); auto *dockContents = new QWidget; dockContents->setLayout(mainLayout); tempControlsDock = new QDockWidget(tr("Temperatures"), this); tempControlsDock->setWidget(dockContents); menuView->insertAction(nullptr, tempControlsDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, tempControlsDock); } void MainWindow::makeSdDock() { auto *hBoxLayout = new QHBoxLayout; auto *newButton = new QPushButton(tr("Get List")); connect(newButton, &QPushButton::clicked, this, &MainWindow::getSdList); hBoxLayout->addWidget(newButton); newButton = new QPushButton(tr("Print Selected")); connect(newButton, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); hBoxLayout->addWidget(newButton); newButton = new QPushButton(tr("Delete Selected")); connect(newButton, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); hBoxLayout->addWidget(newButton); auto *groupFiles = new QGroupBox(tr("Files On Sd Card")); listSdFiles = new QListWidget; auto *groupLayout = new QVBoxLayout; groupLayout->addWidget(listSdFiles); groupFiles->setLayout(groupLayout); auto *mainLayout = new QVBoxLayout; mainLayout->addItem(hBoxLayout); mainLayout->addWidget(groupFiles); auto *dockContents = new QWidget; dockContents->setLayout(mainLayout); sdDock = new QDockWidget(tr("Sd Card"), this); sdDock->setWidget(dockContents); menuView->insertAction(nullptr, sdDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, sdDock); } void MainWindow::closeEvent(QCloseEvent *event) { core->close(); event->accept(); } MainWindow::~MainWindow() { } 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->appendLog(msg); } /** * @brief MainWindow::locateSerialPort * Locate all active serial ports on the computer and add to the list * of serial ports */ void MainWindow::locateSerialPort(const QStringList &ports) { comboPort->clear(); if (!ports.isEmpty()) { comboPort->addItems(ports); logWidget->appendLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); } else { QString portError(tr("No available ports! Please connect a serial device to continue!")); if (! logWidget->endsWith(portError)) { logWidget->appendLog(portError); } } } void MainWindow::connectPBClicked() { if (core->state() == AtCore::DISCONNECTED) { if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) { connect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); connect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); buttonConnect->setText(tr("Disconnect")); logWidget->appendLog(tr("Serial connected")); if (comboPlugin->currentText().contains(tr("Autodetect"))) { logWidget->appendLog(tr("No plugin loaded !")); logWidget->appendLog(tr("Requesting Firmware...")); } else { core->loadFirmwarePlugin(comboPlugin->currentText()); } } else { logWidget->appendLog(tr("Failed to open serial in r/w mode")); } } else { disconnect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); disconnect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); core->closeConnection(); core->setState(AtCore::DISCONNECTED); logWidget->appendLog(tr("Disconnected")); buttonConnect->setText(tr("Connect")); } } void MainWindow::homeAllPBClicked() { logWidget->appendLog(tr("Home All")); core->home(); } void MainWindow::homeXPBClicked() { logWidget->appendLog(tr("Home X")); core->home(AtCore::X); } void MainWindow::homeYPBClicked() { logWidget->appendLog(tr("Home Y")); core->home(AtCore::Y); } void MainWindow::homeZPBClicked() { logWidget->appendLog(tr("Home Z")); core->home(AtCore::Z); } void MainWindow::bedTempPBClicked() { if (checkAndWait->isChecked()) { logWidget->appendLog(GCode::description(GCode::M190)); } else { logWidget->appendLog(GCode::description(GCode::M140)); } core->setBedTemp(sbBedTemp->value(), checkAndWait->isChecked()); } void MainWindow::extTempPBClicked() { if (checkAndWait->isChecked()) { logWidget->appendLog(GCode::description(GCode::M109)); } else { logWidget->appendLog(GCode::description(GCode::M104)); } core->setExtruderTemp(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked()); } void MainWindow::mvAxisPBClicked() { logWidget->appendLog(GCode::description(GCode::G1)); if (comboMoveAxis->currentIndex() == 0) { core->move(AtCore::X, sbMoveAxis->value()); } else if (comboMoveAxis->currentIndex() == 1) { core->move(AtCore::Y, sbMoveAxis->value()); } else if (comboMoveAxis->currentIndex() == 2) { core->move(AtCore::Z, sbMoveAxis->value()); } } void MainWindow::fanSpeedPBClicked() { logWidget->appendLog(GCode::description(GCode::M106)); core->setFanSpeed(sbFanSpeed->value(), comboFanSelect->currentIndex()); } void MainWindow::printPBClicked() { QString fileName; switch (core->state()) { case AtCore::DISCONNECTED: QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); break; case AtCore::CONNECTING: QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); comboPlugin->setCurrentText(QStringLiteral("repetier")); break; case AtCore::IDLE: fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), tr("*.gcode")); if (fileName.isNull()) { logWidget->appendLog(tr("No File Selected")); } else { logWidget->appendLog(tr("Print: %1").arg(fileName)); core->print(fileName); } break; case AtCore::BUSY: core->pause(printWidget->postPauseCommand()); break; case AtCore::PAUSE: core->resume(); break; default: qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; } } void MainWindow::pluginCBChanged(QString currentText) { if (core->state() != AtCore::DISCONNECTED) { if (!currentText.contains(tr("Autodetect"))) { core->loadFirmwarePlugin(currentText); } } } void MainWindow::printerStateChanged(AtCore::STATES state) { QString stateString; switch (state) { case AtCore::IDLE: printWidget->setPrintText(tr("Print File")); stateString = tr("Connected to ") + core->connectedPort(); break; case AtCore::STARTPRINT: stateString = tr("START PRINT"); printWidget->setPrintText(tr("Pause Print")); - printProgressWidget->setVisible(true); - printTime->start(); - printTimer->start(); + statusWidget->showPrintArea(true); break; case AtCore::FINISHEDPRINT: stateString = tr("Finished Print"); printWidget->setPrintText(tr("Print File")); - printProgressWidget->setVisible(false); - printTimer->stop(); + statusWidget->showPrintArea(false); break; case AtCore::PAUSE: stateString = tr("Paused"); printWidget->setPrintText(tr("Resume Print")); break; case AtCore::BUSY: stateString = tr("Printing"); printWidget->setPrintText(tr("Pause Print")); break; case AtCore::DISCONNECTED: stateString = QStringLiteral("Not Connected"); setDangeriousDocksDisabled(true); break; case AtCore::CONNECTING: stateString = QStringLiteral("Connecting"); setDangeriousDocksDisabled(false); break; case AtCore::STOP: stateString = tr("Stopping Print"); break; case AtCore::ERRORSTATE: stateString = tr("Command ERROR"); break; } - lblState->setText(stateString); + statusWidget->setState(stateString); } void MainWindow::populateCBs() { // Extruders for (int count = 0; count < core->extruderCount(); count++) { comboExtruderSelect->insertItem(count, tr("Extruder %1").arg(count)); } // Fan for (int count = 0; count < fanCount; count++) { comboFanSelect->insertItem(count, tr("Fan %1 speed").arg(count)); } } -void MainWindow::updatePrintTime() -{ - QTime temp(0, 0, 0); - lblTime->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); -} - -void MainWindow::printProgressChanged(int progress) -{ - printingProgress->setValue(progress); - if (progress > 0) { - QTime temp(0, 0, 0); - lblTimeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); - } else { - lblTimeLeft->setText(QStringLiteral("??:??:??")); - } -} void MainWindow::toggleDockTitles(bool checked) { if (checked) { delete connectDock->titleBarWidget(); delete logDock->titleBarWidget(); delete tempTimelineDock->titleBarWidget(); delete commandDock->titleBarWidget(); delete moveDock->titleBarWidget(); delete tempControlsDock->titleBarWidget(); delete printDock->titleBarWidget(); delete sdDock->titleBarWidget(); } else { connectDock->setTitleBarWidget(new QWidget()); logDock->setTitleBarWidget(new QWidget()); tempTimelineDock->setTitleBarWidget(new QWidget()); commandDock->setTitleBarWidget(new QWidget()); moveDock->setTitleBarWidget(new QWidget()); tempControlsDock->setTitleBarWidget(new QWidget()); printDock->setTitleBarWidget(new QWidget()); sdDock->setTitleBarWidget(new QWidget()); } } void MainWindow::setDangeriousDocksDisabled(bool disabled) { commandDock->widget()->setDisabled(disabled); moveDock->widget()->setDisabled(disabled); tempControlsDock->widget()->setDisabled(disabled); printDock->widget()->setDisabled(disabled); sdDock->widget()->setDisabled(disabled); } void MainWindow::axisControlClicked(QLatin1Char axis, int value) { core->setRelativePosition(); core->move(axis, value); core->setAbsolutePosition(); } void MainWindow::disableMotorsPBClicked() { core->disableMotors(0); } -void MainWindow::sdChanged(bool mounted) -{ - QString labelText = mounted ? tr("SD") : QString(); - lblSd->setText(labelText); -} - void MainWindow::getSdList() { core->sdFileList(); } void MainWindow::sdPrintPBClicked() { if (listSdFiles->currentRow() < 0) { QMessageBox::information(this, tr("Print Error"), tr("You must Select a file from the list")); } else { core->print(listSdFiles->currentItem()->text(), true); } } void MainWindow::sdDelPBClicked() { if (listSdFiles->currentRow() < 0) { QMessageBox::information(this, tr("Delete Error"), tr("You must Select a file from the list")); } else { core->sdDelete(listSdFiles->currentItem()->text()); listSdFiles->setCurrentRow(-1); } } diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h index 6f55ccb..120228b 100644 --- a/testclient/mainwindow.h +++ b/testclient/mainwindow.h @@ -1,264 +1,248 @@ /* AtCore Test Client Copyright (C) <2016> Authors: Patrick José Pereira Lays Rodrigues Chris Rizzitello Tomaz Canabrava 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 "atcore.h" -#include "widgets/plotwidget.h" #include "widgets/commandwidget.h" -#include "widgets/printwidget.h" #include "widgets/logwidget.h" +#include "widgets/plotwidget.h" +#include "widgets/printwidget.h" +#include "widgets/statuswidget.h" class SerialLayer; class MainWindow: public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow() override; public slots: /** * @brief Check temperature * * @param sensorType : type of sensor * @param number : index of sensor * @param temp : temperature */ void checkTemperature(uint sensorType, uint number, uint temp); private slots: //ButtonEvents /** * @brief axisControlClicked Used to catch the axis control. * @param axis The Axis clicked on (X |Y |Z) * @param value Distance Value */ void axisControlClicked(QLatin1Char axis, int value); - /** - * @brief the printing progress has changed - * @param progress: the new progress - */ - void printProgressChanged(int progress); /** * @brief Connect Button Clicked will connect or disconnect based on printer state */ void connectPBClicked(); /** * @brief Home All Clicked */ void homeAllPBClicked(); /** * @brief Home X Axis Clicked */ void homeXPBClicked(); /** * @brief Home Y Axis Clicked */ void homeYPBClicked(); /** * @brief Home Z Axis Clicked */ void homeZPBClicked(); /** * @brief Set Bed Temp Clicked */ void bedTempPBClicked(); /** * @brief Set Extruder Temp Clicked */ void extTempPBClicked(); /** * @brief Move Axis Clicked */ void mvAxisPBClicked(); /** * @brief Set Fan Speed Clicked */ void fanSpeedPBClicked(); /** * @brief Print Button Clicked, can also pause /resue print based on printer state */ void printPBClicked(); /** * @brief Print Button for Sd Prints clicked. */ void sdPrintPBClicked(); /** * @brief disableMotorsPB has been clicked */ void disableMotorsPBClicked(); /** * @brief printerStateChanged Catch and proccess printer state commands * @param state: new printer state */ void printerStateChanged(AtCore::STATES state); - /** - * @brief Update the print Time - */ - void updatePrintTime(); - /** * @brief show/hide dock titlebars * @param checked: True if shown */ void toggleDockTitles(bool checked); /** * @brief Toggle disable state of dangerous docks * Command, Sd Card, Movement, Temperature Controls and Printing docks * @param disabled: True if items are disabled. */ void setDangeriousDocksDisabled(bool disabled); /** * @brief List Files on the sd card. */ void getSdList(); /** * @brief Sd Card Delete file clicked */ void sdDelPBClicked(); private: AtCore *core; - QTime *printTime; - QTimer *printTimer; // Define max number of fans static int fanCount; void closeEvent(QCloseEvent *event) override; /** * @brief Locate serial port * */ void locateSerialPort(const QStringList &ports); /** * @brief pluginCB index changed */ void pluginCBChanged(QString currentText); /** * @brief setupActions for KXMLGui */ void setupActions(); /** * @brief Populate comboboxes */ void populateCBs(); /** * @brief Gui Changes for when sd card mount status has changed. */ void sdChanged(bool mounted); //UI Functions /** * @brief Create The Menubar */ void initMenu(); /** * @brief Create StatusBar */ void initStatusBar(); /** * @brief Create Main Widgets. */ void initWidgets(); //Private GUI Items //menuView is global to allow for docks to be added / removed. QMenu *menuView = nullptr; //Status Bar Items - QLabel *lblState = nullptr; - QLabel *lblSd = nullptr; - QWidget *printProgressWidget = nullptr; - QProgressBar *printingProgress = nullptr; - QLabel *lblTime = nullptr; - QLabel *lblTimeLeft = nullptr; + StatusWidget *statusWidget = nullptr; //Docks void makeLogDock(); QDockWidget *logDock = nullptr; LogWidget *logWidget = nullptr; void makeTempTimelineDock(); QDockWidget *tempTimelineDock = nullptr; PlotWidget *plotWidget = nullptr; void makeCommandDock(); QDockWidget *commandDock = nullptr; CommandWidget *commandWidget = nullptr; void makePrintDock(); QDockWidget *printDock = nullptr; PrintWidget *printWidget = nullptr; void makeConnectDock(); QDockWidget *connectDock = nullptr; QComboBox *comboPort = nullptr; QComboBox *comboBAUD = nullptr; QComboBox *comboPlugin = nullptr; QPushButton *buttonConnect = nullptr; void makeMoveDock(); QDockWidget *moveDock = nullptr; QComboBox *comboMoveAxis = nullptr; QDoubleSpinBox *sbMoveAxis = nullptr; void makeTempControlsDock(); QDockWidget *tempControlsDock = nullptr; QCheckBox *checkAndWait = nullptr; QSpinBox *sbBedTemp = nullptr; QComboBox *comboExtruderSelect; QSpinBox *sbExtruderTemp; QComboBox *comboFanSelect; QSpinBox *sbFanSpeed; void makeSdDock(); QDockWidget *sdDock = nullptr; QListWidget *listSdFiles = nullptr; }; diff --git a/testclient/widgets/CMakeLists.txt b/testclient/widgets/CMakeLists.txt index 3862da5..d2a7437 100644 --- a/testclient/widgets/CMakeLists.txt +++ b/testclient/widgets/CMakeLists.txt @@ -1,14 +1,15 @@ set(widgets_SRCS - plotwidget.cpp - axiscontrol.cpp about.cpp + axiscontrol.cpp commandwidget.cpp - printwidget.cpp logwidget.cpp + plotwidget.cpp + printwidget.cpp + statuswidget.cpp ) add_library(AtCoreTestWidgets STATIC ${widgets_SRCS}) if (APPLE) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++11") endif() target_link_libraries(AtCoreTestWidgets Qt5::Core Qt5::Widgets Qt5::Charts) diff --git a/testclient/widgets/statuswidget.cpp b/testclient/widgets/statuswidget.cpp new file mode 100644 index 0000000..a8a0e47 --- /dev/null +++ b/testclient/widgets/statuswidget.cpp @@ -0,0 +1,110 @@ +/* AtCore Test Client + Copyright (C) <2018> + Author: 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 +#include +#include +#include + +#include "statuswidget.h" + +StatusWidget::StatusWidget(QWidget *parent) : + QWidget(parent) +{ + //first create the item for the print Progress. + printingProgress = new QProgressBar; + + auto newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); + connect(newButton, &QPushButton::clicked, [this] { + emit(stopPressed()); + }); + + lblTime = new QLabel(QStringLiteral("00:00:00")); + lblTime->setAlignment(Qt::AlignHCenter); + auto newLabel = new QLabel(QStringLiteral(" / ")); + lblTimeLeft = new QLabel(QStringLiteral("??:??:??")); + lblTimeLeft->setAlignment(Qt::AlignHCenter); + + auto hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(printingProgress); + hBoxLayout->addWidget(newButton); + hBoxLayout->addWidget(lblTime); + hBoxLayout->addWidget(newLabel); + hBoxLayout->addWidget(lblTimeLeft); + printProgressWidget = new QWidget(); + printProgressWidget->setLayout(hBoxLayout); + + //Then Create the full bar. + newLabel = new QLabel(tr("AtCore State:")); + lblState = new QLabel(tr("Not Connected")); + lblSd = new QLabel(); + + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(newLabel); + hBoxLayout->addWidget(lblState); + hBoxLayout->addSpacerItem(new QSpacerItem(10, 20, QSizePolicy::Fixed)); + hBoxLayout->addWidget(lblSd); + hBoxLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); + hBoxLayout->addWidget(printProgressWidget); + + setLayout(hBoxLayout); + + printTime = new QTime(); + printTimer = new QTimer(); + printTimer->setInterval(1000); + printTimer->setSingleShot(false); + connect(printTimer, &QTimer::timeout, this, &StatusWidget::updatePrintTime); +} + +void StatusWidget::setSD(bool hasSd) +{ + QString labelText = hasSd ? tr("SD") : QString(); + lblSd->setText(labelText); +} +void StatusWidget::setState(const QString &state) +{ + lblState->setText(state); +} + +void StatusWidget::showPrintArea(bool visible) +{ + printProgressWidget->setVisible(visible); + if (visible) { + printTime->start(); + printTimer->start(); + } else { + printTimer->stop(); + } +} + +void StatusWidget::updatePrintTime() +{ + QTime temp(0, 0, 0); + lblTime->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); +} + +void StatusWidget::updatePrintProgress(const float &progress) +{ + printingProgress->setValue(progress); + if (progress > 0) { + QTime temp(0, 0, 0); + lblTimeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); + } else { + lblTimeLeft->setText(QStringLiteral("??:??:??")); + } +} diff --git a/testclient/widgets/statuswidget.h b/testclient/widgets/statuswidget.h new file mode 100644 index 0000000..aa2eafa --- /dev/null +++ b/testclient/widgets/statuswidget.h @@ -0,0 +1,55 @@ +/* AtCore Test Client + Copyright (C) <2018> + Author: 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 + +/* Usage: + * + * Create a instance of the status widget. + */ + +class StatusWidget : public QWidget +{ + Q_OBJECT +public: + StatusWidget(QWidget *parent = nullptr); + + void setSD(bool hasSd); + void setState(const QString &state); + void showPrintArea(bool visible); + void updatePrintProgress(const float &progress); + +signals: + void stopPressed(); + +private slots: + void updatePrintTime(); + +private: + QLabel *lblState = nullptr; + QLabel *lblSd = nullptr; + QLabel *lblTime = nullptr; + QLabel *lblTimeLeft = nullptr; + QTime *printTime = nullptr; + QTimer *printTimer = nullptr; + QProgressBar *printingProgress = nullptr; + QWidget *printProgressWidget = nullptr; +};