MachinesPage.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 1.4
  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: CuraApplication.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 * screenScaleFactor
  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. onContentChanged:
  103. {
  104. contents = content;
  105. content.onCompleted.connect(hide)
  106. content.dialog = actionDialog
  107. }
  108. rightButtons: Button
  109. {
  110. text: catalog.i18nc("@action:button", "Close")
  111. iconName: "dialog-close"
  112. onClicked: actionDialog.reject()
  113. }
  114. }
  115. Grid
  116. {
  117. id: machineInfo
  118. anchors.top: machineActions.visible ? machineActions.bottom : machineActions.anchors.top
  119. anchors.topMargin: UM.Theme.getSize("default_margin").height
  120. anchors.left: parent.left
  121. anchors.right: parent.right
  122. spacing: UM.Theme.getSize("default_margin").height
  123. rowSpacing: UM.Theme.getSize("default_lining").height
  124. columns: 2
  125. visible: base.currentItem
  126. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  127. property var connectedPrinter: printerConnected ? Cura.MachineManager.printerOutputDevices[0] : null
  128. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  129. property var printJob: connectedPrinter != null ? connectedPrinter.activePrintJob: null
  130. Label
  131. {
  132. text: catalog.i18nc("@label", "Printer type:")
  133. visible: base.currentItem && "definition_name" in base.currentItem.metadata
  134. }
  135. Label
  136. {
  137. text: (base.currentItem && "definition_name" in base.currentItem.metadata) ? base.currentItem.metadata.definition_name : ""
  138. }
  139. Label
  140. {
  141. text: catalog.i18nc("@label", "Connection:")
  142. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  143. }
  144. Label
  145. {
  146. width: (parent.width * 0.7) | 0
  147. text: machineInfo.printerConnected ? machineInfo.connectedPrinter.connectionText : catalog.i18nc("@info:status", "The printer is not connected.")
  148. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  149. wrapMode: Text.WordWrap
  150. }
  151. Label
  152. {
  153. text: catalog.i18nc("@label", "State:")
  154. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  155. }
  156. Label {
  157. width: (parent.width * 0.7) | 0
  158. text:
  159. {
  160. if(!machineInfo.printerConnected || !machineInfo.printerAcceptsCommands) {
  161. return "";
  162. }
  163. if (machineInfo.printJob == null)
  164. {
  165. return catalog.i18nc("@label:MonitorStatus", "Waiting for a printjob");
  166. }
  167. switch(machineInfo.printJob.state)
  168. {
  169. case "printing":
  170. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  171. case "paused":
  172. return catalog.i18nc("@label:MonitorStatus", "Paused");
  173. case "pre_print":
  174. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  175. case "wait_cleanup":
  176. return catalog.i18nc("@label:MonitorStatus", "Waiting for someone to clear the build plate");
  177. case "error":
  178. return printerOutputDevice.errorText;
  179. case "maintenance":
  180. return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
  181. case "abort": // note sure if this jobState actually occurs in the wild
  182. return catalog.i18nc("@label:MonitorStatus", "Aborting print...");
  183. }
  184. return ""
  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 CuraApplication.additionalComponents["machinesDetailPane"]) {
  201. CuraApplication.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  202. }
  203. }
  204. }
  205. Component.onCompleted: {
  206. addAdditionalComponents("machinesDetailPane")
  207. }
  208. Connections {
  209. target: CuraApplication
  210. onAdditionalComponentsChanged: addAdditionalComponents
  211. }
  212. function addAdditionalComponents (areaId) {
  213. if(areaId == "machinesDetailPane") {
  214. for (var component in CuraApplication.additionalComponents["machinesDetailPane"]) {
  215. CuraApplication.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  216. }
  217. }
  218. }
  219. UM.I18nCatalog { id: catalog; name: "cura"; }
  220. UM.ConfirmRemoveDialog
  221. {
  222. id: confirmDialog;
  223. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  224. onYes:
  225. {
  226. Cura.MachineManager.removeMachine(base.currentItem.id);
  227. if(!base.currentItem)
  228. {
  229. objectList.currentIndex = activeMachineIndex()
  230. }
  231. //Force updating currentItem and the details panel
  232. objectList.onCurrentIndexChanged()
  233. }
  234. }
  235. UM.RenameDialog
  236. {
  237. id: renameDialog;
  238. width: 300 * screenScaleFactor
  239. height: 150 * screenScaleFactor
  240. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  241. property var machine_name_validator: Cura.MachineNameValidator { }
  242. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null;
  243. onAccepted:
  244. {
  245. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  246. //Force updating currentItem and the details panel
  247. objectList.onCurrentIndexChanged()
  248. }
  249. }
  250. Connections
  251. {
  252. target: Cura.MachineManager
  253. onGlobalContainerChanged:
  254. {
  255. objectList.currentIndex = activeMachineIndex()
  256. objectList.onCurrentIndexChanged()
  257. }
  258. }
  259. }
  260. }