MaterialsView.qml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.15
  5. import QtQuick.Layouts 1.3
  6. import QtQuick.Dialogs
  7. import UM 1.5 as UM
  8. import Cura 1.0 as Cura
  9. Item
  10. {
  11. id: base
  12. property QtObject properties
  13. property var currentMaterialNode: null
  14. property bool editingEnabled: false
  15. property string currency: UM.Preferences.getValue("cura/currency") ? UM.Preferences.getValue("cura/currency") : "€"
  16. property string containerId: ""
  17. property var materialPreferenceValues: UM.Preferences.getValue("cura/material_settings") ? JSON.parse(UM.Preferences.getValue("cura/material_settings")) : {}
  18. property var materialManagementModel: CuraApplication.getMaterialManagementModel()
  19. property double spoolLength: calculateSpoolLength()
  20. property real costPerMeter: calculateCostPerMeter()
  21. signal resetSelectedMaterial()
  22. property bool reevaluateLinkedMaterials: false
  23. property string linkedMaterialNames:
  24. {
  25. if (reevaluateLinkedMaterials)
  26. {
  27. reevaluateLinkedMaterials = false;
  28. }
  29. if (!base.containerId || !base.editingEnabled || !base.currentMaterialNode)
  30. {
  31. return "";
  32. }
  33. var linkedMaterials = Cura.ContainerManager.getLinkedMaterials(base.currentMaterialNode, true);
  34. if (linkedMaterials.length == 0)
  35. {
  36. return "";
  37. }
  38. return linkedMaterials.join(", ");
  39. }
  40. function getApproximateDiameter(diameter)
  41. {
  42. return Math.round(diameter);
  43. }
  44. // This trick makes sure to make all fields lose focus so their onEditingFinished will be triggered
  45. // and modified values will be saved. This can happen when a user changes a value and then closes the
  46. // dialog directly.
  47. //
  48. // Please note that somehow this callback is ONLY triggered when visible is false.
  49. onVisibleChanged:
  50. {
  51. if (!visible)
  52. {
  53. base.focus = false;
  54. }
  55. }
  56. Rectangle
  57. {
  58. color: UM.Theme.getColor("main_background")
  59. anchors
  60. {
  61. top: pageSelectorTabRow.bottom
  62. topMargin: -UM.Theme.getSize("default_lining").width
  63. left: parent.left
  64. right: parent.right
  65. bottom: parent.bottom
  66. }
  67. border.width: UM.Theme.getSize("default_lining").width
  68. border.color: UM.Theme.getColor("border_main")
  69. ScrollView
  70. {
  71. id: informationPage
  72. anchors
  73. {
  74. fill: parent
  75. topMargin: UM.Theme.getSize("thin_margin").height
  76. bottomMargin: UM.Theme.getSize("thin_margin").height
  77. leftMargin: UM.Theme.getSize("thin_margin").width
  78. rightMargin: UM.Theme.getSize("thin_margin").width
  79. }
  80. ScrollBar.vertical: UM.ScrollBar
  81. {
  82. id: scrollBar
  83. parent: informationPage.parent
  84. anchors
  85. {
  86. top: parent.top
  87. right: parent.right
  88. bottom: parent.bottom
  89. }
  90. }
  91. ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
  92. clip: true
  93. visible: pageSelectorTabRow.currentItem.activeView === "information"
  94. property real columnWidth: Math.floor((width - scrollBar.width - UM.Theme.getSize("narrow_margin").width) / 2)
  95. property real rowHeight: UM.Theme.getSize("setting_control").height
  96. Column
  97. {
  98. width: informationPage.width
  99. spacing: UM.Theme.getSize("narrow_margin").height
  100. Cura.MessageDialog
  101. {
  102. id: confirmDiameterChangeDialog
  103. title: catalog.i18nc("@title:window", "Confirm Diameter Change")
  104. text: catalog.i18nc("@label (%1 is a number)", "The new filament diameter is set to %1 mm, which is not compatible with the current extruder. Do you wish to continue?".arg(new_diameter_value))
  105. standardButtons: Dialog.Yes | Dialog.No
  106. property var new_diameter_value: null
  107. property var old_diameter_value: null
  108. property var old_approximate_diameter_value: null
  109. onAccepted:
  110. {
  111. base.setMetaDataEntry("approximate_diameter", old_approximate_diameter_value, getApproximateDiameter(new_diameter_value).toString());
  112. base.setMetaDataEntry("properties/diameter", properties.diameter, new_diameter_value);
  113. // CURA-6868 Make sure to update the extruder to user a diameter-compatible material.
  114. Cura.MachineManager.updateMaterialWithVariant()
  115. base.resetSelectedMaterial()
  116. }
  117. onRejected:
  118. {
  119. base.properties.diameter = old_diameter_value;
  120. diameterTextField.valueText = Qt.binding(function() { return base.properties.diameter })
  121. }
  122. }
  123. Row
  124. {
  125. spacing: UM.Theme.getSize("narrow_margin").width
  126. UM.Label
  127. {
  128. height: informationPage.rowHeight
  129. width: informationPage.columnWidth
  130. text: catalog.i18nc("@label", "Display Name")
  131. }
  132. Cura.TextField
  133. {
  134. id: displayNameTextField
  135. width: informationPage.columnWidth
  136. text: properties.name
  137. enabled: base.editingEnabled
  138. onEditingFinished: base.updateMaterialDisplayName(properties.name, text)
  139. }
  140. }
  141. Row
  142. {
  143. spacing: UM.Theme.getSize("narrow_margin").width
  144. UM.Label
  145. {
  146. height: informationPage.rowHeight
  147. width: informationPage.columnWidth
  148. text: catalog.i18nc("@label", "Brand")
  149. }
  150. Cura.TextField
  151. {
  152. id: brandTextField
  153. width: informationPage.columnWidth
  154. text: properties.brand
  155. enabled: base.editingEnabled
  156. onEditingFinished: base.updateMaterialBrand(properties.brand, text)
  157. }
  158. }
  159. Row
  160. {
  161. spacing: UM.Theme.getSize("narrow_margin").width
  162. UM.Label
  163. {
  164. height: informationPage.rowHeight
  165. width: informationPage.columnWidth
  166. text: catalog.i18nc("@label", "Material Type")
  167. }
  168. Cura.TextField
  169. {
  170. id: materialTypeField
  171. width: informationPage.columnWidth
  172. text: properties.material
  173. enabled: base.editingEnabled
  174. onEditingFinished: base.updateMaterialType(properties.material, text)
  175. }
  176. }
  177. Row
  178. {
  179. spacing: UM.Theme.getSize("narrow_margin").width
  180. UM.Label
  181. {
  182. height: informationPage.rowHeight
  183. width: informationPage.columnWidth
  184. verticalAlignment: Qt.AlignVCenter
  185. text: catalog.i18nc("@label", "Color")
  186. }
  187. Row
  188. {
  189. width: informationPage.columnWidth
  190. spacing: Math.round(UM.Theme.getSize("default_margin").width / 2)
  191. // color indicator square
  192. Item
  193. {
  194. id: colorSelector
  195. anchors.verticalCenter: parent.verticalCenter
  196. width: colorSelectorBackground.width + 2 * UM.Theme.getSize("narrow_margin").width
  197. height: colorSelectorBackground.height + 2 * UM.Theme.getSize("narrow_margin").height
  198. Rectangle
  199. {
  200. id: colorSelectorBackground
  201. color: properties.color_code
  202. width: UM.Theme.getSize("icon_indicator").width
  203. height: UM.Theme.getSize("icon_indicator").height
  204. radius: width / 2
  205. anchors.centerIn: parent
  206. }
  207. // open the color selection dialog on click
  208. MouseArea
  209. {
  210. anchors.fill: parent
  211. onClicked: colorDialog.open()
  212. enabled: base.editingEnabled
  213. }
  214. }
  215. // pretty color name text field
  216. Cura.TextField
  217. {
  218. id: colorLabel;
  219. width: parent.width - colorSelector.width - parent.spacing
  220. text: properties.color_name;
  221. enabled: base.editingEnabled
  222. onEditingFinished: base.setMetaDataEntry("color_name", properties.color_name, text)
  223. }
  224. // popup dialog to select a new color
  225. // if successful it sets the properties.color_code value to the new color
  226. ColorDialog
  227. {
  228. id: colorDialog
  229. title: catalog.i18nc("@title", "Material color picker")
  230. selectedColor: properties.color_code
  231. onAccepted: base.setMetaDataEntry("color_code", properties.color_code, selectedColor)
  232. }
  233. }
  234. }
  235. UM.Label
  236. {
  237. width: parent.width
  238. height: parent.rowHeight
  239. font: UM.Theme.getFont("default_bold")
  240. verticalAlignment: Qt.AlignVCenter
  241. text: catalog.i18nc("@label", "Properties")
  242. }
  243. Row
  244. {
  245. height: parent.rowHeight
  246. spacing: UM.Theme.getSize("narrow_margin").width
  247. UM.Label
  248. {
  249. height: informationPage.rowHeight
  250. width: informationPage.columnWidth
  251. text: catalog.i18nc("@label", "Density")
  252. }
  253. Cura.NumericTextFieldWithUnit
  254. {
  255. id: densityTextField
  256. enabled: base.editingEnabled
  257. valueText: properties.density
  258. controlWidth: informationPage.columnWidth
  259. controlHeight: informationPage.rowHeight
  260. spacing: 0
  261. unitText: "g/cm³"
  262. decimals: 2
  263. maximum: 1000
  264. editingFinishedFunction: function()
  265. {
  266. var modified_text = valueText.replace(",", ".");
  267. base.setMetaDataEntry("properties/density", properties.density, modified_text)
  268. }
  269. onValueTextChanged: updateCostPerMeter()
  270. }
  271. }
  272. Row
  273. {
  274. height: parent.rowHeight
  275. spacing: UM.Theme.getSize("narrow_margin").width
  276. UM.Label
  277. {
  278. height: informationPage.rowHeight
  279. width: informationPage.columnWidth
  280. text: catalog.i18nc("@label", "Diameter")
  281. }
  282. Cura.NumericTextFieldWithUnit
  283. {
  284. id: diameterTextField
  285. enabled: base.editingEnabled
  286. valueText: properties.diameter
  287. controlWidth: informationPage.columnWidth
  288. controlHeight: informationPage.rowHeight
  289. spacing: 0
  290. unitText: "mm"
  291. decimals: 2
  292. maximum: 1000
  293. editingFinishedFunction: function()
  294. {
  295. // This does not use a SettingPropertyProvider, because we need to make the change to all containers
  296. // which derive from the same base_file
  297. var old_diameter = Cura.ContainerManager.getContainerMetaDataEntry(base.containerId, "properties/diameter");
  298. var old_approximate_diameter = Cura.ContainerManager.getContainerMetaDataEntry(base.containerId, "approximate_diameter");
  299. var modified_value = valueText.replace(",", ".");
  300. var new_approximate_diameter = getApproximateDiameter(modified_value);
  301. if (new_approximate_diameter != Cura.ExtruderManager.getActiveExtruderStack().approximateMaterialDiameter)
  302. {
  303. confirmDiameterChangeDialog.old_diameter_value = old_diameter;
  304. confirmDiameterChangeDialog.new_diameter_value = modified_value;
  305. confirmDiameterChangeDialog.old_approximate_diameter_value = old_approximate_diameter;
  306. confirmDiameterChangeDialog.open()
  307. }
  308. else {
  309. base.setMetaDataEntry("approximate_diameter", old_approximate_diameter, new_approximate_diameter);
  310. base.setMetaDataEntry("properties/diameter", properties.diameter, modified_value);
  311. }
  312. }
  313. onValueTextChanged: updateCostPerMeter()
  314. }
  315. }
  316. Row
  317. {
  318. height: parent.rowHeight
  319. spacing: UM.Theme.getSize("narrow_margin").width
  320. UM.Label
  321. {
  322. height: informationPage.rowHeight
  323. width: informationPage.columnWidth
  324. text: catalog.i18nc("@label", "Filament Cost")
  325. }
  326. Cura.NumericTextFieldWithUnit
  327. {
  328. id: spoolCostTextField
  329. valueText: base.getMaterialPreferenceValue(properties.guid, "spool_cost")
  330. controlWidth: informationPage.columnWidth
  331. controlHeight: informationPage.rowHeight
  332. spacing: 0
  333. unitText: base.currency
  334. decimals: 2
  335. maximum: 100000000
  336. editingFinishedFunction: function()
  337. {
  338. var modified_text = valueText.replace(",", ".");
  339. base.setMaterialPreferenceValue(properties.guid, "spool_cost", modified_text);
  340. }
  341. onValueTextChanged: updateCostPerMeter()
  342. }
  343. }
  344. Row
  345. {
  346. height: parent.rowHeight
  347. spacing: UM.Theme.getSize("narrow_margin").width
  348. UM.Label
  349. {
  350. height: informationPage.rowHeight
  351. width: informationPage.columnWidth
  352. text: catalog.i18nc("@label", "Filament weight")
  353. }
  354. Cura.NumericTextFieldWithUnit
  355. {
  356. id: spoolWeightTextField
  357. valueText: base.getMaterialPreferenceValue(properties.guid, "spool_weight", Cura.ContainerManager.getContainerMetaDataEntry(properties.container_id, "properties/weight"))
  358. controlWidth: informationPage.columnWidth
  359. controlHeight: informationPage.rowHeight
  360. spacing: 0
  361. unitText: " g"
  362. decimals: 0
  363. maximum: 10000
  364. editingFinishedFunction: function()
  365. {
  366. var modified_text = valueText.replace(",", ".")
  367. base.setMaterialPreferenceValue(properties.guid, "spool_weight", modified_text)
  368. }
  369. onValueTextChanged: updateCostPerMeter()
  370. }
  371. }
  372. Row
  373. {
  374. height: parent.rowHeight
  375. spacing: UM.Theme.getSize("narrow_margin").width
  376. UM.Label
  377. {
  378. height: informationPage.rowHeight
  379. width: informationPage.columnWidth
  380. text: catalog.i18nc("@label", "Filament length")
  381. }
  382. UM.Label
  383. {
  384. width: informationPage.columnWidth
  385. text: "~ %1 m".arg(Math.round(base.spoolLength))
  386. height: informationPage.rowHeight
  387. }
  388. }
  389. Row
  390. {
  391. height: parent.rowHeight
  392. spacing: UM.Theme.getSize("narrow_margin").width
  393. UM.Label
  394. {
  395. height: informationPage.rowHeight
  396. width: informationPage.columnWidth
  397. text: catalog.i18nc("@label", "Cost per Meter")
  398. }
  399. UM.Label
  400. {
  401. height: informationPage.rowHeight
  402. width: informationPage.columnWidth
  403. text: "~ %1 %2/m".arg(base.costPerMeter.toFixed(2)).arg(base.currency)
  404. }
  405. }
  406. UM.Label
  407. {
  408. height: parent.rowHeight
  409. width: informationPage.width
  410. text: catalog.i18nc("@label", "This material is linked to %1 and shares some of its properties.").arg(base.linkedMaterialNames)
  411. wrapMode: Text.WordWrap
  412. visible: unlinkMaterialButton.visible
  413. }
  414. Cura.SecondaryButton
  415. {
  416. id: unlinkMaterialButton
  417. text: catalog.i18nc("@label", "Unlink Material")
  418. visible: base.linkedMaterialNames != ""
  419. onClicked:
  420. {
  421. Cura.ContainerManager.unlinkMaterial(base.currentMaterialNode)
  422. base.reevaluateLinkedMaterials = true
  423. }
  424. }
  425. UM.Label
  426. {
  427. width: informationPage.width
  428. height: parent.rowHeight
  429. text: catalog.i18nc("@label", "Description")
  430. }
  431. Cura.ReadOnlyTextArea
  432. {
  433. text: properties.description
  434. width: informationPage.width - scrollBar.width
  435. height: 0.4 * informationPage.width
  436. wrapMode: Text.WordWrap
  437. readOnly: !base.editingEnabled
  438. onEditingFinished: base.setMetaDataEntry("description", properties.description, text)
  439. }
  440. UM.Label
  441. {
  442. width: informationPage.width
  443. height: parent.rowHeight
  444. text: catalog.i18nc("@label", "Adhesion Information")
  445. }
  446. Cura.ReadOnlyTextArea
  447. {
  448. text: properties.adhesion_info
  449. width: informationPage.width - scrollBar.width
  450. height: 0.4 * informationPage.width
  451. wrapMode: Text.WordWrap
  452. readOnly: !base.editingEnabled
  453. onEditingFinished: base.setMetaDataEntry("adhesion_info", properties.adhesion_info, text)
  454. }
  455. }
  456. }
  457. ListView
  458. {
  459. id: settingsPage
  460. visible: pageSelectorTabRow.currentItem.activeView === "settings"
  461. clip: true
  462. anchors
  463. {
  464. fill: parent
  465. topMargin: UM.Theme.getSize("thin_margin").height
  466. bottomMargin: UM.Theme.getSize("thin_margin").height
  467. leftMargin: UM.Theme.getSize("thin_margin").width
  468. rightMargin: UM.Theme.getSize("thin_margin").width
  469. }
  470. width: settingsPage.width
  471. spacing: UM.Theme.getSize("narrow_margin").height
  472. ScrollBar.vertical: UM.ScrollBar
  473. {
  474. id: settingScrollBar
  475. parent: settingsPage.parent
  476. anchors
  477. {
  478. top: parent.top
  479. right: parent.right
  480. bottom: parent.bottom
  481. }
  482. }
  483. property real columnWidth: Math.floor((width - settingScrollBar.width - UM.Theme.getSize("narrow_margin").width) / 2)
  484. model: UM.SettingDefinitionsModel
  485. {
  486. containerId: Cura.MachineManager.activeMachine != null ? Cura.MachineManager.activeMachine.definition.id: ""
  487. visibilityHandler: Cura.MaterialSettingsVisibilityHandler { }
  488. expanded: ["*"]
  489. }
  490. delegate: UM.TooltipArea
  491. {
  492. width: childrenRect.width
  493. height: childrenRect.height
  494. UM.TooltipArea
  495. {
  496. anchors.fill: parent
  497. text: model.description
  498. }
  499. UM.Label
  500. {
  501. id: label
  502. width: settingsPage.columnWidth
  503. height: spinBox.height + UM.Theme.getSize("default_lining").height
  504. text: model.label
  505. elide: Text.ElideRight
  506. verticalAlignment: Qt.AlignVCenter
  507. }
  508. Cura.NumericTextFieldWithUnit
  509. {
  510. id: spinBox
  511. anchors.left: label.right
  512. valueText:
  513. {
  514. // In case the setting is not in the material...
  515. if (!isNaN(parseFloat(materialPropertyProvider.properties.value)))
  516. {
  517. return parseFloat(materialPropertyProvider.properties.value);
  518. }
  519. // ... we search in the variant, and if it is not there...
  520. if (!isNaN(parseFloat(variantPropertyProvider.properties.value)))
  521. {
  522. return parseFloat(variantPropertyProvider.properties.value);
  523. }
  524. // ... then look in the definition container.
  525. if (!isNaN(parseFloat(machinePropertyProvider.properties.value)))
  526. {
  527. return parseFloat(machinePropertyProvider.properties.value);
  528. }
  529. return 0;
  530. }
  531. width: settingsPage.columnWidth
  532. maximum: 99999
  533. unitText: model.unit
  534. decimals: model.unit == "mm" ? 2 : 0
  535. enabled: base.editingEnabled
  536. editingFinishedFunction: function()
  537. {
  538. materialPropertyProvider.setPropertyValue("value", parseFloat(valueText.replace(",", ".")))
  539. }
  540. }
  541. UM.ContainerPropertyProvider
  542. {
  543. id: materialPropertyProvider
  544. containerId: base.containerId
  545. watchedProperties: [ "value" ]
  546. key: model.key
  547. }
  548. UM.ContainerPropertyProvider
  549. {
  550. id: variantPropertyProvider
  551. containerId: Cura.MachineManager.activeStack.variant.id
  552. watchedProperties: [ "value" ]
  553. key: model.key
  554. }
  555. UM.ContainerPropertyProvider
  556. {
  557. id: machinePropertyProvider
  558. containerId: Cura.MachineManager.activeMachine != null ? Cura.MachineManager.activeMachine.definition.id: ""
  559. watchedProperties: ["value"]
  560. key: model.key
  561. }
  562. }
  563. }
  564. }
  565. UM.TabRow
  566. {
  567. id: pageSelectorTabRow
  568. UM.TabRowButton
  569. {
  570. text: catalog.i18nc("@title", "Information")
  571. property string activeView: "information" //To determine which page gets displayed.
  572. }
  573. UM.TabRowButton
  574. {
  575. text: catalog.i18nc("@label", "Print settings")
  576. property string activeView: "settings"
  577. }
  578. }
  579. function updateCostPerMeter()
  580. {
  581. var modified_weight = spoolWeightTextField.valueText.replace(",", ".")
  582. var modified_cost = spoolCostTextField.valueText.replace(",", ".")
  583. var modified_diameter = diameterTextField.valueText.replace(",", ".")
  584. var modified_density = densityTextField.valueText.replace(",", ".")
  585. base.spoolLength = calculateSpoolLength(modified_diameter, modified_density, parseInt(modified_weight));
  586. base.costPerMeter = calculateCostPerMeter(parseFloat(modified_cost));
  587. }
  588. function calculateSpoolLength(diameter, density, spoolWeight)
  589. {
  590. if(!diameter)
  591. {
  592. diameter = properties.diameter;
  593. }
  594. if(!density)
  595. {
  596. density = properties.density;
  597. }
  598. if(!spoolWeight)
  599. {
  600. spoolWeight = base.getMaterialPreferenceValue(properties.guid, "spool_weight", Cura.ContainerManager.getContainerMetaDataEntry(properties.container_id, "properties/weight"));
  601. }
  602. if (diameter == 0 || density == 0 || spoolWeight == 0)
  603. {
  604. return 0;
  605. }
  606. var area = Math.PI * Math.pow(diameter / 2, 2); // in mm2
  607. var volume = (spoolWeight / density); // in cm3
  608. return volume / area; // in m
  609. }
  610. function calculateCostPerMeter(spoolCost)
  611. {
  612. if(!spoolCost)
  613. {
  614. spoolCost = base.getMaterialPreferenceValue(properties.guid, "spool_cost");
  615. }
  616. if (spoolLength == 0)
  617. {
  618. return 0;
  619. }
  620. return spoolCost / spoolLength;
  621. }
  622. // Tiny convenience function to check if a value really changed before trying to set it.
  623. function setMetaDataEntry(entry_name, old_value, new_value)
  624. {
  625. if (old_value != new_value)
  626. {
  627. Cura.ContainerManager.setContainerMetaDataEntry(base.currentMaterialNode, entry_name, new_value)
  628. // make sure the UI properties are updated as well since we don't re-fetch the entire model here
  629. // When the entry_name is something like properties/diameter, we take the last part of the entry_name
  630. var list = entry_name.split("/")
  631. var key = list[list.length - 1]
  632. properties[key] = new_value
  633. }
  634. }
  635. function setMaterialPreferenceValue(material_guid, entry_name, new_value)
  636. {
  637. if(!(material_guid in materialPreferenceValues))
  638. {
  639. materialPreferenceValues[material_guid] = {};
  640. }
  641. if(entry_name in materialPreferenceValues[material_guid] && materialPreferenceValues[material_guid][entry_name] == new_value)
  642. {
  643. // value has not changed
  644. return;
  645. }
  646. if (entry_name in materialPreferenceValues[material_guid] && new_value.toString() == 0)
  647. {
  648. // no need to store a 0, that's the default, so remove it
  649. materialPreferenceValues[material_guid].delete(entry_name);
  650. if (!(materialPreferenceValues[material_guid]))
  651. {
  652. // remove empty map
  653. materialPreferenceValues.delete(material_guid);
  654. }
  655. }
  656. if (new_value.toString() != 0)
  657. {
  658. // store new value
  659. materialPreferenceValues[material_guid][entry_name] = new_value;
  660. }
  661. // store preference
  662. UM.Preferences.setValue("cura/material_settings", JSON.stringify(materialPreferenceValues));
  663. }
  664. function getMaterialPreferenceValue(material_guid, entry_name, default_value)
  665. {
  666. if(material_guid in materialPreferenceValues && entry_name in materialPreferenceValues[material_guid])
  667. {
  668. return materialPreferenceValues[material_guid][entry_name];
  669. }
  670. default_value = default_value | 0;
  671. return default_value;
  672. }
  673. // update the display name of the material
  674. function updateMaterialDisplayName(old_name, new_name)
  675. {
  676. // don't change when new name is the same
  677. if (old_name == new_name)
  678. {
  679. return
  680. }
  681. // update the values
  682. base.materialManagementModel.setMaterialName(base.currentMaterialNode, new_name)
  683. properties.name = new_name
  684. }
  685. // update the type of the material
  686. function updateMaterialType(old_type, new_type)
  687. {
  688. base.setMetaDataEntry("material", old_type, new_type)
  689. properties.material = new_type
  690. }
  691. // update the brand of the material
  692. function updateMaterialBrand(old_brand, new_brand)
  693. {
  694. base.setMetaDataEntry("brand", old_brand, new_brand)
  695. properties.brand = new_brand
  696. }
  697. }