Model#

A Model object gives access to the model items defined in the Swan sources of a project. The unique Model instance of a project is the object returned by the ansys.scadeone.core.project.Project.model property of a project instance.

from ansys.scadeone.core import ScadeOne
with ScadeOne() as app:
    project = app.load_project('project.sproj')
    model = project.model

Model documentation#

class ansys.scadeone.core.model.Model#

Bases: object

Model handling class. A model contains module and interface declarations.

Loading of Swan sources is lazy.

configure(project_instance: IProject)#

Configures model for a given project. The configuration associates the project and the model and prepares internal data to store module bodies and interfaces.

It is called by ansys.scadeone.core.project.Project.model.

filter_declarations(filter_fn) List[GlobalDeclaration]#

Returns declarations matched by a filter.

Parameters:
filter_fnfunction

A function of one argument of type S.GlobalDeclaration, returning True or False.

Returns:
List[S.GlobalDeclaration]

List of matching declarations.

find_declaration(predicate_fn) GlobalDeclaration | None#

Finds a declaration for which predicate_fn returns True.

Parameters:
predicate_fnfunction

Function taking one S.GlobalDeclaration as argument and returning True when some property holds, else False.

Returns:
Union[S.GlobalDeclaration, None]

Found declaration or None.

get_module_body(name: str) ModuleBody | None#

Returns module body of name ‘name’

get_module_from_pathid(pathid: str, module: Module) Module | None#

Return the Module instance for a given pathid A path is of the form [ID ::]+ ID, where the last ID is the object name, and the “ID::ID…::” is the module path.

If the pathid has no path part (reduced to ID), return module.

Parameters:
pathidstr

object full path

moduleModule

Context module where the search occurs.

Returns:
Union[S.Module, None]

Module of the object, or None if not module found

get_module_interface(name: str) ModuleInterface | None#

Returns module interface of name ‘name’

static get_path_in_module(declaration: Declaration, module: Module) PathIdentifier#

Get the path of declaration in module. If the declaration is in module, return the identifier, else return the path of the declaration in the module based on the use directives.

Parameters:
item: SwanItem

Declaration to get the path for.

module: Module

Module where the declaration is used.

Returns:
PathIdentifier

Path of the item in the module.

Raises:
ScadeOneException
  • If the declaration does not have a module.

  • If the module does not exist.

  • If the module does not have a use directive for the declaration module.

get_test_harness(name: str) TestModule | None#

Returns module test harness of name ‘name’

load_all_modules(bodies: bool = True, interfaces: bool = True, harnesses: bool = True) None#

Loads systematically all modules.

Parameters:
bodiesbool, optional

Includes module bodies

interfacesbool, optional

Includes module interfaces

harnessesbool, optional

Includes test harnesses

module_exists(module: SwanFile | Module) bool#

Check if a module exists in the model.

Parameters:
module :Union[swan.SwanFile, swan.Module]

Module source or module object to check. In case of a source, it is not loaded.

Returns:
bool

True if the module exists, False otherwise.

property all_modules: List[Module | SwanFile]#

Returns all modules (loaded Module objects, or not-yet-loaded module files) as a list.

property all_modules_loaded: bool#

Returns True when all Swan modules have been loaded.

property constants: List[ConstDecl]#

Returns a list of constant declarations.

property declarations: List[GlobalDeclaration]#

Declarations found in all modules/interfaces as a list.

The Swan code of a module/interface is loaded if not yet loaded.

property groups: List[GroupDecl]#

Returns a list of group declarations.

property modules: List[Module]#

Returns all loaded Module objects (module body, interface, test module) as a list.

property operators: List[Operator]#

Returns a list of operator declarations.

property parser: SwanParser#

Swan parser.

property project: IProject#

Model project, as a Project object.

property sensors: List[SensorDecl]#

Returns a list of sensor declarations.

property signatures: List[Signature]#

Returns a list of operator signature declarations.

property types: List[TypeDecl]#

Returns a list of type declarations.