Merge branch 'master' into CURA-7022_Add_cloud_printer_within_add_a_connected_printer

This commit is contained in:
Kostas Karmas 2020-04-23 15:07:18 +02:00
commit 15e7cb44af
21 changed files with 208 additions and 157 deletions

View File

@ -29,10 +29,12 @@ class Account(QObject):
# Signal emitted when user logged in or out.
loginStateChanged = pyqtSignal(bool)
accessTokenChanged = pyqtSignal()
cloudPrintersDetectedChanged = pyqtSignal(bool)
def __init__(self, application: "CuraApplication", parent = None) -> None:
super().__init__(parent)
self._application = application
self._new_cloud_printers_detected = False
self._error_message = None # type: Optional[Message]
self._logged_in = False
@ -74,6 +76,10 @@ class Account(QObject):
def isLoggedIn(self) -> bool:
return self._logged_in
@pyqtProperty(bool, notify=cloudPrintersDetectedChanged)
def newCloudPrintersDetected(self) -> bool:
return self._new_cloud_printers_detected
def _onLoginStateChanged(self, logged_in: bool = False, error_message: Optional[str] = None) -> None:
if error_message:
if self._error_message:

View File

@ -196,6 +196,7 @@ class Arrange:
start_idx = 0
else:
start_idx = 0
priority = 0
for priority in self._priority_unique_values[start_idx::step]:
tryout_idx = numpy.where(self._priority == priority)
for idx in range(len(tryout_idx[0])):

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019 Ultimaker B.V.
# Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import os
@ -206,8 +206,11 @@ class ContainerManager(QObject):
if contents is None:
return {"status": "error", "message": "Serialization returned None. Unable to write to file"}
with SaveFile(file_url, "w") as f:
f.write(contents)
try:
with SaveFile(file_url, "w") as f:
f.write(contents)
except OSError:
return {"status": "error", "message": "Unable to write to this location.", "path": file_url}
return {"status": "success", "message": "Successfully exported container", "path": file_url}

View File

@ -243,6 +243,10 @@ class WelcomePagesModel(ListModel):
{"id": "data_collections",
"page_url": self._getBuiltinWelcomePagePath("DataCollectionsContent.qml"),
},
{"id": "cloud",
"page_url": self._getBuiltinWelcomePagePath("CloudContent.qml"),
"should_show_function": self.shouldShowCloudPage,
},
{"id": "add_network_or_local_printer",
"page_url": self._getBuiltinWelcomePagePath("AddNetworkOrLocalPrinterContent.qml"),
"next_page_id": "machine_actions",
@ -253,12 +257,8 @@ class WelcomePagesModel(ListModel):
},
{"id": "machine_actions",
"page_url": self._getBuiltinWelcomePagePath("FirstStartMachineActionsContent.qml"),
"next_page_id": "cloud",
"should_show_function": self.shouldShowMachineActions,
},
{"id": "cloud",
"page_url": self._getBuiltinWelcomePagePath("CloudContent.qml"),
},
]
pages_to_show = all_pages_list
@ -287,6 +287,17 @@ class WelcomePagesModel(ListModel):
first_start_actions = self._application.getMachineActionManager().getFirstStartActions(definition_id)
return len([action for action in first_start_actions if action.needsUserInteraction()]) > 0
def shouldShowCloudPage(self) -> bool:
"""
The cloud page should be shown only if the user is not logged in
:return: True if the user is not logged in, False if he/she is
"""
# Import CuraApplication locally or else it fails
from cura.CuraApplication import CuraApplication
api = CuraApplication.getInstance().getCuraAPI()
return not api.account.isLoggedIn
def addPage(self) -> None:
pass

View File

@ -720,9 +720,12 @@ class CuraEngineBackend(QObject, Backend):
## Creates a new socket connection.
def _createSocket(self, protocol_file: str = None) -> None:
if not protocol_file:
if not self.getPluginId():
Logger.error("Can't create socket before CuraEngineBackend plug-in is registered.")
return
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
if not plugin_path:
Logger.log("e", "Could not get plugin path!", self.getPluginId())
Logger.error("Could not get plugin path!", self.getPluginId())
return
protocol_file = os.path.abspath(os.path.join(plugin_path, "Cura.proto"))
super()._createSocket(protocol_file)

