-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiSliceView.qml
374 lines (316 loc) · 11.3 KB
/
MultiSliceView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import UM 1.3 as UM
import Cura 1.1 as Cura
UM.Dialog
{
id: dialog
title: catalog.i18nc("@title:window", "Multi slicing");
width: 1000 * screenScaleFactor;
height: 550 * screenScaleFactor;
minimumWidth: 400 * screenScaleFactor;
minimumHeight: 250 * screenScaleFactor;
color: UM.Theme.getColor("main_background");
margin: screenScaleFactor * 20
// append a list of strings to the output log - used to print a list of file names
function appendOutput(strList) {
// if we don't have any elements, notify and return
if (strList.length == 0) {
outputBox.append("Found 0 files, please try again")
outputBox.append("-----")
return
}
for (var s in strList) {
outputBox.append(strList[s])
}
outputBox.append("-----")
outputBox.append("Found " + strList.length + " files")
outputBox.append("Click Slice to start slicing")
outputBox.append("-----")
outputScroll.updateScroll()
}
// apply all settings applied in the GUI and try to validate
function applySettings() {
manager.set_file_pattern(regexText.text.toString())
manager.set_follow_dirs(followCheckBox.checked)
manager.set_follow_depth(followDepthField.text.toString())
manager.set_preserve_dirs(preserveDirsCheckBox.checked)
manager.set_input_path(manager.trim(selectInputDirectoryDialog.folder.toString()))
manager.set_output_path(manager.trim(selectOutputDirectoryDialog.folder.toString()))
return manager.validate_input
}
// main runner
function run() {
manager.prepare_and_run()
}
Item {
// custom signal connections
Connections {
target: manager
// on error signals, set the message as the text on the error popup and display it
function onError(msg) {
if (errorPopupText.text === "") {
errorPopupText.text = msg
errorPopup.open()
}
}
// on log signals, append the message to the output log
function onLog(msg) {
outputBox.append(msg)
outputScroll.updateScroll()
}
// stuff to do when everything is done
function onProcessingDone() {
sliceButton.visible = true
cancelButton.visible = false
}
}
}
GridLayout {
id: grid
columns: 2
ColumnLayout {
id: leftCol
Layout.preferredWidth: dialog.width * 0.5
UM.I18nCatalog {
id: catalog
name: "cura"
}
// regex input field segment
ColumnLayout {
id: regexRow
Label {
id: textAreaLabel
text: "File name pattern (default: all .stl files)"
font.bold: true
}
TextField {
id: regexText;
placeholderText: "regex"
color: UM.Theme.getColor("text")
background: Rectangle {
color: UM.Theme.getColor("main_background")
border.color: "black"
implicitWidth: dialog.width * 0.45
}
}
}
// input directory selection segment
ColumnLayout {
id: inputDirRow
Layout.minimumWidth: dialog.width * 0.9
Label {
id: inputDirButtonLabel
text: "Root directory"
font.bold: true
}
Button {
id: btnSelectDir
text: "Select folder"
onClicked: selectInputDirectoryDialog.open()
}
Label {
id: inputDirChoiceRowText
text: ""
font.italic: true
}
}
// output directory selection segment
ColumnLayout {
id: outputDirRow
Label {
id: outputDirButtonLabel
text: "Output directory"
font.bold: true
}
Button {
id: btnOutputDir
text: "Select folder"
onClicked: selectOutputDirectoryDialog.open()
}
Label {
id: outputDirChoiceRowText
text: ""
font.italic: true
}
}
// checkbox setting segment
ColumnLayout {
id: checkBoxRow
RowLayout {
CheckBox {
id: followCheckBox
text: "Follow directories"
checked: false
font.bold: true
}
Label {
id: followDepthLabel
text: "Max depth (default: 0):"
visible: followCheckBox.checked
font.bold: true
}
TextField {
id: followDepthField
placeholderText: "depth"
visible: followCheckBox.checked
color: UM.Theme.getColor("text")
// if top is set to 10, any two digit number is valid input
// also avoids recursion exceptions
validator: IntValidator {bottom: 0; top: 9;}
background: Rectangle {
color: UM.Theme.getColor("main_background")
border.color: "black"
implicitWidth: dialog.width * 0.05
}
}
}
CheckBox {
id: preserveDirsCheckBox
text: "Preserve directories in output"
visible: followCheckBox.checked
checked: false
font.bold: true
}
}
// button segment
ColumnLayout {
id: buttonRow
RowLayout {
Button {
id: checkButton
text: "Check files"
onClicked: {
if (applySettings()) appendOutput(manager.files_names);
}
}
Button {
id: sliceButton
text: "Slice"
visible: true
onClicked: {
if (applySettings()) {
sliceButton.visible = false
cancelButton.visible = true
run();
}
}
}
Button {
id: cancelButton
text: "Cancel"
visible: false
onClicked: {
sliceButton.visible = true
cancelButton.visible = false
manager.stop_multi_slice()
}
}
Button {
id: closeButton
text: "Close"
onClicked: {
dialog.close()
}
}
}
}
}
// output log segment
ColumnLayout {
ScrollView {
id: outputScroll
implicitWidth: dialog.width * 0.45
implicitHeight: dialog.height * 0.9
clip: true
function updateScroll() {
/*
set the scroll view position to the end of the contents
without the increase() call it will scroll past the text - the call ensures
that the last line of the text is always at the bottom
*/
ScrollBar.vertical.position = 1.0
ScrollBar.vertical.increase()
}
TextArea {
id: outputBox
readOnly: true
textFormat: TextEdit.PlainText
text: "Output log\n-----"
color: UM.Theme.getColor("text")
wrapMode: TextEdit.Wrap
background: Rectangle {
color: UM.Theme.getColor("main_background")
border.color: "black"
implicitWidth: dialog.width * 0.45
implicitHeight: dialog.height * 0.9
}
}
}
}
}
Item {
// needs to be in Item otherwise the qml loader dies
// output directory selection
FileDialog {
id: selectOutputDirectoryDialog
title: "Select directory"
selectExisting: true
selectFolder: true
onAccepted: {
outputDirChoiceRowText.text = manager.trim(selectOutputDirectoryDialog.folder.toString())
}
onRejected: {
outputDirChoiceRowText.text = manager.trim(selectOutputDirectoryDialog.folder.toString())
}
}
}
Item {
// needs to be in Item otherwise the qml loader dies
// input directory selection
FileDialog {
id: selectInputDirectoryDialog
title: "Select directory"
selectExisting: true
selectFolder: true
onAccepted: {
inputDirChoiceRowText.text = manager.trim(selectInputDirectoryDialog.folder.toString())
}
onRejected: {
inputDirChoiceRowText.text = manager.trim(selectInputDirectoryDialog.folder.toString())
}
}
}
Item {
// error popup
Popup {
id: errorPopup
width: dialog.width * 0.5
height: dialog.height * 0.2
x: errorPopup.width / 2
y: errorPopup.height / 2
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
onClosed: {
errorPopupText.text = ""
}
contentItem: ColumnLayout {
Text {
id: errorPopupText
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter
text: ""
}
Button {
id: popupCloseButton
text: "Close"
Layout.alignment: Qt.AlignHCenter
onClicked: {
errorPopup.close()
}
}
}
}
}
}