diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bf382b..feb0fb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,72 +1,73 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(atelier) find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(KDECompilerSettings) include(KDEInstallDirs) include(KDECMakeSettings) include(ECMInstallIcons) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) set(QT_MIN_VERSION "5.9.0") set(KF5_DEP_VERSION "5.30.0") set(KDE_APPLICATIONS_VERSION_MAJOR "1") set(KDE_APPLICATIONS_VERSION_MINOR "0") set(KDE_APPLICATIONS_VERSION_MICRO "0") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ") endif() #Atelier Dependencies find_package(AtCore REQUIRED COMPONENTS AtCore ) find_package(Qwt6 REQUIRED) find_package(KF5 ${KF5_DEP_VERSION} REQUIRED COMPONENTS Solid I18n XmlGui ConfigWidgets TextEditor ) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Core Widgets SerialPort Charts Quick Qml 3DCore 3DExtras 3DRender 3DInput Multimedia MultimediaWidgets ) - + if(BUILD_TESTING) find_package(Qt5Test ${QT_MIN_VERSION} CONFIG REQUIRED) endif() # config.h configure_file (config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) include(ECMPoQmTools) include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(src) add_subdirectory(deploy) if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/widgets/bedextruderwidget.cpp b/src/widgets/bedextruderwidget.cpp index 2faafd6..d26a0e3 100644 --- a/src/widgets/bedextruderwidget.cpp +++ b/src/widgets/bedextruderwidget.cpp @@ -1,146 +1,141 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodriguessilva@gmail.com Chris Rizzitello - rizzitello@kde.org This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "bedextruderwidget.h" #include "ui_bedextruderwidget.h" #include #include -#include "thermowidget.h" #include +#include "thermowidget.h" + BedExtruderWidget::BedExtruderWidget(QWidget *parent) : QWidget(parent), m_bedThermo(new ThermoWidget(this)), m_exturderThermo(new ThermoWidget(this)) { m_bedThermo->setScale(0, 150); m_exturderThermo->setScale(0, 250); auto centralLayout = new QBoxLayout(QBoxLayout::Direction::LeftToRight); centralLayout->addWidget(m_bedThermo); centralLayout->addWidget(m_exturderThermo); setLayout(centralLayout); //Add Default Extruder setExtruderCount(1); -/* - connect(ui->heatBedPB, &QPushButton::clicked, this, &BedExtruderWidget::heatBedClicked); - connect(ui->heatExtPB, &QPushButton::clicked, this, &BedExtruderWidget::heatExtruderClicked); - connect(ui->bedTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](double tmp) { - if (ui->heatBedPB->isChecked()) { - emit bedTemperatureChanged(tmp,ui->bedAndWaitCB->isChecked()); - } - }); + connect(m_bedThermo, &ThermoWidget::targetTemperatureChanged, [this](double v) { + qDebug() << "Receiving the temperature change for bed"; + emit bedTemperatureChanged((int)v, false); + }); - connect(ui->extTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](double tmp) { - if (ui->heatExtPB->isChecked()) { - emit extTemperatureChanged(tmp, currentExtruder(),ui->extAndWaitCB->isChecked()); - } - }); -*/ + connect(m_exturderThermo, &ThermoWidget::targetTemperatureChanged, [this](double v) { + qDebug() << "Receiving the temperature changed for thermo"; + emit extTemperatureChanged((int)v, currentExtruder(), false); + }); } BedExtruderWidget::~BedExtruderWidget() { } void BedExtruderWidget::setExtruderCount(int value) { if (value == extruderCount) { return; } else if (extruderCount < value) { //loop for the new buttons for (int i = extruderCount; i < value; i++) { auto *rb = new QRadioButton(QString::number(i + 1)); // ui->extRadioButtonLayout->addWidget(rb); extruderMap.insert(i, rb); } } else { //remove buttons - need to test it! for (int i = extruderCount; i >= value; i--) { auto *rb = extruderMap.value(i); // ui->extRadioButtonLayout->removeWidget(rb); extruderMap.remove(i); delete (rb); } } extruderCount = value; } void BedExtruderWidget::updateBedTemp(const float temp) { m_bedThermo->setCurrentTemperature(temp); } void BedExtruderWidget::updateExtTemp(const float temp) { m_exturderThermo->setCurrentTemperature(temp); } void BedExtruderWidget::updateBedTargetTemp(const float temp) { m_bedThermo->setTargetTemperature(temp); } void BedExtruderWidget::updateExtTargetTemp(const float temp) { m_exturderThermo->setTargetTemperature(temp); } void BedExtruderWidget::stopHeating() { /* emit bedTemperatureChanged(0,ui->bedAndWaitCB->isChecked()); for (int i = 0; i < extruderCount; i++) { emit extTemperatureChanged(0, i,ui->extAndWaitCB->isChecked()); } ui->heatBedPB->setChecked(false); ui->heatExtPB->setChecked(false); */ } void BedExtruderWidget::heatExtruderClicked(bool clicked) { /* int temp = ui->extTempSB->value() * clicked; emit extTemperatureChanged(temp, currentExtruder(),ui->extAndWaitCB->isChecked()); */ } void BedExtruderWidget::heatBedClicked(bool clicked) { /* int temp = ui->bedTempSB->value() * clicked; emit bedTemperatureChanged(temp,ui->bedAndWaitCB->isChecked()); */ } int BedExtruderWidget::currentExtruder() { int currExt = 0; for (int i = 0; i < extruderMap.size(); i++) { if (extruderMap.value(i)->isChecked()) { currExt = i; break; } } return currExt; } diff --git a/src/widgets/plotwidget.cpp b/src/widgets/plotwidget.cpp index 62e0ebf..800b6a2 100644 --- a/src/widgets/plotwidget.cpp +++ b/src/widgets/plotwidget.cpp @@ -1,81 +1,85 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Patrick José Pereira - patrickelectric@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "plotwidget.h" #include #include PlotWidget::PlotWidget(QWidget *parent) : QWidget(parent), _chart(new QChartView()), _axisX(new QDateTimeAxis()), _axisY(new QValueAxis()) { QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(_chart); setLayout(mainLayout); _axisX->setTickCount(3); _axisX->setFormat(QStringLiteral("hh:mm:ss")); _axisY->setLabelFormat(QStringLiteral("%d")); _axisY->setTitleText(i18n("Temp.")); _chart->chart()->addAxis(_axisY, Qt::AlignLeft); _chart->chart()->addAxis(_axisX, Qt::AlignBottom); _chart->chart()->axisY()->setRange(0, 3e2); _chart->chart()->axisX()->setRange(QDateTime::currentDateTime().addSecs(-120), QDateTime::currentDateTime()); _chart->setRenderHint(QPainter::Antialiasing); - + newPlot(i18n("Actual Bed")); newPlot(i18n("Target Bed")); // The extruder need to be added after some signal emitted (ExtruderCountChanged) newPlot(i18n("Actual Ext.1")); newPlot(i18n("Target Ext.1")); - + } void PlotWidget::newPlot(const QString& name) { _name2Index[name] = _plots.size(); plot _newPlot; _newPlot.setName(name); _chart->chart()->addSeries(_newPlot.serie()); _newPlot.serie()->attachAxis(_axisY); _newPlot.serie()->attachAxis(_axisX); _plots.append(_newPlot); } void PlotWidget::deletePlot(const QString& name) { _plots.remove(_name2Index[name]); _name2Index.remove(name); } void PlotWidget::appendPoint(const QString& name, float value) { _plots[_name2Index[name]].pushPoint(value); } void PlotWidget::update() { - _chart->chart()->axisX()->setRange(QDateTime::currentDateTime().addSecs(-120), QDateTime::currentDateTime()); + auto chart = _chart->chart(); + auto axisX = chart->axisX(); + auto curr = QDateTime::currentDateTime(); + auto past = curr.addSecs(-120); + axisX->setRange(past, curr); } PlotWidget::~PlotWidget() { } diff --git a/src/widgets/thermowidget.cpp b/src/widgets/thermowidget.cpp index da87033..4d2ca60 100644 --- a/src/widgets/thermowidget.cpp +++ b/src/widgets/thermowidget.cpp @@ -1,92 +1,103 @@ #include "thermowidget.h" #include #include #include #include #include #include ThermoWidget::ThermoWidget(QWidget *parent) : QwtDial(parent), m_currentTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow)), - m_targetTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow)) + m_targetTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, Qt::red, Qt::darkRed)) { setScaleArc(40, 320); setNeedle(m_currentTemperatureNeedle); setReadOnly(false); setFocusPolicy(Qt::StrongFocus); m_currentTemperature = 0; m_targetTemperature = 0; - } void ThermoWidget::keyPressEvent(QKeyEvent* ev) { if (ev->key() >= Qt::Key_0 && ev->key() <= Qt::Key_9) { auto tmp = m_currentTemperatureTextFromEditor + ev->key(); if (tmp.toInt() <= upperBound() && tmp.toInt() >= lowerBound()) { m_currentTemperatureTextFromEditor = tmp; } } else if (ev->key() == Qt::Key_Backspace && m_currentTemperatureTextFromEditor.count()) { m_currentTemperatureTextFromEditor.remove(m_currentTemperatureTextFromEditor.count() - 1, 1); } else if (ev->key() == Qt::Key_Enter) { m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); } else if (ev->key() == Qt::Key_Escape) { m_currentTemperatureTextFromEditor = '0'; } else { QwtDial::keyPressEvent(ev); return; } - m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); - update(); + if (m_targetTemperature != m_currentTemperatureTextFromEditor.toInt()) { + m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); + emit targetTemperatureChanged(m_targetTemperature); + update(); + } } void ThermoWidget::focusOutEvent(QFocusEvent*) { - m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); - update(); + if (m_targetTemperature != m_currentTemperatureTextFromEditor.toInt()) { + m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); + emit targetTemperatureChanged(m_targetTemperature); + update(); + } } void ThermoWidget::paintEvent(QPaintEvent* ev) { QwtDial::paintEvent(ev); QFontMetrics fm(font()); const double width = fm.width(m_currentTemperatureTextFromEditor); const double height = fm.height(); const double xpos = (geometry().width() / 2) - (width / 2); const double ypos = geometry().height() - height * 2 - 2; QPainter p(this); p.setBrush(Qt::white); p.setPen(Qt::white); p.drawText(xpos, ypos, m_currentTemperatureTextFromEditor); } void ThermoWidget::drawNeedle( QPainter *painter, const QPointF ¢er, double radius, double dir, QPalette::ColorGroup colorGroup ) const { Q_UNUSED( dir ); const double relativePercent = upperBound() - lowerBound(); const double currentTemperaturePercent = (m_currentTemperature - lowerBound()) / relativePercent; const double targetTemperaturePercent = (m_targetTemperature - lowerBound()) / relativePercent; const double currentTemperatureAngle = (maxScaleArc() - minScaleArc()) * currentTemperaturePercent + minScaleArc(); const double targetTemperatureAngle = (maxScaleArc() - minScaleArc()) * targetTemperaturePercent + minScaleArc(); - m_targetTemperatureNeedle->draw(painter, center, radius, 360 - currentTemperatureAngle - origin(), colorGroup); - m_currentTemperatureNeedle->draw(painter, center, radius, 360 - targetTemperatureAngle - origin(), colorGroup); + m_targetTemperatureNeedle->draw(painter, center, radius, 360 - targetTemperatureAngle - origin(), colorGroup); + m_currentTemperatureNeedle->draw(painter, center, radius, 360 - currentTemperatureAngle - origin(), colorGroup); } void ThermoWidget::setCurrentTemperature(double temperature) { - m_currentTemperature = temperature; - update(); + if (m_currentTemperature != temperature) { + m_currentTemperature = temperature; + update(); + } } void ThermoWidget::setTargetTemperature(double temperature) { - m_targetTemperature = temperature; - update(); + if (m_targetTemperature != temperature) { + m_currentTemperatureTextFromEditor = QString::number(temperature); + m_targetTemperature = temperature; + emit targetTemperatureChanged(m_targetTemperature); + update(); + } } diff --git a/src/widgets/thermowidget.h b/src/widgets/thermowidget.h index 3d9cd4b..25fc818 100644 --- a/src/widgets/thermowidget.h +++ b/src/widgets/thermowidget.h @@ -1,36 +1,40 @@ #ifndef THERMOWIDGET_H #define THERMOWIDGET_H #include #include class QKeyEvent; class QPaintEvent; class QFocusEvent; class ThermoWidget : public QwtDial { Q_OBJECT + public: ThermoWidget(QWidget *parent); void setTargetTemperature(double temperature); void setCurrentTemperature(double temperature); void drawNeedle( QPainter *painter, const QPointF ¢er, double radius, double dir, QPalette::ColorGroup colorGroup ) const; +signals: + void targetTemperatureChanged(double targetTemperature); + protected: void keyPressEvent (QKeyEvent *); void paintEvent(QPaintEvent *); void focusOutEvent(QFocusEvent *); private: QwtDialSimpleNeedle *m_currentTemperatureNeedle; QwtDialSimpleNeedle *m_targetTemperatureNeedle; double m_currentTemperature; double m_targetTemperature; QString m_currentTemperatureTextFromEditor; }; #endif