Changeset View
Changeset View
Standalone View
Standalone View
testclient/mainwindow.cpp
Show All 14 Lines | 1 | /* AtCore Test Client | |||
---|---|---|---|---|---|
15 | This program is distributed in the hope that it will be useful, | 15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | 18 | GNU General Public License for more details. | ||
19 | 19 | | |||
20 | You should have received a copy of the GNU General Public License | 20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | */ | 22 | */ | ||
23 | #include <QTime> | | |||
24 | #include <QSerialPortInfo> | 23 | #include <QSerialPortInfo> | ||
25 | #include <QMessageBox> | 24 | #include <QMessageBox> | ||
26 | #include <QFileDialog> | 25 | #include <QFileDialog> | ||
27 | #include <QTextStream> | 26 | #include <QTextStream> | ||
28 | #include <QLoggingCategory> | 27 | #include <QLoggingCategory> | ||
29 | 28 | | |||
30 | #include "mainwindow.h" | 29 | #include "mainwindow.h" | ||
31 | #include "seriallayer.h" | 30 | #include "seriallayer.h" | ||
32 | #include "gcodecommands.h" | 31 | #include "gcodecommands.h" | ||
33 | #include "widgets/axiscontrol.h" | | |||
34 | #include "widgets/about.h" | 32 | #include "widgets/about.h" | ||
35 | 33 | | |||
36 | Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core") | 34 | Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core") | ||
37 | 35 | | |||
38 | int MainWindow::fanCount = 4; | 36 | int MainWindow::fanCount = 4; | ||
39 | 37 | | |||
40 | MainWindow::MainWindow(QWidget *parent) : | 38 | MainWindow::MainWindow(QWidget *parent) : | ||
41 | QMainWindow(parent), | 39 | QMainWindow(parent), | ||
42 | core(new AtCore(this)), | 40 | core(new AtCore(this)) | ||
43 | logFile(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))) | | |||
44 | { | 41 | { | ||
45 | setWindowTitle(tr("AtCore - Test Client")); | 42 | setWindowTitle(tr("AtCore - Test Client")); | ||
46 | setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); | 43 | setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); | ||
47 | QCoreApplication::setApplicationVersion(core->version()); | 44 | QCoreApplication::setApplicationVersion(core->version()); | ||
48 | initMenu(); | 45 | initMenu(); | ||
49 | initStatusBar(); | 46 | initStatusBar(); | ||
50 | initWidgets(); | 47 | initWidgets(); | ||
51 | 48 | | |||
52 | addLog(tr("Attempting to locate Serial Ports")); | 49 | logWidget->appendLog(tr("Attempting to locate Serial Ports")); | ||
53 | core->setSerialTimerInterval(1000); | 50 | core->setSerialTimerInterval(1000); | ||
54 | 51 | | |||
55 | printTime = new QTime(); | | |||
56 | printTimer = new QTimer(); | | |||
57 | printTimer->setInterval(1000); | | |||
58 | printTimer->setSingleShot(false); | | |||
59 | connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); | | |||
60 | | ||||
61 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | 52 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | ||
62 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | 53 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | ||
63 | connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); | | |||
64 | connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); | | |||
65 | 54 | | |||
66 | connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { | 55 | connect(core, &AtCore::sdCardFileListChanged, sdWidget, &SdWidget::updateFilelist); | ||
67 | listSdFiles->clear(); | | |||
68 | listSdFiles->addItems(fileList); | | |||
69 | }); | | |||
70 | 56 | | |||
71 | connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { | 57 | connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { | ||
72 | checkTemperature(0x00, 0, temp); | 58 | checkTemperature(0x00, 0, temp); | ||
73 | plotWidget->appendPoint(tr("Actual Bed"), temp); | 59 | plotWidget->appendPoint(tr("Actual Bed"), temp); | ||
74 | plotWidget->update(); | 60 | plotWidget->update(); | ||
75 | }); | 61 | }); | ||
76 | connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { | 62 | connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { | ||
77 | checkTemperature(0x01, 0, temp); | 63 | checkTemperature(0x01, 0, temp); | ||
Show All 37 Lines | 80 | { | |||
115 | 101 | | |||
116 | menuBar()->addMenu(menuFile); | 102 | menuBar()->addMenu(menuFile); | ||
117 | menuBar()->addMenu(menuView); | 103 | menuBar()->addMenu(menuView); | ||
118 | menuBar()->addMenu(menuHelp); | 104 | menuBar()->addMenu(menuHelp); | ||
119 | } | 105 | } | ||
120 | 106 | | |||
121 | void MainWindow::initStatusBar() | 107 | void MainWindow::initStatusBar() | ||
122 | { | 108 | { | ||
123 | //first create the item for the print Progress. | 109 | statusWidget = new StatusWidget; | ||
124 | printingProgress = new QProgressBar; | 110 | connect(statusWidget, &StatusWidget::stopPressed, core, &AtCore::stop); | ||
125 | auto *newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); | 111 | connect(core, &AtCore::printProgressChanged, statusWidget, &StatusWidget::updatePrintProgress); | ||
126 | connect(newButton, &QPushButton::clicked, core, &AtCore::stop); | 112 | connect(core, &AtCore::sdMountChanged, statusWidget, &StatusWidget::setSD); | ||
127 | lblTime = new QLabel(QStringLiteral("00:00:00")); | 113 | statusBar()->addPermanentWidget(statusWidget, 100); | ||
128 | lblTime->setAlignment(Qt::AlignHCenter); | | |||
129 | auto *newLabel = new QLabel(QStringLiteral(" / ")); | | |||
130 | lblTimeLeft = new QLabel(QStringLiteral("00:00:00")); | | |||
131 | lblTimeLeft->setAlignment(Qt::AlignHCenter); | | |||
132 | | ||||
133 | auto *hBoxLayout = new QHBoxLayout; | | |||
134 | hBoxLayout->addWidget(printingProgress); | | |||
135 | hBoxLayout->addWidget(newButton); | | |||
136 | hBoxLayout->addWidget(lblTime); | | |||
137 | hBoxLayout->addWidget(newLabel); | | |||
138 | hBoxLayout->addWidget(lblTimeLeft); | | |||
139 | printProgressWidget = new QWidget(); | | |||
140 | printProgressWidget->setLayout(hBoxLayout); | | |||
141 | | ||||
142 | //Then Create the full bar. | | |||
143 | newLabel = new QLabel(tr("AtCore State:")); | | |||
144 | lblState = new QLabel(tr("Not Connected")); | | |||
145 | lblSd = new QLabel(); | | |||
146 | | ||||
147 | hBoxLayout = new QHBoxLayout; | | |||
148 | hBoxLayout->addWidget(newLabel); | | |||
149 | hBoxLayout->addWidget(lblState); | | |||
150 | hBoxLayout->addSpacerItem(new QSpacerItem(10, 20, QSizePolicy::Fixed)); | | |||
151 | hBoxLayout->addWidget(lblSd); | | |||
152 | hBoxLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); | | |||
153 | hBoxLayout->addWidget(printProgressWidget); | | |||
154 | | ||||
155 | //Then put it all into a widget on the bar. | | |||
156 | QWidget *sBar = new QWidget(); | | |||
157 | sBar->setLayout(hBoxLayout); | | |||
158 | statusBar()->addPermanentWidget(sBar, 100); | | |||
159 | } | 114 | } | ||
160 | 115 | | |||
161 | void MainWindow::initWidgets() | 116 | void MainWindow::initWidgets() | ||
162 | { | 117 | { | ||
163 | //Make the Docks | 118 | //Make the Docks | ||
164 | makeCommandDock(); | 119 | makeCommandDock(); | ||
165 | makePrintDock(); | 120 | makePrintDock(); | ||
166 | makeTempTimelineDock(); | 121 | makeTempTimelineDock(); | ||
Show All 12 Lines | |||||
179 | moveDock->raise(); | 134 | moveDock->raise(); | ||
180 | 135 | | |||
181 | tabifyDockWidget(connectDock, printDock); | 136 | tabifyDockWidget(connectDock, printDock); | ||
182 | tabifyDockWidget(connectDock, commandDock); | 137 | tabifyDockWidget(connectDock, commandDock); | ||
183 | connectDock->raise(); | 138 | connectDock->raise(); | ||
184 | setCentralWidget(nullptr); | 139 | setCentralWidget(nullptr); | ||
185 | 140 | | |||
186 | //More Gui stuff | 141 | //More Gui stuff | ||
187 | populateCBs(); | | |||
188 | //hide the printing progress bar. | 142 | //hide the printing progress bar. | ||
189 | printProgressWidget->setVisible(false); | 143 | statusWidget->showPrintArea(false); | ||
190 | } | 144 | } | ||
191 | 145 | | |||
192 | void MainWindow::makeCommandDock() | 146 | void MainWindow::makeCommandDock() | ||
193 | { | 147 | { | ||
194 | //The processing for making a dock is the same for all docks | 148 | commandWidget = new CommandWidget; | ||
195 | //Expose the least amount of object outside the creation function. | 149 | //Connect the commandPressed signal | ||
196 | 150 | connect(commandWidget, &CommandWidget::commandPressed, [this](const QString & command) { | |||
197 | // First we make our mainLayout for the dock. | 151 | core->pushCommand(command.toUpper()); | ||
198 | auto *mainLayout = new QVBoxLayout; | 152 | }); | ||
199 | 153 | //Connect the messagePressed signal | |||
200 | //Begin making content from top to bottom or left to right. | 154 | connect(commandWidget, &CommandWidget::messagePressed, [this](const QString & message) { | ||
201 | //Making child layouts in the order you want to put them | 155 | core->showMessage(message); | ||
202 | // onto the mainLayout | 156 | }); | ||
203 | lineCommand = new QLineEdit; | 157 | //Create the dock, and set the Widget. | ||
204 | lineCommand->setPlaceholderText(tr("Send Command")); | | |||
205 | | ||||
206 | //we have a few buttons to make here. Lets name this newButton so its easier to reuse | | |||
207 | auto *newButton = new QPushButton(tr("Send")); | | |||
208 | connect(newButton, &QPushButton::clicked, this, &MainWindow::sendPBClicked); | | |||
209 | | ||||
210 | //When you have created a Row put the items into layout. | | |||
211 | auto *hBoxLayout = new QHBoxLayout; | | |||
212 | hBoxLayout->addWidget(lineCommand); | | |||
213 | hBoxLayout->addWidget(newButton); | | |||
214 | //Put the Layout or Widget on the mainLayout when its finished. | | |||
215 | //This will free your pointers for reuse. | | |||
216 | mainLayout->addLayout(hBoxLayout); | | |||
217 | | ||||
218 | //Start making items for the next layout to place onto the mainLayout. | | |||
219 | lineMessage = new QLineEdit; | | |||
220 | lineMessage->setPlaceholderText(tr("Show Message")); | | |||
221 | | ||||
222 | //Here we reuse our button pointer my having it point to a new button. | | |||
223 | newButton = new QPushButton(tr("Send")); | | |||
224 | connect(newButton, &QPushButton::clicked, this, &MainWindow::showMessage); | | |||
225 | | ||||
226 | //We reuse the hBoxLayout pointer in the same way as the button pointer. | | |||
227 | hBoxLayout = new QHBoxLayout; | | |||
228 | hBoxLayout->addWidget(lineMessage); | | |||
229 | hBoxLayout->addWidget(newButton); | | |||
230 | mainLayout->addLayout(hBoxLayout); | | |||
231 | | ||||
232 | //QDockWidget::setLayout is not ment to be used by us | | |||
233 | //We must instead Create a widget to hold or dock contents. | | |||
234 | auto *dockContents = new QWidget; | | |||
235 | dockContents->setLayout(mainLayout); | | |||
236 | | ||||
237 | //Finally create the dock, and set the Widget. | | |||
238 | commandDock = new QDockWidget(tr("Commands"), this); | 158 | commandDock = new QDockWidget(tr("Commands"), this); | ||
239 | commandDock->setWidget(dockContents); | 159 | commandDock->setWidget(commandWidget); | ||
240 | 160 | | |||
241 | //Push the toggle view action into our view menu | 161 | //Push the toggle view action into our view menu | ||
242 | menuView->insertAction(nullptr, commandDock->toggleViewAction()); | 162 | menuView->insertAction(nullptr, commandDock->toggleViewAction()); | ||
243 | 163 | | |||
244 | //Place the Dock into a DockWidget Area. | 164 | //Place the Dock into a DockWidget Area. | ||
245 | //Failure todo this will create some odd side effects at runtime | 165 | //Failure todo this will create some odd side effects at runtime | ||
246 | addDockWidget(Qt::LeftDockWidgetArea, commandDock); | 166 | addDockWidget(Qt::LeftDockWidgetArea, commandDock); | ||
247 | } | 167 | } | ||
248 | 168 | | |||
249 | void MainWindow::makePrintDock() | 169 | void MainWindow::makePrintDock() | ||
250 | { | 170 | { | ||
251 | auto *mainLayout = new QVBoxLayout; | 171 | printWidget = new PrintWidget; | ||
252 | 172 | connect(printWidget, &PrintWidget::printPressed, this, &MainWindow::printPBClicked); | |||
253 | buttonPrint = new QPushButton(tr("Print File")); | 173 | connect(printWidget, &PrintWidget::emergencyStopPressed, core, &AtCore::emergencyStop); | ||
254 | connect(buttonPrint, &QPushButton::clicked, this, &MainWindow::printPBClicked); | | |||
255 | | ||||
256 | auto *newButton = new QPushButton(tr("Emergency Stop")); | | |||
257 | connect(newButton, &QPushButton::clicked, core, &AtCore::emergencyStop); | | |||
258 | 174 | | |||
259 | auto *hBoxLayout = new QHBoxLayout; | 175 | connect(printWidget, &PrintWidget::printSpeedChanged, [this](const int speed) { | ||
260 | hBoxLayout->addWidget(buttonPrint); | 176 | core->setPrinterSpeed(speed); | ||
261 | hBoxLayout->addWidget(newButton); | 177 | }); | ||
262 | mainLayout->addLayout(hBoxLayout); | | |||
263 | | ||||
264 | auto *newLabel = new QLabel(tr("On Pause:")); | | |||
265 | linePostPause = new QLineEdit; | | |||
266 | linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); | | |||
267 | | ||||
268 | hBoxLayout = new QHBoxLayout; | | |||
269 | hBoxLayout->addWidget(newLabel); | | |||
270 | hBoxLayout->addWidget(linePostPause); | | |||
271 | mainLayout->addLayout(hBoxLayout); | | |||
272 | | ||||
273 | newLabel = new QLabel(tr("Printer Speed")); | | |||
274 | sbPrintSpeed = new QSpinBox; | | |||
275 | sbPrintSpeed->setRange(1, 300); | | |||
276 | sbPrintSpeed->setValue(100); | | |||
277 | sbPrintSpeed->setSuffix(QStringLiteral("%")); | | |||
278 | | ||||
279 | newButton = new QPushButton(tr("Set")); | | |||
280 | connect(newButton, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); | | |||
281 | | ||||
282 | hBoxLayout = new QHBoxLayout; | | |||
283 | hBoxLayout->addWidget(newLabel, 35); | | |||
284 | hBoxLayout->addWidget(sbPrintSpeed, 10); | | |||
285 | hBoxLayout->addWidget(newButton, 20); | | |||
286 | mainLayout->addLayout(hBoxLayout); | | |||
287 | | ||||
288 | newLabel = new QLabel(tr("Flow Rate")); | | |||
289 | sbFlowRate = new QSpinBox; | | |||
290 | sbFlowRate->setRange(1, 300); | | |||
291 | sbFlowRate->setValue(100); | | |||
292 | sbFlowRate->setSuffix(QStringLiteral("%")); | | |||
293 | | ||||
294 | newButton = new QPushButton(tr("Set")); | | |||
295 | connect(newButton, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked); | | |||
296 | | ||||
297 | hBoxLayout = new QHBoxLayout; | | |||
298 | hBoxLayout->addWidget(newLabel, 35); | | |||
299 | hBoxLayout->addWidget(sbFlowRate, 10); | | |||
300 | hBoxLayout->addWidget(newButton, 20); | | |||
301 | mainLayout->addLayout(hBoxLayout); | | |||
302 | 178 | | |||
303 | auto *dockContents = new QWidget; | 179 | connect(printWidget, &PrintWidget::flowRateChanged, [this](const int rate) { | ||
304 | dockContents->setLayout(mainLayout); | 180 | core->setFlowRate(rate); | ||
181 | }); | ||||
305 | 182 | | |||
306 | printDock = new QDockWidget(tr("Print"), this); | 183 | printDock = new QDockWidget(tr("Print"), this); | ||
307 | printDock->setWidget(dockContents); | 184 | printDock->setWidget(printWidget); | ||
308 | 185 | | |||
309 | menuView->insertAction(nullptr, printDock->toggleViewAction()); | 186 | menuView->insertAction(nullptr, printDock->toggleViewAction()); | ||
310 | addDockWidget(Qt::LeftDockWidgetArea, printDock); | 187 | addDockWidget(Qt::LeftDockWidgetArea, printDock); | ||
311 | } | 188 | } | ||
312 | 189 | | |||
313 | void MainWindow::makeTempTimelineDock() | 190 | void MainWindow::makeTempTimelineDock() | ||
314 | { | 191 | { | ||
315 | plotWidget = new PlotWidget; | 192 | plotWidget = new PlotWidget; | ||
316 | tempTimelineDock = new QDockWidget(tr("Temperature Timeline"), this); | 193 | tempTimelineDock = new QDockWidget(tr("Temperature Timeline"), this); | ||
317 | tempTimelineDock->setWidget(plotWidget); | 194 | tempTimelineDock->setWidget(plotWidget); | ||
318 | menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); | 195 | menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); | ||
319 | addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); | 196 | addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); | ||
320 | } | 197 | } | ||
321 | 198 | | |||
322 | void MainWindow::makeLogDock() | 199 | void MainWindow::makeLogDock() | ||
323 | { | 200 | { | ||
324 | textLog = new QPlainTextEdit; | 201 | logWidget = new LogWidget(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))); | ||
325 | textLog->setReadOnly(true); | | |||
326 | textLog->setMaximumBlockCount(1000); | | |||
327 | | ||||
328 | auto *newButton = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton), tr("Save Session Log")); | | |||
329 | connect(newButton, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); | | |||
330 | | ||||
331 | auto *mainLayout = new QVBoxLayout; | | |||
332 | mainLayout->addWidget(textLog); | | |||
333 | mainLayout->addWidget(newButton); | | |||
334 | | ||||
335 | auto *dockContents = new QWidget(); | | |||
336 | dockContents->setLayout(mainLayout); | | |||
337 | | ||||
338 | logDock = new QDockWidget(tr("Session Log"), this); | 202 | logDock = new QDockWidget(tr("Session Log"), this); | ||
339 | logDock->setWidget(dockContents); | 203 | logDock->setWidget(logWidget); | ||
340 | 204 | | |||
341 | menuView->insertAction(nullptr, logDock->toggleViewAction()); | 205 | menuView->insertAction(nullptr, logDock->toggleViewAction()); | ||
342 | addDockWidget(Qt::RightDockWidgetArea, logDock); | 206 | addDockWidget(Qt::RightDockWidgetArea, logDock); | ||
343 | } | 207 | } | ||
344 | 208 | | |||
345 | void MainWindow::makeConnectDock() | 209 | void MainWindow::makeConnectDock() | ||
346 | { | 210 | { | ||
347 | auto *mainLayout = new QVBoxLayout; | 211 | auto *mainLayout = new QVBoxLayout; | ||
Show All 39 Lines | |||||
387 | connectDock->setWidget(dockContents); | 251 | connectDock->setWidget(dockContents); | ||
388 | 252 | | |||
389 | menuView->insertAction(nullptr, connectDock->toggleViewAction()); | 253 | menuView->insertAction(nullptr, connectDock->toggleViewAction()); | ||
390 | addDockWidget(Qt::LeftDockWidgetArea, connectDock); | 254 | addDockWidget(Qt::LeftDockWidgetArea, connectDock); | ||
391 | } | 255 | } | ||
392 | 256 | | |||
393 | void MainWindow::makeMoveDock() | 257 | void MainWindow::makeMoveDock() | ||
394 | { | 258 | { | ||
395 | auto *mainLayout = new QVBoxLayout; | 259 | movementWidget = new MovementWidget; | ||
396 | auto *hBoxLayout = new QHBoxLayout; | | |||
397 | 260 | | |||
398 | auto *newButton = new QPushButton(tr("Home All")); | 261 | connect(movementWidget, &MovementWidget::homeAllPressed, [this] { | ||
399 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); | 262 | logWidget->appendLog(tr("Home All")); | ||
400 | hBoxLayout->addWidget(newButton); | 263 | core->home(); | ||
401 | 264 | }); | |||
402 | newButton = new QPushButton(tr("Home X")); | | |||
403 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); | | |||
404 | hBoxLayout->addWidget(newButton); | | |||
405 | | ||||
406 | newButton = new QPushButton(tr("Home Y")); | | |||
407 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); | | |||
408 | hBoxLayout->addWidget(newButton); | | |||
409 | | ||||
410 | newButton = new QPushButton(tr("Home Z")); | | |||
411 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); | | |||
412 | hBoxLayout->addWidget(newButton); | | |||
413 | | ||||
414 | mainLayout->addLayout(hBoxLayout); | | |||
415 | 265 | | |||
416 | comboMoveAxis = new QComboBox; | 266 | connect(movementWidget, &MovementWidget::homeXPressed, [this] { | ||
417 | comboMoveAxis->addItem(tr("Move X Axis to")); | 267 | logWidget->appendLog(tr("Home X")); | ||
418 | comboMoveAxis->addItem(tr("Move Y Axis to")); | 268 | core->home(AtCore::X); | ||
419 | comboMoveAxis->addItem(tr("Move Z Axis to")); | 269 | }); | ||
420 | 270 | | |||
421 | sbMoveAxis = new QDoubleSpinBox; | 271 | connect(movementWidget, &MovementWidget::homeYPressed, [this] { | ||
422 | sbMoveAxis->setRange(0, 200); | 272 | logWidget->appendLog(tr("Home Y")); | ||
273 | core->home(AtCore::Y); | ||||
274 | }); | ||||
423 | 275 | | |||
424 | newButton = new QPushButton(tr("Go")); | 276 | connect(movementWidget, &MovementWidget::homeZPressed, [this] { | ||
425 | connect(newButton, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); | 277 | logWidget->appendLog(tr("Home Z")); | ||
278 | core->home(AtCore::Z); | ||||
279 | }); | ||||
426 | 280 | | |||
427 | hBoxLayout = new QHBoxLayout; | 281 | connect(movementWidget, &MovementWidget::absoluteMove, [this](const QLatin1Char & axis, const double & value) { | ||
428 | hBoxLayout->addWidget(comboMoveAxis); | 282 | logWidget->appendLog(GCode::description(GCode::G1)); | ||
429 | hBoxLayout->addWidget(sbMoveAxis); | 283 | core->move(axis, value); | ||
430 | hBoxLayout->addWidget(newButton); | 284 | }); | ||
431 | mainLayout->addLayout(hBoxLayout); | | |||
432 | 285 | | |||
433 | newButton = new QPushButton(tr("Disable Motors")); | 286 | connect(movementWidget, &MovementWidget::disableMotorsPressed, [this] { | ||
434 | connect(newButton, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); | 287 | core->disableMotors(0); | ||
435 | mainLayout->addWidget(newButton); | 288 | }); | ||
436 | | ||||
437 | auto *axisControl = new AxisControl; | | |||
438 | connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); | | |||
439 | mainLayout->addWidget(axisControl); | | |||
440 | 289 | | |||
441 | auto *dockContents = new QWidget; | 290 | connect(movementWidget, &MovementWidget::relativeMove, [this](const QLatin1Char & axis, const double & value) { | ||
442 | dockContents->setLayout(mainLayout); | 291 | core->setRelativePosition(); | ||
292 | core->move(axis, value); | ||||
293 | core->setAbsolutePosition(); | ||||
294 | }); | ||||
443 | 295 | | |||
444 | moveDock = new QDockWidget(tr("Movement"), this); | 296 | moveDock = new QDockWidget(tr("Movement"), this); | ||
445 | moveDock->setWidget(dockContents); | 297 | moveDock->setWidget(movementWidget); | ||
446 | 298 | | |||
447 | menuView->insertAction(nullptr, moveDock->toggleViewAction()); | 299 | menuView->insertAction(nullptr, moveDock->toggleViewAction()); | ||
448 | addDockWidget(Qt::LeftDockWidgetArea, moveDock); | 300 | addDockWidget(Qt::LeftDockWidgetArea, moveDock); | ||
449 | } | 301 | } | ||
450 | 302 | | |||
451 | void MainWindow::makeTempControlsDock() | 303 | void MainWindow::makeTempControlsDock() | ||
452 | { | 304 | { | ||
453 | auto *mainLayout = new QVBoxLayout; | 305 | temperatureWidget = new TemperatureWidget; | ||
454 | checkAndWait = new QCheckBox(tr("Wait Until Temperature Stabilizes")); | 306 | connect(temperatureWidget, &TemperatureWidget::bedTempChanged, core, &AtCore::setBedTemp); | ||
455 | mainLayout->addWidget(checkAndWait); | 307 | connect(temperatureWidget, &TemperatureWidget::extTempChanged, core, &AtCore::setExtruderTemp); | ||
456 | 308 | connect(temperatureWidget, &TemperatureWidget::fanSpeedChanged, core, &AtCore::setFanSpeed); | |||
457 | auto label = new QLabel(tr("Bed Temp")); | | |||
458 | | ||||
459 | sbBedTemp = new QSpinBox; | | |||
460 | sbBedTemp->setRange(0, 120); | | |||
461 | sbBedTemp->setSuffix(QStringLiteral("°C")); | | |||
462 | | ||||
463 | auto *newButton = new QPushButton(tr("Set")); | | |||
464 | connect(newButton, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); | | |||
465 | | ||||
466 | auto *hboxLayout = new QHBoxLayout; | | |||
467 | hboxLayout->addWidget(label, 80); | | |||
468 | hboxLayout->addWidget(sbBedTemp); | | |||
469 | hboxLayout->addWidget(newButton); | | |||
470 | mainLayout->addItem(hboxLayout); | | |||
471 | | ||||
472 | comboExtruderSelect = new QComboBox; | | |||
473 | sbExtruderTemp = new QSpinBox; | | |||
474 | sbExtruderTemp->setRange(0, 275); | | |||
475 | sbExtruderTemp->setSuffix(QStringLiteral("°C")); | | |||
476 | | ||||
477 | newButton = new QPushButton(tr("Set")); | | |||
478 | connect(newButton, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); | | |||
479 | hboxLayout = new QHBoxLayout; | | |||
480 | hboxLayout->addWidget(comboExtruderSelect, 80); | | |||
481 | hboxLayout->addWidget(sbExtruderTemp); | | |||
482 | hboxLayout->addWidget(newButton); | | |||
483 | mainLayout->addItem(hboxLayout); | | |||
484 | | ||||
485 | comboFanSelect = new QComboBox; | | |||
486 | sbFanSpeed = new QSpinBox; | | |||
487 | sbFanSpeed->setRange(0, 100); | | |||
488 | sbFanSpeed->setSuffix(QStringLiteral("%")); | | |||
489 | | ||||
490 | newButton = new QPushButton(tr("Set")); | | |||
491 | connect(newButton, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); | | |||
492 | hboxLayout = new QHBoxLayout; | | |||
493 | hboxLayout->addWidget(comboFanSelect, 80); | | |||
494 | hboxLayout->addWidget(sbFanSpeed); | | |||
495 | hboxLayout->addWidget(newButton); | | |||
496 | mainLayout->addItem(hboxLayout); | | |||
497 | | ||||
498 | auto *dockContents = new QWidget; | | |||
499 | dockContents->setLayout(mainLayout); | | |||
500 | 309 | | |||
501 | tempControlsDock = new QDockWidget(tr("Temperatures"), this); | 310 | tempControlsDock = new QDockWidget(tr("Temperatures"), this); | ||
502 | tempControlsDock->setWidget(dockContents); | 311 | tempControlsDock->setWidget(temperatureWidget); | ||
503 | | ||||
504 | menuView->insertAction(nullptr, tempControlsDock->toggleViewAction()); | 312 | menuView->insertAction(nullptr, tempControlsDock->toggleViewAction()); | ||
505 | addDockWidget(Qt::LeftDockWidgetArea, tempControlsDock); | 313 | addDockWidget(Qt::LeftDockWidgetArea, tempControlsDock); | ||
506 | } | 314 | } | ||
507 | 315 | | |||
508 | void MainWindow::makeSdDock() | 316 | void MainWindow::makeSdDock() | ||
509 | { | 317 | { | ||
510 | auto *hBoxLayout = new QHBoxLayout; | | |||
511 | 318 | | |||
512 | auto *newButton = new QPushButton(tr("Get List")); | 319 | sdWidget = new SdWidget; | ||
513 | connect(newButton, &QPushButton::clicked, this, &MainWindow::getSdList); | 320 | connect(sdWidget, &SdWidget::requestSdList, core, &AtCore::sdFileList); | ||
514 | hBoxLayout->addWidget(newButton); | | |||
515 | | ||||
516 | newButton = new QPushButton(tr("Print Selected")); | | |||
517 | connect(newButton, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); | | |||
518 | hBoxLayout->addWidget(newButton); | | |||
519 | | ||||
520 | newButton = new QPushButton(tr("Delete Selected")); | | |||
521 | connect(newButton, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); | | |||
522 | hBoxLayout->addWidget(newButton); | | |||
523 | | ||||
524 | auto *groupFiles = new QGroupBox(tr("Files On Sd Card")); | | |||
525 | listSdFiles = new QListWidget; | | |||
526 | auto *groupLayout = new QVBoxLayout; | | |||
527 | groupLayout->addWidget(listSdFiles); | | |||
528 | groupFiles->setLayout(groupLayout); | | |||
529 | 321 | | |||
530 | auto *mainLayout = new QVBoxLayout; | 322 | connect(sdWidget, &SdWidget::printSdFile, [this](const QString & fileName) { | ||
531 | mainLayout->addItem(hBoxLayout); | 323 | if (fileName.isEmpty()) { | ||
532 | mainLayout->addWidget(groupFiles); | 324 | QMessageBox::information(this, tr("Print Error"), tr("You must Select a file from the list")); | ||
325 | } else { | ||||
326 | core->print(fileName, true); | ||||
327 | } | ||||
328 | }); | ||||
533 | 329 | | |||
534 | auto *dockContents = new QWidget; | 330 | connect(sdWidget, &SdWidget::deleteSdFile, [this](const QString & fileName) { | ||
535 | dockContents->setLayout(mainLayout); | 331 | if (fileName.isEmpty()) { | ||
332 | QMessageBox::information(this, tr("Delete Error"), tr("You must Select a file from the list")); | ||||
333 | } else { | ||||
334 | core->sdDelete(fileName); | ||||
335 | } | ||||
336 | }); | ||||
536 | 337 | | |||
537 | sdDock = new QDockWidget(tr("Sd Card"), this); | 338 | sdDock = new QDockWidget(tr("Sd Card"), this); | ||
538 | sdDock->setWidget(dockContents); | 339 | sdDock->setWidget(sdWidget); | ||
539 | | ||||
540 | menuView->insertAction(nullptr, sdDock->toggleViewAction()); | 340 | menuView->insertAction(nullptr, sdDock->toggleViewAction()); | ||
541 | addDockWidget(Qt::LeftDockWidgetArea, sdDock); | 341 | addDockWidget(Qt::LeftDockWidgetArea, sdDock); | ||
542 | } | 342 | } | ||
543 | 343 | | |||
544 | void MainWindow::closeEvent(QCloseEvent *event) | 344 | void MainWindow::closeEvent(QCloseEvent *event) | ||
545 | { | 345 | { | ||
546 | core->close(); | 346 | core->close(); | ||
547 | event->accept(); | 347 | event->accept(); | ||
548 | } | 348 | } | ||
549 | 349 | | |||
550 | MainWindow::~MainWindow() | 350 | MainWindow::~MainWindow() | ||
551 | { | 351 | { | ||
552 | delete logFile; | | |||
553 | } | | |||
554 | | ||||
555 | QString MainWindow::getTime() | | |||
556 | { | | |||
557 | return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); | | |||
558 | } | | |||
559 | | ||||
560 | QString MainWindow::logHeader() | | |||
561 | { | | |||
562 | return QStringLiteral("[%1] ").arg(getTime()); | | |||
563 | } | | |||
564 | | ||||
565 | QString MainWindow::rLogHeader() | | |||
566 | { | | |||
567 | return QStringLiteral("[%1]< ").arg(getTime()); | | |||
568 | } | | |||
569 | | ||||
570 | QString MainWindow::sLogHeader() | | |||
571 | { | | |||
572 | return QStringLiteral("[%1]> ").arg(getTime()); | | |||
573 | } | | |||
574 | | ||||
575 | void MainWindow::writeTempFile(QString text) | | |||
576 | { | | |||
577 | /* | | |||
578 | A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, | | |||
579 | this allows easy access to the data in the file. This function will | | |||
580 | return true upon success and will set the fileName() to the unique | | |||
581 | filename used. | | |||
582 | */ | | |||
583 | logFile->open(); | | |||
584 | logFile->seek(logFile->size()); | | |||
585 | logFile->write(text.toLatin1()); | | |||
586 | logFile->putChar('\n'); | | |||
587 | logFile->close(); | | |||
588 | } | | |||
589 | 352 | | |||
590 | void MainWindow::addLog(QString msg) | | |||
591 | { | | |||
592 | QString message(logHeader() + msg); | | |||
593 | textLog->appendPlainText(message); | | |||
594 | writeTempFile(message); | | |||
595 | } | | |||
596 | | ||||
597 | void MainWindow::addRLog(QString msg) | | |||
598 | { | | |||
599 | QString message(rLogHeader() + msg); | | |||
600 | textLog->appendPlainText(message); | | |||
601 | writeTempFile(message); | | |||
602 | } | | |||
603 | | ||||
604 | void MainWindow::addSLog(QString msg) | | |||
605 | { | | |||
606 | QString message(sLogHeader() + msg); | | |||
607 | textLog->appendPlainText(message); | | |||
608 | writeTempFile(message); | | |||
609 | } | | |||
610 | | ||||
611 | void MainWindow::checkReceivedCommand(const QByteArray &message) | | |||
612 | { | | |||
613 | addRLog(QString::fromUtf8(message)); | | |||
614 | } | | |||
615 | | ||||
616 | void MainWindow::checkPushedCommands(QByteArray bmsg) | | |||
617 | { | | |||
618 | QString msg = QString::fromUtf8(bmsg); | | |||
619 | QRegExp _newLine(QChar::fromLatin1('\n')); | | |||
620 | QRegExp _return(QChar::fromLatin1('\r')); | | |||
621 | msg.replace(_newLine, QStringLiteral("\\n")); | | |||
622 | msg.replace(_return, QStringLiteral("\\r")); | | |||
623 | addSLog(msg); | | |||
624 | } | 353 | } | ||
625 | 354 | | |||
626 | void MainWindow::checkTemperature(uint sensorType, uint number, uint temp) | 355 | void MainWindow::checkTemperature(uint sensorType, uint number, uint temp) | ||
627 | { | 356 | { | ||
628 | QString msg; | 357 | QString msg; | ||
629 | switch (sensorType) { | 358 | switch (sensorType) { | ||
630 | case 0x00: // bed | 359 | case 0x00: // bed | ||
631 | msg = QString::fromLatin1("Bed Temperature "); | 360 | msg = QString::fromLatin1("Bed Temperature "); | ||
Show All 19 Lines | 379 | case 0x05: // enclosure target | |||
651 | msg = QString::fromLatin1("Enclosure Target Temperature "); | 380 | msg = QString::fromLatin1("Enclosure Target Temperature "); | ||
652 | break; | 381 | break; | ||
653 | } | 382 | } | ||
654 | 383 | | |||
655 | msg.append(QString::fromLatin1("[%1] : %2")); | 384 | msg.append(QString::fromLatin1("[%1] : %2")); | ||
656 | msg = msg.arg(QString::number(number)) | 385 | msg = msg.arg(QString::number(number)) | ||
657 | .arg(QString::number(temp)); | 386 | .arg(QString::number(temp)); | ||
658 | 387 | | |||
659 | addRLog(msg); | 388 | logWidget->appendLog(msg); | ||
660 | } | 389 | } | ||
661 | /** | 390 | /** | ||
662 | * @brief MainWindow::locateSerialPort | 391 | * @brief MainWindow::locateSerialPort | ||
663 | * Locate all active serial ports on the computer and add to the list | 392 | * Locate all active serial ports on the computer and add to the list | ||
664 | * of serial ports | 393 | * of serial ports | ||
665 | */ | 394 | */ | ||
666 | void MainWindow::locateSerialPort(const QStringList &ports) | 395 | void MainWindow::locateSerialPort(const QStringList &ports) | ||
667 | { | 396 | { | ||
668 | comboPort->clear(); | 397 | comboPort->clear(); | ||
669 | if (!ports.isEmpty()) { | 398 | if (!ports.isEmpty()) { | ||
670 | comboPort->addItems(ports); | 399 | comboPort->addItems(ports); | ||
671 | addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); | 400 | logWidget->appendLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); | ||
672 | } else { | 401 | } else { | ||
673 | QString portError(tr("No available ports! Please connect a serial device to continue!")); | 402 | QString portError(tr("No available ports! Please connect a serial device to continue!")); | ||
674 | if (! textLog->toPlainText().endsWith(portError)) { | 403 | if (! logWidget->endsWith(portError)) { | ||
675 | addLog(portError); | 404 | logWidget->appendLog(portError); | ||
676 | } | 405 | } | ||
677 | } | 406 | } | ||
678 | } | 407 | } | ||
679 | 408 | | |||
680 | void MainWindow::connectPBClicked() | 409 | void MainWindow::connectPBClicked() | ||
681 | { | 410 | { | ||
682 | if (core->state() == AtCore::DISCONNECTED) { | 411 | if (core->state() == AtCore::DISCONNECTED) { | ||
683 | if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) { | 412 | if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) { | ||
684 | connect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | 413 | connect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); | ||
685 | connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | 414 | connect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); | ||
686 | buttonConnect->setText(tr("Disconnect")); | 415 | buttonConnect->setText(tr("Disconnect")); | ||
687 | addLog(tr("Serial connected")); | 416 | logWidget->appendLog(tr("Serial connected")); | ||
688 | if (comboPlugin->currentText().contains(tr("Autodetect"))) { | 417 | if (comboPlugin->currentText().contains(tr("Autodetect"))) { | ||
689 | addLog(tr("No plugin loaded !")); | 418 | logWidget->appendLog(tr("No plugin loaded !")); | ||
690 | addLog(tr("Requesting Firmware...")); | 419 | logWidget->appendLog(tr("Requesting Firmware...")); | ||
691 | } else { | 420 | } else { | ||
692 | core->loadFirmwarePlugin(comboPlugin->currentText()); | 421 | core->loadFirmwarePlugin(comboPlugin->currentText()); | ||
693 | } | 422 | } | ||
694 | } else { | 423 | } else { | ||
695 | addLog(tr("Failed to open serial in r/w mode")); | 424 | logWidget->appendLog(tr("Failed to open serial in r/w mode")); | ||
696 | } | 425 | } | ||
697 | } else { | 426 | } else { | ||
698 | disconnect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | 427 | disconnect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); | ||
699 | disconnect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | 428 | disconnect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); | ||
700 | core->closeConnection(); | 429 | core->closeConnection(); | ||
701 | core->setState(AtCore::DISCONNECTED); | 430 | core->setState(AtCore::DISCONNECTED); | ||
702 | addLog(tr("Disconnected")); | 431 | logWidget->appendLog(tr("Disconnected")); | ||
703 | buttonConnect->setText(tr("Connect")); | 432 | buttonConnect->setText(tr("Connect")); | ||
704 | } | 433 | } | ||
705 | } | 434 | } | ||
706 | 435 | | |||
707 | void MainWindow::sendPBClicked() | | |||
708 | { | | |||
709 | QString comm = lineCommand->text().toUpper(); | | |||
710 | core->pushCommand(comm); | | |||
711 | lineCommand->clear(); | | |||
712 | } | | |||
713 | | ||||
714 | void MainWindow::homeAllPBClicked() | | |||
715 | { | | |||
716 | addSLog(tr("Home All")); | | |||
717 | core->home(); | | |||
718 | } | | |||
719 | | ||||
720 | void MainWindow::homeXPBClicked() | | |||
721 | { | | |||
722 | addSLog(tr("Home X")); | | |||
723 | core->home(AtCore::X); | | |||
724 | } | | |||
725 | | ||||
726 | void MainWindow::homeYPBClicked() | | |||
727 | { | | |||
728 | addSLog(tr("Home Y")); | | |||
729 | core->home(AtCore::Y); | | |||
730 | } | | |||
731 | | ||||
732 | void MainWindow::homeZPBClicked() | | |||
733 | { | | |||
734 | addSLog(tr("Home Z")); | | |||
735 | core->home(AtCore::Z); | | |||
736 | } | | |||
737 | | ||||
738 | void MainWindow::bedTempPBClicked() | | |||
739 | { | | |||
740 | if (checkAndWait->isChecked()) { | | |||
741 | addSLog(GCode::description(GCode::M190)); | | |||
742 | } else { | | |||
743 | addSLog(GCode::description(GCode::M140)); | | |||
744 | } | | |||
745 | core->setBedTemp(sbBedTemp->value(), checkAndWait->isChecked()); | | |||
746 | } | | |||
747 | | ||||
748 | void MainWindow::extTempPBClicked() | | |||
749 | { | | |||
750 | if (checkAndWait->isChecked()) { | | |||
751 | addSLog(GCode::description(GCode::M109)); | | |||
752 | } else { | | |||
753 | addSLog(GCode::description(GCode::M104)); | | |||
754 | } | | |||
755 | core->setExtruderTemp(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked()); | | |||
756 | } | | |||
757 | | ||||
758 | void MainWindow::mvAxisPBClicked() | | |||
759 | { | | |||
760 | addSLog(GCode::description(GCode::G1)); | | |||
761 | if (comboMoveAxis->currentIndex() == 0) { | | |||
762 | core->move(AtCore::X, sbMoveAxis->value()); | | |||
763 | } else if (comboMoveAxis->currentIndex() == 1) { | | |||
764 | core->move(AtCore::Y, sbMoveAxis->value()); | | |||
765 | } else if (comboMoveAxis->currentIndex() == 2) { | | |||
766 | core->move(AtCore::Z, sbMoveAxis->value()); | | |||
767 | } | | |||
768 | } | | |||
769 | | ||||
770 | void MainWindow::fanSpeedPBClicked() | | |||
771 | { | | |||
772 | addSLog(GCode::description(GCode::M106)); | | |||
773 | core->setFanSpeed(sbFanSpeed->value(), comboFanSelect->currentIndex()); | | |||
774 | } | | |||
775 | | ||||
776 | void MainWindow::printPBClicked() | 436 | void MainWindow::printPBClicked() | ||
777 | { | 437 | { | ||
778 | QString fileName; | 438 | QString fileName; | ||
779 | switch (core->state()) { | 439 | switch (core->state()) { | ||
780 | 440 | | |||
781 | case AtCore::DISCONNECTED: | 441 | case AtCore::DISCONNECTED: | ||
782 | QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); | 442 | QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); | ||
783 | break; | 443 | break; | ||
784 | 444 | | |||
785 | case AtCore::CONNECTING: | 445 | case AtCore::CONNECTING: | ||
786 | QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); | 446 | QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); | ||
787 | comboPlugin->setCurrentText(QStringLiteral("repetier")); | 447 | comboPlugin->setCurrentText(QStringLiteral("repetier")); | ||
788 | break; | 448 | break; | ||
789 | 449 | | |||
790 | case AtCore::IDLE: | 450 | case AtCore::IDLE: | ||
791 | fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), tr("*.gcode")); | 451 | fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), tr("*.gcode")); | ||
792 | if (fileName.isNull()) { | 452 | if (fileName.isNull()) { | ||
793 | addLog(tr("No File Selected")); | 453 | logWidget->appendLog(tr("No File Selected")); | ||
794 | } else { | 454 | } else { | ||
795 | addLog(tr("Print: %1").arg(fileName)); | 455 | logWidget->appendLog(tr("Print: %1").arg(fileName)); | ||
796 | core->print(fileName); | 456 | core->print(fileName); | ||
797 | } | 457 | } | ||
798 | break; | 458 | break; | ||
799 | 459 | | |||
800 | case AtCore::BUSY: | 460 | case AtCore::BUSY: | ||
801 | core->pause(linePostPause->text()); | 461 | core->pause(printWidget->postPauseCommand()); | ||
802 | break; | 462 | break; | ||
803 | 463 | | |||
804 | case AtCore::PAUSE: | 464 | case AtCore::PAUSE: | ||
805 | core->resume(); | 465 | core->resume(); | ||
806 | break; | 466 | break; | ||
807 | 467 | | |||
808 | default: | 468 | default: | ||
809 | qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; | 469 | qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; | ||
810 | } | 470 | } | ||
811 | } | 471 | } | ||
812 | 472 | | |||
813 | void MainWindow::saveLogPBClicked() | | |||
814 | { | | |||
815 | // Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it). | | |||
816 | QString fileName = QDir::homePath() + QChar::fromLatin1('/') + QFileInfo(logFile->fileName()).fileName() + QStringLiteral(".txt"); | | |||
817 | QString saveFileName = QFileDialog::getSaveFileName(this, tr("Save Log to file"), fileName); | | |||
818 | QFile::copy(logFile->fileName(), saveFileName); | | |||
819 | logFile->close(); | | |||
820 | } | | |||
821 | void MainWindow::pluginCBChanged(QString currentText) | 473 | void MainWindow::pluginCBChanged(QString currentText) | ||
822 | { | 474 | { | ||
823 | if (core->state() != AtCore::DISCONNECTED) { | 475 | if (core->state() != AtCore::DISCONNECTED) { | ||
824 | if (!currentText.contains(tr("Autodetect"))) { | 476 | if (!currentText.contains(tr("Autodetect"))) { | ||
825 | core->loadFirmwarePlugin(currentText); | 477 | core->loadFirmwarePlugin(currentText); | ||
826 | } | 478 | } | ||
827 | } | 479 | } | ||
828 | } | 480 | } | ||
829 | 481 | | |||
830 | void MainWindow::flowRatePBClicked() | | |||
831 | { | | |||
832 | core->setFlowRate(sbFlowRate->value()); | | |||
833 | } | | |||
834 | | ||||
835 | void MainWindow::printerSpeedPBClicked() | | |||
836 | { | | |||
837 | core->setPrinterSpeed(sbPrintSpeed->value()); | | |||
838 | } | | |||
839 | | ||||
840 | void MainWindow::printerStateChanged(AtCore::STATES state) | 482 | void MainWindow::printerStateChanged(AtCore::STATES state) | ||
841 | { | 483 | { | ||
842 | QString stateString; | 484 | QString stateString; | ||
843 | switch (state) { | 485 | switch (state) { | ||
844 | case AtCore::IDLE: | 486 | case AtCore::IDLE: | ||
845 | buttonPrint->setText(tr("Print File")); | 487 | printWidget->setPrintText(tr("Print File")); | ||
846 | stateString = tr("Connected to ") + core->connectedPort(); | 488 | stateString = tr("Connected to ") + core->connectedPort(); | ||
847 | break; | 489 | break; | ||
848 | 490 | | |||
849 | case AtCore::STARTPRINT: | 491 | case AtCore::STARTPRINT: | ||
850 | stateString = tr("START PRINT"); | 492 | stateString = tr("START PRINT"); | ||
851 | buttonPrint->setText(tr("Pause Print")); | 493 | printWidget->setPrintText(tr("Pause Print")); | ||
852 | printProgressWidget->setVisible(true); | 494 | statusWidget->showPrintArea(true); | ||
853 | printTime->start(); | | |||
854 | printTimer->start(); | | |||
855 | break; | 495 | break; | ||
856 | 496 | | |||
857 | case AtCore::FINISHEDPRINT: | 497 | case AtCore::FINISHEDPRINT: | ||
858 | stateString = tr("Finished Print"); | 498 | stateString = tr("Finished Print"); | ||
859 | buttonPrint->setText(tr("Print File")); | 499 | printWidget->setPrintText(tr("Print File")); | ||
860 | printProgressWidget->setVisible(false); | 500 | statusWidget->showPrintArea(false); | ||
861 | printTimer->stop(); | | |||
862 | break; | 501 | break; | ||
863 | 502 | | |||
864 | case AtCore::PAUSE: | 503 | case AtCore::PAUSE: | ||
865 | stateString = tr("Paused"); | 504 | stateString = tr("Paused"); | ||
866 | buttonPrint->setText(tr("Resume Print")); | 505 | printWidget->setPrintText(tr("Resume Print")); | ||
867 | break; | 506 | break; | ||
868 | 507 | | |||
869 | case AtCore::BUSY: | 508 | case AtCore::BUSY: | ||
870 | stateString = tr("Printing"); | 509 | stateString = tr("Printing"); | ||
871 | buttonPrint->setText(tr("Pause Print")); | 510 | printWidget->setPrintText(tr("Pause Print")); | ||
872 | break; | 511 | break; | ||
873 | 512 | | |||
874 | case AtCore::DISCONNECTED: | 513 | case AtCore::DISCONNECTED: | ||
875 | stateString = QStringLiteral("Not Connected"); | 514 | stateString = QStringLiteral("Not Connected"); | ||
876 | setDangeriousDocksDisabled(true); | 515 | setDangeriousDocksDisabled(true); | ||
877 | break; | 516 | break; | ||
878 | 517 | | |||
879 | case AtCore::CONNECTING: | 518 | case AtCore::CONNECTING: | ||
880 | stateString = QStringLiteral("Connecting"); | 519 | stateString = QStringLiteral("Connecting"); | ||
881 | setDangeriousDocksDisabled(false); | 520 | setDangeriousDocksDisabled(false); | ||
882 | break; | 521 | break; | ||
883 | 522 | | |||
884 | case AtCore::STOP: | 523 | case AtCore::STOP: | ||
885 | stateString = tr("Stopping Print"); | 524 | stateString = tr("Stopping Print"); | ||
886 | break; | 525 | break; | ||
887 | 526 | | |||
888 | case AtCore::ERRORSTATE: | 527 | case AtCore::ERRORSTATE: | ||
889 | stateString = tr("Command ERROR"); | 528 | stateString = tr("Command ERROR"); | ||
890 | break; | 529 | break; | ||
891 | } | 530 | } | ||
892 | lblState->setText(stateString); | 531 | statusWidget->setState(stateString); | ||
893 | } | | |||
894 | | ||||
895 | void MainWindow::populateCBs() | | |||
896 | { | | |||
897 | // Extruders | | |||
898 | for (int count = 0; count < core->extruderCount(); count++) { | | |||
899 | comboExtruderSelect->insertItem(count, tr("Extruder %1").arg(count)); | | |||
900 | } | 532 | } | ||
901 | 533 | | |||
902 | // Fan | | |||
903 | for (int count = 0; count < fanCount; count++) { | | |||
904 | comboFanSelect->insertItem(count, tr("Fan %1 speed").arg(count)); | | |||
905 | } | | |||
906 | } | | |||
907 | | ||||
908 | void MainWindow::showMessage() | | |||
909 | { | | |||
910 | core->showMessage(lineMessage->text()); | | |||
911 | } | | |||
912 | | ||||
913 | void MainWindow::updatePrintTime() | | |||
914 | { | | |||
915 | QTime temp(0, 0, 0); | | |||
916 | lblTime->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); | | |||
917 | } | | |||
918 | | ||||
919 | void MainWindow::printProgressChanged(int progress) | | |||
920 | { | | |||
921 | printingProgress->setValue(progress); | | |||
922 | if (progress > 0) { | | |||
923 | QTime temp(0, 0, 0); | | |||
924 | lblTimeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); | | |||
925 | } else { | | |||
926 | lblTimeLeft->setText(QStringLiteral("??:??:??")); | | |||
927 | } | | |||
928 | } | | |||
929 | void MainWindow::toggleDockTitles(bool checked) | 534 | void MainWindow::toggleDockTitles(bool checked) | ||
930 | { | 535 | { | ||
931 | if (checked) { | 536 | if (checked) { | ||
932 | delete connectDock->titleBarWidget(); | 537 | delete connectDock->titleBarWidget(); | ||
933 | delete logDock->titleBarWidget(); | 538 | delete logDock->titleBarWidget(); | ||
934 | delete tempTimelineDock->titleBarWidget(); | 539 | delete tempTimelineDock->titleBarWidget(); | ||
935 | delete commandDock->titleBarWidget(); | 540 | delete commandDock->titleBarWidget(); | ||
936 | delete moveDock->titleBarWidget(); | 541 | delete moveDock->titleBarWidget(); | ||
Show All 14 Lines | |||||
951 | 556 | | |||
952 | void MainWindow::setDangeriousDocksDisabled(bool disabled) | 557 | void MainWindow::setDangeriousDocksDisabled(bool disabled) | ||
953 | { | 558 | { | ||
954 | commandDock->widget()->setDisabled(disabled); | 559 | commandDock->widget()->setDisabled(disabled); | ||
955 | moveDock->widget()->setDisabled(disabled); | 560 | moveDock->widget()->setDisabled(disabled); | ||
956 | tempControlsDock->widget()->setDisabled(disabled); | 561 | tempControlsDock->widget()->setDisabled(disabled); | ||
957 | printDock->widget()->setDisabled(disabled); | 562 | printDock->widget()->setDisabled(disabled); | ||
958 | sdDock->widget()->setDisabled(disabled); | 563 | sdDock->widget()->setDisabled(disabled); | ||
959 | } | | |||
960 | | ||||
961 | void MainWindow::axisControlClicked(QLatin1Char axis, int value) | | |||
962 | { | | |||
963 | core->setRelativePosition(); | | |||
964 | core->move(axis, value); | | |||
965 | core->setAbsolutePosition(); | | |||
966 | } | | |||
967 | | ||||
968 | void MainWindow::disableMotorsPBClicked() | | |||
969 | { | | |||
970 | core->disableMotors(0); | | |||
971 | } | | |||
972 | | ||||
973 | void MainWindow::sdChanged(bool mounted) | | |||
974 | { | | |||
975 | QString labelText = mounted ? tr("SD") : QString(); | | |||
976 | lblSd->setText(labelText); | | |||
977 | } | | |||
978 | | ||||
979 | void MainWindow::getSdList() | | |||
980 | { | | |||
981 | core->sdFileList(); | | |||
982 | } | | |||
983 | 564 | | |||
984 | void MainWindow::sdPrintPBClicked() | 565 | if (!disabled) { | ||
985 | { | 566 | temperatureWidget->updateExtruderCount(core->extruderCount()); | ||
986 | if (listSdFiles->currentRow() < 0) { | 567 | temperatureWidget->updateFanCount(fanCount); | ||
987 | QMessageBox::information(this, tr("Print Error"), tr("You must Select a file from the list")); | | |||
988 | } else { | | |||
989 | core->print(listSdFiles->currentItem()->text(), true); | | |||
990 | } | | |||
991 | } | | |||
992 | | ||||
993 | void MainWindow::sdDelPBClicked() | | |||
994 | { | | |||
995 | if (listSdFiles->currentRow() < 0) { | | |||
996 | QMessageBox::information(this, tr("Delete Error"), tr("You must Select a file from the list")); | | |||
997 | } else { | | |||
998 | core->sdDelete(listSdFiles->currentItem()->text()); | | |||
999 | listSdFiles->setCurrentRow(-1); | | |||
1000 | } | 568 | } | ||
1001 | } | 569 | } |