SimulationViewMenuComponent.qml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. dragPreferencesNamePrefix: "view/colorscheme"
  14. contentHeaderTitle: catalog.i18nc("@label", "Color scheme")
  15. Connections
  16. {
  17. target: UM.Preferences
  18. onPreferenceChanged:
  19. {
  20. if (preference !== "view/only_show_top_layers" && preference !== "view/top_layer_count" && ! preference.match("layerview/"))
  21. {
  22. return;
  23. }
  24. layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type")
  25. layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex)
  26. viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|")
  27. viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves")
  28. viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers")
  29. viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin")
  30. viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill")
  31. viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers")
  32. viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count")
  33. }
  34. }
  35. headerItem: Item
  36. {
  37. Label
  38. {
  39. id: colorSchemeLabel
  40. text: catalog.i18nc("@label", "Color scheme")
  41. verticalAlignment: Text.AlignVCenter
  42. height: parent.height
  43. elide: Text.ElideRight
  44. font: UM.Theme.getFont("medium")
  45. color: UM.Theme.getColor("text_medium")
  46. renderType: Text.NativeRendering
  47. }
  48. Label
  49. {
  50. text: layerTypeCombobox.currentText
  51. verticalAlignment: Text.AlignVCenter
  52. anchors
  53. {
  54. left: colorSchemeLabel.right
  55. leftMargin: UM.Theme.getSize("default_margin").width
  56. right: parent.right
  57. }
  58. height: parent.height
  59. elide: Text.ElideRight
  60. font: UM.Theme.getFont("medium")
  61. color: UM.Theme.getColor("text")
  62. renderType: Text.NativeRendering
  63. }
  64. }
  65. contentItem: Column
  66. {
  67. id: viewSettings
  68. property var extruder_opacities: UM.Preferences.getValue("layerview/extruder_opacities").split("|")
  69. property bool show_travel_moves: UM.Preferences.getValue("layerview/show_travel_moves")
  70. property bool show_helpers: UM.Preferences.getValue("layerview/show_helpers")
  71. property bool show_skin: UM.Preferences.getValue("layerview/show_skin")
  72. property bool show_infill: UM.Preferences.getValue("layerview/show_infill")
  73. // If we are in compatibility mode, we only show the "line type"
  74. property bool show_legend: UM.SimulationView.compatibilityMode ? true : UM.Preferences.getValue("layerview/layer_view_type") == 1
  75. property bool show_gradient: UM.SimulationView.compatibilityMode ? false : UM.Preferences.getValue("layerview/layer_view_type") == 2 || UM.Preferences.getValue("layerview/layer_view_type") == 3
  76. property bool show_feedrate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 2
  77. property bool show_thickness_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 3
  78. property bool only_show_top_layers: UM.Preferences.getValue("view/only_show_top_layers")
  79. property int top_layer_count: UM.Preferences.getValue("view/top_layer_count")
  80. width: UM.Theme.getSize("layerview_menu_size").width - 2 * UM.Theme.getSize("default_margin").width
  81. height: implicitHeight
  82. spacing: UM.Theme.getSize("layerview_row_spacing").height
  83. ListModel // matches SimulationView.py
  84. {
  85. id: layerViewTypes
  86. }
  87. Component.onCompleted:
  88. {
  89. layerViewTypes.append({
  90. text: catalog.i18nc("@label:listbox", "Material Color"),
  91. type_id: 0
  92. })
  93. layerViewTypes.append({
  94. text: catalog.i18nc("@label:listbox", "Line Type"),
  95. type_id: 1
  96. })
  97. layerViewTypes.append({
  98. text: catalog.i18nc("@label:listbox", "Feedrate"),
  99. type_id: 2
  100. })
  101. layerViewTypes.append({
  102. text: catalog.i18nc("@label:listbox", "Layer thickness"),
  103. type_id: 3 // these ids match the switching in the shader
  104. })
  105. }
  106. ComboBox
  107. {
  108. id: layerTypeCombobox
  109. width: parent.width
  110. model: layerViewTypes
  111. visible: !UM.SimulationView.compatibilityMode
  112. style: UM.Theme.styles.combobox
  113. onActivated:
  114. {
  115. UM.Preferences.setValue("layerview/layer_view_type", index);
  116. }
  117. Component.onCompleted:
  118. {
  119. currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type");
  120. updateLegends(currentIndex);
  121. }
  122. function updateLegends(type_id)
  123. {
  124. // Update the visibility of the legends.
  125. viewSettings.show_legend = UM.SimulationView.compatibilityMode || (type_id == 1);
  126. viewSettings.show_gradient = !UM.SimulationView.compatibilityMode && (type_id == 2 || type_id == 3);
  127. viewSettings.show_feedrate_gradient = viewSettings.show_gradient && (type_id == 2);
  128. viewSettings.show_thickness_gradient = viewSettings.show_gradient && (type_id == 3);
  129. }
  130. }
  131. Label
  132. {
  133. id: compatibilityModeLabel
  134. text: catalog.i18nc("@label", "Compatibility Mode")
  135. font: UM.Theme.getFont("default")
  136. color: UM.Theme.getColor("text")
  137. visible: UM.SimulationView.compatibilityMode
  138. height: UM.Theme.getSize("layerview_row").height
  139. width: parent.width
  140. renderType: Text.NativeRendering
  141. }
  142. Item // Spacer
  143. {
  144. height: UM.Theme.getSize("narrow_margin").width
  145. width: width
  146. }
  147. Repeater
  148. {
  149. model: CuraApplication.getExtrudersModel()
  150. CheckBox
  151. {
  152. id: extrudersModelCheckBox
  153. checked: viewSettings.extruder_opacities[index] > 0.5 || viewSettings.extruder_opacities[index] == undefined || viewSettings.extruder_opacities[index] == ""
  154. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  155. width: parent.width
  156. visible: !UM.SimulationView.compatibilityMode
  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. }