[docs]classAASModelUtils:"""This class contains utility methods related to the AAS model."""
[docs]@staticmethoddefread_aas_model_object_store():""" This method reads the AAS model according to the selected serialization format. Returns: basyx.aas.model.DictObjectStore: object with all Python elements of the AAS model. """object_store=Noneaas_model_file_path=properties_file_utils.get_aas_model_filepath()aas_model_file_name,aas_model_file_extension=path.splitext(SMIAGeneralInfo.CM_AAS_MODEL_FILENAME)try:# The AAS model is read depending on the serialization format (extension of the AAS model file)ifaas_model_file_extension=='.json':object_store=basyx.aas.adapter.json.read_aas_json_file(aas_model_file_path)elifaas_model_file_extension=='.xml':object_store=basyx.aas.adapter.xml.read_aas_xml_file(aas_model_file_path)elifaas_model_file_extension=='.aasx':withaasx.AASXReader(aas_model_file_path)asreader:# Read all contained AAS objects and all referenced auxiliary filesobject_store=model.DictObjectStore()suppl_file_store=aasx.DictSupplementaryFileContainer()reader.read_into(object_store=object_store,file_store=suppl_file_store)exceptValueErrorase:_logger.error("Failed to read AAS model: invalid file.")_logger.error(e)raiseCriticalError("Failed to read AAS model: invalid file.")ifobject_storeisNoneorlen(object_store)==0:raiseCriticalError("The AAS model is not valid. It is not possible to read and obtain elements of the AAS ""metamodel.")else:returnobject_store
# Methods related to AASX Package# -------------------------------
[docs]@staticmethoddefget_file_bytes_from_aasx_by_path(file_path):""" This method gets the bytes of a file appended inside an AASX package by a given internal path. Args: file_path (str): the internal path of the file within the AASX package. Returns: obj: the content of the file in the form of bytes. """withaasx.AASXReader(properties_file_utils.get_aas_model_filepath())asaasx_reader:forpart_name,content_typeinaasx_reader.reader.list_parts():ifpart_name==file_path:returnaasx_reader.reader.open_part(part_name).read()else:_logger.warning("The file with path {} does not find within the AASX Package.".format(file_path))returnNone
# Methods related to the AAS model# --------------------------------
[docs]@staticmethoddefget_configuration_file_path_from_standard_submodel():""" This method gets the configuration file defined in the 'Software Nameplate' submodel, used as standard submodel for the SMIA software definition. Returns: str: path inside the AASX package of the configuration file. """# First, the AAS model need to be readobject_store=AASModelUtils.read_aas_model_object_store()soft_nameplate_config_paths=AASModelUtils.get_elem_of_software_nameplate_by_semantic_id(object_store)ifsoft_nameplate_config_pathsisNone:raiseCriticalError("Configuration of SMIA is required and it is not defined within the Software Nameplate submodel.")forconfig_path_eleminsoft_nameplate_config_paths:sm_elem=config_path_elem.get_sm_element_by_semantic_id(AASModelInfo.SEMANTIC_ID_SOFTWARE_NAMEPLATE_CONFIG_TYPE)if(sm_elemisnotNone)and(sm_elem.value=='initial configuration'):returnconfig_path_elem.get_sm_element_by_semantic_id(AASModelInfo.SEMANTIC_ID_SOFTWARE_NAMEPLATE_CONFIG_URI).valuereturnNone
[docs]@staticmethoddefget_elem_of_software_nameplate_by_semantic_id(object_store):""" This method obtains a SubmodelElement of the Software Nameplate submodel. Args: object_store (basyx.aas.model.DictObjectStore): storage with all AAS information, Returns: basyx.aas.model.SubmodelElement: submodelElement with the given semanticID """forobjectinobject_store:ifisinstance(object,basyx.aas.model.Submodel):ifobject.check_semantic_id_exist(AASModelInfo.SEMANTICID_SOFTWARE_NAMEPLATE_SUBMODEL):forelemintraversal.walk_submodel(object):ifisinstance(elem,basyx.aas.model.SubmodelElement):ifelem.check_semantic_id_exist(AASModelInfo.SEMANTIC_ID_SOFTWARE_NAMEPLATE_CONFIG_PATHS):returnelemreturnNone
[docs]@staticmethodasyncdefget_key_type_by_string(key_type_string):""" This method gets the KeyType defined in BaSyx SDK related to the given string. Args: key_type_string (str): string of the desired KeyType. Returns: basyx.aas.model.KeyTypes: object of the KeyType defined in BaSyx. """try:returngetattr(basyx.aas.model.KeyTypes,key_type_string)exceptAttributeErrorase:_logger.error(e)raiseAASModelReadingError("The KeyType with string {} does not exist in the AAS model defined"" types".format(key_type_string),sme_class=None,reason='KeyTypeAttributeError')
[docs]@staticmethodasyncdefget_model_type_by_key_type(key_type):""" This method gets the AAS model class by a given KeyType defined in BaSyx SDK. Args: key_type (basyx.aas.model.KeyTypes): desired KeyType. Returns: object of the AAS model class. """formodel_class,key_type_classinbasyx.aas.model.KEY_TYPES_CLASSES.items():ifkey_type_class==key_type:returnmodel_classreturnNone
[docs]@staticmethodasyncdefcreate_aas_reference_object(reference_type,keys_dict=None,external_ref=None):""" This method creates the AAS BaSyx Reference Python object. Depending on the reference type to create (ModelReference or ExternalReference), some information is required. If a Reference cannot be created, it returns None. Args: reference_type (str): type of the reference to be created (ModelReference or ExternalReference). keys_dict (list): if ModelReference is selected, the required keys information in form of a JSON array. external_ref (str): if ExternalReference is selected, the required globally unique identifier. Returns: basyx.aas.model.Reference: BaSyx Python object of the AAS Reference. """ref_object=Noneif'ModelReference'==reference_type:keys=()last_type=Noneforkeyinkeys_dict:basyx_key_type=awaitAASModelUtils.get_key_type_by_string(key['type'])keys+=(model.Key(basyx_key_type,key['value']),)last_type=basyx_key_typeref_object=basyx.aas.model.ModelReference(key=keys,type_=awaitAASModelUtils.get_model_type_by_key_type(last_type))elif'ExternalReference'==reference_type:ref_object=model.ExternalReference((model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE,value=external_ref),))returnref_object
[docs]classAASModelInfo:"""This class contains the information related to AAS model."""SEMANTICID_SOFTWARE_NAMEPLATE_SUBMODEL='https://admin-shell.io/idta/SoftwareNameplate/1/0'SEMANTICID_SOFTWARE_NAMEPLATE_INSTANCE_NAME=('https://admin-shell.io/idta/SoftwareNameplate/1/0/SoftwareNameplate''/SoftwareNameplateInstance/InstanceName')SEMANTIC_ID_SOFTWARE_NAMEPLATE_CONFIG_PATHS=('https://admin-shell.io/idta/SoftwareNameplate/1/0''/SoftwareNameplate/SoftwareNameplateInstance/ConfigurationPaths')SEMANTIC_ID_SOFTWARE_NAMEPLATE_CONFIG_TYPE=('https://admin-shell.io/idta/SoftwareNameplate/1/0/SoftwareNameplate''/SoftwareNameplateInstance/ConfigurationType')SEMANTIC_ID_SOFTWARE_NAMEPLATE_CONFIG_URI=('https://admin-shell.io/idta/SoftwareNameplate/1/0/SoftwareNameplate''/SoftwareNameplateInstance/ConfigurationURI')
# TODO pasar aqui todos los IDs requeridos en el AAS (p.e el de AID submodel)