SimulationViewMenuComponent.qml 20 KB

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