Skip to content

Commit b762eca

Browse files
authored
OCCT dual-version harden: Handle aliases, failure messages, warning cleanup (#197)
## Summary - Harden shared `src/` for **desktop OCCT 8** vs **WASM OCCT 7.9.3**: `standard_failure_message()`, `*_ptr` aliases instead of `Handle(T)`, agent conventions for both. - Clear native/WASM compiler warnings (nodiscard `clear_tmps`, `Standard_Real`, doc-link wchar narrowing, ImGui dock enum OR under emscripten). Closes #196 ## Test plan - [x] Native Debug rebuild `EzyCad_lib` / `EzyCad_tests` (listed C4834 / C4996 / C4244 gone) - [x] WASM `build-em-793` ninja link succeeds; dock enum warning addressed - [x] CI Windows MSVC green - [x] Spot-check fillet/chamfer/revolve error paths still surface OCCT messages - [x] Spot-check Esc cancel still two-stage (tmp tool then parent mode) ## Notes - Temporary agent note `agents/conventions/occt-wasm-dual-version.md` should be retired when wasm on OCCT 8 is supported. - Prefer `agents/conventions/occt-handles.md` for new handle types (add to `utl_types.h`). Made with [Cursor](https://cursor.com)
1 parent 03c7218 commit b762eca

33 files changed

Lines changed: 503 additions & 287 deletions

agents.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Pointer for AI coding assistants. Details live in [agents/README.md](agents/READ
2121
- Script consoles: [src/doc/script.md](src/doc/script.md) (read; update when bindings or console UI change)
2222
- Utilities: [src/doc/utility.md](src/doc/utility.md) (read; update when utl_* contracts or I/O change)
2323
- Build/test: [agents/workflows/local-dev.md](agents/workflows/local-dev.md) or root README
24+
- OCCT APIs / WASM (desktop 8 vs wasm 7.9.3): [agents/conventions/occt-wasm-dual-version.md](agents/conventions/occt-wasm-dual-version.md) — until wasm works on OCCT 8
25+
- OCCT handles (`Handle` vs `*_ptr`): [agents/conventions/occt-handles.md](agents/conventions/occt-handles.md)
2426
- Release (maintainers only): [agents/workflows/release.md](agents/workflows/release.md)
2527
- Open work context: one file under [agents/drafts/](agents/drafts/) if relevant
2628

agents/README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ Root markers: [AGENTS.md](../AGENTS.md) / [agents.md](../agents.md).
66

77
## Quick index
88

9-
| Need | File |
10-
| ------------------------- | -------------------------------------------------------------------------------------------------------------------- |
11-
| ASCII / `src/` edits | [conventions/ascii-source.md](conventions/ascii-source.md) |
12-
| C++ style (full) | [docs/ezycad_code_style.md](../docs/ezycad_code_style.md) |
13-
| User docs when UI changes | [conventions/user-docs-sync.md](conventions/user-docs-sync.md) |
14-
| Sketch module (dev doc) | [src/doc/sketch.md](../src/doc/sketch.md) — read when editing sketch code; update if API/architecture changes |
15-
| Shape module (dev doc) | [src/doc/shape.md](../src/doc/shape.md) — read when editing `shp_*` code; update if API/operations change |
16-
| GUI module (dev doc) | [src/doc/gui.md](../src/doc/gui.md) — read when editing `gui_*` / viewer shell; update if routing or settings change |
17-
| Script module (dev doc) | [src/doc/script.md](../src/doc/script.md) — read when editing `scr_*`; update if bindings change |
18-
| Utility module (dev doc) | [src/doc/utility.md](../src/doc/utility.md) — read when editing `utl_*`; update if shared helpers or I/O change |
19-
| Build / test / wasm | [workflows/local-dev.md](workflows/local-dev.md) |
20-
| Release | [workflows/release.md](workflows/release.md) |
21-
| Issue/PR drafts | [drafts/](drafts/)[github-drafts.md](conventions/github-drafts.md) |
22-
| Token-saving rules | [conventions/token-lean.md](conventions/token-lean.md) |
23-
| Markdown tables | [conventions/markdown-tables.md](conventions/markdown-tables.md) — align GFM pipes for source + preview |
24-
| Outreach (optional) | [outreach/discoverability.md](outreach/discoverability.md) |
9+
| Need | File |
10+
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------- |
11+
| ASCII / `src/` edits | [conventions/ascii-source.md](conventions/ascii-source.md) |
12+
| C++ style (full) | [docs/ezycad_code_style.md](../docs/ezycad_code_style.md) |
13+
| User docs when UI changes | [conventions/user-docs-sync.md](conventions/user-docs-sync.md) |
14+
| Sketch module (dev doc) | [src/doc/sketch.md](../src/doc/sketch.md) — read when editing sketch code; update if API/architecture changes |
15+
| Shape module (dev doc) | [src/doc/shape.md](../src/doc/shape.md) — read when editing `shp_*` code; update if API/operations change |
16+
| GUI module (dev doc) | [src/doc/gui.md](../src/doc/gui.md) — read when editing `gui_*` / viewer shell; update if routing or settings change |
17+
| Script module (dev doc) | [src/doc/script.md](../src/doc/script.md) — read when editing `scr_*`; update if bindings change |
18+
| Utility module (dev doc) | [src/doc/utility.md](../src/doc/utility.md) — read when editing `utl_*`; update if shared helpers or I/O change |
19+
| Build / test / wasm | [workflows/local-dev.md](workflows/local-dev.md) |
20+
| OCCT desktop 8 vs wasm 7.9.3 | [conventions/occt-wasm-dual-version.md](conventions/occt-wasm-dual-version.md) — until wasm works on OCCT 8 |
21+
| OCCT handles (`*_ptr`) | [conventions/occt-handles.md](conventions/occt-handles.md) — prefer aliases over `Handle()` for clang-format |
22+
| Release | [workflows/release.md](workflows/release.md) |
23+
| Issue/PR drafts | [drafts/](drafts/)[github-drafts.md](conventions/github-drafts.md) |
24+
| Token-saving rules | [conventions/token-lean.md](conventions/token-lean.md) |
25+
| Markdown tables | [conventions/markdown-tables.md](conventions/markdown-tables.md) — align GFM pipes for source + preview |
26+
| Outreach (optional) | [outreach/discoverability.md](outreach/discoverability.md) |
2527

2628
Full user-doc style: [docs/ezycad_doc_style.md](../docs/ezycad_doc_style.md). OCCT build: [docs/building-occt.md](../docs/building-occt.md).

agents/conventions/occt-handles.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# OCCT handles vs `Handle()` macro
2+
3+
Prefer the pattern in [`src/utl_types.h`](../../src/utl_types.h):
4+
5+
```cpp
6+
using AIS_Shape_ptr = opencascade::handle<AIS_Shape>;
7+
```
8+
9+
Use those `*_ptr` aliases (or `opencascade::handle<T>` inline) in new and touched code.
10+
11+
## Why not `Handle(T)`?
12+
13+
OCCT's `Handle(T)` macro is valid and expands to `opencascade::handle<T>`, but **clang-format does not treat it as a type**. With `PointerAlignment: Left`, format runs produce awkward spacing such as:
14+
15+
```cpp
16+
const Handle(Geom_TrimmedCurve) & curve; // bad (formatter)
17+
const Geom_TrimmedCurve_ptr& curve; // good
18+
```
19+
20+
Do **not** paper over this with `// clang-format off` for routine handle declarations.
21+
22+
## Agent rules
23+
24+
1. For a type used as a handle in EzyCad, add or reuse a `using TypeName_ptr = opencascade::handle<TypeName>;` in `utl_types.h` (forward-declare the class there if needed, matching existing entries).
25+
2. Prefer `TypeName_ptr` in signatures, locals, and members.
26+
3. `DownCast`: `TypeName_ptr::DownCast(obj)` (or `opencascade::handle<TypeName>::DownCast(obj)`), not `Handle(TypeName)::DownCast(obj)`.
27+
4. When editing a function that already uses `Handle(...)`, convert that local scope to `*_ptr` / `opencascade::handle` if the change is small; do not mass-rewrite unrelated files.
28+
29+
Style summary: [docs/ezycad_code_style.md](../../docs/ezycad_code_style.md) (OCCT handles).
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# OCCT desktop vs WASM (until v8 wasm works)
2+
3+
**Temporary:** keep this file until EzyCad WASM builds and runs correctly against OCCT **8.x** (GLES shading and any remaining regressions fixed; see [docs/bugs.md](../../docs/bugs.md)). Then delete this convention and drop the pointers from `AGENTS.md` / `agents/README.md` / `token-lean.md`.
4+
5+
## Pins
6+
7+
| Target | OCCT version | Notes |
8+
| ----------------- | ----------------------------------- | ------------------------------------------ |
9+
| Desktop (Windows) | **8.0.0** | Prebuilts + `TKOpenGl` |
10+
| WASM (Emscripten) | **7.9.3** (`V7_9_3`) recommended | `scripts/build-occt-793-wasm.ps1` |
11+
| WASM (compare) | 8.0.0.p1 (`V8_0_0_p1`) experimental | Shading regressions; not for demos/release |
12+
13+
Details: [docs/building-occt.md](../../docs/building-occt.md), [workflows/local-dev.md](../workflows/local-dev.md).
14+
15+
## Shared `src/` must compile on both
16+
17+
Most app code is one tree linked against **desktop 8** and **wasm 7.9.3**. Prefer the **API intersection**. Do not assume an OCCT 8-only symbol or overload is available on the wasm kit.
18+
19+
### `Standard_Failure` messages
20+
21+
Use `standard_failure_message(e)` from [`utl_occt.h`](../../src/utl_occt.h) — not raw `what()` or `GetMessageString()`:
22+
23+
```cpp
24+
catch (const Standard_Failure& e)
25+
{
26+
const char* msg = standard_failure_message(e);
27+
// ...
28+
}
29+
```
30+
31+
OCCT **8** (desktop) deprecates `GetMessageString()` in favor of `what()`; OCCT **7.9.3** (wasm) has no `what()` on `Standard_Failure`. The helper picks the right API via `OCC_VERSION_HEX` so shared code builds on both without warnings or missing-member errors.
32+
33+
### Other dual-version habits
34+
35+
- Prefer existing call patterns already used for both targets over newer OCCT 8 helpers.
36+
- If you must use an 8-only API, gate it or verify a wasm 7.9.3 configure/build still succeeds.
37+
- Default wasm work to **7.9.3**; use the v8 wasm script only when comparing upstream regressions.
38+
39+
## When retiring this note
40+
41+
After wasm on OCCT 8 is the supported path: switch demo/release scripts to `build-occt-v8-wasm.ps1`, update [docs/building-occt.md](../../docs/building-occt.md) / [docs/bugs.md](../../docs/bugs.md), then remove this file and its index links.

agents/conventions/token-lean.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Goal: give assistants **only what they need** for the task at hand. Full style g
1515
| Task | Read |
1616
| ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
1717
| Build / test | [workflows/local-dev.md](../workflows/local-dev.md) — or root [README.md](../../README.md#building-instructions) |
18+
| OCCT / WASM (shared `src/` APIs) | [occt-wasm-dual-version.md](occt-wasm-dual-version.md) — desktop 8 vs wasm 7.9.3 until wasm works on OCCT 8 |
19+
| OCCT handles | [occt-handles.md](occt-handles.md)`*_ptr` / `opencascade::handle` over `Handle()` (clang-format) |
1820
| User-visible UI/settings | [user-docs-sync.md](user-docs-sync.md) + target `docs/usage-*.md` only |
1921
| Sketch subsystem (`src/sketch*`, `tests/sketch_*_tests.cpp`, sketch behavior in `occt_view` / `gui`) | [src/doc/sketch.md](../../src/doc/sketch.md) — read before editing; update when API, invariants, module layout, or workflows change |
2022
| Shape module (`src/shp*`, shape ops in `occt_view` / `gui`) | [src/doc/shape.md](../../src/doc/shape.md) — read before editing; update when API, operation patterns, or registration/undo change |
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
github_issue: 196
3+
github_pr: 197
4+
status: active
5+
paired_draft: ../prs/active/gh-197-occt-dual-version-handle-warnings.md
6+
---
7+
8+
# OCCT dual-version (desktop 8 / WASM 7.9.3) harden
9+
10+
**Suggested labels:** `bug`, `documentation`, `refactor`
11+
12+
---
13+
14+
## Title (GitHub)
15+
16+
OCCT dual-version (desktop 8 / WASM 7.9.3): Handle aliases, failure messages, build warning cleanup
17+
18+
## Body (GitHub)
19+
20+
Filed: https://github.com/trailcode/EzyCad/issues/196
21+
22+
### Summary
23+
24+
Shared `src/` must build against desktop OCCT **8.0.0** and recommended WASM OCCT **7.9.3** until OCCT 8 GLES shading works for wasm. Harden that split: stop using `Handle(T)`, add dual-version `Standard_Failure` messaging, document agent conventions, clear native/WASM warnings.
25+
26+
### Acceptance criteria
27+
28+
- [x] `standard_failure_message()` used at `Standard_Failure` catch sites
29+
- [x] `Handle(...)` -> `*_ptr` aliases in `utl_types.h`
30+
- [x] Agent conventions wired (`occt-wasm-dual-version.md`, `occt-handles.md`)
31+
- [x] Native/WASM listed warnings cleared
32+
- [ ] CI green
33+
34+
### Related
35+
36+
- PR: https://github.com/trailcode/EzyCad/pull/197
37+
- Draft: `agents/drafts/prs/active/gh-197-occt-dual-version-handle-warnings.md`
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
github_issue: 196
3+
github_pr: 197
4+
status: active
5+
paired_draft: ../issues/active/gh-196-occt-dual-version-handle-warnings.md
6+
---
7+
8+
# PR - OCCT dual-version harden
9+
10+
## Title
11+
12+
OCCT dual-version harden: Handle aliases, failure messages, warning cleanup
13+
14+
## Summary
15+
16+
- Desktop OCCT 8 vs WASM 7.9.3: `standard_failure_message()`, `*_ptr` over `Handle(T)`, agent conventions.
17+
- Compiler warning cleanup (native + emscripten dock flags).
18+
19+
## Related
20+
21+
- Issue: https://github.com/trailcode/EzyCad/issues/196
22+
- PR: https://github.com/trailcode/EzyCad/pull/197
23+
- Branch: `Trailcode/gen-fixes-refactor`
24+
25+
## Test Plan
26+
27+
- [x] Native Debug rebuild clean of listed warnings
28+
- [x] WASM build-em-793 dock enum warning fixed
29+
- [ ] CI Windows MSVC
30+
- [ ] Spot-check OCCT error paths and Esc cancel
31+
32+
## Post-merge
33+
34+
- [ ] Archive this draft and paired issue draft
35+
- [ ] Close #196 if fully addressed
36+
- [ ] Consider `CHANGELOG.md` `[Unreleased]` note

agents/workflows/local-dev.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ See root [README.md](../../README.md#building-instructions) and [docs/building-o
4747

4848
## WebAssembly (Emscripten)
4949

50+
**Agent note:** desktop uses OCCT **8**, recommended wasm uses **7.9.3** until OCCT 8 wasm works. Shared `src/` must compile on both — see [conventions/occt-wasm-dual-version.md](../conventions/occt-wasm-dual-version.md).
51+
5052
Full OCCT + EzyCad wasm instructions live in [docs/building-occt.md](../../docs/building-occt.md#webassembly-emscripten) and the root README.
5153

5254
High-level flow (after `emsdk_env`):

docs/ezycad_code_style.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ User-facing Markdown (now in `docs/`: `usage.md`, `usage-*.md`, `scripting.md`,
6969
- **Helper functions** (`.cpp`): Prefer **file-local static helpers** in an anonymous namespace at the **bottom** of the implementing `.cpp` file. Forward-declare them near the top (or above their first use) when needed. Avoid large helper blocks at the top of the file; the goal is high-level code first, helpers last for readability.
7070
- **PIMPL** (`class Foo; class Foo::Impl`): Use when hiding implementation details or when you want to swap implementations (e.g. `Sketch_nodes`, `Sketch_op_recorder`). Keep the public surface in the header; put data members, private record types, and apply/clone logic in `Impl` inside the `.cpp`.
7171
- **Templates**: Prefer putting template implementations in `.inl` files included from the header (e.g. `utl_types.inl`, `utl.inl`).
72-
- **OCCT handles**: Use `opencascade::handle<T>` and project aliases (e.g. `AIS_Shape_ptr`, `Shp_ptr`).
72+
- **OCCT handles**: Prefer `opencascade::handle<T>` and project `*_ptr` aliases from `utl_types.h` (e.g. `AIS_Shape_ptr`, `Shp_ptr`). Avoid the OCCT `Handle(T)` macro in new/touched code -- clang-format mishandles it with `PointerAlignment: Left` (e.g. `Handle(Foo) &`). See [agents/conventions/occt-handles.md](../agents/conventions/occt-handles.md).
73+
- **OCCT desktop vs WASM**: Until WASM runs correctly on OCCT 8, desktop is OCCT **8** and recommended WASM is **7.9.3**. Prefer APIs available on both; for `Standard_Failure` use `standard_failure_message(e)` from `utl_occt.h` (not raw `what()` / `GetMessageString()`). See [agents/conventions/occt-wasm-dual-version.md](../agents/conventions/occt-wasm-dual-version.md).
7374
- **Result/error handling**: See **Fail fast** below. Use `Result<T>` and `Status` from `utl.h`, `CHK_RET(...)` for early return on failure.
7475
- **Assertions**: See **Fail fast** below. Use `EZY_ASSERT` and `EZY_ASSERT_MSG` from `utl_dbg.h`; use `DBG_MSG` for debug logging.
7576

src/doc/utility.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Typical uses:
2424
| [`utl_types.h`](../utl_types.h) | OCCT/AIS handle typedefs, `ScreenCoords`, `Export_format`, `DECL_PTR`, `SafeType` |
2525
| [`utl_geom.h`](../utl_geom.h) / [`.cpp`](../utl_geom.cpp) | 2D/3D geometry, wires, dimensions, Boost polygon tests, plane projection |
2626
| [`utl_geom_boost.inl`](../utl_geom_boost.inl) | `ezy_geom` Boost.Geometry aliases |
27-
| [`utl_occt.h`](../utl_occt.h) / [`.cpp`](../utl_occt.cpp) | `TopAbs` name table, `try_make_solid` |
27+
| [`utl_occt.h`](../utl_occt.h) / [`.cpp`](../utl_occt.cpp) | `TopAbs` name table, `try_make_solid`, `standard_failure_message` |
2828
| [`utl_json.h`](../utl_json.h) / [`.cpp`](../utl_json.cpp) | JSON serializers for `gp_Pnt`, `gp_Pln`, etc. |
2929
| [`utl_io.h`](../utl_io.h) / [`.cpp`](../utl_io.cpp) | `.ezy` zip v3 pack/unpack, format sniff, base64 |
3030
| [`utl_asset_store.h`](../utl_asset_store.h) / [`.cpp`](../utl_asset_store.cpp) | Content-addressed RGBA blobs for sketch underlay assets |
@@ -102,10 +102,11 @@ Includes [`utl_geom_boost.inl`](../utl_geom_boost.inl) for `ezy_geom` polygon /
102102

103103
## OCCT helpers (`utl_occt`)
104104

105-
| API | Role |
106-
| -------------------------- | -------------------------------------------------------- |
107-
| `c_names_TopAbs_ShapeEnum` | String names parallel to OCCT enum (selection filter UI) |
108-
| `try_make_solid(shape)` | Wrap closed shell as solid when possible |
105+
| API | Role |
106+
| ----------------------------- | --------------------------------------------------------------------- |
107+
| `c_names_TopAbs_ShapeEnum` | String names parallel to OCCT enum (selection filter UI) |
108+
| `try_make_solid(shape)` | Wrap closed shell as solid when possible |
109+
| `standard_failure_message(e)` | OCCT 7/8-safe message from `Standard_Failure` (see dual-version note) |
109110

110111
## JSON geom (`utl_json`)
111112

0 commit comments

Comments
 (0)