mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 05:05:53 +08:00
Updated typing
This commit is contained in:
parent
432b0837ce
commit
33c97fcf4a
@ -4,7 +4,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from typing import cast, TYPE_CHECKING, Optional, Callable
|
from typing import cast, TYPE_CHECKING, Optional, Callable, List
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
@ -665,12 +665,12 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
## Handle loading of all plugin types (and the backend explicitly)
|
## Handle loading of all plugin types (and the backend explicitly)
|
||||||
# \sa PluginRegistry
|
# \sa PluginRegistry
|
||||||
def _loadPlugins(self):
|
def _loadPlugins(self) -> None:
|
||||||
self._plugin_registry.addType("profile_reader", self._addProfileReader)
|
self._plugin_registry.addType("profile_reader", self._addProfileReader)
|
||||||
self._plugin_registry.addType("profile_writer", self._addProfileWriter)
|
self._plugin_registry.addType("profile_writer", self._addProfileWriter)
|
||||||
|
|
||||||
if Platform.isLinux():
|
if Platform.isLinux():
|
||||||
lib_suffixes = {"", "64", "32", "x32"} #A few common ones on different distributions.
|
lib_suffixes = {"", "64", "32", "x32"} # A few common ones on different distributions.
|
||||||
else:
|
else:
|
||||||
lib_suffixes = {""}
|
lib_suffixes = {""}
|
||||||
for suffix in lib_suffixes:
|
for suffix in lib_suffixes:
|
||||||
@ -1267,62 +1267,75 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
## Arrange all objects.
|
## Arrange all objects.
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def arrangeObjectsToAllBuildPlates(self):
|
def arrangeObjectsToAllBuildPlates(self) -> None:
|
||||||
nodes = []
|
nodes_to_arrange = []
|
||||||
for node in DepthFirstIterator(self.getController().getScene().getRoot()):
|
for node in DepthFirstIterator(self.getController().getScene().getRoot()): # type: ignore
|
||||||
if not isinstance(node, SceneNode):
|
if not isinstance(node, SceneNode):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not node.getMeshData() and not node.callDecoration("isGroup"):
|
if not node.getMeshData() and not node.callDecoration("isGroup"):
|
||||||
continue # Node that doesnt have a mesh and is not a group.
|
continue # Node that doesnt have a mesh and is not a group.
|
||||||
if node.getParent() and node.getParent().callDecoration("isGroup"):
|
|
||||||
continue # Grouped nodes don't need resetting as their parent (the group) is resetted)
|
parent_node = node.getParent()
|
||||||
|
if parent_node and parent_node.callDecoration("isGroup"):
|
||||||
|
continue # Grouped nodes don't need resetting as their parent (the group) is reset)
|
||||||
|
|
||||||
if not node.callDecoration("isSliceable") and not node.callDecoration("isGroup"):
|
if not node.callDecoration("isSliceable") and not node.callDecoration("isGroup"):
|
||||||
continue # i.e. node with layer data
|
continue # i.e. node with layer data
|
||||||
|
|
||||||
|
bounding_box = node.getBoundingBox()
|
||||||
# Skip nodes that are too big
|
# Skip nodes that are too big
|
||||||
if node.getBoundingBox().width < self._volume.getBoundingBox().width or node.getBoundingBox().depth < self._volume.getBoundingBox().depth:
|
if bounding_box is None or bounding_box.width < self._volume.getBoundingBox().width or bounding_box.depth < self._volume.getBoundingBox().depth:
|
||||||
nodes.append(node)
|
nodes_to_arrange.append(node)
|
||||||
job = ArrangeObjectsAllBuildPlatesJob(nodes)
|
job = ArrangeObjectsAllBuildPlatesJob(nodes_to_arrange)
|
||||||
job.start()
|
job.start()
|
||||||
self.getCuraSceneController().setActiveBuildPlate(0) # Select first build plate
|
self.getCuraSceneController().setActiveBuildPlate(0) # Select first build plate
|
||||||
|
|
||||||
# Single build plate
|
# Single build plate
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def arrangeAll(self):
|
def arrangeAll(self) -> None:
|
||||||
nodes = []
|
nodes_to_arrange = []
|
||||||
active_build_plate = self.getMultiBuildPlateModel().activeBuildPlate
|
active_build_plate = self.getMultiBuildPlateModel().activeBuildPlate
|
||||||
for node in DepthFirstIterator(self.getController().getScene().getRoot()):
|
for node in DepthFirstIterator(self.getController().getScene().getRoot()): # type: ignore
|
||||||
if not isinstance(node, SceneNode):
|
if not isinstance(node, SceneNode):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not node.getMeshData() and not node.callDecoration("isGroup"):
|
if not node.getMeshData() and not node.callDecoration("isGroup"):
|
||||||
continue # Node that doesnt have a mesh and is not a group.
|
continue # Node that doesnt have a mesh and is not a group.
|
||||||
if node.getParent() and node.getParent().callDecoration("isGroup"):
|
|
||||||
|
parent_node = node.getParent()
|
||||||
|
if parent_node and parent_node.callDecoration("isGroup"):
|
||||||
continue # Grouped nodes don't need resetting as their parent (the group) is resetted)
|
continue # Grouped nodes don't need resetting as their parent (the group) is resetted)
|
||||||
|
|
||||||
if not node.isSelectable():
|
if not node.isSelectable():
|
||||||
continue # i.e. node with layer data
|
continue # i.e. node with layer data
|
||||||
|
|
||||||
if not node.callDecoration("isSliceable") and not node.callDecoration("isGroup"):
|
if not node.callDecoration("isSliceable") and not node.callDecoration("isGroup"):
|
||||||
continue # i.e. node with layer data
|
continue # i.e. node with layer data
|
||||||
|
|
||||||
if node.callDecoration("getBuildPlateNumber") == active_build_plate:
|
if node.callDecoration("getBuildPlateNumber") == active_build_plate:
|
||||||
# Skip nodes that are too big
|
# Skip nodes that are too big
|
||||||
if node.getBoundingBox().width < self._volume.getBoundingBox().width or node.getBoundingBox().depth < self._volume.getBoundingBox().depth:
|
bounding_box = node.getBoundingBox()
|
||||||
nodes.append(node)
|
if bounding_box is None or bounding_box.width < self._volume.getBoundingBox().width or bounding_box.depth < self._volume.getBoundingBox().depth:
|
||||||
self.arrange(nodes, fixed_nodes = [])
|
nodes_to_arrange.append(node)
|
||||||
|
self.arrange(nodes_to_arrange, fixed_nodes = [])
|
||||||
|
|
||||||
## Arrange a set of nodes given a set of fixed nodes
|
## Arrange a set of nodes given a set of fixed nodes
|
||||||
# \param nodes nodes that we have to place
|
# \param nodes nodes that we have to place
|
||||||
# \param fixed_nodes nodes that are placed in the arranger before finding spots for nodes
|
# \param fixed_nodes nodes that are placed in the arranger before finding spots for nodes
|
||||||
def arrange(self, nodes, fixed_nodes):
|
def arrange(self, nodes: List[SceneNode], fixed_nodes: List[SceneNode]) -> None:
|
||||||
min_offset = self.getBuildVolume().getEdgeDisallowedSize() + 2 # Allow for some rounding errors
|
min_offset = self.getBuildVolume().getEdgeDisallowedSize() + 2 # Allow for some rounding errors
|
||||||
job = ArrangeObjectsJob(nodes, fixed_nodes, min_offset = max(min_offset, 8))
|
job = ArrangeObjectsJob(nodes, fixed_nodes, min_offset = max(min_offset, 8))
|
||||||
job.start()
|
job.start()
|
||||||
|
|
||||||
## Reload all mesh data on the screen from file.
|
## Reload all mesh data on the screen from file.
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def reloadAll(self):
|
def reloadAll(self) -> None:
|
||||||
Logger.log("i", "Reloading all loaded mesh data.")
|
Logger.log("i", "Reloading all loaded mesh data.")
|
||||||
nodes = []
|
nodes = []
|
||||||
has_merged_nodes = False
|
has_merged_nodes = False
|
||||||
for node in DepthFirstIterator(self.getController().getScene().getRoot()):
|
for node in DepthFirstIterator(self.getController().getScene().getRoot()): # type: ignore
|
||||||
if not isinstance(node, CuraSceneNode) or not node.getMeshData() :
|
if not isinstance(node, CuraSceneNode) or not node.getMeshData():
|
||||||
if node.getName() == "MergedMesh":
|
if node.getName() == "MergedMesh":
|
||||||
has_merged_nodes = True
|
has_merged_nodes = True
|
||||||
continue
|
continue
|
||||||
@ -1336,7 +1349,7 @@ class CuraApplication(QtApplication):
|
|||||||
file_name = node.getMeshData().getFileName()
|
file_name = node.getMeshData().getFileName()
|
||||||
if file_name:
|
if file_name:
|
||||||
job = ReadMeshJob(file_name)
|
job = ReadMeshJob(file_name)
|
||||||
job._node = node
|
job._node = node # type: ignore
|
||||||
job.finished.connect(self._reloadMeshFinished)
|
job.finished.connect(self._reloadMeshFinished)
|
||||||
if has_merged_nodes:
|
if has_merged_nodes:
|
||||||
job.finished.connect(self.updateOriginOfMergedMeshes)
|
job.finished.connect(self.updateOriginOfMergedMeshes)
|
||||||
@ -1345,20 +1358,8 @@ class CuraApplication(QtApplication):
|
|||||||
else:
|
else:
|
||||||
Logger.log("w", "Unable to reload data because we don't have a filename.")
|
Logger.log("w", "Unable to reload data because we don't have a filename.")
|
||||||
|
|
||||||
|
|
||||||
## Get logging data of the backend engine
|
|
||||||
# \returns \type{string} Logging data
|
|
||||||
@pyqtSlot(result = str)
|
|
||||||
def getEngineLog(self):
|
|
||||||
log = ""
|
|
||||||
|
|
||||||
for entry in self.getBackend().getLog():
|
|
||||||
log += entry.decode()
|
|
||||||
|
|
||||||
return log
|
|
||||||
|
|
||||||
@pyqtSlot("QStringList")
|
@pyqtSlot("QStringList")
|
||||||
def setExpandedCategories(self, categories):
|
def setExpandedCategories(self, categories: List[str]) -> None:
|
||||||
categories = list(set(categories))
|
categories = list(set(categories))
|
||||||
categories.sort()
|
categories.sort()
|
||||||
joined = ";".join(categories)
|
joined = ";".join(categories)
|
||||||
@ -1369,7 +1370,7 @@ class CuraApplication(QtApplication):
|
|||||||
expandedCategoriesChanged = pyqtSignal()
|
expandedCategoriesChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtProperty("QStringList", notify = expandedCategoriesChanged)
|
@pyqtProperty("QStringList", notify = expandedCategoriesChanged)
|
||||||
def expandedCategories(self):
|
def expandedCategories(self) -> List[str]:
|
||||||
return self.getPreferences().getValue("cura/categories_expanded").split(";")
|
return self.getPreferences().getValue("cura/categories_expanded").split(";")
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
@ -1419,13 +1420,12 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
|
|
||||||
## Updates origin position of all merged meshes
|
## Updates origin position of all merged meshes
|
||||||
# \param jobNode \type{Job} empty object which passed which is required by JobQueue
|
def updateOriginOfMergedMeshes(self, _):
|
||||||
def updateOriginOfMergedMeshes(self, jobNode):
|
|
||||||
group_nodes = []
|
group_nodes = []
|
||||||
for node in DepthFirstIterator(self.getController().getScene().getRoot()):
|
for node in DepthFirstIterator(self.getController().getScene().getRoot()):
|
||||||
if isinstance(node, CuraSceneNode) and node.getName() == "MergedMesh":
|
if isinstance(node, CuraSceneNode) and node.getName() == "MergedMesh":
|
||||||
|
|
||||||
#checking by name might be not enough, the merged mesh should has "GroupDecorator" decorator
|
# Checking by name might be not enough, the merged mesh should has "GroupDecorator" decorator
|
||||||
for decorator in node.getDecorators():
|
for decorator in node.getDecorators():
|
||||||
if isinstance(decorator, GroupDecorator):
|
if isinstance(decorator, GroupDecorator):
|
||||||
group_nodes.append(node)
|
group_nodes.append(node)
|
||||||
@ -1469,7 +1469,7 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def groupSelected(self):
|
def groupSelected(self) -> None:
|
||||||
# Create a group-node
|
# Create a group-node
|
||||||
group_node = CuraSceneNode()
|
group_node = CuraSceneNode()
|
||||||
group_decorator = GroupDecorator()
|
group_decorator = GroupDecorator()
|
||||||
@ -1485,7 +1485,8 @@ class CuraApplication(QtApplication):
|
|||||||
# Remove nodes that are directly parented to another selected node from the selection so they remain parented
|
# Remove nodes that are directly parented to another selected node from the selection so they remain parented
|
||||||
selected_nodes = Selection.getAllSelectedObjects().copy()
|
selected_nodes = Selection.getAllSelectedObjects().copy()
|
||||||
for node in selected_nodes:
|
for node in selected_nodes:
|
||||||
if node.getParent() in selected_nodes and not node.getParent().callDecoration("isGroup"):
|
parent = node.getParent()
|
||||||
|
if parent is not None and node in selected_nodes and not node.callDecoration("isGroup"):
|
||||||
Selection.remove(node)
|
Selection.remove(node)
|
||||||
|
|
||||||
# Move selected nodes into the group-node
|
# Move selected nodes into the group-node
|
||||||
@ -1497,7 +1498,7 @@ class CuraApplication(QtApplication):
|
|||||||
Selection.add(group_node)
|
Selection.add(group_node)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def ungroupSelected(self):
|
def ungroupSelected(self) -> None:
|
||||||
selected_objects = Selection.getAllSelectedObjects().copy()
|
selected_objects = Selection.getAllSelectedObjects().copy()
|
||||||
for node in selected_objects:
|
for node in selected_objects:
|
||||||
if node.callDecoration("isGroup"):
|
if node.callDecoration("isGroup"):
|
||||||
@ -1520,7 +1521,7 @@ class CuraApplication(QtApplication):
|
|||||||
# Note: The group removes itself from the scene once all its children have left it,
|
# Note: The group removes itself from the scene once all its children have left it,
|
||||||
# see GroupDecorator._onChildrenChanged
|
# see GroupDecorator._onChildrenChanged
|
||||||
|
|
||||||
def _createSplashScreen(self):
|
def _createSplashScreen(self) -> Optional[CuraSplashScreen.CuraSplashScreen]:
|
||||||
if self._is_headless:
|
if self._is_headless:
|
||||||
return None
|
return None
|
||||||
return CuraSplashScreen.CuraSplashScreen()
|
return CuraSplashScreen.CuraSplashScreen()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user