mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Replace NetworkCamera with NetworkMJPGImage
This commit is contained in:
parent
890ddc015e
commit
c187b6a25c
5 changed files with 30 additions and 47 deletions
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant, pyqtSlot
|
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant, pyqtSlot, QUrl
|
||||||
from typing import List, Dict, Optional
|
from typing import List, Dict, Optional
|
||||||
from UM.Math.Vector import Vector
|
from UM.Math.Vector import Vector
|
||||||
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
||||||
|
@ -50,16 +50,16 @@ class PrinterOutputModel(QObject):
|
||||||
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in
|
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in
|
||||||
self._extruders]
|
self._extruders]
|
||||||
|
|
||||||
self._camera = None # type: Optional[NetworkCamera]
|
self._camera`_url = None # type: Optional[QUrl]
|
||||||
|
|
||||||
@pyqtProperty(str, constant = True)
|
@pyqtProperty(str, constant = True)
|
||||||
def firmwareVersion(self) -> str:
|
def firmwareVersion(self) -> str:
|
||||||
return self._firmware_version
|
return self._firmware_version
|
||||||
|
|
||||||
def setCamera(self, camera: Optional["NetworkCamera"]) -> None:
|
def setCameraUrl(self, camera_url: Optional["QUrl"]) -> None:
|
||||||
if self._camera is not camera:
|
if self._camera_url is not camera_url:
|
||||||
self._camera = camera
|
self._camera_url = camera_url
|
||||||
self.cameraChanged.emit()
|
self.cameraUrlChanged.emit()
|
||||||
|
|
||||||
def updateIsPreheating(self, pre_heating: bool) -> None:
|
def updateIsPreheating(self, pre_heating: bool) -> None:
|
||||||
if self._is_preheating != pre_heating:
|
if self._is_preheating != pre_heating:
|
||||||
|
@ -70,9 +70,9 @@ class PrinterOutputModel(QObject):
|
||||||
def isPreheating(self) -> bool:
|
def isPreheating(self) -> bool:
|
||||||
return self._is_preheating
|
return self._is_preheating
|
||||||
|
|
||||||
@pyqtProperty(QObject, notify=cameraChanged)
|
@pyqtProperty(QUrl, notify=cameraUrlChanged)
|
||||||
def camera(self) -> Optional["NetworkCamera"]:
|
def cameraUrl(self) -> Optional["QUrl"]:
|
||||||
return self._camera
|
return self._camera_url
|
||||||
|
|
||||||
@pyqtProperty(str, notify = printerTypeChanged)
|
@pyqtProperty(str, notify = printerTypeChanged)
|
||||||
def type(self) -> str:
|
def type(self) -> str:
|
||||||
|
|
|
@ -10,43 +10,36 @@ Component {
|
||||||
height: maximumHeight;
|
height: maximumHeight;
|
||||||
width: maximumWidth;
|
width: maximumWidth;
|
||||||
|
|
||||||
Cura.CameraView {
|
Cura.NetworkMJPGImage {
|
||||||
id: cameraImage;
|
id: cameraImage;
|
||||||
anchors {
|
anchors {
|
||||||
horizontalCenter: parent.horizontalCenter;
|
horizontalCenter: parent.horizontalCenter;
|
||||||
verticalCenter: parent.verticalCenter;
|
verticalCenter: parent.verticalCenter;
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
|
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||||
OutputDevice.activePrinter.camera.start();
|
cameraImage.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
height: Math.floor((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
|
height: Math.floor((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
|
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||||
OutputDevice.activePrinter.camera.start();
|
cameraImage.start();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
|
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||||
OutputDevice.activePrinter.camera.stop();
|
cameraImage.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
source: {
|
||||||
|
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||||
|
return OutputDevice.activePrinter.cameraUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
|
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
|
||||||
z: 1;
|
z: 1;
|
||||||
|
|
||||||
Connections
|
|
||||||
{
|
|
||||||
target: OutputDevice.activePrinter.camera;
|
|
||||||
onNewImage:
|
|
||||||
{
|
|
||||||
if (cameraImage.visible) {
|
|
||||||
cameraImage.image = OutputDevice.activePrinter.camera.latestImage;
|
|
||||||
cameraImage.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,33 +34,23 @@ Item {
|
||||||
z: 999;
|
z: 999;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cura.CameraView {
|
Cura.NetworkMJPGImage {
|
||||||
id: cameraImage
|
id: cameraImage
|
||||||
anchors.horizontalCenter: parent.horizontalCenter;
|
anchors.horizontalCenter: parent.horizontalCenter;
|
||||||
anchors.verticalCenter: parent.verticalCenter;
|
anchors.verticalCenter: parent.verticalCenter;
|
||||||
height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
|
height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
if (camera != null) {
|
if (cameraUrl != null) {
|
||||||
camera.start();
|
start();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (camera != null) {
|
if (cameraUrl != null) {
|
||||||
camera.stop();
|
stop();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections
|
|
||||||
{
|
|
||||||
target: camera
|
|
||||||
onNewImage: {
|
|
||||||
if (cameraImage.visible) {
|
|
||||||
cameraImage.image = camera.latestImage;
|
|
||||||
cameraImage.update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
source: cameraUrl
|
||||||
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
|
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
|
||||||
z: 1
|
z: 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -548,7 +548,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
def _createPrinterModel(self, data: Dict[str, Any]) -> PrinterOutputModel:
|
def _createPrinterModel(self, data: Dict[str, Any]) -> PrinterOutputModel:
|
||||||
printer = PrinterOutputModel(output_controller = ClusterUM3PrinterOutputController(self),
|
printer = PrinterOutputModel(output_controller = ClusterUM3PrinterOutputController(self),
|
||||||
number_of_extruders = self._number_of_extruders)
|
number_of_extruders = self._number_of_extruders)
|
||||||
printer.setCamera(NetworkCamera("http://" + data["ip_address"] + ":8080/?action=stream"))
|
printer.setCameraUrl(QUrl("http://" + data["ip_address"] + ":8080/?action=stream"))
|
||||||
self._printers.append(printer)
|
self._printers.append(printer)
|
||||||
return printer
|
return printer
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ from UM.i18n import i18nCatalog
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
|
|
||||||
from PyQt5.QtNetwork import QNetworkRequest
|
from PyQt5.QtNetwork import QNetworkRequest
|
||||||
from PyQt5.QtCore import QTimer
|
from PyQt5.QtCore import QTimer, QUrl
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
|
|
||||||
from .LegacyUM3PrinterOutputController import LegacyUM3PrinterOutputController
|
from .LegacyUM3PrinterOutputController import LegacyUM3PrinterOutputController
|
||||||
|
@ -568,7 +568,7 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
# Quickest way to get the firmware version is to grab it from the zeroconf.
|
# Quickest way to get the firmware version is to grab it from the zeroconf.
|
||||||
firmware_version = self._properties.get(b"firmware_version", b"").decode("utf-8")
|
firmware_version = self._properties.get(b"firmware_version", b"").decode("utf-8")
|
||||||
self._printers = [PrinterOutputModel(output_controller=self._output_controller, number_of_extruders=self._number_of_extruders, firmware_version=firmware_version)]
|
self._printers = [PrinterOutputModel(output_controller=self._output_controller, number_of_extruders=self._number_of_extruders, firmware_version=firmware_version)]
|
||||||
self._printers[0].setCamera(NetworkCamera("http://" + self._address + ":8080/?action=stream"))
|
self._printers[0].setCameraUrl(QUrl("http://" + self._address + ":8080/?action=stream"))
|
||||||
for extruder in self._printers[0].extruders:
|
for extruder in self._printers[0].extruders:
|
||||||
extruder.activeMaterialChanged.connect(self.materialIdChanged)
|
extruder.activeMaterialChanged.connect(self.materialIdChanged)
|
||||||
extruder.hotendIDChanged.connect(self.hotendIdChanged)
|
extruder.hotendIDChanged.connect(self.hotendIdChanged)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue