MaterialsPage.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. delegate: Rectangle
  34. {
  35. width: objectList.width;
  36. height: childrenRect.height;
  37. color: isCurrentItem ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
  38. property bool isCurrentItem: ListView.isCurrentItem
  39. Row
  40. {
  41. spacing: UM.Theme.getSize("default_margin").width / 2;
  42. anchors.left: parent.left;
  43. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  44. anchors.right: parent.right;
  45. Rectangle
  46. {
  47. width: parent.height * 0.8
  48. height: parent.height * 0.8
  49. color: model.metadata.color_code
  50. border.color: isCurrentItem ? palette.highlightedText : palette.text;
  51. anchors.verticalCenter: parent.verticalCenter
  52. }
  53. Label
  54. {
  55. width: parent.width * 0.3
  56. text: model.metadata.material
  57. elide: Text.ElideRight
  58. font.italic: model.id == activeId
  59. color: isCurrentItem ? palette.highlightedText : palette.text;
  60. }
  61. Label
  62. {
  63. text: (model.name != model.metadata.material) ? model.name : ""
  64. elide: Text.ElideRight
  65. font.italic: model.id == activeId
  66. color: isCurrentItem ? palette.highlightedText : palette.text;
  67. }
  68. }
  69. MouseArea
  70. {
  71. anchors.fill: parent;
  72. onClicked:
  73. {
  74. if(!parent.ListView.isCurrentItem)
  75. {
  76. parent.ListView.view.currentIndex = index;
  77. base.itemActivated();
  78. }
  79. }
  80. }
  81. }
  82. activeId: Cura.MachineManager.activeMaterialId
  83. activeIndex: {
  84. for(var i = 0; i < model.rowCount(); i++) {
  85. if (model.getItem(i).id == Cura.MachineManager.activeMaterialId) {
  86. return i;
  87. }
  88. }
  89. return -1;
  90. }
  91. scrollviewCaption:
  92. {
  93. if (Cura.MachineManager.hasVariants)
  94. {
  95. 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)
  96. }
  97. else
  98. {
  99. catalog.i18nc("@action:label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName)
  100. }
  101. }
  102. detailsVisible: true
  103. section.property: "section"
  104. section.delegate: Label
  105. {
  106. text: section
  107. font.bold: true
  108. anchors.left: parent.left;
  109. anchors.leftMargin: UM.Theme.getSize("default_lining").width;
  110. }
  111. buttons: [
  112. Button
  113. {
  114. text: catalog.i18nc("@action:button", "Activate");
  115. iconName: "list-activate";
  116. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId
  117. onClicked: Cura.MachineManager.setActiveMaterial(base.currentItem.id)
  118. },
  119. /* // apparently visible does not work on OS X
  120. Button
  121. {
  122. text: catalog.i18nc("@action:button", "Duplicate");
  123. iconName: "list-add";
  124. enabled: base.currentItem != null
  125. onClicked:
  126. {
  127. var material_id = Cura.ContainerManager.duplicateContainer(base.currentItem.id)
  128. if(material_id == "")
  129. {
  130. return
  131. }
  132. if(Cura.MachineManager.filterQualityByMachine)
  133. {
  134. var quality_id = Cura.ContainerManager.duplicateContainer(Cura.MachineManager.activeQualityId)
  135. Cura.ContainerManager.setContainerMetaDataEntry(quality_id, "material", material_id)
  136. Cura.MachineManager.setActiveQuality(quality_id)
  137. }
  138. Cura.MachineManager.setActiveMaterial(material_id)
  139. }
  140. visible: false;
  141. },
  142. */
  143. Button
  144. {
  145. text: catalog.i18nc("@action:button", "Remove");
  146. iconName: "list-remove";
  147. enabled: base.currentItem != null && !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id)
  148. onClicked: confirmDialog.open()
  149. },
  150. /* // apparently visible does not work on OS X
  151. Button
  152. {
  153. text: catalog.i18nc("@action:button", "Import");
  154. iconName: "document-import";
  155. onClicked: importDialog.open();
  156. visible: false;
  157. },
  158. */
  159. Button
  160. {
  161. text: catalog.i18nc("@action:button", "Export")
  162. iconName: "document-export"
  163. onClicked: exportDialog.open()
  164. enabled: currentItem != null
  165. }
  166. ]
  167. Item {
  168. visible: base.currentItem != null
  169. anchors.fill: parent
  170. Item
  171. {
  172. id: profileName
  173. width: parent.width;
  174. height: childrenRect.height
  175. Label { text: materialProperties.name; font: UM.Theme.getFont("large"); }
  176. Button
  177. {
  178. id: editButton
  179. anchors.right: parent.right;
  180. text: catalog.i18nc("@action:button", "Edit");
  181. iconName: "document-edit";
  182. enabled: base.currentItem != null && !base.currentItem.readOnly
  183. checkable: enabled
  184. }
  185. }
  186. MaterialView
  187. {
  188. anchors
  189. {
  190. left: parent.left
  191. right: parent.right
  192. top: profileName.bottom
  193. topMargin: UM.Theme.getSize("default_margin").height
  194. bottom: parent.bottom
  195. }
  196. editingEnabled: editButton.checkable && editButton.checked;
  197. properties: materialProperties
  198. containerId: base.currentItem != null ? base.currentItem.id : ""
  199. }
  200. QtObject
  201. {
  202. id: materialProperties
  203. property string name: "Unknown";
  204. property string profile_type: "Unknown";
  205. property string supplier: "Unknown";
  206. property string material_type: "Unknown";
  207. property string color_name: "Yellow";
  208. property color color_code: "yellow";
  209. property real density: 0.0;
  210. property real diameter: 0.0;
  211. property real spool_cost: 0.0;
  212. property real spool_weight: 0.0;
  213. property real spool_length: 0.0;
  214. property real cost_per_meter: 0.0;
  215. property string description: "";
  216. property string adhesion_info: "";
  217. }
  218. UM.ConfirmRemoveDialog
  219. {
  220. id: confirmDialog
  221. object: base.currentItem != null ? base.currentItem.name : ""
  222. onYes:
  223. {
  224. var containers = Cura.ContainerManager.findInstanceContainers({"id": base.currentItem.id})
  225. for(var i in containers)
  226. {
  227. Cura.ContainerManager.removeContainer(containers[i])
  228. }
  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. }