mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 23:23:57 -06:00
Merge pull request #4656 from fieldOfView/fix_network_camera_memory_leak
[3.6] Fix memory leak in print monitor
This commit is contained in:
commit
1623f66c93
13 changed files with 209 additions and 279 deletions
|
@ -31,10 +31,10 @@ Rectangle {
|
|||
anchors.fill: parent;
|
||||
hoverEnabled: true;
|
||||
onClicked: {
|
||||
if (OutputDevice.activeCamera !== null) {
|
||||
OutputDevice.setActiveCamera(null)
|
||||
if (OutputDevice.activeCameraUrl != "") {
|
||||
OutputDevice.setActiveCameraUrl("");
|
||||
} else {
|
||||
OutputDevice.setActiveCamera(modelData.camera);
|
||||
OutputDevice.setActiveCameraUrl(modelData.cameraUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ Component {
|
|||
height: maximumHeight;
|
||||
onVisibleChanged: {
|
||||
if (monitorFrame != null && !monitorFrame.visible) {
|
||||
OutputDevice.setActiveCamera(null);
|
||||
OutputDevice.setActiveCameraUrl("");
|
||||
}
|
||||
}
|
||||
width: maximumWidth;
|
||||
|
@ -125,8 +125,8 @@ Component {
|
|||
|
||||
PrinterVideoStream {
|
||||
anchors.fill: parent;
|
||||
camera: OutputDevice.activeCamera;
|
||||
visible: OutputDevice.activeCamera != null;
|
||||
cameraUrl: OutputDevice.activeCameraUrl;
|
||||
visible: OutputDevice.activeCameraUrl != "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,43 +10,36 @@ Component {
|
|||
height: maximumHeight;
|
||||
width: maximumWidth;
|
||||
|
||||
Cura.CameraView {
|
||||
Cura.NetworkMJPGImage {
|
||||
id: cameraImage;
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter;
|
||||
verticalCenter: parent.verticalCenter;
|
||||
}
|
||||
Component.onCompleted: {
|
||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
|
||||
OutputDevice.activePrinter.camera.start();
|
||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||
cameraImage.start();
|
||||
}
|
||||
}
|
||||
height: Math.floor((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
|
||||
OutputDevice.activePrinter.camera.start();
|
||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||
cameraImage.start();
|
||||
}
|
||||
} else {
|
||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
|
||||
OutputDevice.activePrinter.camera.stop();
|
||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||
cameraImage.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
source: {
|
||||
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
|
||||
return OutputDevice.activePrinter.cameraUrl;
|
||||
}
|
||||
}
|
||||
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
|
||||
z: 1;
|
||||
|
||||
Connections
|
||||
{
|
||||
target: OutputDevice.activePrinter.camera;
|
||||
onNewImage:
|
||||
{
|
||||
if (cameraImage.visible) {
|
||||
cameraImage.image = OutputDevice.activePrinter.camera.latestImage;
|
||||
cameraImage.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import UM 1.3 as UM
|
|||
import Cura 1.0 as Cura
|
||||
|
||||
Item {
|
||||
property var camera: null;
|
||||
property var cameraUrl: "";
|
||||
|
||||
Rectangle {
|
||||
anchors.fill:parent;
|
||||
|
@ -18,7 +18,7 @@ Item {
|
|||
|
||||
MouseArea {
|
||||
anchors.fill: parent;
|
||||
onClicked: OutputDevice.setActiveCamera(null);
|
||||
onClicked: OutputDevice.setActiveCameraUrl("");
|
||||
z: 0;
|
||||
}
|
||||
|
||||
|
@ -34,33 +34,23 @@ Item {
|
|||
z: 999;
|
||||
}
|
||||
|
||||
Cura.CameraView {
|
||||
Cura.NetworkMJPGImage {
|
||||
id: cameraImage
|
||||
anchors.horizontalCenter: parent.horizontalCenter;
|
||||
anchors.verticalCenter: parent.verticalCenter;
|
||||
height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
if (camera != null) {
|
||||
camera.start();
|
||||
if (cameraUrl != "") {
|
||||
start();
|
||||
}
|
||||
} else {
|
||||
if (camera != null) {
|
||||
camera.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections
|
||||
{
|
||||
target: camera
|
||||
onNewImage: {
|
||||
if (cameraImage.visible) {
|
||||
cameraImage.image = camera.latestImage;
|
||||
cameraImage.update();
|
||||
if (cameraUrl != "") {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
source: cameraUrl
|
||||
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
|
||||
z: 1
|
||||
}
|
||||
|
@ -68,7 +58,7 @@ Item {
|
|||
MouseArea {
|
||||
anchors.fill: cameraImage;
|
||||
onClicked: {
|
||||
OutputDevice.setActiveCamera(null);
|
||||
OutputDevice.setActiveCameraUrl("");
|
||||
}
|
||||
z: 1;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationM
|
|||
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice, AuthState
|
||||
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||
from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
|
||||
from cura.PrinterOutput.NetworkCamera import NetworkCamera
|
||||
|
||||
from .ClusterUM3PrinterOutputController import ClusterUM3PrinterOutputController
|
||||
from .SendMaterialJob import SendMaterialJob
|
||||
|
@ -47,7 +46,7 @@ i18n_catalog = i18nCatalog("cura")
|
|||
class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
printJobsChanged = pyqtSignal()
|
||||
activePrinterChanged = pyqtSignal()
|
||||
activeCameraChanged = pyqtSignal()
|
||||
activeCameraUrlChanged = pyqtSignal()
|
||||
receivedPrintJobsChanged = pyqtSignal()
|
||||
|
||||
# This is a bit of a hack, as the notify can only use signals that are defined by the class that they are in.
|
||||
|
@ -100,7 +99,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
self._latest_reply_handler = None # type: Optional[QNetworkReply]
|
||||
self._sending_job = None
|
||||
|
||||
self._active_camera = None # type: Optional[NetworkCamera]
|
||||
self._active_camera_url = QUrl() # type: QUrl
|
||||
|
||||
def requestWrite(self, nodes: List[SceneNode], file_name: Optional[str] = None, limit_mimetypes: bool = False, file_handler: Optional[FileHandler] = None, **kwargs: str) -> None:
|
||||
self.writeStarted.emit(self)
|
||||
|
@ -264,30 +263,21 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
def activePrinter(self) -> Optional[PrinterOutputModel]:
|
||||
return self._active_printer
|
||||
|
||||
@pyqtProperty(QObject, notify=activeCameraChanged)
|
||||
def activeCamera(self) -> Optional[NetworkCamera]:
|
||||
return self._active_camera
|
||||
|
||||
@pyqtSlot(QObject)
|
||||
def setActivePrinter(self, printer: Optional[PrinterOutputModel]) -> None:
|
||||
if self._active_printer != printer:
|
||||
if self._active_printer and self._active_printer.camera:
|
||||
self._active_printer.camera.stop()
|
||||
self._active_printer = printer
|
||||
self.activePrinterChanged.emit()
|
||||
|
||||
@pyqtSlot(QObject)
|
||||
def setActiveCamera(self, camera: Optional[NetworkCamera]) -> None:
|
||||
if self._active_camera != camera:
|
||||
if self._active_camera:
|
||||
self._active_camera.stop()
|
||||
@pyqtProperty(QUrl, notify = activeCameraUrlChanged)
|
||||
def activeCameraUrl(self) -> "QUrl":
|
||||
return self._active_camera_url
|
||||
|
||||
self._active_camera = camera
|
||||
|
||||
if self._active_camera:
|
||||
self._active_camera.start()
|
||||
|
||||
self.activeCameraChanged.emit()
|
||||
@pyqtSlot(QUrl)
|
||||
def setActiveCameraUrl(self, camera_url: "QUrl") -> None:
|
||||
if self._active_camera_url != camera_url:
|
||||
self._active_camera_url = camera_url
|
||||
self.activeCameraUrlChanged.emit()
|
||||
|
||||
def _onPostPrintJobFinished(self, reply: QNetworkReply) -> None:
|
||||
if self._progress_message:
|
||||
|
@ -548,7 +538,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
def _createPrinterModel(self, data: Dict[str, Any]) -> PrinterOutputModel:
|
||||
printer = PrinterOutputModel(output_controller = ClusterUM3PrinterOutputController(self),
|
||||
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)
|
||||
return printer
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutp
|
|||
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||
from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
|
||||
from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
|
||||
from cura.PrinterOutput.NetworkCamera import NetworkCamera
|
||||
|
||||
from cura.Settings.ContainerManager import ContainerManager
|
||||
from cura.Settings.ExtruderManager import ExtruderManager
|
||||
|
@ -18,7 +17,7 @@ from UM.i18n import i18nCatalog
|
|||
from UM.Message import Message
|
||||
|
||||
from PyQt5.QtNetwork import QNetworkRequest
|
||||
from PyQt5.QtCore import QTimer
|
||||
from PyQt5.QtCore import QTimer, QUrl
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
from .LegacyUM3PrinterOutputController import LegacyUM3PrinterOutputController
|
||||
|
@ -568,7 +567,7 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
# 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")
|
||||
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:
|
||||
extruder.activeMaterialChanged.connect(self.materialIdChanged)
|
||||
extruder.hotendIDChanged.connect(self.hotendIdChanged)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue