pySimBlocks.project.generate_sofa_controller¶
- pySimBlocks.project.generate_sofa_controller.detect_controller_file_from_scene(scene_file: Path) Path[source]¶
Determine the controller source file by loading the SOFA scene in a subprocess.
- Parameters:
scene_file – Path to the SOFA Python scene file. The scene’s
createScenefunction must return(root, controller).- Returns:
Path to the Python source file that defines the controller class.
- Raises:
RuntimeError – If the controller file cannot be determined (e.g. the scene does not return a controller).
- pySimBlocks.project.generate_sofa_controller.inject_base_dir(src: str) str[source]¶
Inject a
BASE_DIRdeclaration after the last import statement if not present.- Parameters:
src – Source code string of the controller file.
- Returns:
Source code with
BASE_DIR = Path(__file__).resolve().parentinjected.
- pySimBlocks.project.generate_sofa_controller.inject_project_path_into_controller(controller_file: Path, project_yaml: Path) None[source]¶
Inject or update the
self.project_yamlassignment in the controller__init__.- Parameters:
controller_file – Path to the controller Python source file.
project_yaml – Path to the
project.yamlfile to reference from the controller.
- pySimBlocks.project.generate_sofa_controller.generate_sofa_controller(project_dir: Path | None = None, project_yaml: Path | None = None) None[source]¶
Update the SOFA controller file with the project YAML path.
Finds the SOFA scene file from the project, detects the controller class, and injects or replaces the
self.project_yamlassignment so the controller can locate the project at runtime.Exactly one of
project_dirorproject_yamlmust be provided.- Parameters:
project_dir – Path to a project folder containing
project.yaml.project_yaml – Explicit path to a
project.yamlfile.
- Raises:
ValueError – If both or neither of
project_dir/project_yamlare given.FileNotFoundError – If
project.yamlor the scene file is not found.RuntimeError – If no SOFA block is found in the project or the controller file cannot be detected.