MaterialsPage.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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" }
  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
  118. onClicked: Cura.MachineManager.setActiveMaterial(base.currentItem.id)
  119. },
  120. Button
  121. {
  122. text: catalog.i18nc("@action:button", "Duplicate");
  123. iconName: "list-add";
  124. enabled: base.currentItem != null
  125. onClicked:
  126. {
  127. var base_file = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "base_file")
  128. // We need to copy the base container instead of the specific variant.
  129. var material_id = base_file == "" ? Cura.ContainerManager.duplicateMaterial(base.currentItem.id): Cura.ContainerManager.duplicateMaterial(base_file)
  130. if(material_id == "")
  131. {
  132. return
  133. }
  134. Cura.MachineManager.setActiveMaterial(material_id)
  135. }
  136. },
  137. Button
  138. {
  139. text: catalog.i18nc("@action:button", "Remove");
  140. iconName: "list-remove";
  141. enabled: base.currentItem != null && !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id)
  142. onClicked: confirmDialog.open()
  143. },
  144. Button
  145. {
  146. text: catalog.i18nc("@action:button", "Import");
  147. iconName: "document-import";
  148. onClicked: importDialog.open();
  149. visible: true;
  150. },
  151. Button
  152. {
  153. text: catalog.i18nc("@action:button", "Export")
  154. iconName: "document-export"
  155. onClicked: exportDialog.open()
  156. enabled: currentItem != null
  157. }
  158. ]
  159. Item {
  160. visible: base.currentItem != null
  161. anchors.fill: parent
  162. Item
  163. {
  164. id: profileName
  165. width: parent.width;
  166. height: childrenRect.height
  167. Label { text: materialProperties.name; font: UM.Theme.getFont("large"); }
  168. Button
  169. {
  170. id: editButton
  171. anchors.right: parent.right;
  172. text: catalog.i18nc("@action:button", "Edit");
  173. iconName: "document-edit";
  174. enabled: base.currentItem != null && !base.currentItem.readOnly
  175. checkable: enabled
  176. }
  177. }
  178. MaterialView
  179. {
  180. anchors
  181. {
  182. left: parent.left
  183. right: parent.right
  184. top: profileName.bottom
  185. topMargin: UM.Theme.getSize("default_margin").height
  186. bottom: parent.bottom
  187. }
  188. editingEnabled: editButton.checkable && editButton.checked;
  189. properties: materialProperties
  190. containerId: base.currentItem != null ? base.currentItem.id : ""
  191. }
  192. QtObject
  193. {
  194. id: materialProperties
  195. property string name: "Unknown";
  196. property string profile_type: "Unknown";
  197. property string supplier: "Unknown";
  198. property string material_type: "Unknown";
  199. property string color_name: "Yellow";
  200. property color color_code: "yellow";
  201. property real density: 0.0;
  202. property real diameter: 0.0;
  203. property real spool_cost: 0.0;
  204. property real spool_weight: 0.0;
  205. property real spool_length: 0.0;
  206. property real cost_per_meter: 0.0;
  207. property string description: "";
  208. property string adhesion_info: "";
  209. }
  210. UM.ConfirmRemoveDialog
  211. {
  212. id: confirmDialog
  213. object: base.currentItem != null ? base.currentItem.name : ""
  214. onYes:
  215. {
  216. // A material container can actually be multiple items, so we need to find (and remove) all of them.
  217. var base_file = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "base_file")
  218. if(base_file == "")
  219. {
  220. base_file = base.currentItem.id
  221. }
  222. var guid = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "GUID")
  223. var containers = Cura.ContainerManager.findInstanceContainers({"GUID": guid, "base_file": base_file, "type": "material"})
  224. for(var i in containers)
  225. {
  226. Cura.ContainerManager.removeContainer(containers[i])
  227. }
  228. currentItem = base.model.getItem(base.objectList.currentIndex) // Refresh the current item.
  229. }
  230. }
  231. FileDialog
  232. {
  233. id: importDialog;
  234. title: catalog.i18nc("@title:window", "Import Material");
  235. selectExisting: true;
  236. nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
  237. folder: CuraApplication.getDefaultPath("dialog_material_path")
  238. onAccepted:
  239. {
  240. var result = Cura.ContainerManager.importContainer(fileUrl)
  241. messageDialog.title = catalog.i18nc("@title:window", "Import Material")
  242. messageDialog.text = catalog.i18nc("@info:status", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
  243. if(result.status == "success")
  244. {
  245. messageDialog.icon = StandardIcon.Information
  246. messageDialog.text = catalog.i18nc("@info:status", "Successfully imported material <filename>%1</filename>").arg(fileUrl)
  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.I18nCatalog { id: catalog; name: "cura"; }
  298. SystemPalette { id: palette }
  299. }
  300. onCurrentItemChanged:
  301. {
  302. if(currentItem == null)
  303. {
  304. return
  305. }
  306. materialProperties.name = currentItem.name;
  307. if(currentItem.metadata != undefined && currentItem.metadata != null)
  308. {
  309. materialProperties.supplier = currentItem.metadata.brand ? currentItem.metadata.brand : "Unknown";
  310. materialProperties.material_type = currentItem.metadata.material ? currentItem.metadata.material : "Unknown";
  311. materialProperties.color_name = currentItem.metadata.color_name ? currentItem.metadata.color_name : "Yellow";
  312. materialProperties.color_code = currentItem.metadata.color_code ? currentItem.metadata.color_code : "yellow";
  313. materialProperties.description = currentItem.metadata.description ? currentItem.metadata.description : "";
  314. materialProperties.adhesion_info = currentItem.metadata.adhesion_info ? currentItem.metadata.adhesion_info : "";
  315. if(currentItem.metadata.properties != undefined && currentItem.metadata.properties != null)
  316. {
  317. materialProperties.density = currentItem.metadata.properties.density ? currentItem.metadata.properties.density : 0.0;
  318. materialProperties.diameter = currentItem.metadata.properties.diameter ? currentItem.metadata.properties.diameter : 0.0;
  319. }
  320. else
  321. {
  322. materialProperties.density = 0.0;
  323. materialProperties.diameter = 0.0;
  324. }
  325. }
  326. }
  327. }