PrinterOutputDevice.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.i18n import i18nCatalog
  4. from UM.OutputDevice.OutputDevice import OutputDevice
  5. from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QTimer, pyqtSignal, QUrl
  6. from PyQt5.QtQml import QQmlComponent, QQmlContext
  7. from PyQt5.QtWidgets import QMessageBox
  8. from enum import IntEnum # For the connection state tracking.
  9. from UM.Settings.ContainerRegistry import ContainerRegistry
  10. from UM.Logger import Logger
  11. from UM.Signal import signalemitter
  12. from UM.PluginRegistry import PluginRegistry
  13. from UM.Application import Application
  14. import os
  15. i18n_catalog = i18nCatalog("cura")
  16. ## Printer output device adds extra interface options on top of output device.
  17. #
  18. # The assumption is made the printer is a FDM printer.
  19. #
  20. # Note that a number of settings are marked as "final". This is because decorators
  21. # are not inherited by children. To fix this we use the private counter part of those
  22. # functions to actually have the implementation.
  23. #
  24. # For all other uses it should be used in the same way as a "regular" OutputDevice.
  25. @signalemitter
  26. class PrinterOutputDevice(QObject, OutputDevice):
  27. def __init__(self, device_id, parent = None):
  28. super().__init__(device_id = device_id, parent = parent)
  29. self._container_registry = ContainerRegistry.getInstance()
  30. self._target_bed_temperature = 0
  31. self._bed_temperature = 0
  32. self._num_extruders = 1
  33. self._hotend_temperatures = [0] * self._num_extruders
  34. self._target_hotend_temperatures = [0] * self._num_extruders
  35. self._material_ids = [""] * self._num_extruders
  36. self._hotend_ids = [""] * self._num_extruders
  37. self._progress = 0
  38. self._head_x = 0
  39. self._head_y = 0
  40. self._head_z = 0
  41. self._connection_state = ConnectionState.closed
  42. self._connection_text = ""
  43. self._time_elapsed = 0
  44. self._time_total = 0
  45. self._job_state = ""
  46. self._job_name = ""
  47. self._error_text = ""
  48. self._accepts_commands = True
  49. self._preheat_bed_timeout = 900 # Default time-out for pre-heating the bed, in seconds.
  50. self._preheat_bed_timer = QTimer() # Timer that tracks how long to preheat still.
  51. self._preheat_bed_timer.setSingleShot(True)
  52. self._preheat_bed_timer.timeout.connect(self.cancelPreheatBed)
  53. self._printer_state = ""
  54. self._printer_type = "unknown"
  55. self._camera_active = False
  56. self._monitor_view_qml_path = ""
  57. self._monitor_component = None
  58. self._monitor_item = None
  59. self._control_view_qml_path = ""
  60. self._control_component = None
  61. self._control_item = None
  62. self._qml_context = None
  63. self._can_pause = True
  64. self._can_abort = True
  65. self._can_pre_heat_bed = True
  66. self._can_control_manually = True
  67. def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
  68. raise NotImplementedError("requestWrite needs to be implemented")
  69. ## Signals
  70. # Signal to be emitted when bed temp is changed
  71. bedTemperatureChanged = pyqtSignal()
  72. # Signal to be emitted when target bed temp is changed
  73. targetBedTemperatureChanged = pyqtSignal()
  74. # Signal when the progress is changed (usually when this output device is printing / sending lots of data)
  75. progressChanged = pyqtSignal()
  76. # Signal to be emitted when hotend temp is changed
  77. hotendTemperaturesChanged = pyqtSignal()
  78. # Signal to be emitted when target hotend temp is changed
  79. targetHotendTemperaturesChanged = pyqtSignal()
  80. # Signal to be emitted when head position is changed (x,y,z)
  81. headPositionChanged = pyqtSignal()
  82. # Signal to be emitted when either of the material ids is changed
  83. materialIdChanged = pyqtSignal(int, str, arguments = ["index", "id"])
  84. # Signal to be emitted when either of the hotend ids is changed
  85. hotendIdChanged = pyqtSignal(int, str, arguments = ["index", "id"])
  86. # Signal that is emitted every time connection state is changed.
  87. # it also sends it's own device_id (for convenience sake)
  88. connectionStateChanged = pyqtSignal(str)
  89. connectionTextChanged = pyqtSignal()
  90. timeElapsedChanged = pyqtSignal()
  91. timeTotalChanged = pyqtSignal()
  92. jobStateChanged = pyqtSignal()
  93. jobNameChanged = pyqtSignal()
  94. errorTextChanged = pyqtSignal()
  95. acceptsCommandsChanged = pyqtSignal()
  96. printerStateChanged = pyqtSignal()
  97. printerTypeChanged = pyqtSignal()
  98. # Signal to be emitted when some drastic change occurs in the remaining time (not when the time just passes on normally).
  99. preheatBedRemainingTimeChanged = pyqtSignal()
  100. # Does the printer support pre-heating the bed at all
  101. @pyqtProperty(bool, constant=True)
  102. def canPreHeatBed(self):
  103. return self._can_pre_heat_bed
  104. # Does the printer support pause at all
  105. @pyqtProperty(bool, constant=True)
  106. def canPause(self):
  107. return self._can_pause
  108. # Does the printer support abort at all
  109. @pyqtProperty(bool, constant=True)
  110. def canAbort(self):
  111. return self._can_abort
  112. # Does the printer support manual control at all
  113. @pyqtProperty(bool, constant=True)
  114. def canControlManually(self):
  115. return self._can_control_manually
  116. @pyqtProperty(QObject, constant=True)
  117. def monitorItem(self):
  118. # Note that we specifically only check if the monitor component is created.
  119. # It could be that it failed to actually create the qml item! If we check if the item was created, it will try to
  120. # create the item (and fail) every time.
  121. if not self._monitor_component:
  122. self._createMonitorViewFromQML()
  123. return self._monitor_item
  124. @pyqtProperty(QObject, constant=True)
  125. def controlItem(self):
  126. if not self._control_component:
  127. self._createControlViewFromQML()
  128. return self._control_item
  129. def _createControlViewFromQML(self):
  130. if not self._control_view_qml_path:
  131. return
  132. path = QUrl.fromLocalFile(self._control_view_qml_path)
  133. # Because of garbage collection we need to keep this referenced by python.
  134. self._control_component = QQmlComponent(Application.getInstance()._engine, path)
  135. # Check if the context was already requested before (Printer output device might have multiple items in the future)
  136. if self._qml_context is None:
  137. self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext())
  138. self._qml_context.setContextProperty("OutputDevice", self)
  139. self._control_item = self._control_component.create(self._qml_context)
  140. if self._control_item is None:
  141. Logger.log("e", "QQmlComponent status %s", self._control_component.status())
  142. Logger.log("e", "QQmlComponent error string %s", self._control_component.errorString())
  143. def _createMonitorViewFromQML(self):
  144. if not self._monitor_view_qml_path:
  145. return
  146. path = QUrl.fromLocalFile(self._monitor_view_qml_path)
  147. # Because of garbage collection we need to keep this referenced by python.
  148. self._monitor_component = QQmlComponent(Application.getInstance()._engine, path)
  149. # Check if the context was already requested before (Printer output device might have multiple items in the future)
  150. if self._qml_context is None:
  151. self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext())
  152. self._qml_context.setContextProperty("OutputDevice", self)
  153. self._monitor_item = self._monitor_component.create(self._qml_context)
  154. if self._monitor_item is None:
  155. Logger.log("e", "QQmlComponent status %s", self._monitor_component.status())
  156. Logger.log("e", "QQmlComponent error string %s", self._monitor_component.errorString())
  157. @pyqtProperty(str, notify=printerTypeChanged)
  158. def printerType(self):
  159. return self._printer_type
  160. @pyqtProperty(str, notify=printerStateChanged)
  161. def printerState(self):
  162. return self._printer_state
  163. @pyqtProperty(str, notify = jobStateChanged)
  164. def jobState(self):
  165. return self._job_state
  166. def _updatePrinterType(self, printer_type):
  167. if self._printer_type != printer_type:
  168. self._printer_type = printer_type
  169. self.printerTypeChanged.emit()
  170. def _updatePrinterState(self, printer_state):
  171. if self._printer_state != printer_state:
  172. self._printer_state = printer_state
  173. self.printerStateChanged.emit()
  174. def _updateJobState(self, job_state):
  175. if self._job_state != job_state:
  176. self._job_state = job_state
  177. self.jobStateChanged.emit()
  178. @pyqtSlot(str)
  179. def setJobState(self, job_state):
  180. self._setJobState(job_state)
  181. def _setJobState(self, job_state):
  182. Logger.log("w", "_setJobState is not implemented by this output device")
  183. @pyqtSlot()
  184. def startCamera(self):
  185. self._camera_active = True
  186. self._startCamera()
  187. def _startCamera(self):
  188. Logger.log("w", "_startCamera is not implemented by this output device")
  189. @pyqtSlot()
  190. def stopCamera(self):
  191. self._camera_active = False
  192. self._stopCamera()
  193. def _stopCamera(self):
  194. Logger.log("w", "_stopCamera is not implemented by this output device")
  195. @pyqtProperty(str, notify = jobNameChanged)
  196. def jobName(self):
  197. return self._job_name
  198. def setJobName(self, name):
  199. if self._job_name != name:
  200. self._job_name = name
  201. self.jobNameChanged.emit()
  202. ## Gives a human-readable address where the device can be found.
  203. @pyqtProperty(str, constant = True)
  204. def address(self):
  205. Logger.log("w", "address is not implemented by this output device.")
  206. ## A human-readable name for the device.
  207. @pyqtProperty(str, constant = True)
  208. def name(self):
  209. Logger.log("w", "name is not implemented by this output device.")
  210. return ""
  211. @pyqtProperty(str, notify = errorTextChanged)
  212. def errorText(self):
  213. return self._error_text
  214. ## Set the error-text that is shown in the print monitor in case of an error
  215. def setErrorText(self, error_text):
  216. if self._error_text != error_text:
  217. self._error_text = error_text
  218. self.errorTextChanged.emit()
  219. @pyqtProperty(bool, notify = acceptsCommandsChanged)
  220. def acceptsCommands(self):
  221. return self._accepts_commands
  222. ## Set a flag to signal the UI that the printer is not (yet) ready to receive commands
  223. def setAcceptsCommands(self, accepts_commands):
  224. if self._accepts_commands != accepts_commands:
  225. self._accepts_commands = accepts_commands
  226. self.acceptsCommandsChanged.emit()
  227. ## Get the bed temperature of the bed (if any)
  228. # This function is "final" (do not re-implement)
  229. # /sa _getBedTemperature implementation function
  230. @pyqtProperty(float, notify = bedTemperatureChanged)
  231. def bedTemperature(self):
  232. return self._bed_temperature
  233. ## Set the (target) bed temperature
  234. # This function is "final" (do not re-implement)
  235. # /param temperature new target temperature of the bed (in deg C)
  236. # /sa _setTargetBedTemperature implementation function
  237. @pyqtSlot(int)
  238. def setTargetBedTemperature(self, temperature):
  239. self._setTargetBedTemperature(temperature)
  240. if self._target_bed_temperature != temperature:
  241. self._target_bed_temperature = temperature
  242. self.targetBedTemperatureChanged.emit()
  243. ## The total duration of the time-out to pre-heat the bed, in seconds.
  244. #
  245. # \return The duration of the time-out to pre-heat the bed, in seconds.
  246. @pyqtProperty(int, constant = True)
  247. def preheatBedTimeout(self):
  248. return self._preheat_bed_timeout
  249. ## The remaining duration of the pre-heating of the bed.
  250. #
  251. # This is formatted in M:SS format.
  252. # \return The duration of the time-out to pre-heat the bed, formatted.
  253. @pyqtProperty(str, notify = preheatBedRemainingTimeChanged)
  254. def preheatBedRemainingTime(self):
  255. if not self._preheat_bed_timer.isActive():
  256. return ""
  257. period = self._preheat_bed_timer.remainingTime()
  258. if period <= 0:
  259. return ""
  260. minutes, period = divmod(period, 60000) #60000 milliseconds in a minute.
  261. seconds, _ = divmod(period, 1000) #1000 milliseconds in a second.
  262. if minutes <= 0 and seconds <= 0:
  263. return ""
  264. return "%d:%02d" % (minutes, seconds)
  265. ## Time the print has been printing.
  266. # Note that timeTotal - timeElapsed should give time remaining.
  267. @pyqtProperty(float, notify = timeElapsedChanged)
  268. def timeElapsed(self):
  269. return self._time_elapsed
  270. ## Total time of the print
  271. # Note that timeTotal - timeElapsed should give time remaining.
  272. @pyqtProperty(float, notify=timeTotalChanged)
  273. def timeTotal(self):
  274. return self._time_total
  275. @pyqtSlot(float)
  276. def setTimeTotal(self, new_total):
  277. if self._time_total != new_total:
  278. self._time_total = new_total
  279. self.timeTotalChanged.emit()
  280. @pyqtSlot(float)
  281. def setTimeElapsed(self, time_elapsed):
  282. if self._time_elapsed != time_elapsed:
  283. self._time_elapsed = time_elapsed
  284. self.timeElapsedChanged.emit()
  285. ## Home the head of the connected printer
  286. # This function is "final" (do not re-implement)
  287. # /sa _homeHead implementation function
  288. @pyqtSlot()
  289. def homeHead(self):
  290. self._homeHead()
  291. ## Home the head of the connected printer
  292. # This is an implementation function and should be overriden by children.
  293. def _homeHead(self):
  294. Logger.log("w", "_homeHead is not implemented by this output device")
  295. ## Home the bed of the connected printer
  296. # This function is "final" (do not re-implement)
  297. # /sa _homeBed implementation function
  298. @pyqtSlot()
  299. def homeBed(self):
  300. self._homeBed()
  301. ## Home the bed of the connected printer
  302. # This is an implementation function and should be overriden by children.
  303. # /sa homeBed
  304. def _homeBed(self):
  305. Logger.log("w", "_homeBed is not implemented by this output device")
  306. ## Protected setter for the bed temperature of the connected printer (if any).
  307. # /parameter temperature Temperature bed needs to go to (in deg celsius)
  308. # /sa setTargetBedTemperature
  309. def _setTargetBedTemperature(self, temperature):
  310. Logger.log("w", "_setTargetBedTemperature is not implemented by this output device")
  311. ## Pre-heats the heated bed of the printer.
  312. #
  313. # \param temperature The temperature to heat the bed to, in degrees
  314. # Celsius.
  315. # \param duration How long the bed should stay warm, in seconds.
  316. @pyqtSlot(float, float)
  317. def preheatBed(self, temperature, duration):
  318. Logger.log("w", "preheatBed is not implemented by this output device.")
  319. ## Cancels pre-heating the heated bed of the printer.
  320. #
  321. # If the bed is not pre-heated, nothing happens.
  322. @pyqtSlot()
  323. def cancelPreheatBed(self):
  324. Logger.log("w", "cancelPreheatBed is not implemented by this output device.")
  325. ## Protected setter for the current bed temperature.
  326. # This simply sets the bed temperature, but ensures that a signal is emitted.
  327. # /param temperature temperature of the bed.
  328. def _setBedTemperature(self, temperature):
  329. if self._bed_temperature != temperature:
  330. self._bed_temperature = temperature
  331. self.bedTemperatureChanged.emit()
  332. ## Get the target bed temperature if connected printer (if any)
  333. @pyqtProperty(int, notify = targetBedTemperatureChanged)
  334. def targetBedTemperature(self):
  335. return self._target_bed_temperature
  336. ## Set the (target) hotend temperature
  337. # This function is "final" (do not re-implement)
  338. # /param index the index of the hotend that needs to change temperature
  339. # /param temperature The temperature it needs to change to (in deg celsius).
  340. # /sa _setTargetHotendTemperature implementation function
  341. @pyqtSlot(int, int)
  342. def setTargetHotendTemperature(self, index, temperature):
  343. self._setTargetHotendTemperature(index, temperature)
  344. if self._target_hotend_temperatures[index] != temperature:
  345. self._target_hotend_temperatures[index] = temperature
  346. self.targetHotendTemperaturesChanged.emit()
  347. ## Implementation function of setTargetHotendTemperature.
  348. # /param index Index of the hotend to set the temperature of
  349. # /param temperature Temperature to set the hotend to (in deg C)
  350. # /sa setTargetHotendTemperature
  351. def _setTargetHotendTemperature(self, index, temperature):
  352. Logger.log("w", "_setTargetHotendTemperature is not implemented by this output device")
  353. @pyqtProperty("QVariantList", notify = targetHotendTemperaturesChanged)
  354. def targetHotendTemperatures(self):
  355. return self._target_hotend_temperatures
  356. @pyqtProperty("QVariantList", notify = hotendTemperaturesChanged)
  357. def hotendTemperatures(self):
  358. return self._hotend_temperatures
  359. ## Protected setter for the current hotend temperature.
  360. # This simply sets the hotend temperature, but ensures that a signal is emitted.
  361. # /param index Index of the hotend
  362. # /param temperature temperature of the hotend (in deg C)
  363. def _setHotendTemperature(self, index, temperature):
  364. if self._hotend_temperatures[index] != temperature:
  365. self._hotend_temperatures[index] = temperature
  366. self.hotendTemperaturesChanged.emit()
  367. @pyqtProperty("QVariantList", notify = materialIdChanged)
  368. def materialIds(self):
  369. return self._material_ids
  370. @pyqtProperty("QVariantList", notify = materialIdChanged)
  371. def materialNames(self):
  372. result = []
  373. for material_id in self._material_ids:
  374. if material_id is None:
  375. result.append(i18n_catalog.i18nc("@item:material", "No material loaded"))
  376. continue
  377. containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_id)
  378. if containers:
  379. result.append(containers[0].getName())
  380. else:
  381. result.append(i18n_catalog.i18nc("@item:material", "Unknown material"))
  382. return result
  383. ## List of the colours of the currently loaded materials.
  384. #
  385. # The list is in order of extruders. If there is no material in an
  386. # extruder, the colour is shown as transparent.
  387. #
  388. # The colours are returned in hex-format AARRGGBB or RRGGBB
  389. # (e.g. #800000ff for transparent blue or #00ff00 for pure green).
  390. @pyqtProperty("QVariantList", notify = materialIdChanged)
  391. def materialColors(self):
  392. result = []
  393. for material_id in self._material_ids:
  394. if material_id is None:
  395. result.append("#00000000") #No material.
  396. continue
  397. containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_id)
  398. if containers:
  399. result.append(containers[0].getMetaDataEntry("color_code"))
  400. else:
  401. result.append("#00000000") #Unknown material.
  402. return result
  403. ## Protected setter for the current material id.
  404. # /param index Index of the extruder
  405. # /param material_id id of the material
  406. def _setMaterialId(self, index, material_id):
  407. if material_id and material_id != "" and material_id != self._material_ids[index]:
  408. Logger.log("d", "Setting material id of hotend %d to %s" % (index, material_id))
  409. self._material_ids[index] = material_id
  410. self.materialIdChanged.emit(index, material_id)
  411. @pyqtProperty("QVariantList", notify = hotendIdChanged)
  412. def hotendIds(self):
  413. return self._hotend_ids
  414. ## Protected setter for the current hotend id.
  415. # /param index Index of the extruder
  416. # /param hotend_id id of the hotend
  417. def _setHotendId(self, index, hotend_id):
  418. if hotend_id and hotend_id != self._hotend_ids[index]:
  419. Logger.log("d", "Setting hotend id of hotend %d to %s" % (index, hotend_id))
  420. self._hotend_ids[index] = hotend_id
  421. self.hotendIdChanged.emit(index, hotend_id)
  422. elif not hotend_id:
  423. Logger.log("d", "Removing hotend id of hotend %d.", index)
  424. self._hotend_ids[index] = None
  425. self.hotendIdChanged.emit(index, None)
  426. ## Let the user decide if the hotends and/or material should be synced with the printer
  427. # NB: the UX needs to be implemented by the plugin
  428. def materialHotendChangedMessage(self, callback):
  429. Logger.log("w", "materialHotendChangedMessage needs to be implemented, returning 'Yes'")
  430. callback(QMessageBox.Yes)
  431. ## Attempt to establish connection
  432. def connect(self):
  433. raise NotImplementedError("connect needs to be implemented")
  434. ## Attempt to close the connection
  435. def close(self):
  436. raise NotImplementedError("close needs to be implemented")
  437. @pyqtProperty(bool, notify = connectionStateChanged)
  438. def connectionState(self):
  439. return self._connection_state
  440. ## Set the connection state of this output device.
  441. # /param connection_state ConnectionState enum.
  442. def setConnectionState(self, connection_state):
  443. if self._connection_state != connection_state:
  444. self._connection_state = connection_state
  445. self.connectionStateChanged.emit(self._id)
  446. @pyqtProperty(str, notify = connectionTextChanged)
  447. def connectionText(self):
  448. return self._connection_text
  449. ## Set a text that is shown on top of the print monitor tab
  450. def setConnectionText(self, connection_text):
  451. if self._connection_text != connection_text:
  452. self._connection_text = connection_text
  453. self.connectionTextChanged.emit()
  454. ## Ensure that close gets called when object is destroyed
  455. def __del__(self):
  456. self.close()
  457. ## Get the x position of the head.
  458. # This function is "final" (do not re-implement)
  459. @pyqtProperty(float, notify = headPositionChanged)
  460. def headX(self):
  461. return self._head_x
  462. ## Get the y position of the head.
  463. # This function is "final" (do not re-implement)
  464. @pyqtProperty(float, notify = headPositionChanged)
  465. def headY(self):
  466. return self._head_y
  467. ## Get the z position of the head.
  468. # In some machines it's actually the bed that moves. For convenience sake we simply see it all as head movements.
  469. # This function is "final" (do not re-implement)
  470. @pyqtProperty(float, notify = headPositionChanged)
  471. def headZ(self):
  472. return self._head_z
  473. ## Update the saved position of the head
  474. # This function should be called when a new position for the head is received.
  475. def _updateHeadPosition(self, x, y ,z):
  476. position_changed = False
  477. if self._head_x != x:
  478. self._head_x = x
  479. position_changed = True
  480. if self._head_y != y:
  481. self._head_y = y
  482. position_changed = True
  483. if self._head_z != z:
  484. self._head_z = z
  485. position_changed = True
  486. if position_changed:
  487. self.headPositionChanged.emit()
  488. ## Set the position of the head.
  489. # In some machines it's actually the bed that moves. For convenience sake we simply see it all as head movements.
  490. # This function is "final" (do not re-implement)
  491. # /param x new x location of the head.
  492. # /param y new y location of the head.
  493. # /param z new z location of the head.
  494. # /param speed Speed by which it needs to move (in mm/minute)
  495. # /sa _setHeadPosition implementation function
  496. @pyqtSlot("long", "long", "long")
  497. @pyqtSlot("long", "long", "long", "long")
  498. def setHeadPosition(self, x, y, z, speed = 3000):
  499. self._setHeadPosition(x, y , z, speed)
  500. ## Set the X position of the head.
  501. # This function is "final" (do not re-implement)
  502. # /param x x position head needs to move to.
  503. # /param speed Speed by which it needs to move (in mm/minute)
  504. # /sa _setHeadx implementation function
  505. @pyqtSlot("long")
  506. @pyqtSlot("long", "long")
  507. def setHeadX(self, x, speed = 3000):
  508. self._setHeadX(x, speed)
  509. ## Set the Y position of the head.
  510. # This function is "final" (do not re-implement)
  511. # /param y y position head needs to move to.
  512. # /param speed Speed by which it needs to move (in mm/minute)
  513. # /sa _setHeadY implementation function
  514. @pyqtSlot("long")
  515. @pyqtSlot("long", "long")
  516. def setHeadY(self, y, speed = 3000):
  517. self._setHeadY(y, speed)
  518. ## Set the Z position of the head.
  519. # In some machines it's actually the bed that moves. For convenience sake we simply see it all as head movements.
  520. # This function is "final" (do not re-implement)
  521. # /param z z position head needs to move to.
  522. # /param speed Speed by which it needs to move (in mm/minute)
  523. # /sa _setHeadZ implementation function
  524. @pyqtSlot("long")
  525. @pyqtSlot("long", "long")
  526. def setHeadZ(self, z, speed = 3000):
  527. self._setHeadZ(z, speed)
  528. ## Move the head of the printer.
  529. # Note that this is a relative move. If you want to move the head to a specific position you can use
  530. # setHeadPosition
  531. # This function is "final" (do not re-implement)
  532. # /param x distance in x to move
  533. # /param y distance in y to move
  534. # /param z distance in z to move
  535. # /param speed Speed by which it needs to move (in mm/minute)
  536. # /sa _moveHead implementation function
  537. @pyqtSlot("long", "long", "long")
  538. @pyqtSlot("long", "long", "long", "long")
  539. def moveHead(self, x = 0, y = 0, z = 0, speed = 3000):
  540. self._moveHead(x, y, z, speed)
  541. ## Implementation function of moveHead.
  542. # /param x distance in x to move
  543. # /param y distance in y to move
  544. # /param z distance in z to move
  545. # /param speed Speed by which it needs to move (in mm/minute)
  546. # /sa moveHead
  547. def _moveHead(self, x, y, z, speed):
  548. Logger.log("w", "_moveHead is not implemented by this output device")
  549. ## Implementation function of setHeadPosition.
  550. # /param x new x location of the head.
  551. # /param y new y location of the head.
  552. # /param z new z location of the head.
  553. # /param speed Speed by which it needs to move (in mm/minute)
  554. # /sa setHeadPosition
  555. def _setHeadPosition(self, x, y, z, speed):
  556. Logger.log("w", "_setHeadPosition is not implemented by this output device")
  557. ## Implementation function of setHeadX.
  558. # /param x new x location of the head.
  559. # /param speed Speed by which it needs to move (in mm/minute)
  560. # /sa setHeadX
  561. def _setHeadX(self, x, speed):
  562. Logger.log("w", "_setHeadX is not implemented by this output device")
  563. ## Implementation function of setHeadY.
  564. # /param y new y location of the head.
  565. # /param speed Speed by which it needs to move (in mm/minute)
  566. # /sa _setHeadY
  567. def _setHeadY(self, y, speed):
  568. Logger.log("w", "_setHeadY is not implemented by this output device")
  569. ## Implementation function of setHeadZ.
  570. # /param z new z location of the head.
  571. # /param speed Speed by which it needs to move (in mm/minute)
  572. # /sa _setHeadZ
  573. def _setHeadZ(self, z, speed):
  574. Logger.log("w", "_setHeadZ is not implemented by this output device")
  575. ## Get the progress of any currently active process.
  576. # This function is "final" (do not re-implement)
  577. # /sa _getProgress
  578. # /returns float progress of the process. -1 indicates that there is no process.
  579. @pyqtProperty(float, notify = progressChanged)
  580. def progress(self):
  581. return self._progress
  582. ## Set the progress of any currently active process
  583. # /param progress Progress of the process.
  584. def setProgress(self, progress):
  585. if self._progress != progress:
  586. self._progress = progress
  587. self.progressChanged.emit()
  588. ## The current processing state of the backend.
  589. class ConnectionState(IntEnum):
  590. closed = 0
  591. connecting = 1
  592. connected = 2
  593. busy = 3
  594. error = 4