MonitorConfigOverrideDialog.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.3
  4. import QtQuick.Controls 2.4
  5. import QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.5 as Cura
  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. buttonSpacing: UM.Theme.getSize("narrow_margin").width
  18. rightButtons:
  19. [
  20. Cura.TertiaryButton
  21. {
  22. id: cancelButton
  23. text: catalog.i18nc("@action:button", "Cancel")
  24. onClicked:
  25. {
  26. overrideConfirmationDialog.reject()
  27. }
  28. },
  29. Cura.PrimaryButton
  30. {
  31. id: overrideButton
  32. text: catalog.i18nc("@action:button", "Override")
  33. onClicked:
  34. {
  35. OutputDevice.forceSendJob(printer.activePrintJob.key)
  36. overrideConfirmationDialog.close()
  37. }
  38. visible:
  39. {
  40. // Don't show the button if we're missing a printer or print job
  41. if (!printer || !printer.activePrintJob)
  42. {
  43. return false
  44. }
  45. // Check each required change...
  46. for (var i = 0; i < printer.activePrintJob.configurationChanges.length; i++)
  47. {
  48. var change = printer.activePrintJob.configurationChanges[i]
  49. // If that type of change is in the list of blocking changes, hide the button
  50. if (!change.canOverride)
  51. {
  52. return false
  53. }
  54. }
  55. return true
  56. }
  57. }
  58. ]
  59. UM.Label
  60. {
  61. anchors
  62. {
  63. fill: parent
  64. margins: 36 * screenScaleFactor // TODO: Theme!
  65. bottomMargin: 56 * screenScaleFactor // TODO: Theme!
  66. }
  67. wrapMode: Text.WordWrap
  68. text:
  69. {
  70. if (!printer || !printer.activePrintJob)
  71. {
  72. return ""
  73. }
  74. var topLine
  75. if (materialsAreKnown(printer.activePrintJob))
  76. {
  77. 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)
  78. }
  79. else
  80. {
  81. topLine = catalog.i18nc("@label", "The printer %1 is assigned, but the job contains an unknown material configuration.").arg(printer.name)
  82. }
  83. var result = "<p>" + topLine +"</p>\n\n"
  84. for (var i = 0; i < printer.activePrintJob.configurationChanges.length; i++)
  85. {
  86. var change = printer.activePrintJob.configurationChanges[i]
  87. var text
  88. switch (change.typeOfChange)
  89. {
  90. case "material_change":
  91. text = catalog.i18nc("@label", "Change material %1 from %2 to %3.").arg(change.index + 1).arg(change.originName).arg(change.targetName)
  92. break
  93. case "material_insert":
  94. text = catalog.i18nc("@label", "Load %3 as material %1 (This cannot be overridden).").arg(change.index + 1).arg(change.targetName)
  95. break
  96. case "print_core_change":
  97. text = catalog.i18nc("@label", "Change print core %1 from %2 to %3.").arg(change.index + 1).arg(change.originName).arg(change.targetName)
  98. break
  99. case "buildplate_change":
  100. text = catalog.i18nc("@label", "Change build plate to %1 (This cannot be overridden).").arg(formatBuildPlateType(change.target_name))
  101. break
  102. default:
  103. text = "unknown"
  104. }
  105. result += "<p><b>" + text + "</b></p>\n\n"
  106. }
  107. var bottomLine = catalog.i18nc("@label", "Override will use the specified settings with the existing printer configuration. This may result in a failed print.")
  108. result += "<p>" + bottomLine + "</p>\n\n"
  109. return result
  110. }
  111. }
  112. // Utils
  113. function formatPrintJobName(name)
  114. {
  115. var extensions = [ ".gcode.gz", ".gz", ".gcode", ".ufp" ]
  116. for (var i = 0; i < extensions.length; i++)
  117. {
  118. var extension = extensions[i]
  119. if (name.slice(-extension.length) === extension)
  120. {
  121. name = name.substring(0, name.length - extension.length)
  122. }
  123. }
  124. return name;
  125. }
  126. function materialsAreKnown(job)
  127. {
  128. var conf0 = job.configuration[0]
  129. if (conf0 && !conf0.material.material)
  130. {
  131. return false
  132. }
  133. var conf1 = job.configuration[1]
  134. if (conf1 && !conf1.material.material)
  135. {
  136. return false
  137. }
  138. return true
  139. }
  140. function formatBuildPlateType(buildPlateType)
  141. {
  142. var translationText = ""
  143. switch (buildPlateType) {
  144. case "glass":
  145. translationText = catalog.i18nc("@label", "Glass")
  146. break
  147. case "aluminum":
  148. translationText = catalog.i18nc("@label", "Aluminum")
  149. break
  150. default:
  151. translationText = null
  152. }
  153. return translationText
  154. }
  155. }