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 = app.model
Model documentation#
- class ansys.scadeone.core.model.Model(app: IScadeOne)#
Bases:
IModelModel handling class. A model contains module and interface declarations.
Loading of Swan sources is lazy: when a module body or interface is needed, it is loaded from the Swan source file.
The IModel base class is an empty interface implemented by the Model class.
- configure(project_instance: IProject) Model#
Configure the model with a project instance.
Deprecated since version 0.7,: use
load_project()instead.
- filter_declarations(filter_fn: Callable[[GlobalDeclaration], bool]) List[GlobalDeclaration]#
Returns declarations matched by a filter.
- Parameters:
- filter_fn
Callable[[GlobalDeclaration], bool] A function of one argument of type GlobalDeclaration, returning True or False.
- filter_fn
- Returns:
List[GlobalDeclaration]List of matching declarations.
- find_declaration(predicate_fn: Callable[[GlobalDeclaration], bool]) GlobalDeclaration | None#
Finds a declaration for which predicate_fn returns True.
- 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
Moduleinstance for a given pathid A pathId is of the form [ID ::]+ ID, where the last ID is the object name, and the previous IDs with “::” form the the module full name.If module’s name is reduced to a single ID, search for the module from the use directive in module.
If the pathid is reduced to a single ID, return module.
- 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:
PathIdentifierPath of the item in the module.
- Raises:
ScadeOneExceptionIf 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.
- load_all_modules(bodies: bool = True, interfaces: bool = True, test_modules: bool = True) None#
Loads systematically all modules.
- load_project(project_instance: IProject) Model#
Add model information from a given project. It prepares internal data to store module bodies and interfaces.
- Parameters:
- project_instance
IProject Project instance to load.
- project_instance
- Returns:
ModelItself, for chaining.
- module_exists(module: Module) bool#
Check if a module exists by its path in the model.
- Parameters:
- module
swan.Module Module source or module object to check. In case of a source, it is not loaded.
- module
- 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 app: IScadeOne#
Scade One application instance.
- property declarations: List[GlobalDeclaration]#
Declarations found in all modules as a list.
The Swan code of a module is loaded if not yet loaded.
- property modules: List[Module]#
Returns all loaded Module objects (module body, module interface interface, test module) as a list.
- property operator_declarations: List[OperatorDeclaration]#
Returns a list of operator declarations.
- property operator_definitions: List[OperatorDefinition]#
Returns a list of operator definitions.
- property parser: SwanParser#
Swan parser.
- property sensors: List[SensorDecl]#
Returns a list of sensor declarations.
A model also handles test modules, see Swan Test constructs section.
- Model.add_test_module(swan_elt: SwanFile | TestModule) None#
Add a test module to the model.
- Parameters:
- swan_elt
Union[swan.SwanFile,swan.TestModule] Content of the test module
- swan_elt
- Model.get_test_module(name: str) TestModule | None#
Returns test module of name ‘name’