Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/atcoreinstancewidget.cpp
Show All 30 Lines | 27 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | |||
---|---|---|---|---|---|
31 | m_printAction(nullptr) | 31 | m_printAction(nullptr) | ||
32 | { | 32 | { | ||
33 | ui = new Ui::AtCoreInstanceWidget; | 33 | ui = new Ui::AtCoreInstanceWidget; | ||
34 | ui->setupUi(this); | 34 | ui->setupUi(this); | ||
35 | 35 | | |||
36 | ui->printProgressWidget->setVisible(false); | 36 | ui->printProgressWidget->setVisible(false); | ||
37 | buildMainToolbar(); | 37 | buildMainToolbar(); | ||
38 | buildToolbar(); | 38 | buildToolbar(); | ||
39 | buildConnectionToolbar(); | ||||
39 | enableControls(false); | 40 | enableControls(false); | ||
41 | updateProfileData(); | ||||
40 | initConnectsToAtCore(); | 42 | initConnectsToAtCore(); | ||
43 | m_mainToolBar->setHidden(true); | ||||
41 | } | 44 | } | ||
42 | 45 | | |||
43 | AtCoreInstanceWidget::~AtCoreInstanceWidget() | 46 | AtCoreInstanceWidget::~AtCoreInstanceWidget() | ||
44 | { | 47 | { | ||
48 | m_core.closeConnection(); | ||||
45 | delete ui; | 49 | delete ui; | ||
46 | } | 50 | } | ||
47 | 51 | | |||
48 | void AtCoreInstanceWidget::buildToolbar() | 52 | void AtCoreInstanceWidget::buildToolbar() | ||
49 | { | 53 | { | ||
50 | m_toolBar = new QToolBar(); | 54 | m_toolBar = new QToolBar(); | ||
51 | 55 | | |||
52 | auto lb = new QAction; | 56 | auto lb = new QAction; | ||
Show All 38 Lines | |||||
91 | ui->toolBarLayout->addWidget(m_toolBar); | 95 | ui->toolBarLayout->addWidget(m_toolBar); | ||
92 | ui->toolBarLayout->addStretch(); | 96 | ui->toolBarLayout->addStretch(); | ||
93 | } | 97 | } | ||
94 | 98 | | |||
95 | void AtCoreInstanceWidget::buildMainToolbar(){ | 99 | void AtCoreInstanceWidget::buildMainToolbar(){ | ||
96 | m_mainToolBar = new QToolBar(); | 100 | m_mainToolBar = new QToolBar(); | ||
97 | m_mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 101 | m_mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||
98 | 102 | | |||
99 | auto disconnectAction = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), i18n("Disconnect")); | | |||
100 | connect(this, &AtCoreInstanceWidget::disableDisconnect, disconnectAction, &QAction::setDisabled); | | |||
101 | connect(disconnectAction, &QAction::triggered, [&](){ | | |||
102 | m_core.closeConnection(); | | |||
103 | }); | | |||
104 | m_mainToolBar->addAction(disconnectAction); | | |||
105 | | ||||
106 | m_printAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay),i18n("Print")); | 103 | m_printAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay),i18n("Print")); | ||
107 | connect(m_printAction, &QAction::triggered, [ & ](){ | 104 | connect(m_printAction, &QAction::triggered, [ & ](){ | ||
108 | if(m_core.state() == AtCore::BUSY) { | 105 | if(m_core.state() == AtCore::BUSY) { | ||
109 | pausePrint(); | 106 | pausePrint(); | ||
110 | return; | 107 | return; | ||
111 | } | 108 | } | ||
112 | if (m_core.state() == AtCore::IDLE){ | 109 | if (m_core.state() == AtCore::IDLE){ | ||
113 | print(); | 110 | print(); | ||
Show All 11 Lines | |||||
125 | }); | 122 | }); | ||
126 | m_mainToolBar->addAction(stopAction); | 123 | m_mainToolBar->addAction(stopAction); | ||
127 | 124 | | |||
128 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | 125 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | ||
129 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | 126 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | ||
130 | m_mainToolBar->addAction(disableMotorsAction); | 127 | m_mainToolBar->addAction(disableMotorsAction); | ||
131 | 128 | | |||
132 | ui->mainToolBarLayout->addWidget(m_mainToolBar); | 129 | ui->mainToolBarLayout->addWidget(m_mainToolBar); | ||
133 | ui->mainToolBarLayout->addStretch(); | | |||
134 | } | 130 | } | ||
135 | void AtCoreInstanceWidget::startConnection(const QString& serialPort, const QMap<QString, QVariant>& profiles){ | 131 | | ||
136 | m_core.initSerial(serialPort, profiles["bps"].toInt()); | 132 | void AtCoreInstanceWidget::buildConnectionToolbar() | ||
133 | { | ||||
134 | m_connectToolBar = new QToolBar(); | ||||
135 | m_comboPort = new QComboBox; | ||||
136 | m_comboPort->setEditable(true); | ||||
137 | QLabel *deviceLabel = new QLabel(i18n("Device")); | ||||
138 | QHBoxLayout *deviceLayout = new QHBoxLayout; | ||||
139 | deviceLayout->addWidget(deviceLabel); | ||||
140 | deviceLayout->addWidget(m_comboPort,100); | ||||
141 | | ||||
142 | m_comboProfile = new QComboBox; | ||||
143 | m_comboProfile->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); | ||||
144 | QHBoxLayout *profileLayout = new QHBoxLayout; | ||||
145 | QLabel *profileLabel = new QLabel(i18n("Profile")); | ||||
146 | profileLayout->addWidget(profileLabel); | ||||
147 | profileLayout->addWidget(m_comboProfile,100); | ||||
148 | | ||||
149 | QHBoxLayout *connectLayout = new QHBoxLayout; | ||||
150 | connectLayout->addLayout(deviceLayout,50); | ||||
151 | connectLayout->addLayout(profileLayout,50); | ||||
152 | | ||||
153 | m_connectWidget = new QWidget(); | ||||
154 | m_connectWidget->setLayout(connectLayout); | ||||
155 | m_connectToolBar->addWidget(m_connectWidget); | ||||
156 | | ||||
157 | m_connectButton = new QPushButton(i18n("Connect")); | ||||
158 | m_connectButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); | ||||
159 | connect(this, &AtCoreInstanceWidget::disableDisconnect, m_connectButton, &QPushButton::setDisabled); | ||||
160 | connect(m_connectButton, &QPushButton::clicked, this, &AtCoreInstanceWidget::connectButtonClicked); | ||||
161 | ui->mainToolBarLayout->addWidget(m_connectToolBar); | ||||
162 | ui->mainToolBarLayout->addWidget(m_connectButton); | ||||
163 | | ||||
164 | } | ||||
165 | | ||||
166 | void AtCoreInstanceWidget::connectButtonClicked() | ||||
167 | { | ||||
168 | if(m_core.state() == AtCore::DISCONNECTED) { | ||||
169 | if (m_comboProfile->currentText().isEmpty()) { | ||||
170 | QMessageBox::critical(this, i18n("Error"), i18n("Please, create a profile to connect on Settings!")); | ||||
171 | return; | ||||
172 | } | ||||
173 | | ||||
174 | if (m_comboPort->currentText().isEmpty()) { | ||||
175 | QMessageBox::critical(this, i18n("Error"), i18n("Please, connect a serial device to continue!")); | ||||
patrickelectric: identantion. | |||||
176 | return; | ||||
177 | } | ||||
178 | | ||||
179 | //Get profile data before connecting. | ||||
180 | QString profile = m_comboProfile->currentText(); | ||||
181 | m_settings.beginGroup("GeneralSettings"); | ||||
182 | m_settings.beginGroup(profile); | ||||
183 | QMap<QString, QVariant> data; | ||||
184 | data["bps"] = m_settings.value(QStringLiteral("bps"), QStringLiteral("115200")); | ||||
185 | data["bedTemp"] = m_settings.value(QStringLiteral("maximumTemperatureBed"), QStringLiteral("0")); | ||||
186 | data["hotendTemp"] = m_settings.value(QStringLiteral("maximumTemperatureExtruder"), QStringLiteral("0")); | ||||
187 | data["firmware"] = m_settings.value(QStringLiteral("firmware"),QStringLiteral("Auto-Detect")); | ||||
188 | data["postPause"] = m_settings.value(QStringLiteral("postPause"),QStringLiteral("")); | ||||
189 | data["name"] = profile; | ||||
190 | m_settings.endGroup(); | ||||
191 | m_settings.endGroup(); | ||||
192 | | ||||
193 | //then connect | ||||
194 | m_core.initSerial(m_comboPort->currentText(), data["bps"].toInt()); | ||||
137 | if(m_core.state() == AtCore::CONNECTING){ | 195 | if(m_core.state() == AtCore::CONNECTING){ | ||
138 | QString fw = profiles["firmware"].toString(); | 196 | profileData = data; | ||
197 | QString fw = profileData["firmware"].toString(); | ||||
139 | if( fw != QString("Auto-Detect")){ | 198 | if( fw != QString("Auto-Detect")){ | ||
140 | m_core.loadFirmwarePlugin(fw); | 199 | m_core.loadFirmwarePlugin(fw); | ||
141 | } | 200 | } | ||
201 | emit(connectionChanged(profileData["name"].toString())); | ||||
202 | } | ||||
203 | } else { | ||||
204 | m_core.closeConnection(); | ||||
205 | emit(connectionChanged(i18n("Connect a Printer"))); | ||||
142 | } | 206 | } | ||
143 | } | 207 | } | ||
144 | 208 | | |||
145 | void AtCoreInstanceWidget::initConnectsToAtCore() | 209 | void AtCoreInstanceWidget::initConnectsToAtCore() | ||
146 | { | 210 | { | ||
211 | m_core.setSerialTimerInterval(100); | ||||
212 | // Handle device changes | ||||
213 | connect(&m_core, &AtCore::portsChanged, this, &AtCoreInstanceWidget::updateSerialPort); | ||||
214 | | ||||
147 | // Handle AtCore status change | 215 | // Handle AtCore status change | ||
148 | connect(&m_core, &AtCore::stateChanged, this, &AtCoreInstanceWidget::handlePrinterStatusChanged); | 216 | connect(&m_core, &AtCore::stateChanged, this, &AtCoreInstanceWidget::handlePrinterStatusChanged); | ||
149 | 217 | | |||
150 | // If the number of extruders from the printer change, we need to update the radiobuttons on the widget | 218 | // If the number of extruders from the printer change, we need to update the radiobuttons on the widget | ||
151 | connect(this, &AtCoreInstanceWidget::extruderCountChanged, ui->bedExtWidget, &BedExtruderWidget::setExtruderCount); | 219 | connect(this, &AtCoreInstanceWidget::extruderCountChanged, ui->bedExtWidget, &BedExtruderWidget::setExtruderCount); | ||
152 | 220 | | |||
153 | // Bed and Extruder temperatures management | 221 | // Bed and Extruder temperatures management | ||
154 | connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &m_core, &AtCore::setBedTemp); | 222 | connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &m_core, &AtCore::setBedTemp); | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 302 | { | |||
235 | m_core.disableMotors(0); | 303 | m_core.disableMotors(0); | ||
236 | } | 304 | } | ||
237 | 305 | | |||
238 | void AtCoreInstanceWidget::handlePrinterStatusChanged(AtCore::STATES newState) | 306 | void AtCoreInstanceWidget::handlePrinterStatusChanged(AtCore::STATES newState) | ||
239 | { | 307 | { | ||
240 | static QString stateString; | 308 | static QString stateString; | ||
241 | switch (newState) { | 309 | switch (newState) { | ||
242 | case AtCore::CONNECTING: { | 310 | case AtCore::CONNECTING: { | ||
311 | m_core.setSerialTimerInterval(0); | ||||
312 | m_connectButton->setText(i18n("Disconnect")); | ||||
313 | m_connectToolBar->setHidden(true); | ||||
314 | m_mainToolBar->setHidden(false); | ||||
243 | stateString = i18n("Connecting..."); | 315 | stateString = i18n("Connecting..."); | ||
244 | connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 316 | connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | ||
245 | connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 317 | connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | ||
246 | } break; | 318 | } break; | ||
247 | case AtCore::IDLE: { | 319 | case AtCore::IDLE: { | ||
248 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | 320 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | ||
249 | emit extruderCountChanged(m_core.extruderCount()); | 321 | emit extruderCountChanged(m_core.extruderCount()); | ||
250 | ui->logWidget->addLog(i18n("Serial connected")); | 322 | ui->logWidget->addLog(i18n("Serial connected")); | ||
251 | emit disableDisconnect(false); | 323 | emit disableDisconnect(false); | ||
252 | enableControls(true); | 324 | enableControls(true); | ||
253 | } break; | 325 | } break; | ||
254 | case AtCore::DISCONNECTED: { | 326 | case AtCore::DISCONNECTED: { | ||
255 | stateString = i18n("Not Connected"); | 327 | stateString = i18n("Not Connected"); | ||
256 | disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 328 | disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | ||
257 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 329 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | ||
258 | ui->logWidget->addLog(i18n("Serial disconnected")); | 330 | ui->logWidget->addLog(i18n("Serial disconnected")); | ||
331 | m_core.setSerialTimerInterval(100); | ||||
332 | m_connectButton->setText(i18n("Connect")); | ||||
333 | m_connectToolBar->setHidden(false); | ||||
334 | m_mainToolBar->setHidden(true); | ||||
259 | enableControls(false); | 335 | enableControls(false); | ||
260 | } break; | 336 | } break; | ||
261 | case AtCore::STARTPRINT: { | 337 | case AtCore::STARTPRINT: { | ||
262 | stateString = i18n("Starting Print"); | 338 | stateString = i18n("Starting Print"); | ||
263 | ui->printProgressWidget->setVisible(true); | 339 | ui->printProgressWidget->setVisible(true); | ||
264 | connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); | 340 | connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); | ||
265 | } break; | 341 | } break; | ||
266 | case AtCore::FINISHEDPRINT: { | 342 | case AtCore::FINISHEDPRINT: { | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | |||||
363 | { | 439 | { | ||
364 | return (m_core.state() != AtCore::DISCONNECTED); | 440 | return (m_core.state() != AtCore::DISCONNECTED); | ||
365 | } | 441 | } | ||
366 | 442 | | |||
367 | void AtCoreInstanceWidget::setOpenFiles(const QList<QUrl>& files) | 443 | void AtCoreInstanceWidget::setOpenFiles(const QList<QUrl>& files) | ||
368 | { | 444 | { | ||
369 | m_files = files; | 445 | m_files = files; | ||
370 | } | 446 | } | ||
447 | | ||||
448 | void AtCoreInstanceWidget::updateSerialPort(const QStringList &ports) | ||||
449 | { | ||||
450 | m_comboPort->clear(); | ||||
451 | m_comboPort->addItems(ports); | ||||
452 | } | ||||
453 | | ||||
no need to test the if. tcanabrava: no need to test the if.
if the list is empty, the call to addItems will not add anything. | |||||
Im sure you have heard the expression
I will double check this is safe and remove the check . rizzitello: Im sure you have heard the expression
>better safe then sorry
I will double check this is… | |||||
454 | void AtCoreInstanceWidget::updateProfileData() | ||||
455 | { | ||||
456 | m_settings.beginGroup("GeneralSettings"); | ||||
457 | QStringList profiles = m_settings.childGroups(); | ||||
458 | m_settings.endGroup(); | ||||
459 | m_comboProfile->clear(); | ||||
460 | m_comboProfile->addItems(profiles); | ||||
laysrodrigues: same on the above lines | |||||
461 | } |
identantion.