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
A model exposes only the modules of its own project. Cross-project
resolution (for example through use directives or path_id references)
is performed transparently by walking the project’s dependencies.
To iterate over the modules of a project together with the modules
of its dependencies, use
ansys.scadeone.core.project.Project.all_modules().
Model documentation#
- class ansys.scadeone.core.model.Model(project: IProject)#
Bases:
IModelPer-project model.
A
Modeldescribes the Swan content of a singleProject(modules in its ownassets/*.swan|.swani|.swant). Cross-project lookups (usedirectives,Lib::M::idpaths) are resolved by walking into the project’s dependencies’ models, with cycle protection.Loading of Swan sources is lazy: when a module body or interface is needed, it is loaded from the Swan source file.
- 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.
- filter_declarations(filter_fn: Callable[[GlobalDeclaration], bool], all: bool = True) List[GlobalDeclaration]#
Returns declarations matched by a filter.
- Parameters:
- Returns:
List[GlobalDeclaration]List of matching declarations.
- find_declaration(predicate_fn: Callable[[GlobalDeclaration], bool], all: bool = True) GlobalDeclaration | None#
- Finds a declaration for which predicate_fn returns True, else only declarations
from the modules of the model project are included.
- Parameters:
- Returns:
Union[GlobalDeclaration,None]Found declaration or None.
- get_declarations(all: bool = True) List[GlobalDeclaration]#
Returns a list of declarations in the model, including those from model project dependencies if all is True
- Parameters:
- allbool,
optional If True, include declarations from dependencies, by default True.
- allbool,
- Returns:
List[swan.GlobalDeclaration]List of all declarations.
- get_module_body(name: str) ModuleBody | None#
Returns module body of name ‘name’, searching dependencies on miss.
- 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’, searching dependencies on miss.
- load_all_modules(*, bodies: bool = True, interfaces: bool = True, test_modules: bool = True, dependencies: bool = True) None#
Loads systematically all modules.
- load_project(project_instance: IProject) Model#
Register the model’s bound project Swan sources as lazy
_PreModuleentries.- Parameters:
- project_instance
IProject Must be the project this model is bound to.
- project_instance
- Returns:
ModelItself, for chaining.
- Raises:
ScadeOneExceptionIf
project_instanceis not the project bound to this model.
- module_exists(module: Module | SwanFile) bool#
Check if a module exists by its path in the model.
- Parameters:
- module
swan.Module|SwanFile 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]#
Returns all modules (loaded Module objects, or not-yet-loaded module files) as a list.
- property constants: List[ConstDecl]#
Returns a list of constant declarations.
Note that this includes all constants, including those from model project dependencies. Consider using
Model.get_declarations()orModel.filter_declarations()for more general queries.
- property declarations: List[GlobalDeclaration]#
Declarations in the model.
Note that this includes all declarations, including those from dependencies. Consider using
Model.get_declarations()orModel.filter_declarations()for more general queries.
- property groups: List[GroupDecl]#
Returns a list of group declarations.
Note that this includes all groups, including those from model project dependencies. Consider using
Model.get_declarations()orModel.filter_declarations()for more general queries.
- property modules: List[Module]#
Returns Module objects of the current Model (module body, module interface, test module) as a list.
- property operator_declarations: List[OperatorDeclaration]#
Returns a list of operator declarations.
Note that this includes all operator declarations, including those from model project dependencies. Consider using
Model.get_declarations()orModel.filter_declarations()for more general queries.
- property operator_definitions: List[OperatorDefinition]#
Returns a list of operator definitions.
Note that this includes all operator definitions, including those from model project dependencies. Consider using
Model.get_declarations()orModel.filter_declarations()for more general queries.
- property parser: Parser#
Swan parser (shared at app level).
- property sensors: List[SensorDecl]#
Returns a list of sensor declarations.
Note that this includes all sensors, including those from model project dependencies. Consider using
Model.get_declarations()orModel.filter_declarations()for more general queries.
- property types: List[TypeDecl]#
Returns a list of type declarations.
Note that this includes all types, including those from model project dependencies. Consider using
Model.get_declarations()orModel.filter_declarations()for more general queries.
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’, searching dependencies on miss.