Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/atcoreinstancewidget.cpp
Show All 27 Lines | 27 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | |||
---|---|---|---|---|---|
28 | QWidget(parent), | 28 | QWidget(parent), | ||
29 | m_mainToolBar(nullptr), | 29 | m_mainToolBar(nullptr), | ||
30 | m_toolBar(nullptr), | 30 | m_toolBar(nullptr), | ||
31 | m_printAction(nullptr) | 31 | m_printAction(nullptr) | ||
32 | { | 32 | { | ||
33 | m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ; | 33 | m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ; | ||
34 | ui = new Ui::AtCoreInstanceWidget; | 34 | ui = new Ui::AtCoreInstanceWidget; | ||
35 | ui->setupUi(this); | 35 | ui->setupUi(this); | ||
36 | | ||||
37 | auto layout = new QHBoxLayout(); | ||||
38 | m_axisControl = new AxisControl(); | ||||
39 | layout->addWidget(m_axisControl); | ||||
40 | ui->gridLayout_3->addLayout(layout, 2, 2, Qt::AlignHCenter); | ||||
41 | | ||||
42 | m_plotWidget = new PlotWidget(); | ||||
43 | layout = new QHBoxLayout(); | ||||
44 | layout->addWidget(m_plotWidget); | ||||
45 | ui->gridLayout_3->addLayout(layout, 3, 0, 1, 3, Qt::AlignHCenter); | ||||
46 | | ||||
47 | m_logWidget = new LogWidget(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/Atelier_"))); | ||||
48 | layout = new QHBoxLayout(); | ||||
49 | layout->addWidget(m_logWidget); | ||||
50 | ui->gridLayout_2->addLayout(layout, 2, 0, Qt::AlignHCenter); | ||||
51 | | ||||
36 | ui->printProgressWidget->setVisible(false); | 52 | ui->printProgressWidget->setVisible(false); | ||
37 | buildMainToolbar(); | 53 | buildMainToolbar(); | ||
38 | buildToolbar(); | 54 | buildToolbar(); | ||
39 | buildConnectionToolbar(); | 55 | buildConnectionToolbar(); | ||
40 | enableControls(false); | 56 | enableControls(false); | ||
41 | updateProfileData(); | 57 | updateProfileData(); | ||
42 | initConnectsToAtCore(); | 58 | initConnectsToAtCore(); | ||
43 | m_mainToolBar->setHidden(true); | 59 | m_mainToolBar->setHidden(true); | ||
Show All 30 Lines | 85 | for(auto homes : std::map<QString, int>{{"X", AtCore::X}, {"Y", AtCore::Y}, {"Z", AtCore::Z}}) { | |||
74 | m_toolBar->addAction(home); | 90 | m_toolBar->addAction(home); | ||
75 | } | 91 | } | ||
76 | 92 | | |||
77 | m_toolBar->addSeparator(); | 93 | m_toolBar->addSeparator(); | ||
78 | 94 | | |||
79 | auto *axis = new QAction("Axis"); | 95 | auto *axis = new QAction("Axis"); | ||
80 | axis->setCheckable(true); | 96 | axis->setCheckable(true); | ||
81 | axis->setChecked(true); | 97 | axis->setChecked(true); | ||
82 | connect(axis, &QAction::toggled, ui->axisViewWidget, &AxisControl::setVisible); | 98 | connect(axis, &QAction::toggled, m_axisControl, &AxisControl::setVisible); | ||
83 | 99 | | |||
84 | auto controls = new QAction("Controls"); | 100 | auto controls = new QAction("Controls"); | ||
85 | controls->setCheckable(true); | 101 | controls->setCheckable(true); | ||
86 | controls->setChecked(true); | 102 | controls->setChecked(true); | ||
87 | connect(controls, &QAction::toggled, ui->bedExtWidget, &BedExtruderWidget::setVisible); | 103 | connect(controls, &QAction::toggled, ui->bedExtWidget, &BedExtruderWidget::setVisible); | ||
88 | 104 | | |||
89 | auto plot = new QAction("Temperature Plot"); | 105 | auto plot = new QAction("Temperature Plot"); | ||
90 | plot->setCheckable(true); | 106 | plot->setCheckable(true); | ||
91 | plot->setChecked(true); | 107 | plot->setChecked(true); | ||
92 | connect(plot, &QAction::toggled, ui->plotWidget, &PlotWidget::setVisible); | 108 | connect(plot, &QAction::toggled, m_plotWidget, &PlotWidget::setVisible); | ||
93 | 109 | | |||
94 | m_toolBar->addAction(axis); | 110 | m_toolBar->addAction(axis); | ||
95 | m_toolBar->addAction(controls); | 111 | m_toolBar->addAction(controls); | ||
96 | m_toolBar->addAction(plot); | 112 | m_toolBar->addAction(plot); | ||
97 | ui->toolBarLayout->addWidget(m_toolBar); | 113 | ui->toolBarLayout->addWidget(m_toolBar); | ||
98 | ui->toolBarLayout->addStretch(); | 114 | ui->toolBarLayout->addStretch(); | ||
99 | } | 115 | } | ||
100 | 116 | | |||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | 230 | { | |||
224 | 240 | | |||
225 | // Bed and Extruder temperatures management | 241 | // Bed and Extruder temperatures management | ||
226 | connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &m_core, &AtCore::setBedTemp); | 242 | connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &m_core, &AtCore::setBedTemp); | ||
227 | connect(ui->bedExtWidget, &BedExtruderWidget::extTemperatureChanged, &m_core, &AtCore::setExtruderTemp); | 243 | connect(ui->bedExtWidget, &BedExtruderWidget::extTemperatureChanged, &m_core, &AtCore::setExtruderTemp); | ||
228 | 244 | | |||
229 | // Connect AtCore temperatures changes on Atelier Plot | 245 | // Connect AtCore temperatures changes on Atelier Plot | ||
230 | connect(&m_core.temperature(), &Temperature::bedTemperatureChanged, [ this ](const float& temp) { | 246 | connect(&m_core.temperature(), &Temperature::bedTemperatureChanged, [ this ](const float& temp) { | ||
231 | checkTemperature(0x00, 0, temp); | 247 | checkTemperature(0x00, 0, temp); | ||
232 | ui->plotWidget->appendPoint(i18n("Actual Bed"), temp); | 248 | m_plotWidget->appendPoint(i18n("Actual Bed"), temp); | ||
233 | ui->plotWidget->update(); | 249 | m_plotWidget->update(); | ||
234 | ui->bedExtWidget->updateBedTemp(temp); | 250 | ui->bedExtWidget->updateBedTemp(temp); | ||
235 | }); | 251 | }); | ||
236 | connect(&m_core.temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](const float& temp) { | 252 | connect(&m_core.temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](const float& temp) { | ||
237 | checkTemperature(0x01, 0, temp); | 253 | checkTemperature(0x01, 0, temp); | ||
238 | ui->plotWidget->appendPoint(i18n("Target Bed"), temp); | 254 | m_plotWidget->appendPoint(i18n("Target Bed"), temp); | ||
239 | ui->plotWidget->update(); | 255 | m_plotWidget->update(); | ||
240 | ui->bedExtWidget->updateBedTargetTemp(temp); | 256 | ui->bedExtWidget->updateBedTargetTemp(temp); | ||
241 | }); | 257 | }); | ||
242 | connect(&m_core.temperature(), &Temperature::extruderTemperatureChanged, [ this ](const float& temp) { | 258 | connect(&m_core.temperature(), &Temperature::extruderTemperatureChanged, [ this ](const float& temp) { | ||
243 | checkTemperature(0x02, 0, temp); | 259 | checkTemperature(0x02, 0, temp); | ||
244 | ui->plotWidget->appendPoint(i18n("Actual Ext.1"), temp); | 260 | m_plotWidget->appendPoint(i18n("Actual Ext.1"), temp); | ||
245 | ui->plotWidget->update(); | 261 | m_plotWidget->update(); | ||
246 | ui->bedExtWidget->updateExtTemp(temp); | 262 | ui->bedExtWidget->updateExtTemp(temp); | ||
247 | }); | 263 | }); | ||
248 | connect(&m_core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](const float& temp) { | 264 | connect(&m_core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](const float& temp) { | ||
249 | checkTemperature(0x03, 0, temp); | 265 | checkTemperature(0x03, 0, temp); | ||
250 | ui->plotWidget->appendPoint(i18n("Target Ext.1"), temp); | 266 | m_plotWidget->appendPoint(i18n("Target Ext.1"), temp); | ||
251 | ui->plotWidget->update(); | 267 | m_plotWidget->update(); | ||
252 | ui->bedExtWidget->updateExtTargetTemp(temp); | 268 | ui->bedExtWidget->updateExtTargetTemp(temp); | ||
253 | }); | 269 | }); | ||
254 | 270 | | |||
255 | connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ this ](QString command) { | 271 | connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ this ](QString command) { | ||
256 | ui->logWidget->addLog("Push " + command); | 272 | m_logWidget->appendLog("Push " + command); | ||
257 | m_core.pushCommand(command); | 273 | m_core.pushCommand(command); | ||
258 | }); | 274 | }); | ||
259 | 275 | | |||
260 | // Fan, Flow and Speed management | 276 | // Fan, Flow and Speed management | ||
261 | connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &m_core, &AtCore::setFanSpeed); | 277 | connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &m_core, &AtCore::setFanSpeed); | ||
262 | connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &m_core, &AtCore::setFlowRate); | 278 | connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &m_core, &AtCore::setFlowRate); | ||
263 | connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &m_core, &AtCore::setPrinterSpeed); | 279 | connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &m_core, &AtCore::setPrinterSpeed); | ||
264 | connect(ui->axisViewWidget, &AxisControl::clicked, this, &AtCoreInstanceWidget::axisControlClicked); | 280 | connect(m_axisControl, &AxisControl::clicked, this, &AtCoreInstanceWidget::axisControlClicked); | ||
265 | } | 281 | } | ||
266 | 282 | | |||
267 | void AtCoreInstanceWidget::printFile(const QUrl& fileName) | 283 | void AtCoreInstanceWidget::printFile(const QUrl& fileName) | ||
268 | { | 284 | { | ||
269 | if (!fileName.isEmpty() && (m_core.state() == AtCore::IDLE)) { | 285 | if (!fileName.isEmpty() && (m_core.state() == AtCore::IDLE)) { | ||
270 | m_core.print(fileName.toLocalFile()); | 286 | m_core.print(fileName.toLocalFile()); | ||
271 | } | 287 | } | ||
272 | } | 288 | } | ||
Show All 40 Lines | 327 | { | |||
313 | switch (newState) { | 329 | switch (newState) { | ||
314 | case AtCore::CONNECTING: { | 330 | case AtCore::CONNECTING: { | ||
315 | m_core.setSerialTimerInterval(0); | 331 | m_core.setSerialTimerInterval(0); | ||
316 | m_connectButton->setText(i18n("Disconnect")); | 332 | m_connectButton->setText(i18n("Disconnect")); | ||
317 | m_connectButton->setIcon(QIcon::fromTheme("network-disconnect", QIcon(QString(":/%1/disconnect").arg(m_theme)))); | 333 | m_connectButton->setIcon(QIcon::fromTheme("network-disconnect", QIcon(QString(":/%1/disconnect").arg(m_theme)))); | ||
318 | m_connectToolBar->setHidden(true); | 334 | m_connectToolBar->setHidden(true); | ||
319 | m_mainToolBar->setHidden(false); | 335 | m_mainToolBar->setHidden(false); | ||
320 | stateString = i18n("Connecting..."); | 336 | stateString = i18n("Connecting..."); | ||
321 | connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 337 | connect(&m_core, &AtCore::receivedMessage, m_logWidget, &LogWidget::appendRLog); | ||
322 | connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 338 | connect(m_core.serial(), &SerialLayer::pushedCommand, m_logWidget, &LogWidget::appendSLog); | ||
323 | } break; | 339 | } break; | ||
324 | case AtCore::IDLE: { | 340 | case AtCore::IDLE: { | ||
325 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | 341 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | ||
326 | emit extruderCountChanged(m_core.extruderCount()); | 342 | emit extruderCountChanged(m_core.extruderCount()); | ||
327 | ui->logWidget->addLog(i18n("Serial connected")); | 343 | m_logWidget->appendLog(i18n("Serial connected")); | ||
328 | emit disableDisconnect(false); | 344 | emit disableDisconnect(false); | ||
329 | enableControls(true); | 345 | enableControls(true); | ||
330 | } break; | 346 | } break; | ||
331 | case AtCore::DISCONNECTED: { | 347 | case AtCore::DISCONNECTED: { | ||
332 | stateString = i18n("Not Connected"); | 348 | stateString = i18n("Not Connected"); | ||
333 | disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 349 | disconnect(&m_core, &AtCore::receivedMessage, m_logWidget, &LogWidget::appendRLog); | ||
334 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 350 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, m_logWidget, &LogWidget::appendSLog); | ||
335 | ui->logWidget->addLog(i18n("Serial disconnected")); | 351 | m_logWidget->appendLog(i18n("Serial disconnected")); | ||
336 | m_core.setSerialTimerInterval(100); | 352 | m_core.setSerialTimerInterval(100); | ||
337 | m_connectButton->setText(i18n("Connect")); | 353 | m_connectButton->setText(i18n("Connect")); | ||
338 | m_connectButton->setIcon(QIcon::fromTheme("network-connect",QIcon(QString(":/%1/connect").arg(m_theme)))); | 354 | m_connectButton->setIcon(QIcon::fromTheme("network-connect",QIcon(QString(":/%1/connect").arg(m_theme)))); | ||
339 | m_connectToolBar->setHidden(false); | 355 | m_connectToolBar->setHidden(false); | ||
340 | m_mainToolBar->setHidden(true); | 356 | m_mainToolBar->setHidden(true); | ||
341 | enableControls(false); | 357 | enableControls(false); | ||
342 | } break; | 358 | } break; | ||
343 | case AtCore::STARTPRINT: { | 359 | case AtCore::STARTPRINT: { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 419 | case 0x05: // enclosure target | |||
404 | msg = QString::fromLatin1("Enclosure Target Temperature "); | 420 | msg = QString::fromLatin1("Enclosure Target Temperature "); | ||
405 | break; | 421 | break; | ||
406 | } | 422 | } | ||
407 | 423 | | |||
408 | msg.append(QString::fromLatin1("[%1] : %2")); | 424 | msg.append(QString::fromLatin1("[%1] : %2")); | ||
409 | msg = msg.arg(QString::number(number)) | 425 | msg = msg.arg(QString::number(number)) | ||
410 | .arg(QString::number(temp)); | 426 | .arg(QString::number(temp)); | ||
411 | 427 | | |||
412 | ui->logWidget->addRLog(msg); | 428 | m_logWidget->appendLog(msg); | ||
413 | } | | |||
414 | | ||||
415 | void AtCoreInstanceWidget::checkReceivedCommand(const QByteArray &message) | | |||
416 | { | | |||
417 | ui->logWidget->addRLog(QString::fromUtf8(message)); | | |||
418 | } | | |||
419 | | ||||
420 | void AtCoreInstanceWidget::checkPushedCommands(const QByteArray &bmsg) | | |||
421 | { | | |||
422 | QString msg = QString::fromUtf8(bmsg); | | |||
423 | QRegExp _newLine(QChar::fromLatin1('\n')); | | |||
424 | QRegExp _return(QChar::fromLatin1('\r')); | | |||
425 | msg.replace(_newLine, QStringLiteral("\\n")); | | |||
426 | msg.replace(_return, QStringLiteral("\\r")); | | |||
427 | ui->logWidget->addSLog(msg); | | |||
428 | } | 429 | } | ||
429 | 430 | | |||
430 | void AtCoreInstanceWidget::axisControlClicked(QChar axis, int value) | 431 | void AtCoreInstanceWidget::axisControlClicked(QChar axis, int value) | ||
431 | { | 432 | { | ||
432 | m_core.setRelativePosition(); | 433 | m_core.setRelativePosition(); | ||
433 | m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); | 434 | m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); | ||
434 | m_core.setAbsolutePosition(); | 435 | m_core.setAbsolutePosition(); | ||
435 | } | 436 | } | ||
Show All 32 Lines |