MaterialsPage.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura 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", "approximate_diameter": Math.round(materialDiameterProvider.properties.value) }
  17. if(Cura.MachineManager.filterMaterialsByMachine)
  18. {
  19. result.definition = Cura.MachineManager.activeQualityDefinitionId;
  20. if(Cura.MachineManager.hasVariants)
  21. {
  22. result.variant = Cura.MachineManager.activeQualityVariantId;
  23. }
  24. }
  25. else
  26. {
  27. result.definition = "fdmprinter";
  28. result.compatible = true; //NB: Only checks for compatibility in global version of material, but we don't have machine-specific materials anyway.
  29. }
  30. return result
  31. }
  32. sectionProperty: "brand"
  33. }
  34. delegate: Rectangle
  35. {
  36. width: objectList.width;
  37. height: childrenRect.height;
  38. color: isCurrentItem ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
  39. property bool isCurrentItem: ListView.isCurrentItem
  40. Row
  41. {
  42. spacing: UM.Theme.getSize("default_margin").width / 2;
  43. anchors.left: parent.left;
  44. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  45. anchors.right: parent.right;
  46. Rectangle
  47. {
  48. width: parent.height * 0.8
  49. height: parent.height * 0.8
  50. color: model.metadata.color_code
  51. border.color: isCurrentItem ? palette.highlightedText : palette.text;
  52. anchors.verticalCenter: parent.verticalCenter
  53. }
  54. Label
  55. {
  56. width: parent.width * 0.3
  57. text: model.metadata.material
  58. elide: Text.ElideRight
  59. font.italic: model.id == activeId
  60. color: isCurrentItem ? palette.highlightedText : palette.text;
  61. }
  62. Label
  63. {
  64. text: (model.name != model.metadata.material) ? model.name : ""
  65. elide: Text.ElideRight
  66. font.italic: model.id == activeId
  67. color: isCurrentItem ? palette.highlightedText : palette.text;
  68. }
  69. }
  70. MouseArea
  71. {
  72. anchors.fill: parent;
  73. onClicked:
  74. {
  75. if(!parent.ListView.isCurrentItem)
  76. {
  77. parent.ListView.view.currentIndex = index;
  78. base.itemActivated();
  79. }
  80. }
  81. }
  82. }
  83. activeId: Cura.MachineManager.activeMaterialId
  84. activeIndex: {
  85. for(var i = 0; i < model.rowCount(); i++) {
  86. if (model.getItem(i).id == Cura.MachineManager.activeMaterialId) {
  87. return i;
  88. }
  89. }
  90. return -1;
  91. }
  92. scrollviewCaption:
  93. {
  94. if (Cura.MachineManager.hasVariants)
  95. {
  96. 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)
  97. }
  98. else
  99. {
  100. catalog.i18nc("@action:label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName)
  101. }
  102. }
  103. detailsVisible: true
  104. section.property: "section"
  105. section.delegate: Label
  106. {
  107. text: section
  108. font.bold: true
  109. anchors.left: parent.left;
  110. anchors.leftMargin: UM.Theme.getSize("default_lining").width;
  111. }
  112. buttons: [
  113. Button
  114. {
  115. text: catalog.i18nc("@action:button", "Activate");
  116. iconName: "list-activate";
  117. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId && Cura.MachineManager.hasMaterials
  118. onClicked:
  119. {
  120. Cura.MachineManager.setActiveMaterial(base.currentItem.id)
  121. currentItem = base.model.getItem(base.objectList.currentIndex) // Refresh the current item.
  122. }
  123. },
  124. Button
  125. {
  126. text: catalog.i18nc("@action:button", "Duplicate");
  127. iconName: "list-add";
  128. enabled: base.currentItem != null
  129. onClicked:
  130. {
  131. var base_file = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "base_file")
  132. // We need to copy the base container instead of the specific variant.
  133. var material_id = base_file == "" ? Cura.ContainerManager.duplicateMaterial(base.currentItem.id): Cura.ContainerManager.duplicateMaterial(base_file)
  134. if(material_id == "")
  135. {
  136. return
  137. }
  138. if(Cura.MachineManager.hasMaterials)
  139. {
  140. Cura.MachineManager.setActiveMaterial(material_id)
  141. }
  142. }
  143. },
  144. Button
  145. {
  146. text: catalog.i18nc("@action:button", "Remove");
  147. iconName: "list-remove";
  148. enabled: base.currentItem != null && !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id)
  149. onClicked: confirmDialog.open()
  150. },
  151. Button
  152. {
  153. text: catalog.i18nc("@action:button", "Import");
  154. iconName: "document-import";
  155. onClicked: importDialog.open();
  156. visible: true;
  157. },
  158. Button
  159. {
  160. text: catalog.i18nc("@action:button", "Export")
  161. iconName: "document-export"
  162. onClicked: exportDialog.open()
  163. enabled: currentItem != null
  164. }
  165. ]
  166. Item {
  167. visible: base.currentItem != null
  168. anchors.fill: parent
  169. Item
  170. {
  171. id: profileName
  172. width: parent.width;
  173. height: childrenRect.height
  174. Label { text: materialProperties.name; font: UM.Theme.getFont("large"); }
  175. }
  176. MaterialView
  177. {
  178. anchors
  179. {
  180. left: parent.left
  181. right: parent.right
  182. top: profileName.bottom
  183. topMargin: UM.Theme.getSize("default_margin").height
  184. bottom: parent.bottom
  185. }
  186. editingEnabled: base.currentItem != null && !base.currentItem.readOnly
  187. properties: materialProperties
  188. containerId: base.currentItem != null ? base.currentItem.id : ""
  189. }
  190. QtObject
  191. {
  192. id: materialProperties
  193. property string guid: "00000000-0000-0000-0000-000000000000"
  194. property string name: "Unknown";
  195. property string profile_type: "Unknown";
  196. property string supplier: "Unknown";
  197. property string material_type: "Unknown";
  198. property string color_name: "Yellow";
  199. property color color_code: "yellow";
  200. property real density: 0.0;
  201. property real diameter: 0.0;
  202. property real spool_cost: 0.0;
  203. property real spool_weight: 0.0;
  204. property real spool_length: 0.0;
  205. property real cost_per_meter: 0.0;
  206. property string description: "";
  207. property string adhesion_info: "";
  208. }
  209. UM.ConfirmRemoveDialog
  210. {
  211. id: confirmDialog
  212. object: base.currentItem != null ? base.currentItem.name : ""
  213. onYes:
  214. {
  215. // A material container can actually be multiple items, so we need to find (and remove) all of them.
  216. var base_file = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "base_file")
  217. if(base_file == "")
  218. {
  219. base_file = base.currentItem.id
  220. }
  221. var guid = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "GUID")
  222. var containers = Cura.ContainerManager.findInstanceContainers({"GUID": guid, "base_file": base_file, "type": "material"})
  223. for(var i in containers)
  224. {
  225. Cura.ContainerManager.removeContainer(containers[i])
  226. }
  227. currentItem = base.model.getItem(base.objectList.currentIndex) // Refresh the current item.
  228. }
  229. }
  230. FileDialog
  231. {
  232. id: importDialog;
  233. title: catalog.i18nc("@title:window", "Import Material");
  234. selectExisting: true;
  235. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  236. folder: CuraApplication.getDefaultPath("dialog_material_path")
  237. onAccepted:
  238. {
  239. var result = Cura.ContainerManager.importContainer(fileUrl)
  240. messageDialog.title = catalog.i18nc("@title:window", "Import Material")
  241. messageDialog.text = catalog.i18nc("@info:status", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
  242. if(result.status == "success")
  243. {
  244. messageDialog.icon = StandardIcon.Information
  245. messageDialog.text = catalog.i18nc("@info:status", "Successfully imported material <filename>%1</filename>").arg(fileUrl)
  246. currentItem = base.model.getItem(base.objectList.currentIndex)
  247. }
  248. else if(result.status == "duplicate")
  249. {
  250. messageDialog.icon = StandardIcon.Warning
  251. }
  252. else
  253. {
  254. messageDialog.icon = StandardIcon.Critical
  255. }
  256. messageDialog.open()
  257. CuraApplication.setDefaultPath("dialog_material_path", folder)
  258. }
  259. }
  260. FileDialog
  261. {
  262. id: exportDialog;
  263. title: catalog.i18nc("@title:window", "Export Material");
  264. selectExisting: false;
  265. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  266. folder: CuraApplication.getDefaultPath("dialog_material_path")
  267. onAccepted:
  268. {
  269. if(base.currentItem.metadata.base_file)
  270. {
  271. var result = Cura.ContainerManager.exportContainer(base.currentItem.metadata.base_file, selectedNameFilter, fileUrl)
  272. }
  273. else
  274. {
  275. var result = Cura.ContainerManager.exportContainer(base.currentItem.id, selectedNameFilter, fileUrl)
  276. }
  277. messageDialog.title = catalog.i18nc("@title:window", "Export Material")
  278. if(result.status == "error")
  279. {
  280. messageDialog.icon = StandardIcon.Critical
  281. messageDialog.text = catalog.i18nc("@info:status", "Failed to export material to <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
  282. messageDialog.open()
  283. }
  284. else if(result.status == "success")
  285. {
  286. messageDialog.icon = StandardIcon.Information
  287. messageDialog.text = catalog.i18nc("@info:status", "Successfully exported material to <filename>%1</filename>").arg(result.path)
  288. messageDialog.open()
  289. }
  290. CuraApplication.setDefaultPath("dialog_material_path", folder)
  291. }
  292. }
  293. MessageDialog
  294. {
  295. id: messageDialog
  296. }
  297. UM.SettingPropertyProvider
  298. {
  299. id: materialDiameterProvider
  300. containerStackId: Cura.MachineManager.activeMachineId
  301. key: "material_diameter"
  302. watchedProperties: [ "value" ]
  303. }
  304. UM.I18nCatalog { id: catalog; name: "cura"; }
  305. SystemPalette { id: palette }
  306. }
  307. onCurrentItemChanged:
  308. {
  309. if(currentItem == null)
  310. {
  311. return
  312. }
  313. materialProperties.name = currentItem.name;
  314. materialProperties.guid = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "GUID");
  315. if(currentItem.metadata != undefined && currentItem.metadata != null)
  316. {
  317. materialProperties.supplier = currentItem.metadata.brand ? currentItem.metadata.brand : "Unknown";
  318. materialProperties.material_type = currentItem.metadata.material ? currentItem.metadata.material : "Unknown";
  319. materialProperties.color_name = currentItem.metadata.color_name ? currentItem.metadata.color_name : "Yellow";
  320. materialProperties.color_code = currentItem.metadata.color_code ? currentItem.metadata.color_code : "yellow";
  321. materialProperties.description = currentItem.metadata.description ? currentItem.metadata.description : "";
  322. materialProperties.adhesion_info = currentItem.metadata.adhesion_info ? currentItem.metadata.adhesion_info : "";
  323. if(currentItem.metadata.properties != undefined && currentItem.metadata.properties != null)
  324. {
  325. materialProperties.density = currentItem.metadata.properties.density ? currentItem.metadata.properties.density : 0.0;
  326. materialProperties.diameter = currentItem.metadata.properties.diameter ? currentItem.metadata.properties.diameter : 0.0;
  327. }
  328. else
  329. {
  330. materialProperties.density = 0.0;
  331. materialProperties.diameter = 0.0;
  332. }
  333. }
  334. }
  335. }