SimulationViewMenuComponent.qml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. enabled: index < 4
  157. onClicked:
  158. {
  159. viewSettings.extruder_opacities[index] = checked ? 1.0 : 0.0
  160. UM.Preferences.setValue("layerview/extruder_opacities", viewSettings.extruder_opacities.join("|"));
  161. }
  162. style: UM.Theme.styles.checkbox
  163. UM.RecolorImage
  164. {
  165. id: swatch
  166. anchors.verticalCenter: parent.verticalCenter
  167. anchors.right: extrudersModelCheckBox.right
  168. width: UM.Theme.getSize("layerview_legend_size").width
  169. height: UM.Theme.getSize("layerview_legend_size").height
  170. source: UM.Theme.getIcon("extruder_button")
  171. color: model.color
  172. }
  173. Label
  174. {
  175. text: model.name
  176. elide: Text.ElideRight
  177. color: UM.Theme.getColor("setting_control_text")
  178. font: UM.Theme.getFont("default")
  179. anchors
  180. {
  181. verticalCenter: parent.verticalCenter
  182. left: extrudersModelCheckBox.left
  183. right: extrudersModelCheckBox.right
  184. leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
  185. rightMargin: UM.Theme.getSize("default_margin").width * 2
  186. }
  187. renderType: Text.NativeRendering
  188. }
  189. }
  190. }
  191. Repeater
  192. {
  193. model: ListModel
  194. {
  195. id: typesLegendModel
  196. Component.onCompleted:
  197. {
  198. typesLegendModel.append({
  199. label: catalog.i18nc("@label", "Travels"),
  200. initialValue: viewSettings.show_travel_moves,
  201. preference: "layerview/show_travel_moves",
  202. colorId: "layerview_move_combing"
  203. });
  204. typesLegendModel.append({
  205. label: catalog.i18nc("@label", "Helpers"),
  206. initialValue: viewSettings.show_helpers,
  207. preference: "layerview/show_helpers",
  208. colorId: "layerview_support"
  209. });
  210. typesLegendModel.append({
  211. label: catalog.i18nc("@label", "Shell"),
  212. initialValue: viewSettings.show_skin,
  213. preference: "layerview/show_skin",
  214. colorId: "layerview_inset_0"
  215. });
  216. typesLegendModel.append({
  217. label: catalog.i18nc("@label", "Infill"),
  218. initialValue: viewSettings.show_infill,
  219. preference: "layerview/show_infill",
  220. colorId: "layerview_infill"
  221. });
  222. }
  223. }
  224. CheckBox
  225. {
  226. id: legendModelCheckBox
  227. checked: model.initialValue
  228. onClicked: UM.Preferences.setValue(model.preference, checked)
  229. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  230. width: parent.width
  231. style: UM.Theme.styles.checkbox
  232. Rectangle
  233. {
  234. anchors.verticalCenter: parent.verticalCenter
  235. anchors.right: legendModelCheckBox.right
  236. width: UM.Theme.getSize("layerview_legend_size").width
  237. height: UM.Theme.getSize("layerview_legend_size").height
  238. color: UM.Theme.getColor(model.colorId)
  239. border.width: UM.Theme.getSize("default_lining").width
  240. border.color: UM.Theme.getColor("lining")
  241. visible: viewSettings.show_legend
  242. }
  243. Label
  244. {
  245. text: label
  246. font: UM.Theme.getFont("default")
  247. elide: Text.ElideRight
  248. renderType: Text.NativeRendering
  249. color: UM.Theme.getColor("setting_control_text")
  250. anchors.verticalCenter: parent.verticalCenter
  251. anchors.left: legendModelCheckBox.left
  252. anchors.right: legendModelCheckBox.right
  253. anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
  254. anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2
  255. }
  256. }
  257. }
  258. CheckBox
  259. {
  260. checked: viewSettings.only_show_top_layers
  261. onClicked: UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0)
  262. text: catalog.i18nc("@label", "Only Show Top Layers")
  263. visible: UM.SimulationView.compatibilityMode
  264. style: UM.Theme.styles.checkbox
  265. width: parent.width
  266. }
  267. CheckBox
  268. {
  269. checked: viewSettings.top_layer_count == 5
  270. onClicked: UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1)
  271. text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top")
  272. width: parent.width
  273. visible: UM.SimulationView.compatibilityMode
  274. style: UM.Theme.styles.checkbox
  275. }
  276. Repeater
  277. {
  278. model: ListModel
  279. {
  280. id: typesLegendModelNoCheck
  281. Component.onCompleted:
  282. {
  283. typesLegendModelNoCheck.append({
  284. label: catalog.i18nc("@label", "Top / Bottom"),
  285. colorId: "layerview_skin",
  286. });
  287. typesLegendModelNoCheck.append({
  288. label: catalog.i18nc("@label", "Inner Wall"),
  289. colorId: "layerview_inset_x",
  290. });
  291. }
  292. }
  293. Label
  294. {
  295. text: label
  296. visible: viewSettings.show_legend
  297. id: typesLegendModelLabel
  298. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  299. width: parent.width
  300. color: UM.Theme.getColor("setting_control_text")
  301. font: UM.Theme.getFont("default")
  302. renderType: Text.NativeRendering
  303. Rectangle
  304. {
  305. anchors.verticalCenter: parent.verticalCenter
  306. anchors.right: typesLegendModelLabel.right
  307. width: UM.Theme.getSize("layerview_legend_size").width
  308. height: UM.Theme.getSize("layerview_legend_size").height
  309. color: UM.Theme.getColor(model.colorId)
  310. border.width: UM.Theme.getSize("default_lining").width
  311. border.color: UM.Theme.getColor("lining")
  312. }
  313. }
  314. }
  315. // Text for the minimum, maximum and units for the feedrates and layer thickness
  316. Item
  317. {
  318. id: gradientLegend
  319. visible: viewSettings.show_gradient
  320. width: parent.width
  321. height: UM.Theme.getSize("layerview_row").height
  322. Label //Minimum value.
  323. {
  324. text:
  325. {
  326. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  327. {
  328. // Feedrate selected
  329. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  330. {
  331. return parseFloat(UM.SimulationView.getMinFeedrate()).toFixed(2)
  332. }
  333. // Layer thickness selected
  334. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  335. {
  336. return parseFloat(UM.SimulationView.getMinThickness()).toFixed(2)
  337. }
  338. }
  339. return catalog.i18nc("@label","min")
  340. }
  341. anchors.left: parent.left
  342. color: UM.Theme.getColor("setting_control_text")
  343. font: UM.Theme.getFont("default")
  344. renderType: Text.NativeRendering
  345. }
  346. Label //Unit in the middle.
  347. {
  348. text:
  349. {
  350. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  351. {
  352. // Feedrate selected
  353. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  354. {
  355. return "mm/s"
  356. }
  357. // Layer thickness selected
  358. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  359. {
  360. return "mm"
  361. }
  362. }
  363. return ""
  364. }
  365. anchors.horizontalCenter: parent.horizontalCenter
  366. color: UM.Theme.getColor("setting_control_text")
  367. font: UM.Theme.getFont("default")
  368. }
  369. Label //Maximum value.
  370. {
  371. text: {
  372. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  373. {
  374. // Feedrate selected
  375. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  376. {
  377. return parseFloat(UM.SimulationView.getMaxFeedrate()).toFixed(2)
  378. }
  379. // Layer thickness selected
  380. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  381. {
  382. return parseFloat(UM.SimulationView.getMaxThickness()).toFixed(2)
  383. }
  384. }
  385. return catalog.i18nc("@label","max")
  386. }
  387. anchors.right: parent.right
  388. color: UM.Theme.getColor("setting_control_text")
  389. font: UM.Theme.getFont("default")
  390. }
  391. }
  392. // Gradient colors for feedrate
  393. Rectangle
  394. {
  395. id: feedrateGradient
  396. visible: viewSettings.show_feedrate_gradient
  397. anchors.left: parent.left
  398. anchors.right: parent.right
  399. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  400. border.width: UM.Theme.getSize("default_lining").width
  401. border.color: UM.Theme.getColor("lining")
  402. LinearGradient
  403. {
  404. anchors
  405. {
  406. left: parent.left
  407. leftMargin: UM.Theme.getSize("default_lining").width
  408. right: parent.right
  409. rightMargin: UM.Theme.getSize("default_lining").width
  410. top: parent.top
  411. topMargin: UM.Theme.getSize("default_lining").width
  412. bottom: parent.bottom
  413. bottomMargin: UM.Theme.getSize("default_lining").width
  414. }
  415. start: Qt.point(0, 0)
  416. end: Qt.point(parent.width, 0)
  417. gradient: Gradient
  418. {
  419. GradientStop
  420. {
  421. position: 0.000
  422. color: Qt.rgba(0, 0, 1, 1)
  423. }
  424. GradientStop
  425. {
  426. position: 0.25
  427. color: Qt.rgba(0.25, 1, 0, 1)
  428. }
  429. GradientStop
  430. {
  431. position: 0.375
  432. color: Qt.rgba(0.375, 0.5, 0, 1)
  433. }
  434. GradientStop
  435. {
  436. position: 1.0
  437. color: Qt.rgba(1, 0.5, 0, 1)
  438. }
  439. }
  440. }
  441. }
  442. // Gradient colors for layer thickness (similar to parula colormap)
  443. Rectangle
  444. {
  445. id: thicknessGradient
  446. visible: viewSettings.show_thickness_gradient
  447. anchors.left: parent.left
  448. anchors.right: parent.right
  449. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  450. border.width: UM.Theme.getSize("default_lining").width
  451. border.color: UM.Theme.getColor("lining")
  452. LinearGradient
  453. {
  454. anchors
  455. {
  456. left: parent.left
  457. leftMargin: UM.Theme.getSize("default_lining").width
  458. right: parent.right
  459. rightMargin: UM.Theme.getSize("default_lining").width
  460. top: parent.top
  461. topMargin: UM.Theme.getSize("default_lining").width
  462. bottom: parent.bottom
  463. bottomMargin: UM.Theme.getSize("default_lining").width
  464. }
  465. start: Qt.point(0, 0)
  466. end: Qt.point(parent.width, 0)
  467. gradient: Gradient
  468. {
  469. GradientStop
  470. {
  471. position: 0.000
  472. color: Qt.rgba(0, 0, 0.5, 1)
  473. }
  474. GradientStop
  475. {
  476. position: 0.25
  477. color: Qt.rgba(0, 0.375, 0.75, 1)
  478. }
  479. GradientStop
  480. {
  481. position: 0.5
  482. color: Qt.rgba(0, 0.75, 0.5, 1)
  483. }
  484. GradientStop
  485. {
  486. position: 0.75
  487. color: Qt.rgba(1, 0.75, 0.25, 1)
  488. }
  489. GradientStop
  490. {
  491. position: 1.0
  492. color: Qt.rgba(1, 1, 0, 1)
  493. }
  494. }
  495. }
  496. }
  497. }
  498. FontMetrics
  499. {
  500. id: fontMetrics
  501. font: UM.Theme.getFont("default")
  502. }
  503. }