brep_kernel/feature_pipeline/schema.rs
1//! The feature-schema catalogue — kernel-owned feature DEFINITIONS.
2//!
3//! Each feature's schema lives WITH its own code (`features/<feat>.rs` exposes
4//! `schema()` — name, display-builder flag, `inputParamsSchema` — exactly the
5//! shape the caller's feature classes declared). This module only AGGREGATES them, in
6//! the registry's presentation order, and serves the catalogue to the caller's feature editor
7//! via [`feature_schemas_json`]. The caller's feature registry initializes from this;
8//! there is no caller-side schema. Function-valued UI fields (button actions,
9//! custom widgets) cannot cross the JSON boundary — the caller's hook code merges
10//! those back per-param at registry init.
11
12use wasm_bindgen::prelude::*;
13
14/// Assemble the catalogue from every feature's own `schema()`. The assembly
15/// constraint schemas join the export under their own `assemblyConstraints`
16/// namespace so the dialog engine renders them with the same machinery.
17pub fn feature_schema_catalogue() -> serde_json::Value {
18 serde_json::json!({
19 "version": 1,
20 "assemblyConstraints": super::assembly::constraint_schema_catalogue(),
21 "features": [
22 super::features::datum::schema(),
23 super::features::plane::schema(),
24 super::features::cube::schema(),
25 super::features::cylinder::schema(),
26 super::features::cone::schema(),
27 super::features::sphere::schema(),
28 super::features::torus::schema(),
29 super::features::pyramid::schema(),
30 super::features::import3d::schema(),
31 super::features::sketch::schema(),
32 super::features::spline::schema(),
33 super::features::waypoint::schema(),
34 super::features::helix::schema(),
35 super::features::extrude::schema(),
36 super::features::boolean::schema(),
37 super::features::fillet::schema(),
38 super::features::chamfer::schema(),
39 super::features::offset_shell::schema(),
40 super::features::offset_face::schema(),
41 super::features::push_face::schema(),
42 super::features::transform_face::schema(),
43 super::features::delete_face::schema(),
44 super::features::refit_faces::schema(),
45 super::features::thicken::schema(),
46 super::features::sheet_metal_tab::schema(),
47 super::features::sheet_metal_contour_flange::schema(),
48 super::features::sheet_metal_flange::schema(),
49 super::features::sheet_metal_hem::schema(),
50 super::features::sheet_metal_corner::schema_fillet(),
51 super::features::sheet_metal_corner::schema_chamfer(),
52 super::features::sheet_metal_cutout::schema(),
53 super::features::loft::schema(),
54 super::features::mirror::schema(),
55 super::features::split::schema(),
56 super::features::revolve::schema(),
57 super::features::rib::schema(),
58 super::features::sweep::schema(),
59 super::features::path_sweep::schema(),
60 super::features::hole::schema(),
61 super::features::tube::schema(),
62 super::features::transform::schema(),
63 super::features::pattern::schema(),
64 super::features::assembly_component::schema()
65 ]
66 })
67}
68
69/// wasm boundary: the whole feature-schema catalogue as JSON.
70#[wasm_bindgen]
71pub fn feature_schemas_json() -> String {
72 feature_schema_catalogue().to_string()
73}
74
75/// The DIALOG FIELD-VISIBILITY hook, kernel-owned like the schemas themselves.
76///
77/// Given a feature's `type` (its `shortName`, e.g. `"H"`) and the dialog's
78/// CURRENT param values, return the param keys that should be HIDDEN for those
79/// values — the choke point every schema-driven dialog consults to decide which
80/// fields to draw. A feature opts in by exposing its own `hidden_params(values)`
81/// beside its `schema()` (see `features::hole::hidden_params`); the mechanism is
82/// uniform across every dialog, and a feature that declares no hook (or an
83/// unknown type) hides nothing, so all its fields stay visible.
84///
85/// The form engine is immediate-mode and re-runs this every frame against the
86/// live values, which is what makes one pure function serve both "the dialog was
87/// just opened" and "a field just changed" — there is no separate event to wire.
88pub fn feature_hidden_params(feature_type: &str, values: &serde_json::Value) -> Vec<String> {
89 let keys: Vec<&'static str> = match feature_type {
90 "H" => super::features::hole::hidden_params(values),
91 _ => Vec::new(),
92 };
93 keys.into_iter().map(str::to_owned).collect()
94}
95