View File

@ -1429,93 +1429,3 @@ class ChangeAtZProcessor:
# move to the next command
return
def debug():
# get our input file
file = r"C:\Users\Wes\Desktop\Archive\gcode test\emit + single layer\AC_Retraction.gcode"
# read the whole thing
f = open(file, "r")
gcode = f.read()
f.close()
# boot up change
caz_instance = ChangeAtZProcessor()
caz_instance.IsTargetByLayer = False
caz_instance.TargetZ = 5
caz_instance.TargetValues["printspeed"] = 100
caz_instance.TargetValues["retractfeedrate"] = 60
# process gcode
gcode = debug_iteration(gcode, caz_instance)
# write our file
debug_write(gcode, file + ".1.modified")
caz_instance.reset()
caz_instance.IsTargetByLayer = False
caz_instance.IsDisplayingChangesToLcd = True
caz_instance.IsApplyToSingleLayer = False
caz_instance.TargetZ = 10.6
caz_instance.TargetValues["bedTemp"] = 75.111
caz_instance.TargetValues["printspeed"] = 150
caz_instance.TargetValues["retractfeedrate"] = 40.555
caz_instance.TargetValues["retractlength"] = 10.3333
# and again
gcode = debug_iteration(gcode, caz_instance)
# write our file
debug_write(gcode, file + ".2.modified")
caz_instance.reset()
caz_instance.IsTargetByLayer = False
caz_instance.TargetZ = 15
caz_instance.IsApplyToSingleLayer = True
caz_instance.TargetValues["bedTemp"] = 80
caz_instance.TargetValues["printspeed"] = 100
caz_instance.TargetValues["retractfeedrate"] = 10
caz_instance.TargetValues["retractlength"] = 0
caz_instance.TargetValues["extruderOne"] = 100
caz_instance.TargetValues["extruderTwo"] = 200
# and again
gcode = debug_iteration(gcode, caz_instance)
# write our file
debug_write(gcode, file + ".3.modified")
def debug_write(gcode, file):
# write our file
f = open(file, "w")
f.write(gcode)
f.close()
def debug_iteration(gcode, caz_instance):
index = 0
# break apart the GCODE like cura
layers = re.split(r"^;LAYER:\d+\n", gcode)
# add the layer numbers back
for layer in layers:
# if this is the first layer, skip it, basically
if index == 0:
# leave our first layer as is
layers[index] = layer
# move the cursor
index += 1
# skip to the next layer
continue
layers[index] = ";LAYER:" + str(index - 1) + ";\n" + layer
return "".join(caz_instance.execute(layers))
# debug()

View File

