diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index 4567226060..21ab8e16aa 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -211,6 +211,34 @@ class CuraContainerRegistry(ContainerRegistry): return { "status": "error", "message": catalog.i18nc("@info:status Don't translate the XML tags or !", "Failed to import profile from {0}: {1}", file_name, str(e))} if profile_or_list: + # Ensure it is always a list of profiles + if not isinstance(profile_or_list, list): + profile_or_list = [profile_or_list] + + # First check if this profile is suitable for this machine + global_profile = None + if len(profile_or_list) == 1: + global_profile = profile_or_list[0] + else: + for profile in profile_or_list: + if not profile.getMetaDataEntry("extruder"): + global_profile = profile + break + if not global_profile: + Logger.log("e", "Incorrect profile [%s]. Could not find global profile", file_name) + return { "status": "error", + "message": catalog.i18nc("@info:status Don't translate the XML tags or !", "This profile {0} contains incorrect data, could not import it.", file_name)} + profile_definition = global_profile.getMetaDataEntry("definition") + expected_machine_definition = "fdmprinter" + if global_container_stack.getMetaDataEntry("has_machine_quality"): + expected_machine_definition = global_container_stack.getMetaDataEntry("quality_definition") + if not expected_machine_definition: + expected_machine_definition = global_container_stack.definition.getId() + if expected_machine_definition is not None and profile_definition is not None and profile_definition != expected_machine_definition: + Logger.log("e", "Profile [%s] is for machine [%s] but the current active machine is [%s]. Will not import the profile", file_name) + return { "status": "error", + "message": catalog.i18nc("@info:status Don't translate the XML tags or !", "The machine defined in profile {0} doesn't match with your current machine, could not import it.", file_name)} + name_seed = os.path.splitext(os.path.basename(file_name))[0] new_name = self.uniqueName(name_seed)