Moved calculating UCP only to Preread and getting value here

CURA-11403
This commit is contained in:
Saumya Jain 2024-03-05 16:34:41 +01:00
parent 0e70b80446
commit b119a010ca
3 changed files with 8 additions and 12 deletions

View File

@ -1,6 +1,5 @@
# Copyright (c) 2023 UltiMaker # Copyright (c) 2023 UltiMaker
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import zipfile
from typing import List, cast from typing import List, cast
from PyQt6.QtCore import QObject, QUrl, pyqtSignal, pyqtProperty from PyQt6.QtCore import QObject, QUrl, pyqtSignal, pyqtProperty
@ -33,8 +32,6 @@ from cura.Operations.SetBuildPlateNumberOperation import SetBuildPlateNumberOper
from UM.Logger import Logger from UM.Logger import Logger
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
USER_SETTINGS_PATH = "Cura/user-settings.json"
class CuraActions(QObject): class CuraActions(QObject):
def __init__(self, parent: QObject = None) -> None: def __init__(self, parent: QObject = None) -> None:
super().__init__(parent) super().__init__(parent)
@ -196,13 +193,6 @@ class CuraActions(QObject):
operation.addOperation(SetObjectExtruderOperation(node, extruder_id)) operation.addOperation(SetObjectExtruderOperation(node, extruder_id))
operation.push() operation.push()
@pyqtSlot(str, result = bool)
def isProjectUcp(self, file_url) -> bool:
file_name = QUrl(file_url).toLocalFile()
archive = zipfile.ZipFile(file_name, "r")
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
return USER_SETTINGS_PATH in cura_file_names
@pyqtSlot(int) @pyqtSlot(int)
def setBuildPlateForSelection(self, build_plate_nr: int) -> None: def setBuildPlateForSelection(self, build_plate_nr: int) -> None:
Logger.log("d", "Setting build plate number... %d" % build_plate_nr) Logger.log("d", "Setting build plate number... %d" % build_plate_nr)

View File

@ -2194,6 +2194,12 @@ class CuraApplication(QtApplication):
def addNonSliceableExtension(self, extension): def addNonSliceableExtension(self, extension):
self._non_sliceable_extensions.append(extension) self._non_sliceable_extensions.append(extension)
@pyqtSlot(str, result = bool)
def isProjectUcp(self, file_url) -> bool:
file_path = QUrl(file_url).toLocalFile()
workspace_reader = self.getWorkspaceFileHandler().getReaderForFile(file_path)
return workspace_reader.getIsProjectUcp()
@pyqtSlot(str, result=bool) @pyqtSlot(str, result=bool)
def checkIsValidProjectFile(self, file_url): def checkIsValidProjectFile(self, file_url):
"""Checks if the given file URL is a valid project file. """ """Checks if the given file URL is a valid project file. """

View File

@ -702,7 +702,7 @@ UM.MainWindow
if (hasProjectFile) if (hasProjectFile)
{ {
var projectFile = projectFileUrlList[0] var projectFile = projectFileUrlList[0]
var is_ucp = CuraActions.isProjectUcp(projectFile); var is_ucp = CuraApplication.isProjectUcp(projectFile);
if (is_ucp) if (is_ucp)
{ {
askOpenAsProjectOrUcpOrImportModelsDialog.fileUrl = projectFile; askOpenAsProjectOrUcpOrImportModelsDialog.fileUrl = projectFile;
@ -788,7 +788,7 @@ UM.MainWindow
target: CuraApplication target: CuraApplication
function onOpenProjectFile(project_file, add_to_recent_files) function onOpenProjectFile(project_file, add_to_recent_files)
{ {
var is_ucp = CuraActions.isProjectUcp(project_file); var is_ucp = CuraApplication.isProjectUcp(project_file);
if (is_ucp) if (is_ucp)
{ {