ocp-viewer-cadinterface 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ name: publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ pypi:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ with:
16
+ fetch-depth: 0 # the tags, which give the version
17
+
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+
22
+ - name: Build
23
+ run: pip install build && python -m build
24
+
25
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,27 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - uses: actions/setup-python@v5
14
+ with:
15
+ python-version: "3.12"
16
+
17
+ - name: System libraries for OCP
18
+ run: sudo apt-get update && sudo apt-get install -y libgl1 libglu1-mesa libxrender1
19
+
20
+ - name: Install
21
+ run: pip install -e ".[test]"
22
+
23
+ - name: Lint
24
+ run: ruff check . && ruff format --check .
25
+
26
+ - name: Test
27
+ run: pytest
@@ -0,0 +1,18 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .venv/
7
+ .pytest_cache/
8
+ .benchmarks/
9
+ .ipynb_checkpoints/
10
+
11
+ # CAD files written while experimenting
12
+ *.step
13
+ *.stp
14
+ *.brep
15
+ *.msh
16
+
17
+ # written by hatch-vcs from the git tag
18
+ ocp_viewer_cadinterface/_version.py
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 David Straub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.5
2
+ Name: ocp-viewer-cadinterface
3
+ Version: 0.1.0
4
+ Summary: Show any object that implements __cad_interface__ in the OCP viewers
5
+ Project-URL: Homepage, https://github.com/DavidMStraub/ocp-viewer-cadinterface
6
+ Project-URL: Protocol, https://github.com/DavidMStraub/cad-interface
7
+ Author: David Straub
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: build123d,cad,cad-interface,cadquery,occt,ocp,viewer
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: numpy
15
+ Requires-Dist: ocp-tessellate<3.8.0,>=3.7.0
16
+ Provides-Extra: test
17
+ Requires-Dist: build123d; extra == 'test'
18
+ Requires-Dist: ocp-viewer-core<1.3.0,>=1.2.0; extra == 'test'
19
+ Requires-Dist: ocp-vscode>=4.3; extra == 'test'
20
+ Requires-Dist: pytest; extra == 'test'
21
+ Requires-Dist: ruff; extra == 'test'
22
+ Requires-Dist: solidfunc>=0.1.0; extra == 'test'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # ocp-viewer-cadinterface
26
+
27
+ A plugin for the OCP viewers ([OCP CAD Viewer for VS Code](https://github.com/bernhard-42/vscode-ocp-cad-viewer),
28
+ OCP Viewer, Jupyter CadQuery, build123d Studio). With it, `show` and `show_all` display any
29
+ object that implements the [`__cad_interface__`](https://github.com/DavidMStraub/cad-interface)
30
+ protocol, and the viewer's measurement tools work on it, including between it and build123d
31
+ or CadQuery objects in the same scene.
32
+
33
+ ```python
34
+ import build123d as bd
35
+ import solidfunc as sf # a CAD library on a non-OCCT kernel
36
+ from ocp_vscode import show
37
+
38
+ plate = sf.box(size_x=80, size_y=50, size_z=10) - sf.cylinder(diameter=20, height=10)
39
+ cube = bd.Pos(65, 0, 5) * bd.Box(10, 10, 10)
40
+
41
+ show(plate, cube, names=["plate", "cube"]) # measure the 20 mm between them in the viewer
42
+ ```
43
+
44
+ [examples/demo.ipynb](examples/demo.ipynb) has the full example.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install ocp-viewer-cadinterface
50
+ ```
51
+
52
+ Install it in the environment your script runs in. Your script does not import it: the viewer
53
+ finds it through its entry point at the first `show`. A Jupyter kernel that has already shown
54
+ something needs a restart after the install.
55
+
56
+ The measurement backend's environment needs nothing extra, because the plugin hands only OCCT
57
+ shapes to the viewer (see below).
58
+
59
+ It needs ocp-tessellate 3.7 and, for the viewer, ocp-viewer-core 1.2 or later.
60
+
61
+ ## What it shows
62
+
63
+ - A `ShapeDict` in any version 1 format: `"ocp"`, `"brep_binary"`, `"brep_text"`, `"step"`.
64
+ The plugin asks for them in that order. `"ocp"` shapes are used as they are, without a copy.
65
+ - An `AssemblyDict`: a tree of groups, with the nodes' names, locations and colours. A node
66
+ without a colour takes its parent's. Geometry used by several nodes is read and meshed once.
67
+ - Solids, shells, faces, wires, edges, vertices and compounds of them, including compounds that
68
+ mix several kinds.
69
+
70
+ Names, colours and alphas passed to `show` take precedence over the producer's, as the protocol
71
+ asks consumers to do. An unnamed shape is named by its type, as an OCCT shape is.
72
+
73
+ build123d and CadQuery objects, and objects of your own subclasses of their classes, are never
74
+ taken by this plugin, even once they implement the protocol. The viewer draws them itself, with more information (joints, parents, materials).
75
+
76
+ ## How it works
77
+
78
+ Every result becomes OCCT shapes, read with the OCCT binding ocp-tessellate runs on. From there
79
+ the shapes take the viewer's OCCT path: OCCT tessellates them, and the measurement backend
80
+ measures them as OCCT shapes. So the plugin has only the drawing half of a
81
+ [kernel plugin](https://bernhard-42.github.io/ocp_viewer_docs/plugins/overview/), one module
82
+ registered through the entry point group `ocp_viewer.kernels.show`, and no tessellation and no
83
+ backend of its own.
84
+
85
+ Each `show` calls `__cad_interface__` once per object, so a changed object is shown as it is now. What
86
+ was read is cached by its content, so the same STEP data is parsed once (a STEP header's time
87
+ stamp is ignored), and OCCT reuses its mesh.
88
+
89
+ ## Limits
90
+
91
+ - The viewer shows and measures OCCT's reading of the producer's data (for solidfunc, of its
92
+ STEP output), not the producer's kernel's own geometry. Showing a kernel's own geometry needs a
93
+ kernel plugin. The two complement each other: the protocol makes any library visible with one
94
+ method, and a kernel plugin makes one kernel first-class.
95
+ - Faces and edges can only be shown on their own if the producer implements the protocol on
96
+ them. A face picked in the viewer does not map back to the producer's face: names of
97
+ sub-shapes are not part of version 1 of the protocol.
98
+ - Kernel plugins are asked in no defined order. If a kernel with its own plugin also implemented
99
+ the protocol, both plugins would claim its objects.
100
+
101
+ ## Development
102
+
103
+ ```bash
104
+ python -m venv .venv && . .venv/bin/activate
105
+ pip install -e ".[test]"
106
+ pytest
107
+ ruff check . && ruff format --check .
108
+ ```
109
+
110
+ The tests use producers written by hand with plain OCP, one per format, plus solidfunc and
111
+ build123d parts measured against each other through ocp-viewer-core's backend.
112
+
113
+ ## Licence
114
+
115
+ MIT
@@ -0,0 +1,91 @@
1
+ # ocp-viewer-cadinterface
2
+
3
+ A plugin for the OCP viewers ([OCP CAD Viewer for VS Code](https://github.com/bernhard-42/vscode-ocp-cad-viewer),
4
+ OCP Viewer, Jupyter CadQuery, build123d Studio). With it, `show` and `show_all` display any
5
+ object that implements the [`__cad_interface__`](https://github.com/DavidMStraub/cad-interface)
6
+ protocol, and the viewer's measurement tools work on it, including between it and build123d
7
+ or CadQuery objects in the same scene.
8
+
9
+ ```python
10
+ import build123d as bd
11
+ import solidfunc as sf # a CAD library on a non-OCCT kernel
12
+ from ocp_vscode import show
13
+
14
+ plate = sf.box(size_x=80, size_y=50, size_z=10) - sf.cylinder(diameter=20, height=10)
15
+ cube = bd.Pos(65, 0, 5) * bd.Box(10, 10, 10)
16
+
17
+ show(plate, cube, names=["plate", "cube"]) # measure the 20 mm between them in the viewer
18
+ ```
19
+
20
+ [examples/demo.ipynb](examples/demo.ipynb) has the full example.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install ocp-viewer-cadinterface
26
+ ```
27
+
28
+ Install it in the environment your script runs in. Your script does not import it: the viewer
29
+ finds it through its entry point at the first `show`. A Jupyter kernel that has already shown
30
+ something needs a restart after the install.
31
+
32
+ The measurement backend's environment needs nothing extra, because the plugin hands only OCCT
33
+ shapes to the viewer (see below).
34
+
35
+ It needs ocp-tessellate 3.7 and, for the viewer, ocp-viewer-core 1.2 or later.
36
+
37
+ ## What it shows
38
+
39
+ - A `ShapeDict` in any version 1 format: `"ocp"`, `"brep_binary"`, `"brep_text"`, `"step"`.
40
+ The plugin asks for them in that order. `"ocp"` shapes are used as they are, without a copy.
41
+ - An `AssemblyDict`: a tree of groups, with the nodes' names, locations and colours. A node
42
+ without a colour takes its parent's. Geometry used by several nodes is read and meshed once.
43
+ - Solids, shells, faces, wires, edges, vertices and compounds of them, including compounds that
44
+ mix several kinds.
45
+
46
+ Names, colours and alphas passed to `show` take precedence over the producer's, as the protocol
47
+ asks consumers to do. An unnamed shape is named by its type, as an OCCT shape is.
48
+
49
+ build123d and CadQuery objects, and objects of your own subclasses of their classes, are never
50
+ taken by this plugin, even once they implement the protocol. The viewer draws them itself, with more information (joints, parents, materials).
51
+
52
+ ## How it works
53
+
54
+ Every result becomes OCCT shapes, read with the OCCT binding ocp-tessellate runs on. From there
55
+ the shapes take the viewer's OCCT path: OCCT tessellates them, and the measurement backend
56
+ measures them as OCCT shapes. So the plugin has only the drawing half of a
57
+ [kernel plugin](https://bernhard-42.github.io/ocp_viewer_docs/plugins/overview/), one module
58
+ registered through the entry point group `ocp_viewer.kernels.show`, and no tessellation and no
59
+ backend of its own.
60
+
61
+ Each `show` calls `__cad_interface__` once per object, so a changed object is shown as it is now. What
62
+ was read is cached by its content, so the same STEP data is parsed once (a STEP header's time
63
+ stamp is ignored), and OCCT reuses its mesh.
64
+
65
+ ## Limits
66
+
67
+ - The viewer shows and measures OCCT's reading of the producer's data (for solidfunc, of its
68
+ STEP output), not the producer's kernel's own geometry. Showing a kernel's own geometry needs a
69
+ kernel plugin. The two complement each other: the protocol makes any library visible with one
70
+ method, and a kernel plugin makes one kernel first-class.
71
+ - Faces and edges can only be shown on their own if the producer implements the protocol on
72
+ them. A face picked in the viewer does not map back to the producer's face: names of
73
+ sub-shapes are not part of version 1 of the protocol.
74
+ - Kernel plugins are asked in no defined order. If a kernel with its own plugin also implemented
75
+ the protocol, both plugins would claim its objects.
76
+
77
+ ## Development
78
+
79
+ ```bash
80
+ python -m venv .venv && . .venv/bin/activate
81
+ pip install -e ".[test]"
82
+ pytest
83
+ ruff check . && ruff format --check .
84
+ ```
85
+
86
+ The tests use producers written by hand with plain OCP, one per format, plus solidfunc and
87
+ build123d parts measured against each other through ocp-viewer-core's backend.
88
+
89
+ ## Licence
90
+
91
+ MIT
@@ -0,0 +1,101 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "cell-0",
6
+ "metadata": {},
7
+ "source": [
8
+ "# A solidfunc part and a build123d part in one scene\n",
9
+ "\n",
10
+ "[solidfunc](https://github.com/DavidMStraub/solidfunc) is built on SolidCore, a B-rep kernel written in Rust, not on OpenCASCADE. It has no viewer plugin of its own. It implements one method, [`__cad_interface__`](https://github.com/DavidMStraub/cad-interface), and with `ocp-viewer-cadinterface` installed, the OCP viewers show its parts next to build123d parts and measure between them.\n",
11
+ "\n",
12
+ "Needs: `pip install ocp-viewer-cadinterface solidfunc build123d ocp-vscode`, and the OCP CAD Viewer open in VS Code."
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "id": "cell-1",
18
+ "metadata": {},
19
+ "source": [
20
+ "import build123d as bd\n",
21
+ "import solidfunc as sf\n",
22
+ "from ocp_vscode import show"
23
+ ],
24
+ "execution_count": null,
25
+ "outputs": []
26
+ },
27
+ {
28
+ "cell_type": "markdown",
29
+ "id": "cell-2",
30
+ "metadata": {},
31
+ "source": [
32
+ "A plate with a hole, made by solidfunc:"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "id": "cell-3",
38
+ "metadata": {},
39
+ "source": [
40
+ "plate = sf.box(size_x=80, size_y=50, size_z=10) - sf.cylinder(diameter=20, height=10)\n",
41
+ "type(plate), type(plate).__cad_interface__"
42
+ ],
43
+ "execution_count": null,
44
+ "outputs": []
45
+ },
46
+ {
47
+ "cell_type": "markdown",
48
+ "id": "cell-4",
49
+ "metadata": {},
50
+ "source": [
51
+ "A bracket made by build123d, 20 mm beyond the plate's +x face:"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "id": "cell-5",
57
+ "metadata": {},
58
+ "source": [
59
+ "with bd.BuildPart() as bracket:\n",
60
+ " bd.Box(10, 50, 30, align=(bd.Align.MIN, bd.Align.CENTER, bd.Align.MIN))\n",
61
+ " with bd.Locations((10, 0, 5)):\n",
62
+ " bd.Box(20, 50, 5, align=(bd.Align.MIN, bd.Align.CENTER, bd.Align.MIN), mode=bd.Mode.SUBTRACT)\n",
63
+ "bracket = bracket.part.moved(bd.Location((sf.bounds(plate).max[0] + 20, 0, 0)))"
64
+ ],
65
+ "execution_count": null,
66
+ "outputs": []
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "id": "cell-6",
71
+ "metadata": {},
72
+ "source": [
73
+ "show(plate, bracket, names=[\"plate (solidfunc)\", \"bracket (build123d)\"], colors=[\"steelblue\", \"orange\"])"
74
+ ],
75
+ "execution_count": null,
76
+ "outputs": []
77
+ },
78
+ {
79
+ "cell_type": "markdown",
80
+ "id": "cell-7",
81
+ "metadata": {},
82
+ "source": [
83
+ "Both are OCCT shapes in the viewer, so the measurement tools work across them: pick the distance tool and click the plate's +x face and the bracket's \u2212x face. The viewer reports 20 mm.\n",
84
+ "\n",
85
+ "What the viewer shows and measures is OCCT's reading of solidfunc's STEP output, not SolidCore's own geometry. A native kernel plugin would show the kernel's own geometry; the protocol makes any library visible with one method."
86
+ ]
87
+ }
88
+ ],
89
+ "metadata": {
90
+ "kernelspec": {
91
+ "display_name": "Python 3",
92
+ "language": "python",
93
+ "name": "python3"
94
+ },
95
+ "language_info": {
96
+ "name": "python"
97
+ }
98
+ },
99
+ "nbformat": 4,
100
+ "nbformat_minor": 5
101
+ }
@@ -0,0 +1,10 @@
1
+ """Show any object that implements ``__cad_interface__`` in the OCP viewers.
2
+
3
+ Installing the package is all it takes: the viewers import
4
+ ``ocp_viewer_cadinterface.show`` through its entry point. This module imports
5
+ nothing, so that importing the package registers nothing.
6
+ """
7
+
8
+ from ._version import __version__
9
+
10
+ __all__ = ["__version__"]
@@ -0,0 +1,166 @@
1
+ """The shapes of a ``__cad_interface__`` result as OCCT shapes, and what the viewer
2
+ draws them as.
3
+
4
+ Everything here is OCCT's: once a result is read, the shapes take the viewer's OCCT
5
+ path, which tessellates and measures them.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import io
12
+ import os
13
+ import tempfile
14
+ from collections import OrderedDict
15
+ from collections.abc import Mapping
16
+ from types import ModuleType
17
+ from typing import Any
18
+
19
+ from ocp_tessellate._kernel import binding_of, kernel
20
+ from ocp_tessellate.convert import get_kind, get_type
21
+ from ocp_tessellate.ocp_utils.predicates import is_topods_compound
22
+ from ocp_tessellate.ocp_utils.topology import downcast, get_compound_type, get_edges, get_vertices
23
+
24
+ __all__ = ["ACCEPT", "classify", "read_shape"]
25
+
26
+ # most preferred first: "ocp" shares the producer's shape, the binary BREP is the
27
+ # fastest to read, STEP the slowest
28
+ ACCEPT = ["ocp", "brep_binary", "brep_text", "step"]
29
+
30
+ # what was read, by format and a digest of the bytes: each show asks the producer
31
+ # again, and a STEP file is only parsed once. Returning the same shape again also
32
+ # lets ocp-tessellate reuse its mesh.
33
+ _CACHE_SIZE = 128
34
+ _cache: OrderedDict[tuple[str, bytes], Any] = OrderedDict()
35
+
36
+
37
+ def read_shape(entry: Mapping[str, Any]) -> Any:
38
+ """The ``TopoDS_Shape`` of a ShapeDict, downcast to its type."""
39
+ fmt = entry.get("format")
40
+ data = entry.get("data")
41
+ if fmt == "ocp":
42
+ binding = binding_of(data)
43
+ if binding is None or binding.__name__ != "OCP":
44
+ raise TypeError(f'__cad_interface__ format "ocp" needs an OCP TopoDS_Shape, not {type(data).__name__}')
45
+ return downcast(data)
46
+ if fmt not in _READERS:
47
+ raise ValueError(f"__cad_interface__ returned format {fmt!r}, which was not asked for (accept={ACCEPT})")
48
+ if not isinstance(data, (bytes, bytearray, memoryview)):
49
+ raise TypeError(f"__cad_interface__ format {fmt!r} needs bytes, not {type(data).__name__}")
50
+ data = bytes(data)
51
+ key = (fmt, hashlib.blake2b(_content(fmt, data), digest_size=16).digest())
52
+ shape = _cache.get(key)
53
+ if shape is None:
54
+ shape = downcast(_READERS[fmt](kernel(), data))
55
+ _cache[key] = shape
56
+ if len(_cache) > _CACHE_SIZE:
57
+ _cache.popitem(last=False)
58
+ else:
59
+ _cache.move_to_end(key)
60
+ return shape
61
+
62
+
63
+ def _content(fmt: str, data: bytes) -> bytes:
64
+ """What decides the shape: a STEP file's header holds a time stamp, which differs
65
+ each time a producer writes the same shape."""
66
+ if fmt == "step":
67
+ start = data.find(b"\nDATA;")
68
+ if start >= 0:
69
+ return data[start:]
70
+ return data
71
+
72
+
73
+ def _read_brep_text(k: ModuleType, data: bytes) -> Any:
74
+ shape = k.TopoDS.TopoDS_Shape()
75
+ builder = k.BRep.BRep_Builder()
76
+ # OCP takes a bytes stream, nanocct a text stream
77
+ stream = io.BytesIO(data) if k.__name__ == "OCP" else io.StringIO(data.decode("latin-1"))
78
+ try:
79
+ k.BRepTools.BRepTools.Read_s(shape, stream, builder)
80
+ except Exception: # noqa: BLE001 # a binding without stream support reads a file
81
+ with _temp_file(data, ".brep") as path:
82
+ k.BRepTools.BRepTools.Read_s(shape, path, builder)
83
+ return _checked(shape, "brep_text")
84
+
85
+
86
+ def _read_brep_binary(k: ModuleType, data: bytes) -> Any:
87
+ shape = k.TopoDS.TopoDS_Shape()
88
+ try:
89
+ k.BinTools.BinTools.Read_s(shape, io.BytesIO(data))
90
+ except Exception: # noqa: BLE001
91
+ with _temp_file(data, ".bin.brep") as path:
92
+ k.BinTools.BinTools.Read_s(shape, path)
93
+ return _checked(shape, "brep_binary")
94
+
95
+
96
+ def _read_step(k: ModuleType, data: bytes) -> Any:
97
+ reader = k.STEPControl.STEPControl_Reader()
98
+ with _temp_file(data, ".step") as path:
99
+ status = reader.ReadFile(path)
100
+ if status != k.IFSelect.IFSelect_RetDone:
101
+ raise ValueError(f"__cad_interface__ returned STEP data that OCCT cannot read ({status})")
102
+ reader.TransferRoots()
103
+ return _checked(reader.OneShape(), "step")
104
+
105
+
106
+ def _checked(shape: Any, fmt: str) -> Any:
107
+ if shape.IsNull():
108
+ raise ValueError(f"__cad_interface__ returned {fmt!r} data without a shape")
109
+ return shape
110
+
111
+
112
+ class _temp_file: # a context manager, used like a function
113
+ """A temporary file holding `data`, removed afterwards."""
114
+
115
+ def __init__(self, data: bytes, suffix: str):
116
+ self.data, self.suffix = data, suffix
117
+
118
+ def __enter__(self) -> str:
119
+ fd, self.path = tempfile.mkstemp(suffix=self.suffix, prefix="cadinterface-")
120
+ with os.fdopen(fd, "wb") as f:
121
+ f.write(self.data)
122
+ return self.path
123
+
124
+ def __exit__(self, *exc: object) -> None:
125
+ os.unlink(self.path)
126
+
127
+
128
+ _READERS = {"brep_binary": _read_brep_binary, "brep_text": _read_brep_text, "step": _read_step}
129
+
130
+
131
+ def classify(shape: Any) -> tuple[str, str, Any]:
132
+ """What the viewer draws `shape` as, as OCCT's own path does for a raw shape:
133
+ ``(kind, type name, payload)``.
134
+
135
+ - kind ``"solid"`` or ``"face"`` (faces and shells): the payload is the shape
136
+ - kind ``"edge"`` (edges and wires) or ``"vertex"``: the payload is a list of them
137
+ - kind ``"mixed"``: a compound of shapes of several kinds, the payload is the list
138
+ of its direct children, each to be classified on its own
139
+ - kind ``"empty"``: a compound without shapes, the payload is None
140
+ """
141
+ shape = downcast(shape)
142
+ if is_topods_compound(shape):
143
+ typ = get_compound_type(shape)
144
+ if typ is None:
145
+ return "empty", "Compound", None
146
+ if typ == "mixed":
147
+ return "mixed", "Compound", _children(shape)
148
+ else:
149
+ typ = get_type(shape)
150
+ kind = get_kind(typ)
151
+ if kind == "edge":
152
+ return kind, typ, list(get_edges(shape))
153
+ if kind == "vertex":
154
+ return kind, typ, list(get_vertices(shape))
155
+ return kind, typ, shape
156
+
157
+
158
+ def _children(compound: Any) -> list[Any]:
159
+ k = binding_of(compound)
160
+ assert k is not None, "an OCCT compound"
161
+ result = []
162
+ iterator = k.TopoDS.TopoDS_Iterator(compound)
163
+ while iterator.More():
164
+ result.append(downcast(iterator.Value()))
165
+ iterator.Next()
166
+ return result
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.1.0'
22
+ __version_tuple__ = version_tuple = (0, 1, 0)
23
+
24
+ __commit_id__ = commit_id = None