SimulationViewMenuComponent.qml 21 KB

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