@ -267,13 +267,23 @@ class SolidView(View):
Class that ducktypes to be a Numpy ndarray.
"""
def __init__(self, qimage):
self.__array_interface__ = {
"shape": (qimage.height(), qimage.width()),
"typestr": "|u4", # Use 4 bytes per pixel rather than 3, since Numpy doesn't support 3.
"data": (int(qimage.bits()), False),
"strides": (qimage.bytesPerLine(), 3), # This does the magic: For each line, skip the correct number of bytes. Bytes per pixel is always 3 due to QImage.Format.Format_RGB888.
"version": 3
}
bits_pointer = qimage.bits()
if bits_pointer is None: # If this happens before there is a window.
self.__array_interface__ = {
"shape": (0, 0),
"typestr": "|u4",
"data": (0, False),
"strides": (1, 3),
"version": 3
}
else:
self.__array_interface__ = {
"shape": (qimage.height(), qimage.width()),
"typestr": "|u4", # Use 4 bytes per pixel rather than 3, since Numpy doesn't support 3.
"data": (int(bits_pointer), False),
"strides": (qimage.bytesPerLine(), 3), # This does the magic: For each line, skip the correct number of bytes. Bytes per pixel is always 3 due to QImage.Format.Format_RGB888.
"version": 3
}
array = np.asarray(QImageArrayView(xray_img)).view(np.dtype({
"r": (np.uint8, 0, "red"),
"g": (np.uint8, 1, "green"),

View File

@ -99,14 +99,17 @@ class CloudOutputDeviceManager:
new_clusters = []
online_clusters = {c.cluster_id: c for c in clusters if c.is_online} # type: Dict[str, CloudClusterResponse]
for device_id, cluster_data in online_clusters.items():
if device_id not in self._remote_clusters:
new_clusters.append(cluster_data)
else:
self._onDiscoveredDeviceUpdated(cluster_data)
self._onDevicesDiscovered(new_clusters)
# Inform whether new cloud printers have been detected. If they have, the welcome wizard can close.
self._account._new_cloud_printers_detected = len(new_clusters) > 0
self._account.cloudPrintersDetectedChanged.emit(len(new_clusters) > 0)
removed_device_keys = set(self._remote_clusters.keys()) - set(online_clusters.keys())
for device_id in removed_device_keys:
self._onDiscoveredDeviceRemoved(device_id)
@ -128,6 +131,7 @@ class CloudOutputDeviceManager:
Shows a Message informing the user of progress.
"""
new_devices = []
remote_clusters_added = False
for cluster_data in clusters:
device = CloudOutputDevice(self._api, cluster_data)
# Create a machine if we don't already have it. Do not make it the active machine.
@ -137,8 +141,13 @@ class CloudOutputDeviceManager:
if machine_manager.getMachine(device.printerType, {self.META_CLUSTER_ID: device.key}) is None \
and machine_manager.getMachine(device.printerType, {self.META_NETWORK_KEY: cluster_data.host_name + "*"}) is None: # The host name is part of the network key.
new_devices.append(device)
elif device.getId() not in self._remote_clusters:
self._remote_clusters[device.getId()] = device
remote_clusters_added = True
if not new_devices:
if remote_clusters_added:
self._connectToActiveMachine()
return
new_devices.sort(key = lambda x: x.name.lower())
@ -172,7 +181,10 @@ class CloudOutputDeviceManager:
message.setProgress((idx / len(new_devices)) * 100)
CuraApplication.getInstance().processEvents()
self._remote_clusters[device.getId()] = device
self._createMachineFromDiscoveredDevice(device.getId(), activate = False)
# If there is no active machine, activate the first available cloud printer
activate = not CuraApplication.getInstance().getMachineManager().activeMachine
self._createMachineFromDiscoveredDevice(device.getId(), activate = activate)
message.setProgress(None)
@ -192,17 +204,6 @@ class CloudOutputDeviceManager:
)
message.setText(message_text)
def _onDiscoveredDeviceUpdated(self, cluster_data: CloudClusterResponse) -> None:
device = self._remote_clusters.get(cluster_data.cluster_id)
if not device:
return
CuraApplication.getInstance().getDiscoveredPrintersModel().updateDiscoveredPrinter(
ip_address=device.key,
name=cluster_data.friendly_name,
machine_type=device.printerType
)
self.discoveredDevicesChanged.emit()
def _onDiscoveredDeviceRemoved(self, device_id: str) -> None:
device = self._remote_clusters.pop(device_id, None) # type: Optional[CloudOutputDevice]
if not device:

View File

@ -92,9 +92,13 @@ class SendMaterialJob(Job):
parts = []
# Add the material file.
with open(file_path, "rb") as f:
parts.append(self.device.createFormPart("name=\"file\"; filename=\"{file_name}\""
.format(file_name = file_name), f.read()))
try:
with open(file_path, "rb") as f:
parts.append(self.device.createFormPart("name=\"file\"; filename=\"{file_name}\""
.format(file_name = file_name), f.read()))
except FileNotFoundError:
Logger.error("Unable to send material {material_id}, since it has been deleted in the meanwhile.".format(material_id = material_id))
return
# Add the material signature file if needed.
signature_file_path = "{}.sig".format(file_path)

View File

@ -52,7 +52,6 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
super().__init__(device_id=device_id, address=address, properties=properties, connection_type=connection_type,
parent=parent)
# Trigger the printersChanged signal when the private signal is triggered.
self.printersChanged.connect(self._clusterPrintersChanged)

View File

@ -191,7 +191,10 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
try:
self._serial = Serial(str(self._serial_port), self._baud_rate, timeout=self._timeout, writeTimeout=self._timeout)
except SerialException:
Logger.log("w", "An exception occurred while trying to create serial connection")
Logger.warning("An exception occurred while trying to create serial connection.")
return
except OSError as e:
Logger.warning("The serial device is suddenly unavailable while trying to create a serial connection: {err}".format(err = str(e)))
return
CuraApplication.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
self._onGlobalContainerStackChanged()

