MaterialsPage.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Uranium is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Dialogs 1.2
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. UM.ManagementPage
  9. {
  10. id: base;
  11. title: catalog.i18nc("@title:tab", "Materials");
  12. model: UM.InstanceContainersModel
  13. {
  14. filter:
  15. {
  16. var result = { "type": "material" }
  17. if(Cura.MachineManager.filterMaterialsByMachine)
  18. {
  19. result.definition = Cura.MachineManager.activeDefinitionId
  20. if(Cura.MachineManager.hasVariants)
  21. {
  22. result.variant = Cura.MachineManager.activeVariantId
  23. }
  24. }
  25. else
  26. {
  27. result.definition = "fdmprinter"
  28. }
  29. return result
  30. }
  31. sectionProperty: "brand"
  32. }
  33. activeId: Cura.MachineManager.activeMaterialId
  34. activeIndex: {
  35. for(var i = 0; i < model.rowCount(); i++) {
  36. if (model.getItem(i).id == Cura.MachineManager.activeMaterialId) {
  37. return i;
  38. }
  39. }
  40. return -1;
  41. }
  42. scrollviewCaption: "Printer: %1, Nozzle: %2".arg(Cura.MachineManager.activeMachineName).arg(Cura.MachineManager.activeVariantName)
  43. detailsVisible: true
  44. section.property: "section"
  45. section.delegate: Label
  46. {
  47. text: section
  48. font.bold: true
  49. anchors.left: parent.left;
  50. anchors.leftMargin: UM.Theme.getSize("default_lining").width;
  51. }
  52. buttons: [
  53. Button
  54. {
  55. text: catalog.i18nc("@action:button", "Activate");
  56. iconName: "list-activate";
  57. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId
  58. onClicked: Cura.MachineManager.setActiveMaterial(base.currentItem.id)
  59. },
  60. Button
  61. {
  62. text: catalog.i18nc("@action:button", "Duplicate");
  63. iconName: "list-add";
  64. enabled: base.currentItem != null
  65. onClicked:
  66. {
  67. var material_id = Cura.ContainerManager.duplicateContainer(base.currentItem.id)
  68. if(material_id == "")
  69. {
  70. return
  71. }
  72. if(Cura.MachineManager.filterQualityByMachine)
  73. {
  74. var quality_id = Cura.ContainerManager.duplicateContainer(Cura.MachineManager.activeQualityId)
  75. Cura.ContainerManager.setContainerMetaDataEntry(quality_id, "material", material_id)
  76. Cura.MachineManager.setActiveQuality(quality_id)
  77. }
  78. Cura.MachineManager.setActiveMaterial(material_id)
  79. }
  80. },
  81. Button
  82. {
  83. text: catalog.i18nc("@action:button", "Remove");
  84. iconName: "list-remove";
  85. enabled: base.currentItem != null && !base.currentItem.readOnly
  86. onClicked: confirmDialog.open()
  87. },
  88. Button
  89. {
  90. text: catalog.i18nc("@action:button", "Import");
  91. iconName: "document-import";
  92. onClicked: importDialog.open();
  93. },
  94. Button
  95. {
  96. text: catalog.i18nc("@action:button", "Export")
  97. iconName: "document-export"
  98. onClicked: exportDialog.open()
  99. enabled: currentItem != null
  100. }
  101. ]
  102. Item {
  103. UM.I18nCatalog { id: catalog; name: "cura"; }
  104. visible: base.currentItem != null
  105. anchors.fill: parent
  106. Item
  107. {
  108. id: profileName
  109. width: parent.width;
  110. height: childrenRect.height
  111. Label { text: materialProperties.name; font: UM.Theme.getFont("large"); }
  112. Button
  113. {
  114. id: editButton
  115. anchors.right: parent.right;
  116. text: catalog.i18nc("@action:button", "Edit");
  117. iconName: "document-edit";
  118. enabled: base.currentItem != null && !base.currentItem.readOnly
  119. checkable: enabled
  120. }
  121. }
  122. MaterialView
  123. {
  124. anchors
  125. {
  126. left: parent.left
  127. right: parent.right
  128. top: profileName.bottom
  129. topMargin: UM.Theme.getSize("default_margin").height
  130. bottom: parent.bottom
  131. }
  132. editingEnabled: editButton.checkable && editButton.checked;
  133. properties: materialProperties
  134. containerId: base.currentItem != null ? base.currentItem.id : ""
  135. }
  136. QtObject
  137. {
  138. id: materialProperties
  139. property string name: "Unknown";
  140. property string profile_type: "Unknown";
  141. property string supplier: "Unknown";
  142. property string material_type: "Unknown";
  143. property string color_name: "Yellow";
  144. property color color_code: "yellow";
  145. property real density: 0.0;
  146. property real diameter: 0.0;
  147. property real spool_cost: 0.0;
  148. property real spool_weight: 0.0;
  149. property real spool_length: 0.0;
  150. property real cost_per_meter: 0.0;
  151. property string description: "";
  152. property string adhesion_info: "";
  153. }
  154. UM.ConfirmRemoveDialog
  155. {
  156. id: confirmDialog
  157. object: base.currentItem != null ? base.currentItem.name : ""
  158. onYes:
  159. {
  160. var containers = Cura.ContainerManager.findInstanceContainers({"GUID": base.currentItem.metadata.GUID})
  161. for(var i in containers)
  162. {
  163. Cura.ContainerManager.removeContainer(containers[i])
  164. }
  165. }
  166. }
  167. FileDialog
  168. {
  169. id: importDialog;
  170. title: catalog.i18nc("@title:window", "Import Material");
  171. selectExisting: true;
  172. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  173. folder: CuraApplication.getDefaultPath("dialog_material_path")
  174. onAccepted:
  175. {
  176. var result = Cura.ContainerManager.importContainer(fileUrl)
  177. messageDialog.title = catalog.i18nc("@title:window", "Import Material")
  178. messageDialog.text = catalog.i18nc("@info:status", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
  179. if(result.status == "success")
  180. {
  181. messageDialog.icon = StandardIcon.Information
  182. messageDialog.text = catalog.i18nc("@info:status", "Successfully imported material <filename>%1</filename>").arg(fileUrl)
  183. }
  184. else if(result.status == "duplicate")
  185. {
  186. messageDialog.icon = StandardIcon.Warning
  187. }
  188. else
  189. {
  190. messageDialog.icon = StandardIcon.Critical
  191. }
  192. messageDialog.open()
  193. CuraApplication.setDefaultPath("dialog_material_path", folder)
  194. }
  195. }
  196. FileDialog
  197. {
  198. id: exportDialog;
  199. title: catalog.i18nc("@title:window", "Export Material");
  200. selectExisting: false;
  201. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  202. folder: CuraApplication.getDefaultPath("dialog_material_path")
  203. onAccepted:
  204. {
  205. if(base.currentItem.metadata.base_file)
  206. {
  207. var result = Cura.ContainerManager.exportContainer(base.currentItem.metadata.base_file, selectedNameFilter, fileUrl)
  208. }
  209. else
  210. {
  211. var result = Cura.ContainerManager.exportContainer(base.currentItem.id, selectedNameFilter, fileUrl)
  212. }
  213. messageDialog.title = catalog.i18nc("@title:window", "Export Material")
  214. if(result.status == "error")
  215. {
  216. messageDialog.icon = StandardIcon.Critical
  217. messageDialog.text = catalog.i18nc("@info:status", "Failed to export material to <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
  218. messageDialog.open()
  219. }
  220. else if(result.status == "success")
  221. {
  222. messageDialog.icon = StandardIcon.Information
  223. messageDialog.text = catalog.i18nc("@info:status", "Successfully exported material to <filename>%1</filename>").arg(fileUrl)
  224. messageDialog.open()
  225. }
  226. CuraApplication.setDefaultPath("dialog_material_path", folder)
  227. }
  228. }
  229. MessageDialog
  230. {
  231. id: messageDialog
  232. }
  233. }
  234. onCurrentItemChanged:
  235. {
  236. if(currentItem == null)
  237. {
  238. return
  239. }
  240. materialProperties.name = currentItem.name;
  241. if(currentItem.metadata != undefined && currentItem.metadata != null)
  242. {
  243. materialProperties.supplier = currentItem.metadata.brand ? currentItem.metadata.brand : "Unknown";
  244. materialProperties.material_type = currentItem.metadata.material ? currentItem.metadata.material : "Unknown";
  245. materialProperties.color_name = currentItem.metadata.color_name ? currentItem.metadata.color_name : "Yellow";
  246. materialProperties.color_code = currentItem.metadata.color_code ? currentItem.metadata.color_code : "yellow";
  247. materialProperties.description = currentItem.metadata.description ? currentItem.metadata.description : "";
  248. materialProperties.adhesion_info = currentItem.metadata.adhesion_info ? currentItem.metadata.adhesion_info : "";
  249. if(currentItem.metadata.properties != undefined && currentItem.metadata.properties != null)
  250. {
  251. materialProperties.density = currentItem.metadata.properties.density ? currentItem.metadata.properties.density : 0.0;
  252. materialProperties.diameter = currentItem.metadata.properties.diameter ? currentItem.metadata.properties.diameter : 0.0;
  253. }
  254. else
  255. {
  256. materialProperties.density = 0.0;
  257. materialProperties.diameter = 0.0;
  258. }
  259. }
  260. }
  261. }