MachinesPage.qml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Window 2.1
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. UM.ManagementPage
  9. {
  10. id: base;
  11. title: catalog.i18nc("@title:tab", "Printers");
  12. model: UM.ContainerStacksModel
  13. {
  14. filter: {"type": "machine"}
  15. }
  16. activeId: Cura.MachineManager.activeMachineId
  17. activeIndex: activeMachineIndex()
  18. function activeMachineIndex()
  19. {
  20. for(var i = 0; i < model.rowCount(); i++) {
  21. if (model.getItem(i).id == Cura.MachineManager.activeMachineId) {
  22. return i;
  23. }
  24. }
  25. return -1;
  26. }
  27. buttons: [
  28. Button
  29. {
  30. text: catalog.i18nc("@action:button", "Activate");
  31. iconName: "list-activate";
  32. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId
  33. onClicked: Cura.MachineManager.setActiveMachine(base.currentItem.id)
  34. },
  35. Button
  36. {
  37. text: catalog.i18nc("@action:button", "Add");
  38. iconName: "list-add";
  39. onClicked: Printer.requestAddPrinter()
  40. },
  41. Button
  42. {
  43. text: catalog.i18nc("@action:button", "Remove");
  44. iconName: "list-remove";
  45. enabled: base.currentItem != null && model.rowCount() > 1
  46. onClicked: confirmDialog.open();
  47. },
  48. Button
  49. {
  50. text: catalog.i18nc("@action:button", "Rename");
  51. iconName: "edit-rename";
  52. enabled: base.currentItem != null
  53. onClicked: renameDialog.open();
  54. }
  55. ]
  56. Item
  57. {
  58. visible: base.currentItem != null
  59. anchors.fill: parent
  60. Label
  61. {
  62. id: machineName
  63. text: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  64. font: UM.Theme.getFont("large")
  65. width: parent.width
  66. elide: Text.ElideRight
  67. }
  68. Flow
  69. {
  70. id: machineActions
  71. visible: currentItem && currentItem.id == Cura.MachineManager.activeMachineId
  72. anchors.left: parent.left
  73. anchors.right: parent.right
  74. anchors.top: machineName.bottom
  75. anchors.topMargin: UM.Theme.getSize("default_margin").height
  76. Repeater
  77. {
  78. id: machineActionRepeater
  79. model: base.currentItem ? Cura.MachineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null
  80. Button
  81. {
  82. text: machineActionRepeater.model[index].label
  83. onClicked:
  84. {
  85. actionDialog.content = machineActionRepeater.model[index].displayItem;
  86. machineActionRepeater.model[index].displayItem.reset();
  87. actionDialog.title = machineActionRepeater.model[index].label;
  88. actionDialog.show();
  89. }
  90. }
  91. }
  92. }
  93. UM.Dialog
  94. {
  95. id: actionDialog
  96. property var content
  97. minimumWidth: 350 * Screen.devicePixelRatio;
  98. minimumHeight: 350 * Screen.devicePixelRatio;
  99. onContentChanged:
  100. {
  101. contents = content;
  102. content.onCompleted.connect(hide)
  103. content.dialog = actionDialog
  104. }
  105. rightButtons: Button
  106. {
  107. text: catalog.i18nc("@action:button", "Close")
  108. iconName: "dialog-close"
  109. onClicked: actionDialog.reject()
  110. }
  111. }
  112. Grid
  113. {
  114. id: machineInfo
  115. anchors.top: machineActions.visible ? machineActions.bottom : machineActions.anchors.top
  116. anchors.topMargin: UM.Theme.getSize("default_margin").height
  117. anchors.left: parent.left
  118. anchors.right: parent.right
  119. spacing: UM.Theme.getSize("default_margin").height
  120. rowSpacing: UM.Theme.getSize("default_lining").height
  121. columns: 2
  122. visible: base.currentItem
  123. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  124. property var connectedPrinter: printerConnected ? Cura.MachineManager.printerOutputDevices[0] : null
  125. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  126. Label
  127. {
  128. text: catalog.i18nc("@label", "Printer type:")
  129. visible: base.currentItem && "definition_name" in base.currentItem.metadata
  130. }
  131. Label {
  132. text: (base.currentItem && "definition_name" in base.currentItem.metadata) ? base.currentItem.metadata.definition_name : ""
  133. }
  134. Label
  135. {
  136. text: catalog.i18nc("@label", "Connection:")
  137. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  138. }
  139. Label {
  140. width: parent.width * 0.7
  141. text: machineInfo.printerConnected ? machineInfo.connectedPrinter.connectionText : catalog.i18nc("@info:status", "The printer is not connected.")
  142. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  143. wrapMode: Text.WordWrap
  144. }
  145. Label
  146. {
  147. text: catalog.i18nc("@label", "State:")
  148. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  149. }
  150. Label {
  151. width: parent.width * 0.7
  152. text:
  153. {
  154. if(!machineInfo.printerConnected || !machineInfo.printerAcceptsCommands) {
  155. return "";
  156. }
  157. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  158. {
  159. case "printing":
  160. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  161. case "paused":
  162. return catalog.i18nc("@label:MonitorStatus", "Paused");
  163. case "pre_print":
  164. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  165. case "wait_cleanup":
  166. return catalog.i18nc("@label:MonitorStatus", "Waiting for someone to clear the build plate");
  167. case "error":
  168. return printerOutputDevice.errorText;
  169. case "maintenance":
  170. return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
  171. case "abort": // note sure if this jobState actually occurs in the wild
  172. return catalog.i18nc("@label:MonitorStatus", "Aborting print...");
  173. case "ready": // ready to print or getting ready
  174. case "": // ready to print or getting ready
  175. return catalog.i18nc("@label:MonitorStatus", "Waiting for a printjob");
  176. }
  177. }
  178. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  179. wrapMode: Text.WordWrap
  180. }
  181. }
  182. Column {
  183. id: additionalComponentsColumn
  184. anchors.left: parent.left
  185. anchors.right: parent.right
  186. anchors.top: machineInfo.visible ? machineInfo.bottom : machineInfo.anchors.top
  187. anchors.topMargin: UM.Theme.getSize("default_margin").width
  188. spacing: UM.Theme.getSize("default_margin").width
  189. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  190. Component.onCompleted:
  191. {
  192. for (var component in Printer.additionalComponents["machinesDetailPane"]) {
  193. Printer.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  194. }
  195. }
  196. }
  197. Connections {
  198. target: Printer
  199. onAdditionalComponentsChanged:
  200. {
  201. if(areaId == "machinesDetailPane") {
  202. for (var component in Printer.additionalComponents["machinesDetailPane"]) {
  203. Printer.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  204. }
  205. }
  206. }
  207. }
  208. UM.I18nCatalog { id: catalog; name: "cura"; }
  209. UM.ConfirmRemoveDialog
  210. {
  211. id: confirmDialog;
  212. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  213. onYes:
  214. {
  215. Cura.MachineManager.removeMachine(base.currentItem.id);
  216. if(!base.currentItem)
  217. {
  218. objectList.currentIndex = activeMachineIndex()
  219. }
  220. //Force updating currentItem and the details panel
  221. objectList.onCurrentIndexChanged()
  222. }
  223. }
  224. UM.RenameDialog
  225. {
  226. id: renameDialog;
  227. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  228. onAccepted:
  229. {
  230. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  231. //Force updating currentItem and the details panel
  232. objectList.onCurrentIndexChanged()
  233. }
  234. }
  235. Connections
  236. {
  237. target: Cura.MachineManager
  238. onGlobalContainerChanged:
  239. {
  240. objectList.currentIndex = activeMachineIndex()
  241. objectList.onCurrentIndexChanged()
  242. }
  243. }
  244. }
  245. }