MonitorConfigOverrideDialog.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. default:
  100. text = "unknown"
  101. }
  102. result += "<p><b>" + text + "</b></p>\n\n"
  103. }
  104. var bottomLine = catalog.i18nc("@label", "Override will use the specified settings with the existing printer configuration. This may result in a failed print.")
  105. result += "<p>" + bottomLine + "</p>\n\n"
  106. return result
  107. }
  108. }
  109. // Utils
  110. function formatPrintJobName(name)
  111. {
  112. var extensions = [ ".gcode.gz", ".gz", ".gcode", ".ufp" ]
  113. for (var i = 0; i < extensions.length; i++)
  114. {
  115. var extension = extensions[i]
  116. if (name.slice(-extension.length) === extension)
  117. {
  118. name = name.substring(0, name.length - extension.length)
  119. }
  120. }
  121. return name;
  122. }
  123. function materialsAreKnown(job)
  124. {
  125. var conf0 = job.configuration[0]
  126. if (conf0 && !conf0.material.material)
  127. {
  128. return false
  129. }
  130. var conf1 = job.configuration[1]
  131. if (conf1 && !conf1.material.material)
  132. {
  133. return false
  134. }
  135. return true
  136. }
  137. }