SimulationViewMenuComponent.qml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.15
  4. import QtQuick.Layouts 1.1
  5. import QtQuick.Controls 2.1
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. Cura.ExpandableComponent
  9. {
  10. id: base
  11. dragPreferencesNamePrefix: "view/colorscheme"
  12. contentHeaderTitle: catalog.i18nc("@label", "Color scheme")
  13. Connections
  14. {
  15. target: UM.Preferences
  16. function onPreferenceChanged(preference)
  17. {
  18. if (preference !== "view/only_show_top_layers" && preference !== "view/top_layer_count" && ! preference.match("layerview/"))
  19. {
  20. return;
  21. }
  22. layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type")
  23. layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex)
  24. viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|")
  25. viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves")
  26. viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers")
  27. viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin")
  28. viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill")
  29. viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers")
  30. viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count")
  31. }
  32. }
  33. headerItem: Item
  34. {
  35. UM.Label
  36. {
  37. id: colorSchemeLabel
  38. text: catalog.i18nc("@label", "Color scheme")
  39. height: parent.height
  40. elide: Text.ElideRight
  41. font: UM.Theme.getFont("medium")
  42. color: UM.Theme.getColor("text_medium")
  43. }
  44. UM.Label
  45. {
  46. text: layerTypeCombobox.currentText
  47. anchors
  48. {
  49. left: colorSchemeLabel.right
  50. leftMargin: UM.Theme.getSize("default_margin").width
  51. right: parent.right
  52. }
  53. height: parent.height
  54. elide: Text.ElideRight
  55. font: UM.Theme.getFont("medium")
  56. }
  57. }
  58. contentItem: Column
  59. {
  60. id: viewSettings
  61. property var extruder_opacities: UM.Preferences.getValue("layerview/extruder_opacities").split("|")
  62. property bool show_travel_moves: UM.Preferences.getValue("layerview/show_travel_moves")
  63. property bool show_helpers: UM.Preferences.getValue("layerview/show_helpers")
  64. property bool show_skin: UM.Preferences.getValue("layerview/show_skin")
  65. property bool show_infill: UM.Preferences.getValue("layerview/show_infill")
  66. property bool show_starts: UM.Preferences.getValue("layerview/show_starts")
  67. // If we are in compatibility mode, we only show the "line type"
  68. property bool show_legend: UM.SimulationView.compatibilityMode ? true : UM.Preferences.getValue("layerview/layer_view_type") == 1
  69. property bool show_gradient: UM.SimulationView.compatibilityMode ? false : UM.Preferences.getValue("layerview/layer_view_type") == 2 || UM.Preferences.getValue("layerview/layer_view_type") == 3
  70. property bool show_feedrate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 2
  71. property bool show_thickness_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 3
  72. property bool show_line_width_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 4
  73. property bool show_flow_rate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 5
  74. property bool only_show_top_layers: UM.Preferences.getValue("view/only_show_top_layers")
  75. property int top_layer_count: UM.Preferences.getValue("view/top_layer_count")
  76. width: UM.Theme.getSize("layerview_menu_size").width - 2 * UM.Theme.getSize("default_margin").width
  77. height: implicitHeight
  78. spacing: UM.Theme.getSize("layerview_row_spacing").height
  79. // matches SimulationView.py
  80. ListModel
  81. {
  82. id: layerViewTypes
  83. }
  84. Component.onCompleted:
  85. {
  86. layerViewTypes.append({
  87. text: catalog.i18nc("@label:listbox", "Material Color"),
  88. type_id: 0
  89. })
  90. layerViewTypes.append({
  91. text: catalog.i18nc("@label:listbox", "Line Type"),
  92. type_id: 1
  93. })
  94. layerViewTypes.append({
  95. text: catalog.i18nc("@label:listbox", "Speed"),
  96. type_id: 2
  97. })
  98. layerViewTypes.append({
  99. text: catalog.i18nc("@label:listbox", "Layer Thickness"),
  100. type_id: 3 // these ids match the switching in the shader
  101. })
  102. layerViewTypes.append({
  103. text: catalog.i18nc("@label:listbox", "Line Width"),
  104. type_id: 4
  105. })
  106. layerViewTypes.append({
  107. text: catalog.i18nc("@label:listbox", "Flow"),
  108. type_id: 5
  109. })
  110. }
  111. Cura.ComboBox
  112. {
  113. id: layerTypeCombobox
  114. textRole: "text"
  115. valueRole: "type_id"
  116. width: parent.width
  117. implicitHeight: UM.Theme.getSize("setting_control").height
  118. model: layerViewTypes
  119. visible: !UM.SimulationView.compatibilityMode
  120. onActivated: (index) => {UM.Preferences.setValue("layerview/layer_view_type", index)}
  121. Component.onCompleted:
  122. {
  123. currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type");
  124. updateLegends(currentIndex);
  125. }
  126. function updateLegends(type_id)
  127. {
  128. // Update the visibility of the legends.
  129. viewSettings.show_legend = UM.SimulationView.compatibilityMode || (type_id == 1);
  130. viewSettings.show_gradient = !UM.SimulationView.compatibilityMode &&
  131. (type_id == 2 || type_id == 3 || type_id == 4 || type_id == 5) ;
  132. viewSettings.show_feedrate_gradient = viewSettings.show_gradient && (type_id == 2);
  133. viewSettings.show_thickness_gradient = viewSettings.show_gradient && (type_id == 3);
  134. viewSettings.show_line_width_gradient = viewSettings.show_gradient && (type_id == 4);
  135. viewSettings.show_flow_rate_gradient = viewSettings.show_gradient && (type_id == 5);
  136. }
  137. }
  138. UM.Label
  139. {
  140. id: compatibilityModeLabel
  141. text: catalog.i18nc("@label", "Compatibility Mode")
  142. visible: UM.SimulationView.compatibilityMode
  143. height: UM.Theme.getSize("layerview_row").height
  144. width: parent.width
  145. }
  146. Item // Spacer
  147. {
  148. height: UM.Theme.getSize("narrow_margin").width
  149. width: width
  150. }
  151. Repeater
  152. {
  153. model: CuraApplication.getExtrudersModel()
  154. UM.CheckBox
  155. {
  156. id: extrudersModelCheckBox
  157. checked: viewSettings.extruder_opacities[index] > 0.5 || viewSettings.extruder_opacities[index] == undefined || viewSettings.extruder_opacities[index] == ""
  158. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  159. width: parent.width
  160. visible: !UM.SimulationView.compatibilityMode
  161. onClicked:
  162. {
  163. viewSettings.extruder_opacities[index] = checked ? 1.0 : 0.0
  164. UM.Preferences.setValue("layerview/extruder_opacities", viewSettings.extruder_opacities.join("|"));
  165. }
  166. Rectangle
  167. {
  168. id: swatch
  169. anchors.verticalCenter: parent.verticalCenter
  170. anchors.right: extrudersModelCheckBox.right
  171. width: UM.Theme.getSize("layerview_legend_size").width
  172. height: UM.Theme.getSize("layerview_legend_size").height
  173. color: model.color
  174. border.width: UM.Theme.getSize("default_lining").width
  175. border.color: UM.Theme.getColor("lining")
  176. }
  177. UM.Label
  178. {
  179. text: model.name
  180. elide: Text.ElideRight
  181. color: UM.Theme.getColor("setting_control_text")
  182. anchors
  183. {
  184. verticalCenter: parent.verticalCenter
  185. left: extrudersModelCheckBox.left
  186. right: extrudersModelCheckBox.right
  187. leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
  188. rightMargin: UM.Theme.getSize("default_margin").width * 2
  189. }
  190. }
  191. }
  192. }
  193. Repeater
  194. {
  195. model: ListModel
  196. {
  197. id: typesLegendModel
  198. Component.onCompleted:
  199. {
  200. typesLegendModel.append({
  201. label: catalog.i18nc("@label", "Travels"),
  202. initialValue: viewSettings.show_travel_moves,
  203. preference: "layerview/show_travel_moves",
  204. colorId: "layerview_move_combing"
  205. });
  206. typesLegendModel.append({
  207. label: catalog.i18nc("@label", "Helpers"),
  208. initialValue: viewSettings.show_helpers,
  209. preference: "layerview/show_helpers",
  210. colorId: "layerview_support"
  211. });
  212. typesLegendModel.append({
  213. label: catalog.i18nc("@label", "Shell"),
  214. initialValue: viewSettings.show_skin,
  215. preference: "layerview/show_skin",
  216. colorId: "layerview_inset_0"
  217. });
  218. typesLegendModel.append({
  219. label: catalog.i18nc("@label", "Infill"),
  220. initialValue: viewSettings.show_infill,
  221. preference: "layerview/show_infill",
  222. colorId: "layerview_infill"
  223. });
  224. if (! UM.SimulationView.compatibilityMode)
  225. {
  226. typesLegendModel.append({
  227. label: catalog.i18nc("@label", "Starts"),
  228. initialValue: viewSettings.show_starts,
  229. preference: "layerview/show_starts",
  230. colorId: "layerview_starts"
  231. });
  232. }
  233. }
  234. }
  235. UM.CheckBox
  236. {
  237. id: legendModelCheckBox
  238. checked: model.initialValue
  239. onClicked: UM.Preferences.setValue(model.preference, checked)
  240. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  241. width: parent.width
  242. Rectangle
  243. {
  244. anchors.verticalCenter: parent.verticalCenter
  245. anchors.right: legendModelCheckBox.right
  246. width: UM.Theme.getSize("layerview_legend_size").width
  247. height: UM.Theme.getSize("layerview_legend_size").height
  248. color: UM.Theme.getColor(model.colorId)
  249. border.width: UM.Theme.getSize("default_lining").width
  250. border.color: UM.Theme.getColor("lining")
  251. visible: viewSettings.show_legend
  252. }
  253. UM.Label
  254. {
  255. text: label
  256. elide: Text.ElideRight
  257. color: UM.Theme.getColor("setting_control_text")
  258. anchors.verticalCenter: parent.verticalCenter
  259. anchors.left: legendModelCheckBox.left
  260. anchors.right: legendModelCheckBox.right
  261. anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
  262. anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2
  263. }
  264. }
  265. }
  266. UM.CheckBox
  267. {
  268. checked: viewSettings.only_show_top_layers
  269. onClicked: UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0)
  270. text: catalog.i18nc("@label", "Only Show Top Layers")
  271. visible: UM.SimulationView.compatibilityMode
  272. width: parent.width
  273. }
  274. UM.CheckBox
  275. {
  276. checked: viewSettings.top_layer_count == 5
  277. onClicked: UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1)
  278. text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top")
  279. width: parent.width
  280. visible: UM.SimulationView.compatibilityMode
  281. }
  282. Repeater
  283. {
  284. model: ListModel
  285. {
  286. id: typesLegendModelNoCheck
  287. Component.onCompleted:
  288. {
  289. typesLegendModelNoCheck.append({
  290. label: catalog.i18nc("@label", "Top / Bottom"),
  291. colorId: "layerview_skin",
  292. });
  293. typesLegendModelNoCheck.append({
  294. label: catalog.i18nc("@label", "Inner Wall"),
  295. colorId: "layerview_inset_x",
  296. });
  297. }
  298. }
  299. UM.Label
  300. {
  301. text: label
  302. visible: viewSettings.show_legend
  303. id: typesLegendModelLabel
  304. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  305. width: parent.width
  306. color: UM.Theme.getColor("setting_control_text")
  307. Rectangle
  308. {
  309. anchors.verticalCenter: parent.verticalCenter
  310. anchors.right: typesLegendModelLabel.right
  311. width: UM.Theme.getSize("layerview_legend_size").width
  312. height: UM.Theme.getSize("layerview_legend_size").height
  313. color: UM.Theme.getColor(model.colorId)
  314. border.width: UM.Theme.getSize("default_lining").width
  315. border.color: UM.Theme.getColor("lining")
  316. }
  317. }
  318. }
  319. // Text for the minimum, maximum and units for the feedrates and layer thickness
  320. Item
  321. {
  322. id: gradientLegend
  323. visible: viewSettings.show_gradient
  324. width: parent.width
  325. height: UM.Theme.getSize("layerview_row").height
  326. UM.Label //Minimum value.
  327. {
  328. text:
  329. {
  330. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  331. {
  332. // Feedrate selected
  333. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  334. {
  335. return parseFloat(UM.SimulationView.minFeedrate).toFixed(2)
  336. }
  337. // Layer thickness selected
  338. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  339. {
  340. return parseFloat(UM.SimulationView.minThickness).toFixed(2)
  341. }
  342. // Line width selected
  343. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  344. {
  345. return parseFloat(UM.SimulationView.minLineWidth).toFixed(2);
  346. }
  347. // Flow Rate selected
  348. if(UM.Preferences.getValue("layerview/layer_view_type") == 5)
  349. {
  350. return parseFloat(UM.SimulationView.minFlowRate).toFixed(2);
  351. }
  352. }
  353. return catalog.i18nc("@label","min")
  354. }
  355. anchors.left: parent.left
  356. }
  357. UM.Label //Unit in the middle.
  358. {
  359. text:
  360. {
  361. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  362. {
  363. // Feedrate selected
  364. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  365. {
  366. return "mm/s"
  367. }
  368. // Layer thickness selected
  369. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  370. {
  371. return "mm"
  372. }
  373. //Line width selected
  374. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  375. {
  376. return "mm"
  377. }
  378. // Flow Rate selected
  379. if (UM.Preferences.getValue("layerview/layer_view_type") == 5)
  380. {
  381. return "mm³/s"
  382. }
  383. }
  384. return ""
  385. }
  386. anchors.horizontalCenter: parent.horizontalCenter
  387. color: UM.Theme.getColor("setting_control_text")
  388. }
  389. UM.Label //Maximum value.
  390. {
  391. text: {
  392. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  393. {
  394. // Feedrate selected
  395. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  396. {
  397. return parseFloat(UM.SimulationView.maxFeedrate).toFixed(2)
  398. }
  399. // Layer thickness selected
  400. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  401. {
  402. return parseFloat(UM.SimulationView.maxThickness).toFixed(2)
  403. }
  404. //Line width selected
  405. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  406. {
  407. return parseFloat(UM.SimulationView.maxLineWidth).toFixed(2);
  408. }
  409. // Flow rate selected
  410. if(UM.Preferences.getValue("layerview/layer_view_type") == 5)
  411. {
  412. return parseFloat(UM.SimulationView.maxFlowRate).toFixed(2);
  413. }
  414. }
  415. return catalog.i18nc("@label","max")
  416. }
  417. anchors.right: parent.right
  418. color: UM.Theme.getColor("setting_control_text")
  419. }
  420. }
  421. // Gradient colors for feedrate
  422. Rectangle
  423. {
  424. id: feedrateGradient
  425. visible: (
  426. viewSettings.show_feedrate_gradient ||
  427. viewSettings.show_line_width_gradient
  428. )
  429. anchors.left: parent.left
  430. anchors.right: parent.right
  431. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  432. border.width: UM.Theme.getSize("default_lining").width
  433. border.color: UM.Theme.getColor("lining")
  434. gradient: Gradient
  435. {
  436. orientation: Gradient.Horizontal
  437. GradientStop
  438. {
  439. position: 0.000
  440. color: Qt.rgba(0, 0, 1, 1)
  441. }
  442. GradientStop
  443. {
  444. position: 0.25
  445. color: Qt.rgba(0.25, 1, 0, 1)
  446. }
  447. GradientStop
  448. {
  449. position: 0.375
  450. color: Qt.rgba(0.375, 0.5, 0, 1)
  451. }
  452. GradientStop
  453. {
  454. position: 1.0
  455. color: Qt.rgba(1, 0.5, 0, 1)
  456. }
  457. }
  458. }
  459. // Gradient colors for layer thickness (similar to parula colormap)
  460. Rectangle
  461. {
  462. id: thicknessGradient
  463. visible: (
  464. viewSettings.show_thickness_gradient
  465. )
  466. anchors.left: parent.left
  467. anchors.right: parent.right
  468. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  469. border.width: UM.Theme.getSize("default_lining").width
  470. border.color: UM.Theme.getColor("lining")
  471. gradient: Gradient
  472. {
  473. orientation: Gradient.Horizontal
  474. GradientStop
  475. {
  476. position: 0.000
  477. color: Qt.rgba(0, 0, 0.5, 1)
  478. }
  479. GradientStop
  480. {
  481. position: 0.25
  482. color: Qt.rgba(0, 0.375, 0.75, 1)
  483. }
  484. GradientStop
  485. {
  486. position: 0.5
  487. color: Qt.rgba(0, 0.75, 0.5, 1)
  488. }
  489. GradientStop
  490. {
  491. position: 0.75
  492. color: Qt.rgba(1, 0.75, 0.25, 1)
  493. }
  494. GradientStop
  495. {
  496. position: 1.0
  497. color: Qt.rgba(1, 1, 0, 1)
  498. }
  499. }
  500. }
  501. // Gradient colors for flow (similar to jet colormap)
  502. Rectangle
  503. {
  504. id: jetGradient
  505. visible: (
  506. viewSettings.show_flow_rate_gradient
  507. )
  508. anchors.left: parent.left
  509. anchors.right: parent.right
  510. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  511. border.width: UM.Theme.getSize("default_lining").width
  512. border.color: UM.Theme.getColor("lining")
  513. gradient: Gradient
  514. {
  515. orientation: Gradient.Horizontal
  516. GradientStop
  517. {
  518. position: 0.0
  519. color: Qt.rgba(0, 0, 0.5, 1)
  520. }
  521. GradientStop
  522. {
  523. position: 0.125
  524. color: Qt.rgba(0, 0.0, 1.0, 1)
  525. }
  526. GradientStop
  527. {
  528. position: 0.25
  529. color: Qt.rgba(0, 0.5, 1.0, 1)
  530. }
  531. GradientStop
  532. {
  533. position: 0.375
  534. color: Qt.rgba(0.0, 1.0, 1.0, 1)
  535. }
  536. GradientStop
  537. {
  538. position: 0.5
  539. color: Qt.rgba(0.5, 1.0, 0.5, 1)
  540. }
  541. GradientStop
  542. {
  543. position: 0.625
  544. color: Qt.rgba(1.0, 1.0, 0.0, 1)
  545. }
  546. GradientStop
  547. {
  548. position: 0.75
  549. color: Qt.rgba(1.0, 0.5, 0, 1)
  550. }
  551. GradientStop
  552. {
  553. position: 0.875
  554. color: Qt.rgba(1.0, 0.0, 0, 1)
  555. }
  556. GradientStop
  557. {
  558. position: 1.0
  559. color: Qt.rgba(0.5, 0, 0, 1)
  560. }
  561. }
  562. }
  563. }
  564. FontMetrics
  565. {
  566. id: fontMetrics
  567. font: UM.Theme.getFont("default")
  568. }
  569. }