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

Code queries

Mapping queries

Statistics

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: MappingDataBase

High-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:
versionstr

File format version from the loaded data.

classmethod from_file(file_path: str | Path) → CGMapping#

Load mapping data from a JSON file.

Parameters:
file_pathstr | Path

Path to the JSON file to load.

Returns:
CGMapping

A new CGMapping instance with loaded data.

Raises:
ScadeOneException

If the file cannot be read or parsed or if the specified file does not exist.

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.

Parameters:
namestr

The name to search for.

Returns:
list[CodeElement]

List of code items with the specified 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 ‘::’).

Parameters:
namestr

The name to search for.

Returns:
list[ModelElement]

List of model items matching the name.

get_model_by_path(path: str) → list[ModelElement]#

Get model items by their path.

Parameters:
pathstr

The path to search for (e.g., “MyPackage::MyOperator”).

Returns:
list[ModelElement]

List of model items with the specified 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:
dict

Dictionary containing statistics like counts of various items.