MonitorConfigOverrideDialog.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.3
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Layouts 1.3
  6. import QtQuick.Dialogs 1.2
  7. import UM 1.3 as UM
  8. UM.Dialog
  9. {
  10. id: overrideConfirmationDialog
  11. property var printer: null
  12. minimumWidth: screenScaleFactor * 640;
  13. minimumHeight: screenScaleFactor * 320;
  14. width: minimumWidth
  15. height: minimumHeight
  16. title: catalog.i18nc("@title:window", "Configuration Changes")
  17. rightButtons:
  18. [
  19. Button
  20. {
  21. id: overrideButton
  22. anchors.margins: UM.Theme.getSize("default_margin").width
  23. text: catalog.i18nc("@action:button", "Override")
  24. onClicked:
  25. {
  26. OutputDevice.forceSendJob(printer.activePrintJob.key)
  27. overrideConfirmationDialog.close()
  28. }
  29. },
  30. Button
  31. {
  32. id: cancelButton
  33. anchors.margins: UM.Theme.getSize("default_margin").width
  34. text: catalog.i18nc("@action:button", "Cancel")
  35. onClicked:
  36. {
  37. overrideConfirmationDialog.reject()
  38. }
  39. }
  40. ]
  41. Label
  42. {
  43. anchors
  44. {
  45. fill: parent
  46. margins: 36 * screenScaleFactor // TODO: Theme!
  47. bottomMargin: 56 * screenScaleFactor // TODO: Theme!
  48. }
  49. wrapMode: Text.WordWrap
  50. text:
  51. {
  52. if (!printer || !printer.activePrintJob)
  53. {
  54. return ""
  55. }
  56. var topLine
  57. if (materialsAreKnown(printer.activePrintJob))
  58. {
  59. topLine = catalog.i18ncp("@label", "The assigned printer, %1, requires the following configuration change:", "The assigned printer, %1, requires the following configuration changes:", printer.activePrintJob.configurationChanges.length).arg(printer.name)
  60. }
  61. else
  62. {
  63. topLine = catalog.i18nc("@label", "The printer %1 is assigned, but the job contains an unknown material configuration.").arg(printer.name)
  64. }
  65. var result = "<p>" + topLine +"</p>\n\n"
  66. for (var i = 0; i < printer.activePrintJob.configurationChanges.length; i++)
  67. {
  68. var change = printer.activePrintJob.configurationChanges[i]
  69. var text
  70. switch (change.typeOfChange)
  71. {
  72. case "material_change":
  73. text = catalog.i18nc("@label", "Change material %1 from %2 to %3.").arg(change.index + 1).arg(change.originName).arg(change.targetName)
  74. break
  75. case "material_insert":
  76. text = catalog.i18nc("@label", "Load %3 as material %1 (This cannot be overridden).").arg(change.index + 1).arg(change.targetName)
  77. break
  78. case "print_core_change":
  79. text = catalog.i18nc("@label", "Change print core %1 from %2 to %3.").arg(change.index + 1).arg(change.originName).arg(change.targetName)
  80. break
  81. case "buildplate_change":
  82. text = catalog.i18nc("@label", "Change build plate to %1 (This cannot be overridden).").arg(formatBuildPlateType(change.target_name))
  83. break
  84. default:
  85. text = "unknown"
  86. }
  87. result += "<p><b>" + text + "</b></p>\n\n"
  88. }
  89. var bottomLine = catalog.i18nc("@label", "Override will use the specified settings with the existing printer configuration. This may result in a failed print.")
  90. result += "<p>" + bottomLine + "</p>\n\n"
  91. return result
  92. }
  93. }
  94. // Utils
  95. function formatPrintJobName(name)
  96. {
  97. var extensions = [ ".gcode.gz", ".gz", ".gcode", ".ufp" ]
  98. for (var i = 0; i < extensions.length; i++)
  99. {
  100. var extension = extensions[i]
  101. if (name.slice(-extension.length) === extension)
  102. {
  103. name = name.substring(0, name.length - extension.length)
  104. }
  105. }
  106. return name;
  107. }
  108. function materialsAreKnown(job)
  109. {
  110. var conf0 = job.configuration[0]
  111. if (conf0 && !conf0.material.material)
  112. {
  113. return false
  114. }
  115. var conf1 = job.configuration[1]
  116. if (conf1 && !conf1.material.material)
  117. {
  118. return false
  119. }
  120. return true
  121. }
  122. function formatBuildPlateType(buildPlateType)
  123. {
  124. var translationText = ""
  125. switch (buildPlateType) {
  126. case "glass":
  127. translationText = catalog.i18nc("@label", "Glass")
  128. break
  129. case "aluminum":
  130. translationText = catalog.i18nc("@label", "Aluminum")
  131. break
  132. default:
  133. translationText = null
  134. }
  135. return translationText
  136. }
  137. }