Skip to main content

ocp-viewer-smlibpy

Show smlibpy objects (the SMLib kernel) in the OCP CAD Viewer family: ocp_vscode, jupyter_cadquery, build123d_studio and ocp_viewer. The objects are tessellated by smlib's own kernel and go through ocp-tessellate's plugin interface, so names, colors, the viewer's settings and set_defaults work as for build123d or CadQuery objects.

This package is the reference implementation of a kernel plugin for ocp-tessellate: one class per protocol of CAD kernel plugins, SmlibTessellation in tessellation.py, SmlibShow in show.py and SmlibBackend in backend.py.

Installation

pip install ocp-viewer-smlibpy

Requires Python 3.10+, smlibpy 0.6.2+, ocp-tessellate with the plugin interface (ocp_tessellate.plugin), ocp-viewer-core, and one OCCT binding (OCP or nanocct), which ocp-tessellate needs.

Usage

from smlibpy import *
from ocp_vscode import show, show_all, Camera

plate = Box(80, 60, 10)
plate = plate.fillet(plate.edges().parallel_to(Z), 8)
plate -= GridLocations(25, 16, 2, 3) * Cylinder(4, 10)

show(plate, plate.edges(), Pos(0, 0, 20), names=["plate", "edges", "loc"], reset_camera=Camera.RESET)
show_all()   # every smlibpy object in the current scope, under its variable name

The script imports only smlibpy and the viewer package: ocp_tessellate imports the plugin's drawing half, ocp_viewer_smlibpy.show, through the entry point smlib of the group ocp_viewer.kernels.show at the first show. The viewer's show and show_all take parts, sheets, sketches, faces, edges, wires, vertices, vectors, locations, planes and axes, and lists or dicts of them, also at a debug stop (visual debugging), with the names, colors and alphas lists and every keyword of show (reset_camera, collapse, helper_scale, transparent, ...). Bodies are cached in ocp-tessellate's tessellation cache by their geometry.

Measuring

The viewer's distance and properties tools ask a measurement backend (ocp_viewer_core.backend.ViewerBackend) that holds the geometry behind the mesh. SmlibBackend in ocp_viewer_smlibpy/backend.py is the smlib half of that, its implementation of BackendProtocol: deserialize(data) (the bytes of SmlibShow.serialize: bodies and curves as binary .smp, vertices as their coordinates, what they travel as, since every viewer runs the backend in another process than the user's), moved(shape, placement), parts(shape) (its faces, edges and vertices in the order the viewer numbers them), kind(shape), center(shape), properties(shape) (what smlib knows about it, as plain numbers), closest_points(shape1, shape2) and closest_directions(shape1, shape2). ocp_viewer_core runs that sequence and makes the panel's rows, as it does for OCCT. Importing ocp_viewer_smlibpy.backend registers it under the kernel tag smlib, through ocp_viewer_core.backend.register_plugin, and the entry point smlib of the group ocp_viewer.kernels.backend imports that module in the backend's process, in every viewer. The plugin must be installed where the backend runs: for VS Code in the interpreter the extension starts the backend with, for Jupyter CadQuery in the Jupyter server's environment. The backend protocol describes it. Every leaf of a shown smlibpy object has an entry in the backend's model, tagged smlib by ocp-tessellate.

Mixed scenes

show and show_all take smlibpy objects beside build123d, CadQuery or OCCT objects:

show(plate, build123d_box, names=["plate", "box"])

Each kernel's shapes are measured against each other, but a distance between an smlib shape and an OCCT shape is not: the kernels have no common geometry to measure on except OCCT itself. To measure across kernels, convert the smlib objects to OCCT shapes with to_occt and show them as OCCT objects:

from ocp_viewer_smlibpy import to_occt
show(build123d_box, to_occt(plate), names=["box", "plate"])   # every distance between the two is measured

to_occt converts through smlib's .brep writer (bodies), its NURBS data (edges, wires) or its coordinates (vertices, locations, planes, axes), into the binding of ocp_tessellate._kernel.kernel() or the one named by binding="OCP" / "nanocct". The converted object is OCCT's from then on: OCCT tessellates, numbers and measures it. The conversion fails for geometry smlib cannot write as .brep, offset surfaces of free-form faces, with a ValueError naming the viewer's show as the way to at least see the object.

Development

make lint        # ruff
make typecheck   # ty
make tests       # pytest

The tests need smlibpy and an OCCT binding installed; the comparison tests against the OCCT path build the same boxes with the binding.

License

Apache 2.0

Metadata

Release files for ocp-viewer-smlibpy 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ocp-viewer-smlibpy 0.1.1
File Size Uploaded Provenance Actions
ocp_viewer_smlibpy-0.1.1.tar.gz 38.7 kB Without provenance Details for ocp_viewer_smlibpy-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ocp-viewer-smlibpy 0.1.1
File Interpreter ABI Platform Actions
ocp_viewer_smlibpy-0.1.1-py3-none-any.whl Python 3 none any Details for ocp_viewer_smlibpy-0.1.1-py3-none-any.whl

Total release size: 65.7 kB

Release files / ocp_viewer_smlibpy-0.1.1.tar.gz

Download URL ocp_viewer_smlibpy-0.1.1.tar.gz
Size 38.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8944e78627633e300859ee015b6d0d286c2dd4acae60b68362aab73898b81901
BLAKE2b-256 checksum
How to use checksums
be53aded90d8def4f12836a90dfc5756dbb72b102f060a9facaa791cd2bec1e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Release files / ocp_viewer_smlibpy-0.1.1-py3-none-any.whl

Download URL ocp_viewer_smlibpy-0.1.1-py3-none-any.whl
Size 27.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b24db1b2fbe67c3eb88dc28a4c6d48d93ffb84ee1cdaaf04b3fee6331d54fd0
BLAKE2b-256 checksum
How to use checksums
8839709e1d829eb3fc306bae50e452bb9539b1104c33d5851a84870a3c0d2c99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Security for ocp-viewer-smlibpy 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page