diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h --- a/testclient/mainwindow.h +++ b/testclient/mainwindow.h @@ -22,12 +22,18 @@ */ #pragma once -#include #include #include #include "atcore.h" +#include "widgets/commandwidget.h" +#include "widgets/logwidget.h" +#include "widgets/movementwidget.h" #include "widgets/plotwidget.h" +#include "widgets/printwidget.h" +#include "widgets/sdwidget.h" +#include "widgets/statuswidget.h" +#include "widgets/temperaturewidget.h" class SerialLayer; @@ -40,19 +46,6 @@ ~MainWindow() override; public slots: - /** - * @brief Check received messages - * - */ - void checkReceivedCommand(const QByteArray &message); - - /** - * @brief Check pushed message - * - * @param bmsg : Message - */ - void checkPushedCommands(QByteArray); - /** * @brief Check temperature * @@ -64,113 +57,23 @@ 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 Send Command Clicked - */ - void sendPBClicked(); - - /** - * @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 Save the log file. - */ - void saveLogPBClicked(); - - /** - * @brief set printer speed clicked - */ - void printerSpeedPBClicked(); - - /** - * @brief lowRatePB has been clicked - */ - void flowRatePBClicked(); - - /** - * @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 showMessage show a message on the printers LCD - */ - void showMessage(); - - /** - * @brief Update the print Time - */ - void updatePrintTime(); - /** * @brief show/hide dock titlebars * @param checked: True if shown @@ -184,21 +87,8 @@ */ void setDangeriousDocksDisabled(bool disabled); - /** - * @brief List Files on the sd card. - */ - void getSdList(); - - /** - * @brief Sd Card Delete file clicked - */ - void sdDelPBClicked(); - private: AtCore *core; - QTemporaryFile *logFile; - QTime *printTime; - QTimer *printTimer; // Define max number of fans static int fanCount; @@ -209,62 +99,6 @@ */ void locateSerialPort(const QStringList &ports); - /** - * @brief Return string with actual time - * - * @return QString - */ - QString getTime(); - - /** - * @brief Append text in temporary file - * - * @param text - */ - void writeTempFile(QString text); - - /** - * @brief Normal header - * - * @return QString - */ - QString logHeader(); - - /** - * @brief Header of type received - * - * @return QString - */ - QString rLogHeader(); - - /** - * @brief Header of type send - * - * @return QString - */ - QString sLogHeader(); - - /** - * @brief Add in logger normal type message - * - * @param msg: Message - */ - void addLog(QString msg); - - /** - * @brief Add in logger received type message - * - * @param msg: Message - */ - void addRLog(QString msg); - - /** - * @brief Add in logger send type message - * - * @param msg: Message - */ - void addSLog(QString msg); - /** * @brief pluginCB index changed */ @@ -306,32 +140,23 @@ //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; - QPlainTextEdit *textLog = nullptr; + LogWidget *logWidget = nullptr; void makeTempTimelineDock(); QDockWidget *tempTimelineDock = nullptr; PlotWidget *plotWidget = nullptr; void makeCommandDock(); - QDockWidget *printDock = nullptr; QDockWidget *commandDock = nullptr; - QLineEdit *lineCommand = nullptr; - QLineEdit *lineMessage = nullptr; + CommandWidget *commandWidget = nullptr; void makePrintDock(); - QPushButton *buttonPrint = nullptr; - QLineEdit *linePostPause = nullptr; - QSpinBox *sbFlowRate = nullptr; - QSpinBox *sbPrintSpeed = nullptr; + QDockWidget *printDock = nullptr; + PrintWidget *printWidget = nullptr; void makeConnectDock(); QDockWidget *connectDock = nullptr; @@ -342,19 +167,13 @@ void makeMoveDock(); QDockWidget *moveDock = nullptr; - QComboBox *comboMoveAxis = nullptr; - QDoubleSpinBox *sbMoveAxis = nullptr; + MovementWidget *movementWidget = nullptr; void makeTempControlsDock(); QDockWidget *tempControlsDock = nullptr; - QCheckBox *checkAndWait = nullptr; - QSpinBox *sbBedTemp = nullptr; - QComboBox *comboExtruderSelect; - QSpinBox *sbExtruderTemp; - QComboBox *comboFanSelect; - QSpinBox *sbFanSpeed; + TemperatureWidget *temperatureWidget = nullptr; void makeSdDock(); QDockWidget *sdDock = nullptr; - QListWidget *listSdFiles = nullptr; + SdWidget *sdWidget = nullptr; }; diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -20,7 +20,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include #include #include #include @@ -30,43 +29,30 @@ #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)), - logFile(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))) + core(new AtCore(this)) { setWindowTitle(tr("AtCore - Test Client")); setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); QCoreApplication::setApplicationVersion(core->version()); initMenu(); initStatusBar(); initWidgets(); - addLog(tr("Attempting to locate Serial Ports")); + 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, &AtCore::sdCardFileListChanged, sdWidget, &SdWidget::updateFilelist); connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { checkTemperature(0x00, 0, temp); @@ -120,42 +106,11 @@ 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() @@ -184,59 +139,24 @@ setCentralWidget(nullptr); //More Gui stuff - populateCBs(); //hide the printing progress bar. - printProgressWidget->setVisible(false); + statusWidget->showPrintArea(false); } void MainWindow::makeCommandDock() { - //The processing for making a dock is the same for all docks - //Expose the least amount of object outside the creation function. - - // First we make our mainLayout for the dock. - auto *mainLayout = new QVBoxLayout; - - //Begin making content from top to bottom or left to right. - //Making child layouts in the order you want to put them - // onto the mainLayout - lineCommand = new QLineEdit; - lineCommand->setPlaceholderText(tr("Send Command")); - - //we have a few buttons to make here. Lets name this newButton so its easier to reuse - auto *newButton = new QPushButton(tr("Send")); - connect(newButton, &QPushButton::clicked, this, &MainWindow::sendPBClicked); - - //When you have created a Row put the items into layout. - auto *hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(lineCommand); - hBoxLayout->addWidget(newButton); - //Put the Layout or Widget on the mainLayout when its finished. - //This will free your pointers for reuse. - mainLayout->addLayout(hBoxLayout); - - //Start making items for the next layout to place onto the mainLayout. - lineMessage = new QLineEdit; - lineMessage->setPlaceholderText(tr("Show Message")); - - //Here we reuse our button pointer my having it point to a new button. - newButton = new QPushButton(tr("Send")); - connect(newButton, &QPushButton::clicked, this, &MainWindow::showMessage); - - //We reuse the hBoxLayout pointer in the same way as the button pointer. - hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(lineMessage); - hBoxLayout->addWidget(newButton); - mainLayout->addLayout(hBoxLayout); - - //QDockWidget::setLayout is not ment to be used by us - //We must instead Create a widget to hold or dock contents. - auto *dockContents = new QWidget; - dockContents->setLayout(mainLayout); - - //Finally create the dock, and set the Widget. + 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(dockContents); + commandDock->setWidget(commandWidget); //Push the toggle view action into our view menu menuView->insertAction(nullptr, commandDock->toggleViewAction()); @@ -248,63 +168,20 @@ void MainWindow::makePrintDock() { - auto *mainLayout = new QVBoxLayout; - - buttonPrint = new QPushButton(tr("Print File")); - connect(buttonPrint, &QPushButton::clicked, this, &MainWindow::printPBClicked); - - auto *newButton = new QPushButton(tr("Emergency Stop")); - connect(newButton, &QPushButton::clicked, core, &AtCore::emergencyStop); - - auto *hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(buttonPrint); - hBoxLayout->addWidget(newButton); - mainLayout->addLayout(hBoxLayout); - - auto *newLabel = new QLabel(tr("On Pause:")); - linePostPause = new QLineEdit; - linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); - - hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(newLabel); - hBoxLayout->addWidget(linePostPause); - mainLayout->addLayout(hBoxLayout); - - newLabel = new QLabel(tr("Printer Speed")); - sbPrintSpeed = new QSpinBox; - sbPrintSpeed->setRange(1, 300); - sbPrintSpeed->setValue(100); - sbPrintSpeed->setSuffix(QStringLiteral("%")); - - newButton = new QPushButton(tr("Set")); - connect(newButton, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); - - hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(newLabel, 35); - hBoxLayout->addWidget(sbPrintSpeed, 10); - hBoxLayout->addWidget(newButton, 20); - mainLayout->addLayout(hBoxLayout); + printWidget = new PrintWidget; + connect(printWidget, &PrintWidget::printPressed, this, &MainWindow::printPBClicked); + connect(printWidget, &PrintWidget::emergencyStopPressed, core, &AtCore::emergencyStop); - newLabel = new QLabel(tr("Flow Rate")); - sbFlowRate = new QSpinBox; - sbFlowRate->setRange(1, 300); - sbFlowRate->setValue(100); - sbFlowRate->setSuffix(QStringLiteral("%")); - - newButton = new QPushButton(tr("Set")); - connect(newButton, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked); - - hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(newLabel, 35); - hBoxLayout->addWidget(sbFlowRate, 10); - hBoxLayout->addWidget(newButton, 20); - mainLayout->addLayout(hBoxLayout); + connect(printWidget, &PrintWidget::printSpeedChanged, [this](const int speed) { + core->setPrinterSpeed(speed); + }); - auto *dockContents = new QWidget; - dockContents->setLayout(mainLayout); + connect(printWidget, &PrintWidget::flowRateChanged, [this](const int rate) { + core->setFlowRate(rate); + }); printDock = new QDockWidget(tr("Print"), this); - printDock->setWidget(dockContents); + printDock->setWidget(printWidget); menuView->insertAction(nullptr, printDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, printDock); @@ -321,22 +198,9 @@ void MainWindow::makeLogDock() { - textLog = new QPlainTextEdit; - textLog->setReadOnly(true); - textLog->setMaximumBlockCount(1000); - - auto *newButton = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton), tr("Save Session Log")); - connect(newButton, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); - - auto *mainLayout = new QVBoxLayout; - mainLayout->addWidget(textLog); - mainLayout->addWidget(newButton); - - auto *dockContents = new QWidget(); - dockContents->setLayout(mainLayout); - + logWidget = new LogWidget(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))); logDock = new QDockWidget(tr("Session Log"), this); - logDock->setWidget(dockContents); + logDock->setWidget(logWidget); menuView->insertAction(nullptr, logDock->toggleViewAction()); addDockWidget(Qt::RightDockWidgetArea, logDock); @@ -392,151 +256,87 @@ 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); + movementWidget = new MovementWidget; - 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")); + connect(movementWidget, &MovementWidget::homeAllPressed, [this] { + logWidget->appendLog(tr("Home All")); + core->home(); + }); - sbMoveAxis = new QDoubleSpinBox; - sbMoveAxis->setRange(0, 200); + connect(movementWidget, &MovementWidget::homeXPressed, [this] { + logWidget->appendLog(tr("Home X")); + core->home(AtCore::X); + }); - newButton = new QPushButton(tr("Go")); - connect(newButton, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); + connect(movementWidget, &MovementWidget::homeYPressed, [this] { + logWidget->appendLog(tr("Home Y")); + core->home(AtCore::Y); + }); - hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(comboMoveAxis); - hBoxLayout->addWidget(sbMoveAxis); - hBoxLayout->addWidget(newButton); - mainLayout->addLayout(hBoxLayout); + connect(movementWidget, &MovementWidget::homeZPressed, [this] { + logWidget->appendLog(tr("Home Z")); + core->home(AtCore::Z); + }); - newButton = new QPushButton(tr("Disable Motors")); - connect(newButton, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); - mainLayout->addWidget(newButton); + connect(movementWidget, &MovementWidget::absoluteMove, [this](const QLatin1Char & axis, const double & value) { + logWidget->appendLog(GCode::description(GCode::G1)); + core->move(axis, value); + }); - auto *axisControl = new AxisControl; - connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); - mainLayout->addWidget(axisControl); + connect(movementWidget, &MovementWidget::disableMotorsPressed, [this] { + core->disableMotors(0); + }); - auto *dockContents = new QWidget; - dockContents->setLayout(mainLayout); + connect(movementWidget, &MovementWidget::relativeMove, [this](const QLatin1Char & axis, const double & value) { + core->setRelativePosition(); + core->move(axis, value); + core->setAbsolutePosition(); + }); moveDock = new QDockWidget(tr("Movement"), this); - moveDock->setWidget(dockContents); + moveDock->setWidget(movementWidget); 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); + temperatureWidget = new TemperatureWidget; + connect(temperatureWidget, &TemperatureWidget::bedTempChanged, core, &AtCore::setBedTemp); + connect(temperatureWidget, &TemperatureWidget::extTempChanged, core, &AtCore::setExtruderTemp); + connect(temperatureWidget, &TemperatureWidget::fanSpeedChanged, core, &AtCore::setFanSpeed); tempControlsDock = new QDockWidget(tr("Temperatures"), this); - tempControlsDock->setWidget(dockContents); - + tempControlsDock->setWidget(temperatureWidget); 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); + sdWidget = new SdWidget; + connect(sdWidget, &SdWidget::requestSdList, core, &AtCore::sdFileList); - 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); + connect(sdWidget, &SdWidget::printSdFile, [this](const QString & fileName) { + if (fileName.isEmpty()) { + QMessageBox::information(this, tr("Print Error"), tr("You must Select a file from the list")); + } else { + core->print(fileName, true); + } + }); - auto *dockContents = new QWidget; - dockContents->setLayout(mainLayout); + connect(sdWidget, &SdWidget::deleteSdFile, [this](const QString & fileName) { + if (fileName.isEmpty()) { + QMessageBox::information(this, tr("Delete Error"), tr("You must Select a file from the list")); + } else { + core->sdDelete(fileName); + } + }); sdDock = new QDockWidget(tr("Sd Card"), this); - sdDock->setWidget(dockContents); - + sdDock->setWidget(sdWidget); menuView->insertAction(nullptr, sdDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, sdDock); } @@ -549,78 +349,7 @@ MainWindow::~MainWindow() { - delete logFile; -} - -QString MainWindow::getTime() -{ - return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); -} - -QString MainWindow::logHeader() -{ - return QStringLiteral("[%1] ").arg(getTime()); -} -QString MainWindow::rLogHeader() -{ - return QStringLiteral("[%1]< ").arg(getTime()); -} - -QString MainWindow::sLogHeader() -{ - return QStringLiteral("[%1]> ").arg(getTime()); -} - -void MainWindow::writeTempFile(QString text) -{ - /* - A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, - this allows easy access to the data in the file. This function will - return true upon success and will set the fileName() to the unique - filename used. - */ - logFile->open(); - logFile->seek(logFile->size()); - logFile->write(text.toLatin1()); - logFile->putChar('\n'); - logFile->close(); -} - -void MainWindow::addLog(QString msg) -{ - QString message(logHeader() + msg); - textLog->appendPlainText(message); - writeTempFile(message); -} - -void MainWindow::addRLog(QString msg) -{ - QString message(rLogHeader() + msg); - textLog->appendPlainText(message); - writeTempFile(message); -} - -void MainWindow::addSLog(QString msg) -{ - QString message(sLogHeader() + msg); - textLog->appendPlainText(message); - writeTempFile(message); -} - -void MainWindow::checkReceivedCommand(const QByteArray &message) -{ - 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")); - addSLog(msg); } void MainWindow::checkTemperature(uint sensorType, uint number, uint temp) @@ -656,7 +385,7 @@ msg = msg.arg(QString::number(number)) .arg(QString::number(temp)); - addRLog(msg); + logWidget->appendLog(msg); } /** * @brief MainWindow::locateSerialPort @@ -668,111 +397,42 @@ comboPort->clear(); if (!ports.isEmpty()) { comboPort->addItems(ports); - addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); + 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 (! textLog->toPlainText().endsWith(portError)) { - addLog(portError); + 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, this, &MainWindow::checkReceivedCommand); - connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); + connect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); + connect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); buttonConnect->setText(tr("Disconnect")); - addLog(tr("Serial connected")); + logWidget->appendLog(tr("Serial connected")); if (comboPlugin->currentText().contains(tr("Autodetect"))) { - addLog(tr("No plugin loaded !")); - addLog(tr("Requesting Firmware...")); + logWidget->appendLog(tr("No plugin loaded !")); + logWidget->appendLog(tr("Requesting Firmware...")); } else { core->loadFirmwarePlugin(comboPlugin->currentText()); } } else { - addLog(tr("Failed to open serial in r/w mode")); + logWidget->appendLog(tr("Failed to open serial in r/w mode")); } } else { - disconnect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); - disconnect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); + disconnect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); + disconnect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); core->closeConnection(); core->setState(AtCore::DISCONNECTED); - addLog(tr("Disconnected")); + logWidget->appendLog(tr("Disconnected")); buttonConnect->setText(tr("Connect")); } } -void MainWindow::sendPBClicked() -{ - QString comm = lineCommand->text().toUpper(); - core->pushCommand(comm); - lineCommand->clear(); -} - -void MainWindow::homeAllPBClicked() -{ - addSLog(tr("Home All")); - core->home(); -} - -void MainWindow::homeXPBClicked() -{ - addSLog(tr("Home X")); - core->home(AtCore::X); -} - -void MainWindow::homeYPBClicked() -{ - addSLog(tr("Home Y")); - core->home(AtCore::Y); -} - -void MainWindow::homeZPBClicked() -{ - addSLog(tr("Home Z")); - core->home(AtCore::Z); -} - -void MainWindow::bedTempPBClicked() -{ - if (checkAndWait->isChecked()) { - addSLog(GCode::description(GCode::M190)); - } else { - addSLog(GCode::description(GCode::M140)); - } - core->setBedTemp(sbBedTemp->value(), checkAndWait->isChecked()); -} - -void MainWindow::extTempPBClicked() -{ - if (checkAndWait->isChecked()) { - addSLog(GCode::description(GCode::M109)); - } else { - addSLog(GCode::description(GCode::M104)); - } - core->setExtruderTemp(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked()); -} - -void MainWindow::mvAxisPBClicked() -{ - addSLog(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() -{ - addSLog(GCode::description(GCode::M106)); - core->setFanSpeed(sbFanSpeed->value(), comboFanSelect->currentIndex()); -} - void MainWindow::printPBClicked() { QString fileName; @@ -790,15 +450,15 @@ case AtCore::IDLE: fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), tr("*.gcode")); if (fileName.isNull()) { - addLog(tr("No File Selected")); + logWidget->appendLog(tr("No File Selected")); } else { - addLog(tr("Print: %1").arg(fileName)); + logWidget->appendLog(tr("Print: %1").arg(fileName)); core->print(fileName); } break; case AtCore::BUSY: - core->pause(linePostPause->text()); + core->pause(printWidget->postPauseCommand()); break; case AtCore::PAUSE: @@ -810,14 +470,6 @@ } } -void MainWindow::saveLogPBClicked() -{ - // Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it). - QString fileName = QDir::homePath() + QChar::fromLatin1('/') + QFileInfo(logFile->fileName()).fileName() + QStringLiteral(".txt"); - QString saveFileName = QFileDialog::getSaveFileName(this, tr("Save Log to file"), fileName); - QFile::copy(logFile->fileName(), saveFileName); - logFile->close(); -} void MainWindow::pluginCBChanged(QString currentText) { if (core->state() != AtCore::DISCONNECTED) { @@ -827,48 +479,35 @@ } } -void MainWindow::flowRatePBClicked() -{ - core->setFlowRate(sbFlowRate->value()); -} - -void MainWindow::printerSpeedPBClicked() -{ - core->setPrinterSpeed(sbPrintSpeed->value()); -} - void MainWindow::printerStateChanged(AtCore::STATES state) { QString stateString; switch (state) { case AtCore::IDLE: - buttonPrint->setText(tr("Print File")); + printWidget->setPrintText(tr("Print File")); stateString = tr("Connected to ") + core->connectedPort(); break; case AtCore::STARTPRINT: stateString = tr("START PRINT"); - buttonPrint->setText(tr("Pause Print")); - printProgressWidget->setVisible(true); - printTime->start(); - printTimer->start(); + printWidget->setPrintText(tr("Pause Print")); + statusWidget->showPrintArea(true); break; case AtCore::FINISHEDPRINT: stateString = tr("Finished Print"); - buttonPrint->setText(tr("Print File")); - printProgressWidget->setVisible(false); - printTimer->stop(); + printWidget->setPrintText(tr("Print File")); + statusWidget->showPrintArea(false); break; case AtCore::PAUSE: stateString = tr("Paused"); - buttonPrint->setText(tr("Resume Print")); + printWidget->setPrintText(tr("Resume Print")); break; case AtCore::BUSY: stateString = tr("Printing"); - buttonPrint->setText(tr("Pause Print")); + printWidget->setPrintText(tr("Pause Print")); break; case AtCore::DISCONNECTED: @@ -889,43 +528,9 @@ stateString = tr("Command ERROR"); break; } - lblState->setText(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::showMessage() -{ - core->showMessage(lineMessage->text()); + statusWidget->setState(stateString); } -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) { @@ -956,46 +561,9 @@ 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); + if (!disabled) { + temperatureWidget->updateExtruderCount(core->extruderCount()); + temperatureWidget->updateFanCount(fanCount); } } diff --git a/testclient/widgets/CMakeLists.txt b/testclient/widgets/CMakeLists.txt --- a/testclient/widgets/CMakeLists.txt +++ b/testclient/widgets/CMakeLists.txt @@ -1,7 +1,14 @@ set(widgets_SRCS - plotwidget.cpp - axiscontrol.cpp about.cpp + axiscontrol.cpp + commandwidget.cpp + logwidget.cpp + movementwidget.cpp + plotwidget.cpp + printwidget.cpp + sdwidget.cpp + statuswidget.cpp + temperaturewidget.cpp ) add_library(AtCoreTestWidgets STATIC ${widgets_SRCS}) diff --git a/testclient/widgets/commandwidget.h b/testclient/widgets/commandwidget.h new file mode 100644 --- /dev/null +++ b/testclient/widgets/commandwidget.h @@ -0,0 +1,41 @@ +/* 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 + +/* Usage: + * + * Create a instance of the command widget. + */ + +class CommandWidget : public QWidget +{ + Q_OBJECT +public: + CommandWidget(QWidget *parent = nullptr); + +signals: + void commandPressed(const QString &command); + void messagePressed(const QString &message); + +private: + QLineEdit *lineCommand = nullptr; + QLineEdit *lineMessage = nullptr; +}; diff --git a/testclient/widgets/commandwidget.cpp b/testclient/widgets/commandwidget.cpp new file mode 100644 --- /dev/null +++ b/testclient/widgets/commandwidget.cpp @@ -0,0 +1,70 @@ +/* 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 "commandwidget.h" +#include +#include +#include + +CommandWidget::CommandWidget(QWidget *parent) : + QWidget(parent) +{ + //Expose the least amount of object outside the creation function. + + // First we make our mainLayout + auto mainLayout = new QVBoxLayout; + + //Begin making content from top to bottom or left to right. + //Making child layouts in the order you want to put them + // onto the mainLayout + lineCommand = new QLineEdit; + lineCommand->setPlaceholderText(tr("Send Command")); + + //we have a few buttons to make here. Lets name this newButton so its easier to reuse + auto newButton = new QPushButton(tr("Send")); + connect(newButton, &QPushButton::clicked, [&] { + emit(commandPressed(lineCommand->text())); + lineCommand->clear(); + }); + //When you have created a Row put the items into layout. + auto hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(lineCommand); + hBoxLayout->addWidget(newButton); + //Put the Layout or Widget on the mainLayout when its finished. + //This will free your pointers for reuse. + mainLayout->addLayout(hBoxLayout); + + //Start making items for the next layout to place onto the mainLayout. + lineMessage = new QLineEdit; + lineMessage->setPlaceholderText(tr("Show Message")); + + //Reuse our button pointer. + newButton = new QPushButton(tr("Send")); + + connect(newButton, &QPushButton::clicked, [&] { + emit(messagePressed(lineMessage->text())); + lineMessage->clear(); + }); + + //We reuse the hBoxLayout pointer in the same way as the button pointer. + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(lineMessage); + hBoxLayout->addWidget(newButton); + mainLayout->addLayout(hBoxLayout); + + setLayout(mainLayout); +} diff --git a/testclient/widgets/logwidget.h b/testclient/widgets/logwidget.h new file mode 100644 --- /dev/null +++ b/testclient/widgets/logwidget.h @@ -0,0 +1,85 @@ +/* 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 + +/* Usage: + * + * Create a instance of the log widget. + */ + +class LogWidget : public QWidget +{ + Q_OBJECT +public: + LogWidget(QTemporaryFile *tempFile, QWidget *parent = nullptr); + + /** + * @brief Add in logger normal type message + * + * @param msg: Message + */ + void appendLog(const QString &msg); + + /** + * @brief Add in logger received type message + * + * @param bmsg: Message + */ + void appendRLog(const QByteArray &bmsg); + + /** + * @brief Add in logger send type message + * + * @param bmsg: Message + */ + void appendSLog(const QByteArray &bmsg); + + /** + * @brief test if last line of log is string + * @param string: line to test for + * @return true if last line starts with + */ + bool endsWith(const QString &string); + +private: + /** + * @brief Return string with actual time + * + * @return QString + */ + QString getTime(); + + /** + * @brief save Log pressed. + */ + void savePressed(); + + /** + * @brief Append text in temporary file + * + * @param text + */ + void writeTempFile(QString text); + + QTemporaryFile *logFile = nullptr; + QPlainTextEdit *textLog = nullptr; +}; diff --git a/testclient/widgets/logwidget.cpp b/testclient/widgets/logwidget.cpp new file mode 100644 --- /dev/null +++ b/testclient/widgets/logwidget.cpp @@ -0,0 +1,102 @@ +/* AtCore Test Client + Copyright (C) <2018> + Author: Chris Rizzitello - rizzitello@kde.org + Patrick José Pereira + + 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 "logwidget.h" +#include +#include +#include +#include +#include + +LogWidget::LogWidget(QTemporaryFile *tempFile, QWidget *parent) : + QWidget(parent), + logFile(tempFile) +{ + textLog = new QPlainTextEdit; + textLog->setReadOnly(true); + textLog->setMaximumBlockCount(1000); + + auto newButton = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton), tr("Save Session Log")); + connect(newButton, &QPushButton::clicked, this, &LogWidget::savePressed); + + auto mainLayout = new QVBoxLayout; + mainLayout->addWidget(textLog); + mainLayout->addWidget(newButton); + + setLayout(mainLayout); +} + +QString LogWidget::getTime() +{ + return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); +} + +void LogWidget::appendLog(const QString &msg) +{ + QString message(QStringLiteral("[%1] %2").arg(getTime(), msg)); + textLog->appendPlainText(message); + writeTempFile(message); +} + +void LogWidget::appendRLog(const QByteArray &bmsg) +{ + QString message(QStringLiteral("[%1]< %2").arg(getTime(), QString::fromUtf8(bmsg))); + textLog->appendPlainText(message); + writeTempFile(message); +} + +void LogWidget::appendSLog(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")); + QString message(QStringLiteral("[%1]> %2").arg(getTime(), msg)); + textLog->appendPlainText(message); + writeTempFile(message); +} + +void LogWidget::writeTempFile(QString text) +{ + /* + A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, + this allows easy access to the data in the file. This function will + return true upon success and will set the fileName() to the unique + filename used. + */ + logFile->open(); + logFile->seek(logFile->size()); + logFile->write(text.toLatin1()); + logFile->putChar('\n'); + logFile->close(); +} + +void LogWidget::savePressed() +{ + // Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it). + QString fileName = QDir::homePath() + QChar::fromLatin1('/') + QFileInfo(logFile->fileName()).fileName() + QStringLiteral(".txt"); + QString saveFileName = QFileDialog::getSaveFileName(this, tr("Save Log to file"), fileName); + QFile::copy(logFile->fileName(), saveFileName); + logFile->close(); +} + +bool LogWidget::endsWith(const QString &string) +{ + return textLog->toPlainText().endsWith(string); +} diff --git a/testclient/widgets/movementwidget.h b/testclient/widgets/movementwidget.h new file mode 100644 --- /dev/null +++ b/testclient/widgets/movementwidget.h @@ -0,0 +1,47 @@ +/* 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 + +/* Usage: + * + * Create a instance of the movement widget. + */ + +class MovementWidget : public QWidget +{ + Q_OBJECT +public: + MovementWidget(QWidget *parent = nullptr); + +signals: + void homeAllPressed(); + void homeXPressed(); + void homeYPressed(); + void homeZPressed(); + void absoluteMove(const QLatin1Char &axis, const double &value); + void relativeMove(const QLatin1Char &axis, const double &value); + void disableMotorsPressed(); + +private: + QComboBox *comboMoveAxis = nullptr; + QDoubleSpinBox *sbMoveAxis = nullptr; +}; diff --git a/testclient/widgets/movementwidget.cpp b/testclient/widgets/movementwidget.cpp new file mode 100644 --- /dev/null +++ b/testclient/widgets/movementwidget.cpp @@ -0,0 +1,95 @@ +/* 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 "axiscontrol.h" +#include "movementwidget.h" + +MovementWidget::MovementWidget(QWidget *parent) : + QWidget(parent) +{ + auto mainLayout = new QVBoxLayout; + auto hBoxLayout = new QHBoxLayout; + + auto newButton = new QPushButton(tr("Home All")); + hBoxLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(homeAllPressed()); + }); + + newButton = new QPushButton(tr("Home X")); + hBoxLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(homeXPressed()); + }); + + newButton = new QPushButton(tr("Home Y")); + hBoxLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(homeYPressed()); + }); + + newButton = new QPushButton(tr("Home Z")); + hBoxLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(homeZPressed()); + }); + 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, [this] { + if (comboMoveAxis->currentIndex() == 0) + { + emit(absoluteMove(QLatin1Char('X'), sbMoveAxis->value())); + } else if (comboMoveAxis->currentIndex() == 1) + { + emit(absoluteMove(QLatin1Char('Y'), sbMoveAxis->value())); + } else if (comboMoveAxis->currentIndex() == 2) + { + emit(absoluteMove(QLatin1Char('Z'), sbMoveAxis->value())); + } + }); + + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(comboMoveAxis); + hBoxLayout->addWidget(sbMoveAxis); + hBoxLayout->addWidget(newButton); + mainLayout->addLayout(hBoxLayout); + + newButton = new QPushButton(tr("Disable Motors")); + mainLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(disableMotorsPressed()); + }); + + auto axisControl = new AxisControl; + mainLayout->addWidget(axisControl); + connect(axisControl, &AxisControl::clicked, this, &MovementWidget::relativeMove); + + setLayout(mainLayout); +} diff --git a/testclient/widgets/printwidget.h b/testclient/widgets/printwidget.h new file mode 100644 --- /dev/null +++ b/testclient/widgets/printwidget.h @@ -0,0 +1,49 @@ +/* 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 print widget. + */ + +class PrintWidget : public QWidget +{ + Q_OBJECT +public: + PrintWidget(QWidget *parent = nullptr); + QString postPauseCommand() const; + void setPrintText(const QString &text); + +signals: + void emergencyStopPressed(); + void flowRateChanged(const int rate); + void printPressed(); + void printSpeedChanged(const int speed); + +private: + QPushButton *buttonPrint = nullptr; + QLineEdit *linePostPause = nullptr; + QSpinBox *sbFlowRate = nullptr; + QSpinBox *sbPrintSpeed = nullptr; +}; diff --git a/testclient/widgets/printwidget.cpp b/testclient/widgets/printwidget.cpp new file mode 100644 --- /dev/null +++ b/testclient/widgets/printwidget.cpp @@ -0,0 +1,98 @@ +/* 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 "printwidget.h" +#include +#include +#include +#include + +PrintWidget::PrintWidget(QWidget *parent) : + QWidget(parent) +{ + auto mainLayout = new QVBoxLayout; + + buttonPrint = new QPushButton(tr("Print File")); + connect(buttonPrint, &QPushButton::clicked, [this] { + emit(printPressed()); + }); + + auto newButton = new QPushButton(tr("Emergency Stop")); + connect(newButton, &QPushButton::clicked, [this] { + emit(emergencyStopPressed()); + }); + + auto hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(buttonPrint); + hBoxLayout->addWidget(newButton); + mainLayout->addLayout(hBoxLayout); + + auto newLabel = new QLabel(tr("On Pause:")); + + linePostPause = new QLineEdit; + linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); + + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(newLabel); + hBoxLayout->addWidget(linePostPause); + mainLayout->addLayout(hBoxLayout); + + newLabel = new QLabel(tr("Printer Speed")); + sbPrintSpeed = new QSpinBox; + sbPrintSpeed->setRange(1, 300); + sbPrintSpeed->setValue(100); + sbPrintSpeed->setSuffix(QStringLiteral("%")); + + newButton = new QPushButton(tr("Set")); + connect(newButton, &QPushButton::clicked, [this] { + emit(printSpeedChanged(sbPrintSpeed->value())); + }); + + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(newLabel, 35); + hBoxLayout->addWidget(sbPrintSpeed, 10); + hBoxLayout->addWidget(newButton, 20); + mainLayout->addLayout(hBoxLayout); + + newLabel = new QLabel(tr("Flow Rate")); + sbFlowRate = new QSpinBox; + sbFlowRate->setRange(1, 300); + sbFlowRate->setValue(100); + sbFlowRate->setSuffix(QStringLiteral("%")); + + newButton = new QPushButton(tr("Set")); + connect(newButton, &QPushButton::clicked, [this] { + emit(flowRateChanged(sbFlowRate->value())); + }); + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(newLabel, 35); + hBoxLayout->addWidget(sbFlowRate, 10); + hBoxLayout->addWidget(newButton, 20); + mainLayout->addLayout(hBoxLayout); + + setLayout(mainLayout); +} + +QString PrintWidget::postPauseCommand(void) const +{ + return linePostPause->text(); +} + +void PrintWidget::setPrintText(const QString &text) +{ + buttonPrint->setText(text); +} diff --git a/testclient/widgets/sdwidget.h b/testclient/widgets/sdwidget.h new file mode 100644 --- /dev/null +++ b/testclient/widgets/sdwidget.h @@ -0,0 +1,41 @@ +/* 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 + +/* Usage: + * + * Create a instance of the sd widget. + */ + +class SdWidget : public QWidget +{ + Q_OBJECT +public: + SdWidget(QWidget *parent = nullptr); + void updateFilelist(const QStringList &fileList); +signals: + void requestSdList(); + void printSdFile(const QString &fileName); + void deleteSdFile(const QString &fileName); + +private: + QListWidget *listSdFiles = nullptr; +}; diff --git a/testclient/widgets/sdwidget.cpp b/testclient/widgets/sdwidget.cpp new file mode 100644 --- /dev/null +++ b/testclient/widgets/sdwidget.cpp @@ -0,0 +1,66 @@ +/* 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 "sdwidget.h" + +SdWidget::SdWidget(QWidget *parent) : + QWidget(parent) +{ + auto hBoxLayout = new QHBoxLayout; + + auto newButton = new QPushButton(tr("Get List")); + hBoxLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(requestSdList()); + }); + + newButton = new QPushButton(tr("Print Selected")); + hBoxLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(printSdFile(listSdFiles->currentItem()->text())); + }); + + newButton = new QPushButton(tr("Delete Selected")); + hBoxLayout->addWidget(newButton); + connect(newButton, &QPushButton::clicked, [this] { + emit(deleteSdFile(listSdFiles->currentItem()->text())); + listSdFiles->setCurrentRow(-1); + }); + + 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); + + setLayout(mainLayout); +} + +void SdWidget::updateFilelist(const QStringList &fileList) +{ + listSdFiles->clear(); + listSdFiles->addItems(fileList); +} diff --git a/testclient/widgets/statuswidget.h b/testclient/widgets/statuswidget.h new file mode 100644 --- /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; +}; diff --git a/testclient/widgets/statuswidget.cpp b/testclient/widgets/statuswidget.cpp new file mode 100644 --- /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/temperaturewidget.h b/testclient/widgets/temperaturewidget.h new file mode 100644 --- /dev/null +++ b/testclient/widgets/temperaturewidget.h @@ -0,0 +1,50 @@ +/* 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 temperature widget. + */ + +class TemperatureWidget : public QWidget +{ + Q_OBJECT +public: + TemperatureWidget(QWidget *parent = nullptr); + void updateExtruderCount(const int count); + void updateFanCount(const int count); + +signals: + void bedTempChanged(const int temperature, bool andWait); + void extTempChanged(const int temperature, const int extNum, bool andWait); + void fanSpeedChanged(const int speed, const int fanNum); + +private: + QCheckBox *checkAndWait = nullptr; + QComboBox *comboExtruderSelect; + QComboBox *comboFanSelect; + QSpinBox *sbBedTemp = nullptr; + QSpinBox *sbExtruderTemp; + QSpinBox *sbFanSpeed; +}; diff --git a/testclient/widgets/temperaturewidget.cpp b/testclient/widgets/temperaturewidget.cpp new file mode 100644 --- /dev/null +++ b/testclient/widgets/temperaturewidget.cpp @@ -0,0 +1,95 @@ +/* AtCore Test Client + Copyright (C) <2018> + Author: Chris Rizzitello - rizzitello@kde.org + Lays Rodrigues - lays.rodriguea@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 "temperaturewidget.h" +#include +#include +#include +#include + +TemperatureWidget::TemperatureWidget(QWidget *parent) : + QWidget(parent) +{ + 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] { + emit(bedTempChanged(sbBedTemp->value(), checkAndWait->isChecked())); + }); + + 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] { + emit(extTempChanged(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked())); + }); + + 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] { + emit(fanSpeedChanged(sbFanSpeed->value(), comboFanSelect->currentIndex())); + }); + + hboxLayout = new QHBoxLayout; + hboxLayout->addWidget(comboFanSelect, 80); + hboxLayout->addWidget(sbFanSpeed); + hboxLayout->addWidget(newButton); + mainLayout->addItem(hboxLayout); + + setLayout(mainLayout); +} + +void TemperatureWidget::updateExtruderCount(const int count) +{ + for (int i = 0; i < count; i++) { + comboExtruderSelect->insertItem(i, tr("Extruder %1").arg(i)); + } +} + +void TemperatureWidget::updateFanCount(const int count) +{ + for (int i = 0; i < count; i++) { + comboFanSelect->insertItem(i, tr("Fan %1 speed").arg(i)); + } +}