View File

@ -4,7 +4,7 @@
"inherits": "creality_cr10",
"overrides": {
"machine_name": { "default_value": "Creality CR-10S Pro" },
"machine_start_gcode": { "default_value": "M201 X500.00 Y500.00 Z100.00 E5000.00 ;Setup machine max acceleration\nM203 X500.00 Y500.00 Z10.00 E50.00 ;Setup machine max feedrate\nM204 P500.00 R1000.00 T500.00 ;Setup Print/Retract/Travel acceleration\nM205 X8.00 Y8.00 Z0.40 E5.00 ;Setup Jerk\nM220 S100 ;Reset Feedrate\nM221 S100 ;Reset Flowrate\n\nG28 ;Home\nM420 S1 Z2 ;Enable ABL using saved Mesh and Fade Height\n\nG92 E0 ;Reset Extruder\nG1 Z2.0 F3000 ;Move Z Axis up\nG1 X10.1 Y20 Z0.28 F5000.0 ;Move to start position\nG1 X10.1 Y200.0 Z0.28 F1500.0 E15 ;Draw the first line\nG1 X10.4 Y200.0 Z0.28 F5000.0 ;Move to side a little\nG1 X10.4 Y20 Z0.28 F1500.0 E30 ;Draw the second line\nG92 E0 ;Reset Extruder\nG1 Z2.0 F3000 ;Move Z Axis up\n"},
"machine_start_gcode": { "default_value": "M201 X500.00 Y500.00 Z100.00 E5000.00 ;Setup machine max acceleration\nM203 X500.00 Y500.00 Z10.00 E50.00 ;Setup machine max feedrate\nM204 P500.00 R1000.00 T500.00 ;Setup Print/Retract/Travel acceleration\nM205 X8.00 Y8.00 Z0.40 E5.00 ;Setup Jerk\nM220 S100 ;Reset Feedrate\nM221 S100 ;Reset Flowrate\n\nG28 ;Home\nG29 ;Auto bed Level\n\nG92 E0 ;Reset Extruder\nG1 Z2.0 F3000 ;Move Z Axis up\nG1 X10.1 Y20 Z0.28 F5000.0 ;Move to start position\nG1 X10.1 Y200.0 Z0.28 F1500.0 E15 ;Draw the first line\nG1 X10.4 Y200.0 Z0.28 F5000.0 ;Move to side a little\nG1 X10.4 Y20 Z0.28 F1500.0 E30 ;Draw the second line\nG92 E0 ;Reset Extruder\nG1 Z2.0 F3000 ;Move Z Axis up\n"},
"machine_head_with_fans_polygon": { "default_value": [
[-44, 34],
[-44, -34],
@ -21,4 +21,4 @@
"platform": "creality_cr10spro.stl",
"platform_offset": [ -150, 0, 150]
}
}
}

View File

@ -130,7 +130,7 @@ Item
onTextEdited: invalidInputLabel.visible = false
placeholderText: catalog.i18nc("@text", "Place enter your printer's IP address.")
placeholderText: catalog.i18nc("@text", "Enter your printer's IP address.")
enabled: { ! (addPrinterByIpScreen.hasRequestInProgress || addPrinterByIpScreen.isPrinterDiscovered) }
onAccepted: addPrinterButton.clicked()

View File

