Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MaterialsPage.qml « Preferences « qml « resources - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e014faf2467a0e55b8708611a871cf9d578e76c (plain)
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
//Copyright (c) 2017 Ultimaker B.V.
//Cura is released under the terms of the LGPLv3 or higher.

import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2

import UM 1.2 as UM
import Cura 1.0 as Cura

UM.ManagementPage
{
    id: base;

    title: catalog.i18nc("@title:tab", "Materials");

    Component.onCompleted:
    {
        // Workaround to make sure all of the items are visible
        objectList.positionViewAtBeginning();
    }

    model: Cura.MaterialsModel
    {
        filter:
        {
            var result = { "type": "material", "approximate_diameter": Math.round(materialDiameterProvider.properties.value).toString() }
            if(Cura.MachineManager.filterMaterialsByMachine)
            {
                result.definition = Cura.MachineManager.activeQualityDefinitionId;
                if(Cura.MachineManager.hasVariants)
                {
                    result.variant = Cura.MachineManager.activeQualityVariantId;
                }
            }
            else
            {
                result.definition = "fdmprinter";
                result.compatible = true; //NB: Only checks for compatibility in global version of material, but we don't have machine-specific materials anyway.
            }
            return result
        }

        sectionProperty: "brand"
    }

    delegate: Rectangle
    {
        width: objectList.width;
        height: childrenRect.height;
        color: isCurrentItem ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
        property bool isCurrentItem: ListView.isCurrentItem

        Row
        {
            spacing: (UM.Theme.getSize("default_margin").width / 2) | 0
            anchors.left: parent.left
            anchors.leftMargin: UM.Theme.getSize("default_margin").width
            anchors.right: parent.right
            Rectangle
            {
                width: (parent.height * 0.8) | 0
                height: (parent.height * 0.8) | 0
                color: model.metadata.color_code
                border.color: isCurrentItem ? palette.highlightedText : palette.text;
                anchors.verticalCenter: parent.verticalCenter
            }
            Label
            {
                width: Math.floor((parent.width * 0.3))
                text: model.metadata.material
                elide: Text.ElideRight
                font.italic: model.id == activeId
                color: isCurrentItem ? palette.highlightedText : palette.text;
            }
            Label
            {
                text: (model.name != model.metadata.material) ? model.name : ""
                elide: Text.ElideRight
                font.italic: model.id == activeId
                color: isCurrentItem ? palette.highlightedText : palette.text;
            }
        }

        MouseArea
        {
            anchors.fill: parent;
            onClicked:
            {
                forceActiveFocus();
                if(!parent.ListView.isCurrentItem)
                {
                    parent.ListView.view.currentIndex = index;
                    base.itemActivated();
                }
            }
        }
    }

    activeId: Cura.MachineManager.activeMaterialId
    activeIndex: getIndexById(activeId)
    function getIndexById(material_id)
    {
        for(var i = 0; i < model.rowCount(); i++) {
            if (model.getItem(i).id == material_id) {
                return i;
            }
        }
        return -1;
    }

    scrollviewCaption:
    {
        if (Cura.MachineManager.hasVariants)
        {
            catalog.i18nc("@action:label %1 is printer name, %2 is how this printer names variants, %3 is variant name", "Printer: %1, %2: %3").arg(Cura.MachineManager.activeMachineName).arg(Cura.MachineManager.activeDefinitionVariantsName).arg(Cura.MachineManager.activeVariantName)
        }
        else
        {
            catalog.i18nc("@action:label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName)
        }
    }
    detailsVisible: true

    section.property: "section"
    section.delegate: Label
    {
        text: section
        font.bold: true
        anchors.left: parent.left;
        anchors.leftMargin: UM.Theme.getSize("default_lining").width;
    }

    buttons: [
        Button
        {
            text: catalog.i18nc("@action:button", "Activate");
            iconName: "list-activate";
            enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId && Cura.MachineManager.hasMaterials
            onClicked:
            {
                forceActiveFocus();
                Cura.MachineManager.setActiveMaterial(base.currentItem.id)
                currentItem = base.model.getItem(base.objectList.currentIndex) // Refresh the current item.
            }
        },
        Button
        {
            text: catalog.i18nc("@action:button", "Create")
            iconName: "list-add"
            onClicked:
            {
                forceActiveFocus();
                var material_id = Cura.ContainerManager.createMaterial()
                if(material_id == "")
                {
                    return
                }
                if(Cura.MachineManager.hasMaterials)
                {
                    Cura.MachineManager.setActiveMaterial(material_id)
                }
                base.objectList.currentIndex = base.getIndexById(material_id);
            }
        },
        Button
        {
            text: catalog.i18nc("@action:button", "Duplicate");
            iconName: "list-add";
            enabled: base.currentItem != null
            onClicked:
            {
                forceActiveFocus();
                var base_file = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "base_file")
                // We need to copy the base container instead of the specific variant.
                var material_id = base_file == "" ? Cura.ContainerManager.duplicateMaterial(base.currentItem.id): Cura.ContainerManager.duplicateMaterial(base_file)
                if(material_id == "")
                {
                    return
                }
                if(Cura.MachineManager.hasMaterials)
                {
                    Cura.MachineManager.setActiveMaterial(material_id)
                }
                base.objectList.currentIndex = base.getIndexById(material_id);
            }
        },
        Button
        {
            text: catalog.i18nc("@action:button", "Remove");
            iconName: "list-remove";
            enabled: base.currentItem != null && !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id)
            onClicked:
            {
                forceActiveFocus();
                confirmDialog.open();
            }
        },
        Button
        {
            text: catalog.i18nc("@action:button", "Import");
            iconName: "document-import";
            onClicked:
            {
                forceActiveFocus();
                importDialog.open();
            }
            visible: true;
        },
        Button
        {
            text: catalog.i18nc("@action:button", "Export")
            iconName: "document-export"
            onClicked:
            {
                forceActiveFocus();
                exportDialog.open();
            }
            enabled: currentItem != null
        }
    ]

    Item {
        visible: base.currentItem != null
        anchors.fill: parent

        Item
        {
            id: profileName

            width: parent.width;
            height: childrenRect.height

            Label { text: materialProperties.name; font: UM.Theme.getFont("large"); }
        }

        MaterialView
        {
            anchors
            {
                left: parent.left
                right: parent.right
                top: profileName.bottom
                topMargin: UM.Theme.getSize("default_margin").height
                bottom: parent.bottom
            }

            editingEnabled: base.currentItem != null && !base.currentItem.readOnly

            properties: materialProperties
            containerId: base.currentItem != null ? base.currentItem.id : ""

            property alias pane: base
        }

        QtObject
        {
            id: materialProperties

            property string guid: "00000000-0000-0000-0000-000000000000"
            property string name: "Unknown";
            property string profile_type: "Unknown";
            property string supplier: "Unknown";
            property string material_type: "Unknown";

            property string color_name: "Yellow";
            property color color_code: "yellow";

            property real density: 0.0;
            property real diameter: 0.0;
            property string approximate_diameter: "0";

            property real spool_cost: 0.0;
            property real spool_weight: 0.0;
            property real spool_length: 0.0;
            property real cost_per_meter: 0.0;

            property string description: "";
            property string adhesion_info: "";
        }

        UM.ConfirmRemoveDialog
        {
            id: confirmDialog
            object: base.currentItem != null ? base.currentItem.name : ""
            onYes:
            {
                // A material container can actually be multiple items, so we need to find (and remove) all of them.
                var base_file = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "base_file")
                if(base_file == "")
                {
                    base_file = base.currentItem.id
                }
                var guid = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "GUID")
                var containers = Cura.ContainerManager.findInstanceContainers({"GUID": guid, "base_file": base_file, "type": "material"})
                for(var i in containers)
                {
                    Cura.ContainerManager.removeContainer(containers[i])
                }
                if(base.objectList.currentIndex > 0)
                {
                    base.objectList.currentIndex--;
                }
                currentItem = base.model.getItem(base.objectList.currentIndex) // Refresh the current item.
            }
        }

        FileDialog
        {
            id: importDialog;
            title: catalog.i18nc("@title:window", "Import Material");
            selectExisting: true;
            nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
            folder: CuraApplication.getDefaultPath("dialog_material_path")
            onAccepted:
            {
                var result = Cura.ContainerManager.importContainer(fileUrl)

                messageDialog.title = catalog.i18nc("@title:window", "Import Material")
                messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
                if(result.status == "success")
                {
                    messageDialog.icon = StandardIcon.Information
                    messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully imported material <filename>%1</filename>").arg(fileUrl)
                    currentItem = base.model.getItem(base.objectList.currentIndex)
                }
                else if(result.status == "duplicate")
                {
                    messageDialog.icon = StandardIcon.Warning
                }
                else
                {
                    messageDialog.icon = StandardIcon.Critical
                }
                messageDialog.open()
                CuraApplication.setDefaultPath("dialog_material_path", folder)
            }
        }

        FileDialog
        {
            id: exportDialog;
            title: catalog.i18nc("@title:window", "Export Material");
            selectExisting: false;
            nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
            folder: CuraApplication.getDefaultPath("dialog_material_path")
            onAccepted:
            {
                if(base.currentItem.metadata.base_file)
                {
                    var result = Cura.ContainerManager.exportContainer(base.currentItem.metadata.base_file, selectedNameFilter, fileUrl)
                }
                else
                {
                    var result = Cura.ContainerManager.exportContainer(base.currentItem.id, selectedNameFilter, fileUrl)
                }

                messageDialog.title = catalog.i18nc("@title:window", "Export Material")
                if(result.status == "error")
                {
                    messageDialog.icon = StandardIcon.Critical
                    messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> and <message>!", "Failed to export material to <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
                    messageDialog.open()
                }
                else if(result.status == "success")
                {
                    messageDialog.icon = StandardIcon.Information
                    messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully exported material to <filename>%1</filename>").arg(result.path)
                    messageDialog.open()
                }
                CuraApplication.setDefaultPath("dialog_material_path", folder)
            }
        }

        MessageDialog
        {
            id: messageDialog
        }

        UM.SettingPropertyProvider
        {
            id: materialDiameterProvider

            containerStackId: Cura.MachineManager.activeMachineId
            key: "material_diameter"
            watchedProperties: [ "value" ]
        }

        UM.I18nCatalog { id: catalog; name: "cura"; }
        SystemPalette { id: palette }
    }

    onCurrentItemChanged:
    {
        if(currentItem == null)
        {
            return
        }
        materialProperties.name = currentItem.name;
        materialProperties.guid = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "GUID");

        if(currentItem.metadata != undefined && currentItem.metadata != null)
        {
            materialProperties.supplier = currentItem.metadata.brand ? currentItem.metadata.brand : "Unknown";
            materialProperties.material_type = currentItem.metadata.material ? currentItem.metadata.material : "Unknown";
            materialProperties.color_name = currentItem.metadata.color_name ? currentItem.metadata.color_name : "Yellow";
            materialProperties.color_code = currentItem.metadata.color_code ? currentItem.metadata.color_code : "yellow";

            materialProperties.description = currentItem.metadata.description ? currentItem.metadata.description : "";
            materialProperties.adhesion_info = currentItem.metadata.adhesion_info ? currentItem.metadata.adhesion_info : "";

            if(currentItem.metadata.properties != undefined && currentItem.metadata.properties != null)
            {
                materialProperties.density = currentItem.metadata.properties.density ? currentItem.metadata.properties.density : 0.0;
                materialProperties.diameter = currentItem.metadata.properties.diameter ? currentItem.metadata.properties.diameter : 0.0;
                materialProperties.approximate_diameter = currentItem.metadata.approximate_diameter ? currentItem.metadata.approximate_diameter : "0";
            }
            else
            {
                materialProperties.density = 0.0;
                materialProperties.diameter = 0.0;
                materialProperties.approximate_diameter = "0";
            }

        }
    }
}