PrinterOutputDevice.py 28 KB

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