Coverage for klayout_pex/stl/pex25d_exporter.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-06 13:14 +0000

1# 

2# -------------------------------------------------------------------------------- 

3# SPDX-FileCopyrightText: 2024-2026 Martin Jan Köhler and Harald Pretl 

4# Johannes Kepler University, Institute for Integrated Circuits. 

5# 

6# This file is part of KPEX  

7# (see https://github.com/iic-jku/klayout-pex). 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21# SPDX-License-Identifier: GPL-3.0-or-later 

22# -------------------------------------------------------------------------------- 

23# 

24 

25""" 

26PEX25D scene → STL solids, the built-in exporter ``klayout-pex:stl``. 

27 

28For now the solids are those of the FasterCap model, so STL shows what FasterCap 

29and FastCap2 get. :func:`build_fastercap_model` is the only part of FasterCap this 

30exporter uses; it is meant to become independent of it. 

31""" 

32 

33from __future__ import annotations 

34 

35from dataclasses import dataclass 

36import os 

37from typing import TYPE_CHECKING, Any, ClassVar, List, Mapping, Optional 

38 

39from ..fastercap.pex25d_exporter import FasterCapModelOptions, build_fastercap_model 

40from ..plugin_api.v1 import ExportError, PEX25DSceneExporter 

41 

42if TYPE_CHECKING: 

43 from klayout_pex_protobuf.kpex.pex25d.pex25d_scene_pb2 import PEX25DScene 

44 

45 

46@dataclass 

47class STLExporterOptions(FasterCapModelOptions): 

48 """STL settings; for now those of the FasterCap model the solids come from.""" 

49 

50 

51class STLSceneExporter(PEX25DSceneExporter): 

52 """Write the solids of a resolved PEX25D scene as STL, one file per dielectric and net.""" 

53 

54 name: ClassVar[str] = 'stl' 

55 default_prefix: ClassVar[str] = '' 

56 

57 def export(self, 

58 scene: PEX25DScene, 

59 *, 

60 output_dir_path: str, 

61 prefix: str = '', 

62 options: Optional[Mapping[str, Any]] = None) -> List[str]: 

63 """Build the solids and write them; there is no primary file.""" 

64 try: 

65 settings = STLExporterOptions(**(options or {})) 

66 except TypeError as exc: 

67 raise ExportError(f"Invalid options for '{self.name}': {exc}") from exc 

68 

69 generator = build_fastercap_model(scene, settings, self.name) 

70 

71 os.makedirs(output_dir_path, exist_ok=True) 

72 return generator.dump_stl(output_dir_path=output_dir_path, 

73 prefix=prefix or self.default_prefix)