mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 15:57:52 -06:00
All known materials are now send upon connection
Due to garbage collection issues, the (multi) part requests are now cached. CURA-334
This commit is contained in:
parent
a4117bd3be
commit
ca79e398c8
1 changed files with 40 additions and 0 deletions
|
@ -5,6 +5,8 @@ from UM.Signal import signalemitter
|
||||||
|
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
|
|
||||||
|
import UM.Settings
|
||||||
|
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
|
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
|
||||||
|
|
||||||
from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager
|
from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager
|
||||||
|
@ -63,6 +65,10 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self._post_multi_part = None
|
self._post_multi_part = None
|
||||||
self._post_part = None
|
self._post_part = None
|
||||||
|
|
||||||
|
|
||||||
|
self._material_multi_part = None
|
||||||
|
self._material_part = None
|
||||||
|
|
||||||
self._progress_message = None
|
self._progress_message = None
|
||||||
self._error_message = None
|
self._error_message = None
|
||||||
|
|
||||||
|
@ -93,6 +99,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self._authentication_requested_message = Message(i18n_catalog.i18nc("@info:status", "Requested access. Please aprove the request on the printer"), lifetime = 0, dismissable = False, progress = 0)
|
self._authentication_requested_message = Message(i18n_catalog.i18nc("@info:status", "Requested access. Please aprove the request on the printer"), lifetime = 0, dismissable = False, progress = 0)
|
||||||
self._camera_image = QImage()
|
self._camera_image = QImage()
|
||||||
|
|
||||||
|
self._material_post_objects = {}
|
||||||
|
|
||||||
def _onAuthenticationTimer(self):
|
def _onAuthenticationTimer(self):
|
||||||
self._authentication_counter += 1
|
self._authentication_counter += 1
|
||||||
self._authentication_requested_message.setProgress(self._authentication_counter / self._max_authentication_counter * 100)
|
self._authentication_requested_message.setProgress(self._authentication_counter / self._max_authentication_counter * 100)
|
||||||
|
@ -145,6 +153,9 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self._authentication_requested_message.hide()
|
self._authentication_requested_message.hide()
|
||||||
authentication_succeeded_message = Message(i18n_catalog.i18nc("@info:status", "Printer was successfully paired with Cura"))
|
authentication_succeeded_message = Message(i18n_catalog.i18nc("@info:status", "Printer was successfully paired with Cura"))
|
||||||
authentication_succeeded_message.show()
|
authentication_succeeded_message.show()
|
||||||
|
# Once we are authenticated we need to send all material profiles.
|
||||||
|
#
|
||||||
|
self.sendMaterialProfiles()
|
||||||
elif auth_state == AuthState.AuthenticationDenied:
|
elif auth_state == AuthState.AuthenticationDenied:
|
||||||
self._authentication_requested_message.hide()
|
self._authentication_requested_message.hide()
|
||||||
authentication_failed_message = Message(i18n_catalog.i18nc("@info:status", "Pairing request failed. This can be either due to a timeout or the printer refused the request."))
|
authentication_failed_message = Message(i18n_catalog.i18nc("@info:status", "Pairing request failed. This can be either due to a timeout or the printer refused the request."))
|
||||||
|
@ -326,6 +337,32 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self.setAuthenticationState(AuthState.AuthenticationRequested)
|
self.setAuthenticationState(AuthState.AuthenticationRequested)
|
||||||
self._manager.post(request, json.dumps({"application": "Cura-" + Application.getInstance().getVersion(), "user": self._getUserName()}).encode())
|
self._manager.post(request, json.dumps({"application": "Cura-" + Application.getInstance().getVersion(), "user": self._getUserName()}).encode())
|
||||||
|
|
||||||
|
## Send all material profiles to the printer.
|
||||||
|
def sendMaterialProfiles(self):
|
||||||
|
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "material"):
|
||||||
|
try:
|
||||||
|
xml_data = container.serialize()
|
||||||
|
if xml_data == "":
|
||||||
|
continue
|
||||||
|
material_multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType)
|
||||||
|
|
||||||
|
material_part = QHttpPart()
|
||||||
|
file_name = "none.xml"
|
||||||
|
material_part.setHeader(QNetworkRequest.ContentDispositionHeader, "form-data; name=\"file\";filename=\"%s\"" % file_name)
|
||||||
|
material_part.setBody(xml_data.encode())
|
||||||
|
material_multi_part.append(material_part)
|
||||||
|
url = QUrl("http://" + self._address + self._api_prefix + "materials")
|
||||||
|
material_post_request = QNetworkRequest(url)
|
||||||
|
|
||||||
|
self._manager.post(material_post_request, material_multi_part)
|
||||||
|
|
||||||
|
# Keep reference to material_part and material_multi_part so the garbage collector won't touch them.
|
||||||
|
self._material_post_objects[container.getId()] = (material_part, material_multi_part)
|
||||||
|
except NotImplementedError:
|
||||||
|
# If the material container is not the most "generic" one it can't be serialized an will raise a
|
||||||
|
# NotImplementedError. We can simply ignore these.
|
||||||
|
pass
|
||||||
|
|
||||||
## Handler for all requests that have finished.
|
## Handler for all requests that have finished.
|
||||||
def _onFinished(self, reply):
|
def _onFinished(self, reply):
|
||||||
if reply.operation() == QNetworkAccessManager.GetOperation:
|
if reply.operation() == QNetworkAccessManager.GetOperation:
|
||||||
|
@ -403,6 +440,9 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
|
|
||||||
# Check if the authentication is accepted.
|
# Check if the authentication is accepted.
|
||||||
self._checkAuthentication()
|
self._checkAuthentication()
|
||||||
|
elif "materials" in reply.url().toString():
|
||||||
|
# TODO: Remove cached post request items.
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
reply.uploadProgress.disconnect(self._onUploadProgress)
|
reply.uploadProgress.disconnect(self._onUploadProgress)
|
||||||
self._progress_message.hide()
|
self._progress_message.hide()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue