Basic classes#
This section contains the description of classes that are commonly used by other classes.
SwanItem class#
The SwanItem is the top-level class for all constructs.
- class ansys.scadeone.core.swan.SwanItem#
Base class for Scade objects.
- get_full_path() str#
Full path of the Swan construct.
This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.
- Returns:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf the method is not implemented for the current SwanItem type.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
HasPragma class#
The HasPragma is the top-level class for all constructs which have
pragmas. It is a subclass of SwanItem.
- class ansys.scadeone.core.swan.HasPragma(pragmas: List[Pragma] | None = None)#
Bases:
SwanItemBase class for objects with pragmas.
- get_full_path() str#
Full path of the Swan construct.
This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.
- Returns:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf the method is not implemented for the current SwanItem type.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
Identifier classes#
Swan identifiers are represented by the following classes with a simple identifier or a path identifier, which is a list of identifiers separated by ‘::’.
A luid (Luid) is used to name instances of operators, automata, or activate.
A lunum (Lunum) is used to reference a block in a Diagram.
- class ansys.scadeone.core.swan.Identifier(value: str, comment: str = '', is_name: bool = False)#
Bases:
SwanItemClass for identifier.
An Identifier can be invalid if it was protected while saving it for some reason. In that case, the property _is_valid_ is set to True.
- Parameters:
- get_full_path() str#
Full path of the Swan construct.
This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.
- Returns:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf the method is not implemented for the current SwanItem type.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
There is no specific derived class for protected Identifier, hence it is handled at by the Identifier class itself:
with the is_valid property: when false, the Identifier should be protected.
with the is_protected property: when true, the Identifier should be protected.
The two properties are complementary.
The __str__ method returns the Identifier value, with a protection markup when needed.
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
- class ansys.scadeone.core.swan.PathIdentifier(path_id: List[Identifier] | str)#
Bases:
SwanItemClass for path identifiers, i.e: P1::Id.
The class manipulates the PathIdentifier as separate items.
If the original path was protected (given as a string), the property is_valid is False, and the path is considered to be a single string and is_protected is True.
path_id argument is:
a list of identifiers, for a valid path.
a string if the path was protected.
- static from_string(path: str) PathIdentifier#
Create a PathIdentifier from a string.
- Parameters:
- path
str String containing the path identifier.
- path
- Returns:
PathIdentifierPathIdentifier instance.
- get_full_path() str#
Full path of the Swan construct.
This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.
- Returns:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf the method is not implemented for the current SwanItem type.
- classmethod is_valid_file_path(path: str) bool#
Check if path is a valid file path identifier, i.e. id {- id}, with no possible spaces around ‘-‘.
The path string is the basename of a module or an instance file.
- classmethod is_valid_path(path: str) bool#
Check if path is a valid path identifier, i.e. id {:: id}, with possible spaces around ‘::’.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
- property path_id: List[Identifier] | str#
PathId as a list of Identifier, or a string if protected.
- class ansys.scadeone.core.swan.Luid(value: str)#
Bases:
SwanItemClass for LUID support. The ‘$’ prefix is not saved (potentially removed at creation).
- get_full_path() str#
Full path of the Swan construct.
This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.
- Returns:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf the method is not implemented for the current SwanItem type.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
- class ansys.scadeone.core.swan.Lunum(value: str)#
Bases:
SwanItemClass for LUNUM support: ‘#’ is part of the LUNUM.
- get_full_path() str#
Full path of the Swan construct.
This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.
- Returns:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf the method is not implemented for the current SwanItem type.
- static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
Miscellaneous#
The following class is a helper for Swan literal expressions.
- class ansys.scadeone.core.swan.SwanRE#
Bases:
objectContainer of compiled regular expressions. These expressions can be matched with some strings. Some regular expressions use groups to extract parts.
Attributes:
- TypedInteger: regular expressions for integers with post type (_i, _ui).
Integer part is in the value group, type in the type group, and size in the size group.
- TypeFloat: regular expression for floats with post type (_f).
Mantissa is in the mantissa group, exponent in the exp group, type in the type group, and size in the size group.
- classmethod is_numeric(string: str) bool#
Check whether a string is a Swan numeric value, that is, an integer of float value.
- classmethod parse_float(string: str, minus: bool = False) FloatTuple | None#
Match a string representing a float and return a description of that float as a FloatTuple.
- Parameters:
- Returns:
FloatTupleorNoneIf the string value matches SwanRE.TypedFloat pattern, a FloatTuple is returned. It is a namedtuple with fields:
value: computed value
mantissa: the mantissa part
exp: the exponent part
size: the size part
Note: if there is no type information, type is _f32.
- classmethod parse_integer(string: str, minus: bool = False) IntegerTuple | None#
Matches a string representing an integer and returns a description of that integer as an IntegerTuple.
- Parameters:
- Returns:
IntegerTupleorNoneIf the string value matches SwanRE.TypedInteger pattern, an IntegerTuple is returned. It is a namedtuple with fields:
value: computed value
is_bin, is_oct, is_hex, is_dec: flags set according to found type
is_signed: True when integer is signed
size: the size part
Note: if there is no type information, type is _i32.