MonitorConfigOverrideDialog.qml 5.7 KB

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