SimulationViewMenuComponent.qml 21 KB

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