ocp-viewer-core 1.0.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.
- ocp_viewer_core-1.0.0/LICENSE +201 -0
- ocp_viewer_core-1.0.0/PKG-INFO +89 -0
- ocp_viewer_core-1.0.0/README.md +64 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/__init__.py +125 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/_version.py +21 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/backend.py +242 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/codec.py +57 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/colors.py +518 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/comms.py +321 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/config.py +887 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/host.py +157 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/keys.py +298 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/logo.py +61 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/measure.py +560 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/screenshot.py +45 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/show.py +2129 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/state.py +156 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core/websocket.py +434 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core.egg-info/PKG-INFO +89 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core.egg-info/SOURCES.txt +26 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core.egg-info/dependency_links.txt +1 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core.egg-info/requires.txt +10 -0
- ocp_viewer_core-1.0.0/ocp_viewer_core.egg-info/top_level.txt +1 -0
- ocp_viewer_core-1.0.0/pyproject.toml +92 -0
- ocp_viewer_core-1.0.0/setup.cfg +4 -0
- ocp_viewer_core-1.0.0/tests/test_host_resolution.py +127 -0
- ocp_viewer_core-1.0.0/tests/test_session_cache.py +90 -0
- ocp_viewer_core-1.0.0/tests/test_values.py +275 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2024] Bernhard Walter
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ocp-viewer-core
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Shared viewer core for ocp_vscode, ocp_viewer, Jupyter CadQuery and build123d Studio
|
|
5
|
+
Author-email: Bernhard Walter <b_walter@arcor.de>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/bernhard-42/ocp-viewer-core
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/bernhard-42/ocp-viewer-core/issues
|
|
9
|
+
Keywords: 3d models,3d viewing,3d,brep,cad,cadquery,opencascade,python
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: ocp-tessellate<3.6.0,>=3.5.0
|
|
16
|
+
Requires-Dist: orjson
|
|
17
|
+
Requires-Dist: threejs-materials<1.3.0,>=1.2.0
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: build; extra == "dev"
|
|
20
|
+
Requires-Dist: bump-my-version; extra == "dev"
|
|
21
|
+
Requires-Dist: black; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest; extra == "dev"
|
|
23
|
+
Requires-Dist: twine; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# ocp-viewer-core
|
|
27
|
+
|
|
28
|
+
The shared half of the OCP viewer ecosystem: one show suite, one tessellation, one set of config semantics, used by four viewers that each keep their own transport and their own settings storage.
|
|
29
|
+
|
|
30
|
+
- **ocp_vscode** — the VS Code extension and its Python client
|
|
31
|
+
- **ocp_viewer** — the standalone viewer, `python -m ocp_viewer`
|
|
32
|
+
- **Jupyter CadQuery** — through cad-viewer-widget
|
|
33
|
+
- **build123d Studio**
|
|
34
|
+
|
|
35
|
+
Published as one project under one version to two registries: `ocp-viewer-core` on PyPI for the Python half, `ocp-viewer-core` on npm for the JavaScript half. The two are shipped and versioned together, so which version of the pair a host has is one question rather than two.
|
|
36
|
+
|
|
37
|
+
## The idea
|
|
38
|
+
|
|
39
|
+
Each host provides a `Comms` — a Python encoder and a JavaScript decoder, shipped as a pair — and a settings source. Everything above that is shared and knows nothing about which host it is running in. **No host is nameable inside this package**: no `port=`/`viewer=` pairs, no `is_jupyter_cadquery`, no environment sniffing, and no host name in a string. A conformance kit enforces that by running the shared half end to end over an in-memory loopback with no host at all.
|
|
40
|
+
|
|
41
|
+
Per-host imports stay per host: `from ocp_vscode import show` beside `from build123d_studio import show`. A single universal import with the host discovered at runtime is deliberately not offered — it is how a `show()` once silently drew into somebody else's viewer.
|
|
42
|
+
|
|
43
|
+
## Status
|
|
44
|
+
|
|
45
|
+
Early development. Nothing here is published, and the API changes without notice until the first host adopts it.
|
|
46
|
+
|
|
47
|
+
## Layout
|
|
48
|
+
|
|
49
|
+
| path | what |
|
|
50
|
+
| --------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| `ocp_viewer_core/` | the Python half |
|
|
52
|
+
| `ocp_viewer_core/config.py` | the config keys, each mapped to the name three-cad-viewer knows it by, and the precedence over them |
|
|
53
|
+
| `ocp_viewer_core/comms.py` | the transport a host implements, and the session that caches what it answers |
|
|
54
|
+
| `ocp_viewer_core/logo.py` | the splash logo as measurable geometry, for a host's measurement backend |
|
|
55
|
+
| `js/src/logo.js` | the splash logo as tessellated data plus its config, for the renderer |
|
|
56
|
+
| `js/` | the JavaScript half, published to npm |
|
|
57
|
+
| `tests/` | including the conformance kit |
|
|
58
|
+
|
|
59
|
+
`ocp_viewer_core/__init__.py` is import-free by design: hosts import the submodule they need, so that importing the package never pulls in the tessellator or OCP.
|
|
60
|
+
|
|
61
|
+
## Use
|
|
62
|
+
|
|
63
|
+
### ocp vscode:
|
|
64
|
+
|
|
65
|
+
A host writes one class and supplies one list. `exclude_keys` names the keywords
|
|
66
|
+
it may not be told, because its surface decides them - the show signature is the
|
|
67
|
+
superset of every host's, so a keyword one host owns is a keyword another has to
|
|
68
|
+
refuse by name rather than ignore.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
comms = MyComms()
|
|
72
|
+
session = Session(comms) # sets session cache to None
|
|
73
|
+
config = Config(session, ("cad_width", "height"))
|
|
74
|
+
show(objects)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
What a host *persists* between sessions is its own business and needs no key
|
|
78
|
+
list here: it answers with values, from `Comms.workspace_config()`. Which of the
|
|
79
|
+
viewer's reported state counts as configuration - and so survives into the next
|
|
80
|
+
show - is `keys.CONFIG`, derived from the vocabulary, because that set is a
|
|
81
|
+
property of three-cad-viewer's state and not of any host's settings.
|
|
82
|
+
|
|
83
|
+
## Dependencies
|
|
84
|
+
|
|
85
|
+
`ocp-tessellate` for tessellation, and `three-cad-viewer` as a peer dependency of the JavaScript half. **No OCP provider is declared** — the same `OCP` namespace is supplied by `cadquery_ocp`, `cadquery_ocp_novtk` and conda's `OCP`, and naming one would break users of the other two. The host or the user chooses.
|
|
86
|
+
|
|
87
|
+
## Licence
|
|
88
|
+
|
|
89
|
+
Apache-2.0.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# ocp-viewer-core
|
|
2
|
+
|
|
3
|
+
The shared half of the OCP viewer ecosystem: one show suite, one tessellation, one set of config semantics, used by four viewers that each keep their own transport and their own settings storage.
|
|
4
|
+
|
|
5
|
+
- **ocp_vscode** — the VS Code extension and its Python client
|
|
6
|
+
- **ocp_viewer** — the standalone viewer, `python -m ocp_viewer`
|
|
7
|
+
- **Jupyter CadQuery** — through cad-viewer-widget
|
|
8
|
+
- **build123d Studio**
|
|
9
|
+
|
|
10
|
+
Published as one project under one version to two registries: `ocp-viewer-core` on PyPI for the Python half, `ocp-viewer-core` on npm for the JavaScript half. The two are shipped and versioned together, so which version of the pair a host has is one question rather than two.
|
|
11
|
+
|
|
12
|
+
## The idea
|
|
13
|
+
|
|
14
|
+
Each host provides a `Comms` — a Python encoder and a JavaScript decoder, shipped as a pair — and a settings source. Everything above that is shared and knows nothing about which host it is running in. **No host is nameable inside this package**: no `port=`/`viewer=` pairs, no `is_jupyter_cadquery`, no environment sniffing, and no host name in a string. A conformance kit enforces that by running the shared half end to end over an in-memory loopback with no host at all.
|
|
15
|
+
|
|
16
|
+
Per-host imports stay per host: `from ocp_vscode import show` beside `from build123d_studio import show`. A single universal import with the host discovered at runtime is deliberately not offered — it is how a `show()` once silently drew into somebody else's viewer.
|
|
17
|
+
|
|
18
|
+
## Status
|
|
19
|
+
|
|
20
|
+
Early development. Nothing here is published, and the API changes without notice until the first host adopts it.
|
|
21
|
+
|
|
22
|
+
## Layout
|
|
23
|
+
|
|
24
|
+
| path | what |
|
|
25
|
+
| --------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| `ocp_viewer_core/` | the Python half |
|
|
27
|
+
| `ocp_viewer_core/config.py` | the config keys, each mapped to the name three-cad-viewer knows it by, and the precedence over them |
|
|
28
|
+
| `ocp_viewer_core/comms.py` | the transport a host implements, and the session that caches what it answers |
|
|
29
|
+
| `ocp_viewer_core/logo.py` | the splash logo as measurable geometry, for a host's measurement backend |
|
|
30
|
+
| `js/src/logo.js` | the splash logo as tessellated data plus its config, for the renderer |
|
|
31
|
+
| `js/` | the JavaScript half, published to npm |
|
|
32
|
+
| `tests/` | including the conformance kit |
|
|
33
|
+
|
|
34
|
+
`ocp_viewer_core/__init__.py` is import-free by design: hosts import the submodule they need, so that importing the package never pulls in the tessellator or OCP.
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
### ocp vscode:
|
|
39
|
+
|
|
40
|
+
A host writes one class and supplies one list. `exclude_keys` names the keywords
|
|
41
|
+
it may not be told, because its surface decides them - the show signature is the
|
|
42
|
+
superset of every host's, so a keyword one host owns is a keyword another has to
|
|
43
|
+
refuse by name rather than ignore.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
comms = MyComms()
|
|
47
|
+
session = Session(comms) # sets session cache to None
|
|
48
|
+
config = Config(session, ("cad_width", "height"))
|
|
49
|
+
show(objects)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
What a host *persists* between sessions is its own business and needs no key
|
|
53
|
+
list here: it answers with values, from `Comms.workspace_config()`. Which of the
|
|
54
|
+
viewer's reported state counts as configuration - and so survives into the next
|
|
55
|
+
show - is `keys.CONFIG`, derived from the vocabulary, because that set is a
|
|
56
|
+
property of three-cad-viewer's state and not of any host's settings.
|
|
57
|
+
|
|
58
|
+
## Dependencies
|
|
59
|
+
|
|
60
|
+
`ocp-tessellate` for tessellation, and `three-cad-viewer` as a peer dependency of the JavaScript half. **No OCP provider is declared** — the same `OCP` namespace is supplied by `cadquery_ocp`, `cadquery_ocp_novtk` and conda's `OCP`, and naming one would break users of the other two. The host or the user chooses.
|
|
61
|
+
|
|
62
|
+
## Licence
|
|
63
|
+
|
|
64
|
+
Apache-2.0.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Shared viewer logic for the OCP CAD viewers.
|
|
2
|
+
|
|
3
|
+
The show pipeline, the configuration semantics, the render and camera policy,
|
|
4
|
+
the measurement backend and the wire protocol, used by ocp_vscode, ocp_viewer,
|
|
5
|
+
Jupyter CadQuery and build123d Studio. Each host supplies a transport and its
|
|
6
|
+
own settings; everything above that is here.
|
|
7
|
+
|
|
8
|
+
This module imports nothing. A host imports the submodule it needs, so that
|
|
9
|
+
importing the package never loads the tessellator or OCP - `show`, `backend`
|
|
10
|
+
and `measure` reach the kernel, and `comms`, `config`, `keys`, `state` and
|
|
11
|
+
`websocket` do not.
|
|
12
|
+
|
|
13
|
+
It also carries the universal import: `from ocp_viewer_core import show`
|
|
14
|
+
works in every host's environment and resolves to the host that is meant -
|
|
15
|
+
`host.py` says how that is decided. The resolution is lazy (PEP 562), so the
|
|
16
|
+
paragraph above stays true: a bare import still loads nothing, a star import
|
|
17
|
+
resolves at the import statement, and a named import on first access. The
|
|
18
|
+
resolved names are the chosen host's own bound methods.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Copyright 2026 Bernhard Walter
|
|
23
|
+
#
|
|
24
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
25
|
+
# you may not use this file except in compliance with the License.
|
|
26
|
+
# You may obtain a copy of the License at
|
|
27
|
+
#
|
|
28
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
29
|
+
#
|
|
30
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
31
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
32
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
33
|
+
# See the License for the specific language governing permissions and
|
|
34
|
+
# limitations under the License.
|
|
35
|
+
#
|
|
36
|
+
|
|
37
|
+
from ._version import __version__
|
|
38
|
+
|
|
39
|
+
# The shared vocabulary: the intersection of the hosts' public names,
|
|
40
|
+
# measured 2026-08-16. Everything here exists in every host, so a script
|
|
41
|
+
# using only these runs unchanged under any of them - which is what makes
|
|
42
|
+
# the star import safe to write.
|
|
43
|
+
__all__ = [
|
|
44
|
+
"__version__",
|
|
45
|
+
"combined_config",
|
|
46
|
+
"get_default",
|
|
47
|
+
"get_defaults",
|
|
48
|
+
"push_object",
|
|
49
|
+
"remove_object",
|
|
50
|
+
"reset_defaults",
|
|
51
|
+
"reset_show",
|
|
52
|
+
"save_screenshot",
|
|
53
|
+
"set_defaults",
|
|
54
|
+
"set_viewer_config",
|
|
55
|
+
"show",
|
|
56
|
+
"show_all",
|
|
57
|
+
"show_clear",
|
|
58
|
+
"show_object",
|
|
59
|
+
"show_objects",
|
|
60
|
+
"status",
|
|
61
|
+
"workspace_config",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
# Names some hosts have and others honestly lack, because they are shaped by
|
|
65
|
+
# the transport: a port means nothing to a sidecar, a sidecar means nothing
|
|
66
|
+
# to a websocket. Importable by name from the chosen host; absent from
|
|
67
|
+
# `__all__` so a star import never carries a name that may not exist. Asked
|
|
68
|
+
# of a host that lacks them, the ImportError below names that host rather
|
|
69
|
+
# than letting the name silently not work.
|
|
70
|
+
#
|
|
71
|
+
# This tuple is also the explicit list of *accepted* feature asymmetries
|
|
72
|
+
# under the "all hosts behave the same" rule - anything host-specific that is
|
|
73
|
+
# not a transport shape does not belong here, it belongs fixed.
|
|
74
|
+
_HOST_ONLY = (
|
|
75
|
+
# websocket hosts (ocp_vscode, ocp_viewer): which viewer a port addresses
|
|
76
|
+
"get_port",
|
|
77
|
+
"set_port",
|
|
78
|
+
# jupyter_cadquery: the sidecar lifecycle its host process owns
|
|
79
|
+
"close_viewer",
|
|
80
|
+
"close_viewers",
|
|
81
|
+
"get_default_viewer",
|
|
82
|
+
"get_user_defaults",
|
|
83
|
+
"get_viewer",
|
|
84
|
+
"open_viewer",
|
|
85
|
+
"save_user_defaults",
|
|
86
|
+
"set_default_viewer",
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def __getattr__(name):
|
|
91
|
+
"""PEP 562: called only for names this module does not really have.
|
|
92
|
+
|
|
93
|
+
Restricted to the two published tuples. Delegating every unknown name
|
|
94
|
+
would make any typo - or any `hasattr` probe by tooling - import a host
|
|
95
|
+
and possibly prompt, which is a side effect no attribute miss should
|
|
96
|
+
have. The import of `host` lives here and not at the top so that a bare
|
|
97
|
+
`import ocp_viewer_core` keeps importing nothing.
|
|
98
|
+
"""
|
|
99
|
+
if name in __all__ or name in _HOST_ONLY:
|
|
100
|
+
from . import host
|
|
101
|
+
|
|
102
|
+
viewer = host.chosen()
|
|
103
|
+
try:
|
|
104
|
+
value = getattr(viewer, name)
|
|
105
|
+
except AttributeError:
|
|
106
|
+
raise ImportError(
|
|
107
|
+
f"{name!r} exists in some hosts but not in {viewer.__name__}"
|
|
108
|
+
) from None
|
|
109
|
+
# Written back as a real attribute, and not only as a cache. `show` is
|
|
110
|
+
# also a submodule of this package, and importing the chosen host - who
|
|
111
|
+
# imports `ocp_viewer_core.show` like every host - makes the import
|
|
112
|
+
# machinery set that submodule as this package's `show` attribute,
|
|
113
|
+
# *during* this call. A real attribute wins over `__getattr__`, so
|
|
114
|
+
# without this line the `from ocp_viewer_core import show` that
|
|
115
|
+
# triggered the resolution would bind the submodule, not the host's
|
|
116
|
+
# function: the import statement reads the attribute again after
|
|
117
|
+
# `__getattr__` returns.
|
|
118
|
+
globals()[name] = value
|
|
119
|
+
return value
|
|
120
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def __dir__():
|
|
124
|
+
"""Completion without side effects: listing names must not choose a host."""
|
|
125
|
+
return sorted(set(globals().keys()) | set(__all__) | set(_HOST_ONLY))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""The package version, written by `make bump`.
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# Copyright 2026 Bernhard Walter
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
__version__ = "1.0.0" # DO NOT EDIT THIS DIRECTLY! It is managed by bumpversion
|
|
21
|
+
__version_info__ = tuple(int(p) for p in __version__.split("."))
|