MachinesPage.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 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: 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. Label
  130. {
  131. text: catalog.i18nc("@label", "Printer type:")
  132. visible: base.currentItem && "definition_name" in base.currentItem.metadata
  133. }
  134. Label
  135. {
  136. text: (base.currentItem && "definition_name" in base.currentItem.metadata) ? base.currentItem.metadata.definition_name : ""
  137. }
  138. Label
  139. {
  140. text: catalog.i18nc("@label", "Connection:")
  141. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  142. }
  143. Label
  144. {
  145. width: (parent.width * 0.7) | 0
  146. text: machineInfo.printerConnected ? machineInfo.connectedPrinter.connectionText : catalog.i18nc("@info:status", "The printer is not connected.")
  147. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  148. wrapMode: Text.WordWrap
  149. }
  150. Label
  151. {
  152. text: catalog.i18nc("@label", "State:")
  153. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  154. }
  155. Label {
  156. width: (parent.width * 0.7) | 0
  157. text:
  158. {
  159. if(!machineInfo.printerConnected || !machineInfo.printerAcceptsCommands) {
  160. return "";
  161. }
  162. switch(Cura.MachineManager.printerOutputDevices[0].jobState)
  163. {
  164. case "printing":
  165. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  166. case "paused":
  167. return catalog.i18nc("@label:MonitorStatus", "Paused");
  168. case "pre_print":
  169. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  170. case "wait_cleanup":
  171. return catalog.i18nc("@label:MonitorStatus", "Waiting for someone to clear the build plate");
  172. case "error":
  173. return printerOutputDevice.errorText;
  174. case "maintenance":
  175. return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
  176. case "abort": // note sure if this jobState actually occurs in the wild
  177. return catalog.i18nc("@label:MonitorStatus", "Aborting print...");
  178. case "ready": // ready to print or getting ready
  179. case "": // ready to print or getting ready
  180. return catalog.i18nc("@label:MonitorStatus", "Waiting for a printjob");
  181. }
  182. }
  183. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  184. wrapMode: Text.WordWrap
  185. }
  186. }
  187. Column {
  188. id: additionalComponentsColumn
  189. anchors.left: parent.left
  190. anchors.right: parent.right
  191. anchors.top: machineInfo.visible ? machineInfo.bottom : machineInfo.anchors.top
  192. anchors.topMargin: UM.Theme.getSize("default_margin").width
  193. spacing: UM.Theme.getSize("default_margin").width
  194. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  195. Component.onCompleted:
  196. {
  197. for (var component in CuraApplication.additionalComponents["machinesDetailPane"]) {
  198. CuraApplication.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  199. }
  200. }
  201. }
  202. Component.onCompleted: {
  203. addAdditionalComponents("machinesDetailPane")
  204. }
  205. Connections {
  206. target: CuraApplication
  207. onAdditionalComponentsChanged: addAdditionalComponents
  208. }
  209. function addAdditionalComponents (areaId) {
  210. if(areaId == "machinesDetailPane") {
  211. for (var component in CuraApplication.additionalComponents["machinesDetailPane"]) {
  212. CuraApplication.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  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. width: 300 * screenScaleFactor
  236. height: 150 * screenScaleFactor
  237. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  238. property var machine_name_validator: Cura.MachineNameValidator { }
  239. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null;
  240. onAccepted:
  241. {
  242. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  243. //Force updating currentItem and the details panel
  244. objectList.onCurrentIndexChanged()
  245. }
  246. }
  247. Connections
  248. {
  249. target: Cura.MachineManager
  250. onGlobalContainerChanged:
  251. {
  252. objectList.currentIndex = activeMachineIndex()
  253. objectList.onCurrentIndexChanged()
  254. }
  255. }
  256. }
  257. }