SimulationViewMenuComponent.qml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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. font: UM.Theme.getFont("default")
  257. elide: Text.ElideRight
  258. renderType: Text.NativeRendering
  259. color: UM.Theme.getColor("setting_control_text")
  260. anchors.verticalCenter: parent.verticalCenter
  261. anchors.left: legendModelCheckBox.left
  262. anchors.right: legendModelCheckBox.right
  263. anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
  264. anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2
  265. }
  266. }
  267. }
  268. UM.CheckBox
  269. {
  270. checked: viewSettings.only_show_top_layers
  271. onClicked: UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0)
  272. text: catalog.i18nc("@label", "Only Show Top Layers")
  273. visible: UM.SimulationView.compatibilityMode
  274. width: parent.width
  275. }
  276. UM.CheckBox
  277. {
  278. checked: viewSettings.top_layer_count == 5
  279. onClicked: UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1)
  280. text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top")
  281. width: parent.width
  282. visible: UM.SimulationView.compatibilityMode
  283. }
  284. Repeater
  285. {
  286. model: ListModel
  287. {
  288. id: typesLegendModelNoCheck
  289. Component.onCompleted:
  290. {
  291. typesLegendModelNoCheck.append({
  292. label: catalog.i18nc("@label", "Top / Bottom"),
  293. colorId: "layerview_skin",
  294. });
  295. typesLegendModelNoCheck.append({
  296. label: catalog.i18nc("@label", "Inner Wall"),
  297. colorId: "layerview_inset_x",
  298. });
  299. }
  300. }
  301. UM.Label
  302. {
  303. text: label
  304. visible: viewSettings.show_legend
  305. id: typesLegendModelLabel
  306. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  307. width: parent.width
  308. color: UM.Theme.getColor("setting_control_text")
  309. Rectangle
  310. {
  311. anchors.verticalCenter: parent.verticalCenter
  312. anchors.right: typesLegendModelLabel.right
  313. width: UM.Theme.getSize("layerview_legend_size").width
  314. height: UM.Theme.getSize("layerview_legend_size").height
  315. color: UM.Theme.getColor(model.colorId)
  316. border.width: UM.Theme.getSize("default_lining").width
  317. border.color: UM.Theme.getColor("lining")
  318. }
  319. }
  320. }
  321. // Text for the minimum, maximum and units for the feedrates and layer thickness
  322. Item
  323. {
  324. id: gradientLegend
  325. visible: viewSettings.show_gradient
  326. width: parent.width
  327. height: UM.Theme.getSize("layerview_row").height
  328. UM.Label //Minimum value.
  329. {
  330. text:
  331. {
  332. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  333. {
  334. // Feedrate selected
  335. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  336. {
  337. return parseFloat(UM.SimulationView.minFeedrate).toFixed(2)
  338. }
  339. // Layer thickness selected
  340. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  341. {
  342. return parseFloat(UM.SimulationView.minThickness).toFixed(2)
  343. }
  344. // Line width selected
  345. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  346. {
  347. return parseFloat(UM.SimulationView.minLineWidth).toFixed(2);
  348. }
  349. // Flow Rate selected
  350. if(UM.Preferences.getValue("layerview/layer_view_type") == 5)
  351. {
  352. return parseFloat(UM.SimulationView.minFlowRate).toFixed(2);
  353. }
  354. }
  355. return catalog.i18nc("@label","min")
  356. }
  357. anchors.left: parent.left
  358. }
  359. UM.Label //Unit in the middle.
  360. {
  361. text:
  362. {
  363. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  364. {
  365. // Feedrate selected
  366. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  367. {
  368. return "mm/s"
  369. }
  370. // Layer thickness selected
  371. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  372. {
  373. return "mm"
  374. }
  375. //Line width selected
  376. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  377. {
  378. return "mm"
  379. }
  380. // Flow Rate selected
  381. if (UM.Preferences.getValue("layerview/layer_view_type") == 5)
  382. {
  383. return "mm³/s"
  384. }
  385. }
  386. return ""
  387. }
  388. anchors.horizontalCenter: parent.horizontalCenter
  389. color: UM.Theme.getColor("setting_control_text")
  390. }
  391. UM.Label //Maximum value.
  392. {
  393. text: {
  394. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  395. {
  396. // Feedrate selected
  397. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  398. {
  399. return parseFloat(UM.SimulationView.maxFeedrate).toFixed(2)
  400. }
  401. // Layer thickness selected
  402. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  403. {
  404. return parseFloat(UM.SimulationView.maxThickness).toFixed(2)
  405. }
  406. //Line width selected
  407. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  408. {
  409. return parseFloat(UM.SimulationView.maxLineWidth).toFixed(2);
  410. }
  411. // Flow rate selected
  412. if(UM.Preferences.getValue("layerview/layer_view_type") == 5)
  413. {
  414. return parseFloat(UM.SimulationView.maxFlowRate).toFixed(2);
  415. }
  416. }
  417. return catalog.i18nc("@label","max")
  418. }
  419. anchors.right: parent.right
  420. color: UM.Theme.getColor("setting_control_text")
  421. }
  422. }
  423. // Gradient colors for feedrate
  424. Rectangle
  425. {
  426. id: feedrateGradient
  427. visible: (
  428. viewSettings.show_feedrate_gradient ||
  429. viewSettings.show_line_width_gradient
  430. )
  431. anchors.left: parent.left
  432. anchors.right: parent.right
  433. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  434. border.width: UM.Theme.getSize("default_lining").width
  435. border.color: UM.Theme.getColor("lining")
  436. gradient: Gradient
  437. {
  438. orientation: Gradient.Horizontal
  439. GradientStop
  440. {
  441. position: 0.000
  442. color: Qt.rgba(0, 0, 1, 1)
  443. }
  444. GradientStop
  445. {
  446. position: 0.25
  447. color: Qt.rgba(0.25, 1, 0, 1)
  448. }
  449. GradientStop
  450. {
  451. position: 0.375
  452. color: Qt.rgba(0.375, 0.5, 0, 1)
  453. }
  454. GradientStop
  455. {
  456. position: 1.0
  457. color: Qt.rgba(1, 0.5, 0, 1)
  458. }
  459. }
  460. }
  461. // Gradient colors for layer thickness (similar to parula colormap)
  462. Rectangle
  463. {
  464. id: thicknessGradient
  465. visible: (
  466. viewSettings.show_thickness_gradient
  467. )
  468. anchors.left: parent.left
  469. anchors.right: parent.right
  470. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  471. border.width: UM.Theme.getSize("default_lining").width
  472. border.color: UM.Theme.getColor("lining")
  473. gradient: Gradient
  474. {
  475. orientation: Gradient.Horizontal
  476. GradientStop
  477. {
  478. position: 0.000
  479. color: Qt.rgba(0, 0, 0.5, 1)
  480. }
  481. GradientStop
  482. {
  483. position: 0.25
  484. color: Qt.rgba(0, 0.375, 0.75, 1)
  485. }
  486. GradientStop
  487. {
  488. position: 0.5
  489. color: Qt.rgba(0, 0.75, 0.5, 1)
  490. }
  491. GradientStop
  492. {
  493. position: 0.75
  494. color: Qt.rgba(1, 0.75, 0.25, 1)
  495. }
  496. GradientStop
  497. {
  498. position: 1.0
  499. color: Qt.rgba(1, 1, 0, 1)
  500. }
  501. }
  502. }
  503. // Gradient colors for flow (similar to jet colormap)
  504. Rectangle
  505. {
  506. id: jetGradient
  507. visible: (
  508. viewSettings.show_flow_rate_gradient
  509. )
  510. anchors.left: parent.left
  511. anchors.right: parent.right
  512. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  513. border.width: UM.Theme.getSize("default_lining").width
  514. border.color: UM.Theme.getColor("lining")
  515. gradient: Gradient
  516. {
  517. orientation: Gradient.Horizontal
  518. GradientStop
  519. {
  520. position: 0.0
  521. color: Qt.rgba(0, 0, 0.5, 1)
  522. }
  523. GradientStop
  524. {
  525. position: 0.125
  526. color: Qt.rgba(0, 0.0, 1.0, 1)
  527. }
  528. GradientStop
  529. {
  530. position: 0.25
  531. color: Qt.rgba(0, 0.5, 1.0, 1)
  532. }
  533. GradientStop
  534. {
  535. position: 0.375
  536. color: Qt.rgba(0.0, 1.0, 1.0, 1)
  537. }
  538. GradientStop
  539. {
  540. position: 0.5
  541. color: Qt.rgba(0.5, 1.0, 0.5, 1)
  542. }
  543. GradientStop
  544. {
  545. position: 0.625
  546. color: Qt.rgba(1.0, 1.0, 0.0, 1)
  547. }
  548. GradientStop
  549. {
  550. position: 0.75
  551. color: Qt.rgba(1.0, 0.5, 0, 1)
  552. }
  553. GradientStop
  554. {
  555. position: 0.875
  556. color: Qt.rgba(1.0, 0.0, 0, 1)
  557. }
  558. GradientStop
  559. {
  560. position: 1.0
  561. color: Qt.rgba(0.5, 0, 0, 1)
  562. }
  563. }
  564. }
  565. }
  566. FontMetrics
  567. {
  568. id: fontMetrics
  569. font: UM.Theme.getFont("default")
  570. }
  571. }