@ -15,14 +15,18 @@ Item
{
UM.I18nCatalog { id: catalog; name: "cura" }
property bool isLoggedIn: Cura.API.account.isLoggedIn
property bool newCloudPrintersDetected: Cura.API.account.newCloudPrintersDetected
onIsLoggedInChanged:
onNewCloudPrintersDetectedChanged:
{
if(isLoggedIn)
// When the user signs in successfully, it will be checked whether he/she has cloud printers connected to
// the account. If he/she does, then the welcome wizard can close. If not, then proceed to the next page (if any)
if(newCloudPrintersDetected)
{
base.endWizard()
}
else
{
// If the user created an account or logged in by pressing any button on this page, all the actions that
// need / can be done by this page are completed, so we can just go to the next (if any).
base.showNextPage()
}
}
@ -46,7 +50,7 @@ Item
anchors
{
top: titleLabel.bottom
bottom: finishButton.top
bottom: skipButton.top
left: parent.left
right: parent.right
topMargin: UM.Theme.getSize("default_margin").height
@ -107,35 +111,47 @@ Item
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
// "Sign in" and "Create an account" exist inside the column
Cura.PrimaryButton
{
id: signInButton
height: createAccountButton.height
width: createAccountButton.width
anchors.horizontalCenter: parent.horizontalCenter
text: catalog.i18nc("@button", "Sign in")
onClicked: Cura.API.account.login()
// Content Item is used in order to align the text inside the button. Without it, when resizing the
// button, the text will be aligned on the left
contentItem: Text {
text: signInButton.text
font: UM.Theme.getFont("medium")
color: UM.Theme.getColor("primary_text")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
Cura.SecondaryButton
{
id: createAccountButton
anchors.horizontalCenter: parent.horizontalCenter
text: catalog.i18nc("@button","Create account")
onClicked: Qt.openUrlExternally(CuraApplication.ultimakerCloudAccountRootUrl + "/app/create")
}
}
}
// Bottom buttons go here
Cura.PrimaryButton
{
id: finishButton
anchors.right: parent.right
anchors.bottom: parent.bottom
text: catalog.i18nc("@button", "Finish")
onClicked: base.showNextPage()
}
Cura.SecondaryButton
{
id: createAccountButton
anchors.left: parent.left
anchors.verticalCenter: finishButton.verticalCenter
text: catalog.i18nc("@button", "Create an account")
onClicked: Qt.openUrlExternally(CuraApplication.ultimakerCloudAccountRootUrl + "/app/create")
}
// The "Skip" button exists on the bottom right
Label
{
id: signInButton
anchors.left: createAccountButton.right
anchors.verticalCenter: finishButton.verticalCenter
id: skipButton
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.leftMargin: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@button", "Sign in")
text: catalog.i18nc("@button", "Skip")
color: UM.Theme.getColor("secondary_button_text")
font: UM.Theme.getFont("medium")
renderType: Text.NativeRendering
@ -144,7 +160,7 @@ Item
{
anchors.fill: parent
hoverEnabled: true
onClicked: Cura.API.account.login()
onClicked: base.showNextPage()
onEntered: parent.font.underline = true
onExited: parent.font.underline = false
}

View File

@ -0,0 +1,12 @@
[general]
name = 0.2mm Nozzle
version = 4
definition = creality_ender3pro
[metadata]
setting_version = 13
type = variant
hardware_type = nozzle
[values]
machine_nozzle_size = 0.2

View File

@ -0,0 +1,12 @@
[general]
name = 0.3mm Nozzle
version = 4
definition = creality_ender3pro
[metadata]
setting_version = 13
type = variant
hardware_type = nozzle
[values]
machine_nozzle_size = 0.3

View File

@ -0,0 +1,12 @@
[general]
name = 0.4mm Nozzle
version = 4
definition = creality_ender3pro
[metadata]
setting_version = 13
type = variant
hardware_type = nozzle
[values]
machine_nozzle_size = 0.4

View File

@ -0,0 +1,12 @@
[general]
name = 0.5mm Nozzle
version = 4
definition = creality_ender3pro
[metadata]
setting_version = 13
type = variant
hardware_type = nozzle
[values]
machine_nozzle_size = 0.5

View File

@ -0,0 +1,12 @@
[general]
name = 0.6mm Nozzle
version = 4
definition = creality_ender3pro
[metadata]
setting_version = 13
type = variant
hardware_type = nozzle
[values]
machine_nozzle_size = 0.6

View File

@ -0,0 +1,12 @@
[general]
name = 0.8mm Nozzle
version = 4
definition = creality_ender3pro
[metadata]
setting_version = 13
type = variant
hardware_type = nozzle
[values]
machine_nozzle_size = 0.8

View File

@ -0,0 +1,12 @@
[general]
name = 1.0mm Nozzle
version = 4
definition = creality_ender3pro
[metadata]
setting_version = 13
type = variant
hardware_type = nozzle
[values]
machine_nozzle_size = 1.0