MaterialsPage.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 { text: section }
  46. buttons: [
  47. Button
  48. {
  49. text: catalog.i18nc("@action:button", "Activate");
  50. iconName: "list-activate";
  51. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId
  52. onClicked: Cura.MachineManager.setActiveMaterial(base.currentItem.id)
  53. },
  54. Button
  55. {
  56. text: catalog.i18nc("@action:button", "Duplicate");
  57. iconName: "list-add";
  58. enabled: base.currentItem != null
  59. onClicked:
  60. {
  61. var material_id = Cura.ContainerManager.duplicateContainer(base.currentItem.id)
  62. if(material_id == "")
  63. {
  64. return
  65. }
  66. if(Cura.MachineManager.filterQualityByMachine)
  67. {
  68. var quality_id = Cura.ContainerManager.duplicateContainer(Cura.MachineManager.activeQualityId)
  69. Cura.ContainerManager.setContainerMetaDataEntry(quality_id, "material", material_id)
  70. Cura.MachineManager.setActiveQuality(quality_id)
  71. }
  72. Cura.MachineManager.setActiveMaterial(material_id)
  73. }
  74. },
  75. Button
  76. {
  77. text: catalog.i18nc("@action:button", "Remove");
  78. iconName: "list-remove";
  79. enabled: base.currentItem != null && !base.currentItem.readOnly
  80. onClicked: confirmDialog.open()
  81. },
  82. Button
  83. {
  84. text: catalog.i18nc("@action:button", "Import");
  85. iconName: "document-import";
  86. onClicked: importDialog.open();
  87. },
  88. Button
  89. {
  90. text: catalog.i18nc("@action:button", "Export")
  91. iconName: "document-export"
  92. onClicked: exportDialog.open()
  93. enabled: currentItem != null
  94. }
  95. ]
  96. Item {
  97. UM.I18nCatalog { id: catalog; name: "cura"; }
  98. visible: base.currentItem != null
  99. anchors.fill: parent
  100. Item
  101. {
  102. id: profileName
  103. width: parent.width;
  104. height: childrenRect.height
  105. Label { text: materialProperties.name; font: UM.Theme.getFont("large"); }
  106. Button
  107. {
  108. id: editButton
  109. anchors.right: parent.right;
  110. text: catalog.i18nc("@action:button", "Edit");
  111. iconName: "document-edit";
  112. enabled: base.currentItem != null && !base.currentItem.readOnly
  113. checkable: true
  114. }
  115. }
  116. MaterialView
  117. {
  118. anchors
  119. {
  120. left: parent.left
  121. right: parent.right
  122. top: profileName.bottom
  123. topMargin: UM.Theme.getSize("default_margin").height
  124. bottom: parent.bottom
  125. }
  126. editingEnabled: base.currentItem != null && !base.currentItem.readOnly && editButton.checked;
  127. properties: materialProperties
  128. containerId: base.currentItem != null ? base.currentItem.id : ""
  129. }
  130. QtObject
  131. {
  132. id: materialProperties
  133. property string name: "Unknown";
  134. property string profile_type: "Unknown";
  135. property string supplier: "Unknown";
  136. property string material_type: "Unknown";
  137. property string color_name: "Yellow";
  138. property color color_code: "yellow";
  139. property real density: 0.0;
  140. property real diameter: 0.0;
  141. property real spool_cost: 0.0;
  142. property real spool_weight: 0.0;
  143. property real spool_length: 0.0;
  144. property real cost_per_meter: 0.0;
  145. property string description: "";
  146. property string adhesion_info: "";
  147. }
  148. UM.ConfirmRemoveDialog
  149. {
  150. id: confirmDialog
  151. object: base.currentItem != null ? base.currentItem.name : ""
  152. onYes:
  153. {
  154. var containers = Cura.ContainerManager.findInstanceContainers({"GUID": base.currentItem.metadata.GUID})
  155. for(var i in containers)
  156. {
  157. Cura.ContainerManager.removeContainer(containers[i])
  158. }
  159. }
  160. }
  161. FileDialog
  162. {
  163. id: importDialog;
  164. title: catalog.i18nc("@title:window", "Import Material");
  165. selectExisting: true;
  166. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  167. folder: CuraApplication.getDefaultPath()
  168. onAccepted:
  169. {
  170. var result = Cura.ContainerManager.importContainer(fileUrl)
  171. messageDialog.title = catalog.i18nc("@title:window", "Import Material")
  172. messageDialog.text = catalog.i18nc("@info:status", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
  173. if(result.status == "success")
  174. {
  175. messageDialog.icon = StandardIcon.Information
  176. messageDialog.text = catalog.i18nc("@info:status", "Successfully imported material <filename>%1</filename>").arg(fileUrl)
  177. }
  178. else if(result.status == "duplicate")
  179. {
  180. messageDialog.icon = StandardIcon.Warning
  181. }
  182. else
  183. {
  184. messageDialog.icon = StandardIcon.Critical
  185. }
  186. messageDialog.open()
  187. }
  188. }
  189. FileDialog
  190. {
  191. id: exportDialog;
  192. title: catalog.i18nc("@title:window", "Export Material");
  193. selectExisting: false;
  194. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  195. folder: CuraApplication.getDefaultPath()
  196. onAccepted:
  197. {
  198. if(base.currentItem.metadata.base_file)
  199. {
  200. var result = Cura.ContainerManager.exportContainer(base.currentItem.metadata.base_file, selectedNameFilter, fileUrl)
  201. }
  202. else
  203. {
  204. var result = Cura.ContainerManager.exportContainer(base.currentItem.id, selectedNameFilter, fileUrl)
  205. }
  206. messageDialog.title = catalog.i18nc("@title:window", "Export Material")
  207. if(result.status == "error")
  208. {
  209. messageDialog.icon = StandardIcon.Critical
  210. messageDialog.text = catalog.i18nc("@info:status", "Failed to export material to <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
  211. messageDialog.open()
  212. }
  213. else if(result.status == "success")
  214. {
  215. messageDialog.icon = StandardIcon.Information
  216. messageDialog.text = catalog.i18nc("@info:status", "Successfully exported material to <filename>%1</filename>").arg(fileUrl)
  217. messageDialog.open()
  218. }
  219. }
  220. }
  221. MessageDialog
  222. {
  223. id: messageDialog
  224. }
  225. }
  226. onCurrentItemChanged:
  227. {
  228. if(currentItem == null)
  229. {
  230. return
  231. }
  232. materialProperties.name = currentItem.name;
  233. if(currentItem.metadata != undefined && currentItem.metadata != null)
  234. {
  235. materialProperties.supplier = currentItem.metadata.brand ? currentItem.metadata.brand : "Unknown";
  236. materialProperties.material_type = currentItem.metadata.material ? currentItem.metadata.material : "Unknown";
  237. materialProperties.color_name = currentItem.metadata.color_name ? currentItem.metadata.color_name : "Yellow";
  238. materialProperties.color_code = currentItem.metadata.color_code ? currentItem.metadata.color_code : "yellow";
  239. materialProperties.description = currentItem.metadata.description ? currentItem.metadata.description : "";
  240. materialProperties.adhesion_info = currentItem.metadata.adhesion_info ? currentItem.metadata.adhesion_info : "";
  241. if(currentItem.metadata.properties != undefined && currentItem.metadata.properties != null)
  242. {
  243. materialProperties.density = currentItem.metadata.properties.density ? currentItem.metadata.properties.density : 0.0;
  244. materialProperties.diameter = currentItem.metadata.properties.diameter ? currentItem.metadata.properties.diameter : 0.0;
  245. }
  246. else
  247. {
  248. materialProperties.density = 0.0;
  249. materialProperties.diameter = 0.0;
  250. }
  251. }
  252. }
  253. }