MachinesPage.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. Item
  81. {
  82. width: childrenRect.width + 2
  83. height: childrenRect.height
  84. Button
  85. {
  86. text: machineActionRepeater.model[index].label
  87. onClicked:
  88. {
  89. actionDialog.content = machineActionRepeater.model[index].displayItem;
  90. machineActionRepeater.model[index].displayItem.reset();
  91. actionDialog.title = machineActionRepeater.model[index].label;
  92. actionDialog.show();
  93. }
  94. }
  95. }
  96. }
  97. }
  98. UM.Dialog
  99. {
  100. id: actionDialog
  101. property var content
  102. minimumWidth: 350 * Screen.devicePixelRatio;
  103. minimumHeight: 350 * Screen.devicePixelRatio;
  104. // prevent the Machine Settings dialog from going beyond the top of the screen
  105. x: (x < 0) ? 0 : x
  106. y: (y < 0) ? 0 : y
  107. onContentChanged:
  108. {
  109. contents = content;
  110. content.onCompleted.connect(hide)
  111. content.dialog = actionDialog
  112. }
  113. rightButtons: Button
  114. {
  115. text: catalog.i18nc("@action:button", "Close")
  116. iconName: "dialog-close"
  117. onClicked: actionDialog.reject()
  118. }
  119. }
  120. Grid
  121. {
  122. id: machineInfo
  123. anchors.top: machineActions.visible ? machineActions.bottom : machineActions.anchors.top
  124. anchors.topMargin: UM.Theme.getSize("default_margin").height
  125. anchors.left: parent.left
  126. anchors.right: parent.right
  127. spacing: UM.Theme.getSize("default_margin").height
  128. rowSpacing: UM.Theme.getSize("default_lining").height
  129. columns: 2
  130. visible: base.currentItem
  131. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  132. property var connectedPrinter: printerConnected ? Cura.MachineManager.printerOutputDevices[0] : null
  133. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  134. Label
  135. {
  136. text: catalog.i18nc("@label", "Printer type:")
  137. visible: base.currentItem && "definition_name" in base.currentItem.metadata
  138. }
  139. Label {
  140. text: (base.currentItem && "definition_name" in base.currentItem.metadata) ? base.currentItem.metadata.definition_name : ""
  141. }
  142. Label
  143. {
  144. text: catalog.i18nc("@label", "Connection:")
  145. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  146. }
  147. Label {
  148. width: parent.width * 0.7
  149. text: machineInfo.printerConnected ? machineInfo.connectedPrinter.connectionText : catalog.i18nc("@info:status", "The printer is not connected.")
  150. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  151. wrapMode: Text.WordWrap
  152. }
  153. Label
  154. {
  155. text: catalog.i18nc("@label", "State:")
  156. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  157. }
  158. Label {
  159. width: parent.width * 0.7
  160. text:
  161. {
  162. if(!machineInfo.printerConnected || !machineInfo.printerAcceptsCommands) {
  163. return "";
  164. }
  165. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  166. {
  167. case "printing":
  168. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  169. case "paused":
  170. return catalog.i18nc("@label:MonitorStatus", "Paused");
  171. case "pre_print":
  172. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  173. case "wait_cleanup":
  174. return catalog.i18nc("@label:MonitorStatus", "Waiting for someone to clear the build plate");
  175. case "error":
  176. return printerOutputDevice.errorText;
  177. case "maintenance":
  178. return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
  179. case "abort": // note sure if this jobState actually occurs in the wild
  180. return catalog.i18nc("@label:MonitorStatus", "Aborting print...");
  181. case "ready": // ready to print or getting ready
  182. case "": // ready to print or getting ready
  183. return catalog.i18nc("@label:MonitorStatus", "Waiting for a printjob");
  184. }
  185. }
  186. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  187. wrapMode: Text.WordWrap
  188. }
  189. }
  190. Column {
  191. id: additionalComponentsColumn
  192. anchors.left: parent.left
  193. anchors.right: parent.right
  194. anchors.top: machineInfo.visible ? machineInfo.bottom : machineInfo.anchors.top
  195. anchors.topMargin: UM.Theme.getSize("default_margin").width
  196. spacing: UM.Theme.getSize("default_margin").width
  197. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  198. Component.onCompleted:
  199. {
  200. for (var component in Printer.additionalComponents["machinesDetailPane"]) {
  201. Printer.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  202. }
  203. }
  204. }
  205. Connections {
  206. target: Printer
  207. onAdditionalComponentsChanged:
  208. {
  209. if(areaId == "machinesDetailPane") {
  210. for (var component in Printer.additionalComponents["machinesDetailPane"]) {
  211. Printer.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  212. }
  213. }
  214. }
  215. }
  216. UM.I18nCatalog { id: catalog; name: "cura"; }
  217. UM.ConfirmRemoveDialog
  218. {
  219. id: confirmDialog;
  220. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  221. onYes:
  222. {
  223. Cura.MachineManager.removeMachine(base.currentItem.id);
  224. if(!base.currentItem)
  225. {
  226. objectList.currentIndex = activeMachineIndex()
  227. }
  228. //Force updating currentItem and the details panel
  229. objectList.onCurrentIndexChanged()
  230. }
  231. }
  232. UM.RenameDialog
  233. {
  234. id: renameDialog;
  235. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  236. property var machine_name_validator: Cura.MachineNameValidator { }
  237. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null;
  238. onAccepted:
  239. {
  240. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  241. //Force updating currentItem and the details panel
  242. objectList.onCurrentIndexChanged()
  243. }
  244. }
  245. Connections
  246. {
  247. target: Cura.MachineManager
  248. onGlobalContainerChanged:
  249. {
  250. objectList.currentIndex = activeMachineIndex()
  251. objectList.onCurrentIndexChanged()
  252. }
  253. }
  254. }
  255. }