mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-29 09:38:21 +08:00
Merge branch 'main' into Cura_ankermake_august
This commit is contained in:
commit
8b0f208ee7
@ -3,6 +3,7 @@ checks:
|
||||
diagnostic-mesh-file-size: true
|
||||
diagnostic-definition-redundant-override: true
|
||||
diagnostic-resources-macos-app-directory-name: true
|
||||
diagnostic-material-temperature-defined: true
|
||||
fixes:
|
||||
diagnostic-definition-redundant-override: true
|
||||
format:
|
||||
|
@ -21,18 +21,25 @@ class MaterialNode(ContainerNode):
|
||||
Its subcontainers are quality profiles.
|
||||
"""
|
||||
|
||||
def __init__(self, container_id: str, variant: "VariantNode") -> None:
|
||||
def __init__(self, container_id: str, variant: "VariantNode", *, container: ContainerInterface = None) -> None:
|
||||
super().__init__(container_id)
|
||||
self.variant = variant
|
||||
self.qualities = {} # type: Dict[str, QualityNode] # Mapping container IDs to quality profiles.
|
||||
self.materialChanged = Signal() # Triggered when the material is removed or its metadata is updated.
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
||||
self.base_file = my_metadata["base_file"]
|
||||
self.material_type = my_metadata["material"]
|
||||
self.brand = my_metadata["brand"]
|
||||
self.guid = my_metadata["GUID"]
|
||||
|
||||
if container is not None:
|
||||
self.base_file = container.getMetaDataEntry("base_file")
|
||||
self.material_type = container.getMetaDataEntry("material")
|
||||
self.brand = container.getMetaDataEntry("brand")
|
||||
self.guid = container.getMetaDataEntry("GUID")
|
||||
else:
|
||||
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
||||
self.base_file = my_metadata["base_file"]
|
||||
self.material_type = my_metadata["material"]
|
||||
self.brand = my_metadata["brand"]
|
||||
self.guid = my_metadata["GUID"]
|
||||
self._loadAll()
|
||||
container_registry.containerRemoved.connect(self._onRemoved)
|
||||
container_registry.containerMetaDataChanged.connect(self._onMetadataChanged)
|
||||
|
@ -148,7 +148,7 @@ class VariantNode(ContainerNode):
|
||||
|
||||
if "empty_material" in self.materials:
|
||||
del self.materials["empty_material"]
|
||||
self.materials[base_file] = MaterialNode(container.getId(), variant = self)
|
||||
self.materials[base_file] = MaterialNode(container.getId(), variant = self, container = container)
|
||||
self.materials[base_file].materialChanged.connect(self.materialsChanged)
|
||||
self.materialsChanged.emit(self.materials[base_file])
|
||||
|
||||
|
@ -28,6 +28,10 @@ class Definition(Linter):
|
||||
for check in self.checkRedefineOverride():
|
||||
yield check
|
||||
|
||||
if self._settings["checks"].get("diagnostic-material-temperature-defined", False):
|
||||
for check in self.checkMaterialTemperature():
|
||||
yield check
|
||||
|
||||
# Add other which will yield Diagnostic's
|
||||
# TODO: A check to determine if the user set value is with the min and max value defined in the parent and doesn't trigger a warning
|
||||
# TODO: A check if the key exist in the first place
|
||||
@ -41,7 +45,7 @@ class Definition(Linter):
|
||||
definition = self._definitions[definition_name]
|
||||
if "overrides" in definition and definition_name not in ("fdmprinter", "fdmextruder"):
|
||||
for key, value_dict in definition["overrides"].items():
|
||||
is_redefined, child_key, child_value, parent = self._isDefinedInParent(key, value_dict, definition['inherits'])
|
||||
is_redefined, child_key, child_value, parent, inherited_by= self._isDefinedInParent(key, value_dict, definition['inherits'])
|
||||
if is_redefined:
|
||||
redefined = re.compile(r'.*(\"' + key + r'\"[\s\:\S]*?)\{[\s\S]*?\},?')
|
||||
found = redefined.search(self._content)
|
||||
@ -59,12 +63,40 @@ class Definition(Linter):
|
||||
yield Diagnostic(
|
||||
file = self._file,
|
||||
diagnostic_name = "diagnostic-definition-redundant-override",
|
||||
message = f"Overriding {key} with the same value ({child_key}: {child_value}) as defined in parent definition: {definition['inherits']}",
|
||||
message = f"Overriding {key} with the same value ({child_key}: {child_value}) as defined in parent definition: {inherited_by}",
|
||||
level = "Warning",
|
||||
offset = found.span(0)[0],
|
||||
replacements = replacements
|
||||
)
|
||||
|
||||
def checkMaterialTemperature(self) -> Iterator[Diagnostic]:
|
||||
"""Checks if definition file has material tremperature defined within them"""
|
||||
definition_name = list(self._definitions.keys())[0]
|
||||
definition = self._definitions[definition_name]
|
||||
if "overrides" in definition and definition_name not in ("fdmprinter", "fdmextruder"):
|
||||
for key, value_dict in definition["overrides"].items():
|
||||
if "temperature" in key and "material" in key:
|
||||
|
||||
redefined = re.compile(r'.*(\"' + key + r'\"[\s\:\S]*?)\{[\s\S]*?\},?')
|
||||
found = redefined.search(self._content)
|
||||
if len(found.group().splitlines()) > 1:
|
||||
replacements = []
|
||||
else:
|
||||
replacements = [Replacement(
|
||||
file=self._file,
|
||||
offset=found.span(1)[0],
|
||||
length=len(found.group()),
|
||||
replacement_text="")]
|
||||
|
||||
yield Diagnostic(
|
||||
file=self._file,
|
||||
diagnostic_name="diagnostic-definition-redundant-override",
|
||||
message=f"Overriding {key} as it belongs to material temperature catagory and shouldn't be placed in machine definitions",
|
||||
level="Warning",
|
||||
offset=found.span(0)[0],
|
||||
replacements=replacements
|
||||
)
|
||||
|
||||
def _loadDefinitionFiles(self, definition_file) -> None:
|
||||
""" Loads definition file contents into self._definitions. Also load parent definition if it exists. """
|
||||
definition_name = Path(definition_file.stem).stem
|
||||
@ -85,7 +117,7 @@ class Definition(Linter):
|
||||
|
||||
def _isDefinedInParent(self, key, value_dict, inherits_from):
|
||||
if self._ignore(key, "diagnostic-definition-redundant-override"):
|
||||
return False, None, None, None
|
||||
return False, None, None, None, None
|
||||
if "overrides" not in self._definitions[inherits_from]:
|
||||
return self._isDefinedInParent(key, value_dict, self._definitions[inherits_from]["inherits"])
|
||||
|
||||
@ -114,11 +146,11 @@ class Definition(Linter):
|
||||
v = child_value
|
||||
cv = check_value
|
||||
if v == cv:
|
||||
return True, child_key, child_value, parent
|
||||
return True, child_key, child_value, parent, inherits_from
|
||||
|
||||
if "inherits" in parent:
|
||||
return self._isDefinedInParent(key, value_dict, parent["inherits"])
|
||||
return False, None, None, None
|
||||
return False, None, None, None, None
|
||||
|
||||
def _loadBasePrinterSettings(self):
|
||||
settings = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user