CGMapping#
Entry point#
The CGMapping class provides the entry point to the Code Generator (CG) mapping information.
Use the from_file() method to create an instance
of CGMapping from a CG mapping file (cg_map.json).
from ansys.scadeone.core.svc.cgmapping import CGMapping
cg_mapping = CGMapping.from_file("path/to/cg_map.json")
Helpful methods#
Model queries
get_model_by_path()- Get model items by full path.get_model_by_name()- Get model items by name.get_all_operators()- Get all operators (including monomorphized ones).get_root_operators()- Get operators marked as root.get_all_constants()- Get all constants.get_all_sensors()- Get all sensors.get_all_types()- Get all type declarations.
Code queries
get_code_by_name()- Get code items by name.get_all_code_containers()- Get all code containers.
Mapping queries
get_generated_element()- Get the generated element associated to a model item.get_model_element()- Get the model element associated to a code item.
Statistics
get_statistics()- Get some statistics on loaded mapping data.
API Documentation#
High-level user-facing interface for Swan Code Generator mapping data.
This module provides the main CGMapping class that encapsulates all functionality for querying CG mapping data. It hides internal implementation details and provides intuitive methods for accessing model and code items and their relationships.
- class ansys.scadeone.core.svc.cgmapping.cgmapping.CGMapping(data: CGMappingData)#
Bases:
MappingDataBaseHigh-level interface for querying code generator mapping data.
This class provides a user-friendly API to access Swan model items, C code items, and their mappings. It encapsulates the internal registries and provides convenient methods for common queries.
- Attributes:
- version
str File format version from the loaded data.
- version
- get_all_code_containers() list[CodeContainer]#
Get all code containers (files with declarations).
- Returns:
list[CodeContainer]List of all code containers.
- get_all_constants() list[ModelConstant]#
Get all model constants.
- Returns:
list[ModelConstant]List of all constant items.
- get_all_operators() list[ModelOperator | ModelMonoOperator]#
Get all operators (both regular and monomorphized).
- Returns:
list[ModelOperator|ModelMonoOperator]List of all operator items.
- get_all_sensors() list[ModelSensor]#
Get all model sensors.
- Returns:
list[ModelSensor]List of all sensor items.
- get_all_types() list[ModelElement]#
Get all type declarations (predefined, named, array, struct, enum, variant).
- Returns:
list[ModelElement]List of all type declaration items.
- get_code_by_name(name: str) list[CodeElement]#
Get code items by their name.
- get_model_by_name(name: str) list[ModelElement]#
Get model items by their name.
For items with a ‘path’ attribute, this searches for the last component of the path (after the last ‘::’).
- get_model_by_path(path: str) list[ModelElement]#
Get model items by their path.
- get_root_operators() list[ModelOperator]#
Get all root operators.
- Returns:
list[ModelOperator]List of operators marked as root.
- get_statistics() dict#
Get statistics about the loaded mapping data.
version: File format version
model_items: Total number of model items
code_items: Total number of code items
code_containers: Total number of code containers
mappings: Total number of mappings
operators: Total number of operators
root_operators: Total number of root operators
constants: Total number of constants
sensors: Total number of sensors
types: Total number of types
- Returns:
dictDictionary containing statistics like counts of various items.