From 7b284355fb5939e40d0fdf3226a6a9b29390cee3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 5 Jul 2018 15:24:55 +0200 Subject: [PATCH] Revert "Fix code-style in CuraEngineBackend" This reverts commit 7d7a51d77241026ef665300b944b64dd69dbddcc. That commit broke the start-up sequence. --- .../CuraEngineBackend/CuraEngineBackend.py | 49 +++++++------------ plugins/CuraEngineBackend/StartSliceJob.py | 30 ++++++------ 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 1df694aa86..e7dca2ae3e 100755 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -3,8 +3,6 @@ from collections import defaultdict import os -from typing import Union - from PyQt5.QtCore import QObject, QTimer, pyqtSlot import sys from time import time @@ -62,16 +60,17 @@ class CuraEngineBackend(QObject, Backend): if hasattr(sys, "frozen"): default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), executable_name) if Platform.isLinux() and not default_engine_location: - env_path = os.getenv("PATH") - if not env_path: + if not os.getenv("PATH"): raise OSError("There is something wrong with your Linux installation.") - for pathdir in env_path.split(os.pathsep): + for pathdir in os.getenv("PATH").split(os.pathsep): execpath = os.path.join(pathdir, executable_name) if os.path.exists(execpath): default_engine_location = execpath break self._application = CuraApplication.getInstance() #type: CuraApplication + self._multi_build_plate_model = None #type: MultiBuildPlateModel + self._machine_error_checker = None #type: MachineErrorChecker if not default_engine_location: raise EnvironmentError("Could not find CuraEngine") @@ -121,11 +120,11 @@ class CuraEngineBackend(QObject, Backend): self._engine_is_fresh = True #type: bool # Is the newly started engine used before or not? self._backend_log_max_lines = 20000 #type: int # Maximum number of lines to buffer - self._error_message = None #type: Optional[Message] # Pop-up message that shows errors. + self._error_message = None #type: Message # Pop-up message that shows errors. self._last_num_objects = defaultdict(int) #type: Dict[int, int] # Count number of objects to see if there is something changed self._postponed_scene_change_sources = [] #type: List[SceneNode] # scene change is postponed (by a tool) - self._slice_start_time = time() #type: float + self._slice_start_time = None #type: Optional[float] self._is_disabled = False #type: bool self._application.getPreferences().addPreference("general/auto_slice", False) @@ -143,7 +142,8 @@ class CuraEngineBackend(QObject, Backend): self._application.initializationFinished.connect(self.initialize) def initialize(self) -> None: - self._multi_build_plate_model = self._application.getMultiBuildPlateModel() #type: MultiBuildPlateModel + self._multi_build_plate_model = self._application.getMultiBuildPlateModel() + self._application.getController().activeViewChanged.connect(self._onActiveViewChanged) self._multi_build_plate_model.activeBuildPlateChanged.connect(self._onActiveViewChanged) @@ -160,7 +160,7 @@ class CuraEngineBackend(QObject, Backend): self._application.getController().toolOperationStarted.connect(self._onToolOperationStarted) self._application.getController().toolOperationStopped.connect(self._onToolOperationStopped) - self._machine_error_checker = self._application.getMachineErrorChecker() #type: MachineErrorChecker + self._machine_error_checker = self._application.getMachineErrorChecker() self._machine_error_checker.errorCheckFinished.connect(self._onStackErrorCheckFinished) ## Terminate the engine process. @@ -310,11 +310,6 @@ class CuraEngineBackend(QObject, Backend): if self._start_slice_job is job: self._start_slice_job = None - if not self._global_container_stack: - self.backendStateChange.emit(BackendState.Error) - self.backendError.emit(job) - return - if job.isCancelled() or job.getError() or job.getResult() == StartJobResult.Error: self.backendStateChange.emit(BackendState.Error) self.backendError.emit(job) @@ -452,8 +447,7 @@ class CuraEngineBackend(QObject, Backend): # Only count sliceable objects if node.callDecoration("isSliceable"): build_plate_number = node.callDecoration("getBuildPlateNumber") - if build_plate_number is not None: - num_objects[build_plate_number] += 1 + num_objects[build_plate_number] += 1 return num_objects ## Listener for when the scene has changed. @@ -470,7 +464,7 @@ class CuraEngineBackend(QObject, Backend): if source.callDecoration("isBlockSlicing") and source.callDecoration("getLayerData"): self._stored_optimized_layer_data = {} - build_plate_changed = set() # type: Set[int] + build_plate_changed = set() source_build_plate_number = source.callDecoration("getBuildPlateNumber") if source == self._scene.getRoot(): # we got the root node @@ -482,15 +476,14 @@ class CuraEngineBackend(QObject, Backend): else: # we got a single scenenode if not source.callDecoration("isGroup"): - mesh_data = source.getMeshData() - if mesh_data is None: + if source.getMeshData() is None: return - elif mesh_data.getVertices() is None: + if source.getMeshData().getVertices() is None: return - if source_build_plate_number is not None: - build_plate_changed.add(source_build_plate_number) + build_plate_changed.add(source_build_plate_number) + build_plate_changed.discard(None) build_plate_changed.discard(-1) # object not on build plate if not build_plate_changed: return @@ -584,10 +577,9 @@ class CuraEngineBackend(QObject, Backend): # # \param message The protobuf message containing sliced layer data. def _onOptimizedLayerMessage(self, message: Arcus.PythonMessage) -> None: - if self._start_slice_job_build_plate is not None: - if self._start_slice_job_build_plate not in self._stored_optimized_layer_data: - self._stored_optimized_layer_data[self._start_slice_job_build_plate] = [] - self._stored_optimized_layer_data[self._start_slice_job_build_plate].append(message) + if self._start_slice_job_build_plate not in self._stored_optimized_layer_data: + self._stored_optimized_layer_data[self._start_slice_job_build_plate] = [] + self._stored_optimized_layer_data[self._start_slice_job_build_plate].append(message) ## Called when a progress message is received from the engine. # @@ -666,10 +658,7 @@ class CuraEngineBackend(QObject, Backend): ## Creates a new socket connection. def _createSocket(self, protocol_file: str = None) -> None: if not protocol_file: - plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId()) - if not plugin_path: - return - protocol_file = os.path.abspath(os.path.join(plugin_path, "Cura.proto")) + protocol_file = os.path.abspath(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "Cura.proto")) super()._createSocket(protocol_file) self._engine_is_fresh = True diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 8e429da14d..78dd4eafd2 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -114,14 +114,13 @@ class StartSliceJob(Job): self.setResult(StartJobResult.Error) return - global_stack = CuraApplication.getInstance().getGlobalContainerStack() - machine_manager = CuraApplication.getInstance().getMachineManager() - if not global_stack: + stack = CuraApplication.getInstance().getGlobalContainerStack() + if not stack: self.setResult(StartJobResult.Error) return # Don't slice if there is a setting with an error value. - if machine_manager.stacksHaveErrors: + if CuraApplication.getInstance().getMachineManager().stacksHaveErrors: self.setResult(StartJobResult.SettingError) return @@ -130,12 +129,12 @@ class StartSliceJob(Job): return # Don't slice if the buildplate or the nozzle type is incompatible with the materials - if not machine_manager.variantBuildplateCompatible and \ - not machine_manager.variantBuildplateUsable: + if not CuraApplication.getInstance().getMachineManager().variantBuildplateCompatible and \ + not CuraApplication.getInstance().getMachineManager().variantBuildplateUsable: self.setResult(StartJobResult.MaterialIncompatible) return - for position, extruder_stack in global_stack.extruders.items(): + for position, extruder_stack in stack.extruders.items(): material = extruder_stack.findContainer({"type": "material"}) if not extruder_stack.isEnabled: continue @@ -163,7 +162,7 @@ class StartSliceJob(Job): # Get the objects in their groups to print. object_groups = [] - if global_stack.getProperty("print_sequence", "value") == "one_at_a_time": + if stack.getProperty("print_sequence", "value") == "one_at_a_time": for node in OneAtATimeIterator(self._scene.getRoot()): #type: ignore #Ignore type error because iter() should get called automatically by Python syntax. temp_list = [] @@ -217,11 +216,12 @@ class StartSliceJob(Job): if temp_list: object_groups.append(temp_list) - extruders_enabled = {position: stack.isEnabled for position, stack in global_stack.extruders.items()} + extruders_enabled = {position: stack.isEnabled for position, stack in CuraApplication.getInstance().getGlobalContainerStack().extruders.items()} filtered_object_groups = [] has_model_with_disabled_extruders = False - associated_disabled_extruders = set() # type: Set[str] + associated_disabled_extruders = set() for group in object_groups: + stack = CuraApplication.getInstance().getGlobalContainerStack() skip_group = False for node in group: extruder_position = node.callDecoration("getActiveExtruderPosition") @@ -234,7 +234,7 @@ class StartSliceJob(Job): if has_model_with_disabled_extruders: self.setResult(StartJobResult.ObjectsWithDisabledExtruder) - associated_disabled_extruders = set([str(c) for c in sorted([int(p) + 1 for p in associated_disabled_extruders])]) + associated_disabled_extruders = [str(c) for c in sorted([int(p) + 1 for p in associated_disabled_extruders])] self.setMessage(", ".join(associated_disabled_extruders)) return @@ -245,11 +245,11 @@ class StartSliceJob(Job): self.setResult(StartJobResult.NothingToSlice) return - self._buildGlobalSettingsMessage(global_stack) - self._buildGlobalInheritsStackMessage(global_stack) + self._buildGlobalSettingsMessage(stack) + self._buildGlobalInheritsStackMessage(stack) # Build messages for extruder stacks - for extruder_stack in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()): + for extruder_stack in ExtruderManager.getInstance().getMachineExtruders(stack.getId()): self._buildExtruderMessage(extruder_stack) for group in filtered_object_groups: @@ -326,8 +326,6 @@ class StartSliceJob(Job): def _expandGcodeTokens(self, value: str, default_extruder_nr: int = -1) -> str: if not self._all_extruders_settings: global_stack = CuraApplication.getInstance().getGlobalContainerStack() - if not global_stack: - return str(value) # NB: keys must be strings for the string formatter self._all_extruders_settings = {