Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/atcoreinstancewidget.cpp
Show All 20 Lines | |||||
21 | #include <QToolBar> | 21 | #include <QToolBar> | ||
22 | #include <AtCore/SerialLayer> | 22 | #include <AtCore/SerialLayer> | ||
23 | #include <AtCore/GCodeCommands> | 23 | #include <AtCore/GCodeCommands> | ||
24 | #include <KLocalizedString> | 24 | #include <KLocalizedString> | ||
25 | #include "choosefiledialog.h" | 25 | #include "choosefiledialog.h" | ||
26 | 26 | | |||
27 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | 27 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | ||
28 | QWidget(parent), | 28 | QWidget(parent), | ||
29 | m_mainToolBar(nullptr), | | |||
30 | m_toolBar(nullptr), | 29 | m_toolBar(nullptr), | ||
31 | m_printAction(nullptr) | 30 | m_printAction(nullptr) | ||
32 | { | 31 | { | ||
33 | ui = new Ui::AtCoreInstanceWidget; | 32 | ui = new Ui::AtCoreInstanceWidget; | ||
34 | ui->setupUi(this); | 33 | ui->setupUi(this); | ||
35 | 34 | | |||
36 | ui->printProgressWidget->setVisible(false); | 35 | ui->printProgressWidget->setVisible(false); | ||
37 | buildMainToolbar(); | | |||
38 | buildToolbar(); | 36 | buildToolbar(); | ||
39 | buildConnectionToolbar(); | 37 | buildConnectionToolbar(); | ||
40 | enableControls(false); | 38 | enableControls(false); | ||
41 | updateProfileData(); | 39 | updateProfileData(); | ||
42 | initConnectsToAtCore(); | 40 | initConnectsToAtCore(); | ||
43 | m_mainToolBar->setHidden(true); | 41 | m_toolBar->setHidden(true); | ||
44 | } | 42 | } | ||
45 | 43 | | |||
46 | AtCoreInstanceWidget::~AtCoreInstanceWidget() | 44 | AtCoreInstanceWidget::~AtCoreInstanceWidget() | ||
47 | { | 45 | { | ||
48 | m_core.closeConnection(); | 46 | m_core.closeConnection(); | ||
49 | delete ui; | 47 | delete ui; | ||
50 | } | 48 | } | ||
51 | 49 | | |||
52 | void AtCoreInstanceWidget::buildToolbar() | 50 | void AtCoreInstanceWidget::buildToolbar(){ | ||
53 | { | | |||
54 | m_toolBar = new QToolBar(); | 51 | m_toolBar = new QToolBar(); | ||
52 | m_toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||||
55 | 53 | | |||
56 | auto lb = new QAction; | 54 | auto homeAll = new QAction(QIcon::fromTheme("go-home", style()->standardIcon(QStyle::SP_DirHomeIcon)), "All"); | ||
57 | lb->setIcon(QIcon::fromTheme("go-home", style()->standardIcon(QStyle::SP_DirHomeIcon))); | | |||
58 | lb->setDisabled(true); | | |||
59 | m_toolBar->addAction(lb); | | |||
60 | | ||||
61 | auto homeAll = new QAction("All"); | | |||
62 | connect(homeAll, &QAction::triggered, [this]{ | 55 | connect(homeAll, &QAction::triggered, [this]{ | ||
63 | m_core.home(); | 56 | m_core.home(); | ||
64 | }); | 57 | }); | ||
65 | m_toolBar->addAction(homeAll); | 58 | m_toolBar->addAction(homeAll); | ||
66 | 59 | | |||
67 | for(auto homes : std::map<QString, int>{{"X", AtCore::X}, {"Y", AtCore::Y}, {"Z", AtCore::Z}}) { | 60 | for(auto homes : std::map<QString, int>{{"X", AtCore::X}, {"Y", AtCore::Y}, {"Z", AtCore::Z}}) { | ||
68 | auto home = new QAction(homes.first); | 61 | auto home = new QAction(homes.first); | ||
62 | home->setToolTip(i18n("Home ") + homes.first); | ||||
69 | connect(home, &QAction::triggered, [this, homes] { | 63 | connect(home, &QAction::triggered, [this, homes] { | ||
70 | m_core.home(homes.second); | 64 | m_core.home(homes.second); | ||
71 | }); | 65 | }); | ||
72 | m_toolBar->addAction(home); | 66 | m_toolBar->addAction(home); | ||
73 | } | 67 | } | ||
74 | 68 | | |||
75 | m_toolBar->addSeparator(); | 69 | m_toolBar->addSeparator(); | ||
76 | 70 | | |||
77 | auto *axis = new QAction("Axis"); | | |||
78 | axis->setCheckable(true); | | |||
79 | axis->setChecked(true); | | |||
80 | connect(axis, &QAction::toggled, ui->axisViewWidget, &AxisControl::setVisible); | | |||
81 | | ||||
82 | auto controls = new QAction("Controls"); | | |||
83 | controls->setCheckable(true); | | |||
84 | controls->setChecked(true); | | |||
85 | connect(controls, &QAction::toggled, ui->bedExtWidget, &BedExtruderWidget::setVisible); | | |||
86 | | ||||
87 | auto plot = new QAction("Temperature Plot"); | | |||
88 | plot->setCheckable(true); | | |||
89 | plot->setChecked(true); | | |||
90 | connect(plot, &QAction::toggled, ui->plotWidget, &PlotWidget::setVisible); | | |||
91 | | ||||
92 | m_toolBar->addAction(axis); | | |||
93 | m_toolBar->addAction(controls); | | |||
94 | m_toolBar->addAction(plot); | | |||
95 | ui->toolBarLayout->addWidget(m_toolBar); | | |||
96 | ui->toolBarLayout->addStretch(); | | |||
97 | } | | |||
98 | | ||||
99 | void AtCoreInstanceWidget::buildMainToolbar(){ | | |||
100 | m_mainToolBar = new QToolBar(); | | |||
101 | m_mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | | |||
102 | | ||||
103 | m_printAction = new QAction(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)),i18n("Print")); | 71 | m_printAction = new QAction(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)),i18n("Print")); | ||
104 | connect(m_printAction, &QAction::triggered, [ this ](){ | 72 | connect(m_printAction, &QAction::triggered, [ this ](){ | ||
105 | if(m_core.state() == AtCore::BUSY) { | 73 | if(m_core.state() == AtCore::BUSY) { | ||
106 | pausePrint(); | 74 | pausePrint(); | ||
107 | return; | 75 | return; | ||
108 | } | 76 | } | ||
109 | if (m_core.state() == AtCore::IDLE){ | 77 | if (m_core.state() == AtCore::IDLE){ | ||
110 | print(); | 78 | print(); | ||
111 | } else if (m_core.state() == AtCore::PAUSE) { | 79 | } else if (m_core.state() == AtCore::PAUSE) { | ||
112 | m_core.resume(); | 80 | m_core.resume(); | ||
113 | } | 81 | } | ||
114 | }); | 82 | }); | ||
115 | m_mainToolBar->addAction(m_printAction); | 83 | m_toolBar->addAction(m_printAction); | ||
116 | 84 | | |||
117 | auto stopAction = new QAction(QIcon::fromTheme("media-playback-stop", style()->standardIcon(QStyle::SP_MediaStop)), i18n("Stop")); | 85 | auto stopAction = new QAction(QIcon::fromTheme("media-playback-stop", style()->standardIcon(QStyle::SP_MediaStop)), i18n("Stop")); | ||
118 | connect(stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint); | 86 | connect(stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint); | ||
119 | connect(stopAction, &QAction::triggered, [this](){ | 87 | connect(stopAction, &QAction::triggered, [this](){ | ||
120 | m_printAction->setText(i18n("Print")); | 88 | m_printAction->setText(i18n("Print")); | ||
121 | m_printAction->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay))); | 89 | m_printAction->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay))); | ||
122 | }); | 90 | }); | ||
123 | m_mainToolBar->addAction(stopAction); | 91 | m_toolBar->addAction(stopAction); | ||
124 | 92 | | |||
125 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | 93 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | ||
126 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | 94 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | ||
127 | m_mainToolBar->addAction(disableMotorsAction); | 95 | m_toolBar->addAction(disableMotorsAction); | ||
128 | 96 | | |||
129 | ui->mainToolBarLayout->addWidget(m_mainToolBar); | 97 | ui->toolBarLayout->addWidget(m_toolBar); | ||
130 | } | 98 | } | ||
131 | 99 | | |||
132 | void AtCoreInstanceWidget::buildConnectionToolbar() | 100 | void AtCoreInstanceWidget::buildConnectionToolbar() | ||
133 | { | 101 | { | ||
134 | m_connectToolBar = new QToolBar(); | 102 | m_connectToolBar = new QToolBar(); | ||
135 | m_comboPort = new QComboBox; | 103 | m_comboPort = new QComboBox; | ||
136 | m_comboPort->setEditable(true); | 104 | m_comboPort->setEditable(true); | ||
137 | QLabel *deviceLabel = new QLabel(i18n("Device")); | 105 | QLabel *deviceLabel = new QLabel(i18n("Device")); | ||
Show All 15 Lines | |||||
153 | m_connectWidget = new QWidget(); | 121 | m_connectWidget = new QWidget(); | ||
154 | m_connectWidget->setLayout(connectLayout); | 122 | m_connectWidget->setLayout(connectLayout); | ||
155 | m_connectToolBar->addWidget(m_connectWidget); | 123 | m_connectToolBar->addWidget(m_connectWidget); | ||
156 | 124 | | |||
157 | m_connectButton = new QPushButton(QIcon::fromTheme("network-connect", style()->standardIcon(QStyle::SP_DialogCloseButton)), i18n("Connect")); | 125 | m_connectButton = new QPushButton(QIcon::fromTheme("network-connect", style()->standardIcon(QStyle::SP_DialogCloseButton)), i18n("Connect")); | ||
158 | m_connectButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); | 126 | m_connectButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); | ||
159 | connect(this, &AtCoreInstanceWidget::disableDisconnect, m_connectButton, &QPushButton::setDisabled); | 127 | connect(this, &AtCoreInstanceWidget::disableDisconnect, m_connectButton, &QPushButton::setDisabled); | ||
160 | connect(m_connectButton, &QPushButton::clicked, this, &AtCoreInstanceWidget::connectButtonClicked); | 128 | connect(m_connectButton, &QPushButton::clicked, this, &AtCoreInstanceWidget::connectButtonClicked); | ||
161 | ui->mainToolBarLayout->addWidget(m_connectToolBar); | 129 | ui->toolBarLayout->addWidget(m_connectToolBar); | ||
162 | ui->mainToolBarLayout->addWidget(m_connectButton); | 130 | ui->toolBarLayout->addWidget(m_connectButton); | ||
163 | 131 | | |||
164 | } | 132 | } | ||
165 | 133 | | |||
166 | void AtCoreInstanceWidget::connectButtonClicked() | 134 | void AtCoreInstanceWidget::connectButtonClicked() | ||
167 | { | 135 | { | ||
168 | if(m_core.state() == AtCore::DISCONNECTED) { | 136 | if(m_core.state() == AtCore::DISCONNECTED) { | ||
169 | if (m_comboProfile->currentText().isEmpty()) { | 137 | if (m_comboProfile->currentText().isEmpty()) { | ||
170 | QMessageBox::information(this, i18n("No Profiles!"), i18n("Connecting Requires creating a profile for your printer. Create a profile in the next dialog then try again.")); | 138 | QMessageBox::information(this, i18n("No Profiles!"), i18n("Connecting Requires creating a profile for your printer. Create a profile in the next dialog then try again.")); | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | |||||
308 | { | 276 | { | ||
309 | static QString stateString; | 277 | static QString stateString; | ||
310 | switch (newState) { | 278 | switch (newState) { | ||
311 | case AtCore::CONNECTING: { | 279 | case AtCore::CONNECTING: { | ||
312 | m_core.setSerialTimerInterval(0); | 280 | m_core.setSerialTimerInterval(0); | ||
313 | m_connectButton->setText(i18n("Disconnect")); | 281 | m_connectButton->setText(i18n("Disconnect")); | ||
314 | m_connectButton->setIcon(QIcon::fromTheme("network-disconnect")); | 282 | m_connectButton->setIcon(QIcon::fromTheme("network-disconnect")); | ||
315 | m_connectToolBar->setHidden(true); | 283 | m_connectToolBar->setHidden(true); | ||
316 | m_mainToolBar->setHidden(false); | 284 | m_toolBar->setHidden(false); | ||
317 | stateString = i18n("Connecting..."); | 285 | stateString = i18n("Connecting..."); | ||
318 | connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 286 | connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | ||
319 | connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 287 | connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | ||
320 | } break; | 288 | } break; | ||
321 | case AtCore::IDLE: { | 289 | case AtCore::IDLE: { | ||
322 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | 290 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | ||
323 | emit extruderCountChanged(m_core.extruderCount()); | 291 | emit extruderCountChanged(m_core.extruderCount()); | ||
324 | ui->logWidget->addLog(i18n("Serial connected")); | 292 | ui->logWidget->addLog(i18n("Serial connected")); | ||
325 | emit disableDisconnect(false); | 293 | emit disableDisconnect(false); | ||
326 | enableControls(true); | 294 | enableControls(true); | ||
327 | } break; | 295 | } break; | ||
328 | case AtCore::DISCONNECTED: { | 296 | case AtCore::DISCONNECTED: { | ||
329 | stateString = i18n("Not Connected"); | 297 | stateString = i18n("Not Connected"); | ||
330 | disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 298 | disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | ||
331 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 299 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | ||
332 | ui->logWidget->addLog(i18n("Serial disconnected")); | 300 | ui->logWidget->addLog(i18n("Serial disconnected")); | ||
333 | m_core.setSerialTimerInterval(100); | 301 | m_core.setSerialTimerInterval(100); | ||
334 | m_connectButton->setText(i18n("Connect")); | 302 | m_connectButton->setText(i18n("Connect")); | ||
335 | m_connectButton->setIcon(QIcon::fromTheme("network-connect")); | 303 | m_connectButton->setIcon(QIcon::fromTheme("network-connect")); | ||
336 | m_connectToolBar->setHidden(false); | 304 | m_connectToolBar->setHidden(false); | ||
337 | m_mainToolBar->setHidden(true); | 305 | m_toolBar->setHidden(true); | ||
338 | enableControls(false); | 306 | enableControls(false); | ||
339 | } break; | 307 | } break; | ||
340 | case AtCore::STARTPRINT: { | 308 | case AtCore::STARTPRINT: { | ||
341 | stateString = i18n("Starting Print"); | 309 | stateString = i18n("Starting Print"); | ||
342 | ui->printProgressWidget->setVisible(true); | 310 | ui->printProgressWidget->setVisible(true); | ||
343 | connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); | 311 | connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); | ||
344 | } break; | 312 | } break; | ||
345 | case AtCore::FINISHEDPRINT: { | 313 | case AtCore::FINISHEDPRINT: { | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 396 | { | |||
429 | m_core.setRelativePosition(); | 397 | m_core.setRelativePosition(); | ||
430 | m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); | 398 | m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); | ||
431 | m_core.setAbsolutePosition(); | 399 | m_core.setAbsolutePosition(); | ||
432 | } | 400 | } | ||
433 | 401 | | |||
434 | void AtCoreInstanceWidget::enableControls(bool b) | 402 | void AtCoreInstanceWidget::enableControls(bool b) | ||
435 | { | 403 | { | ||
436 | ui->mainTab->setEnabled(b); | 404 | ui->mainTab->setEnabled(b); | ||
437 | m_mainToolBar->setEnabled(b); | 405 | m_toolBar->setEnabled(b); | ||
438 | m_toolBar->setEnabled(b); | 406 | m_toolBar->setEnabled(b); | ||
439 | } | 407 | } | ||
440 | 408 | | |||
441 | bool AtCoreInstanceWidget::connected() | 409 | bool AtCoreInstanceWidget::connected() | ||
442 | { | 410 | { | ||
443 | return (m_core.state() != AtCore::DISCONNECTED); | 411 | return (m_core.state() != AtCore::DISCONNECTED); | ||
444 | } | 412 | } | ||
445 | 413 | | |||
Show All 19 Lines |