Skip to main content

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
16/// `assemblyConstraints` namespace so the dialog engine renders them with the
17/// same machinery.
18pub fn feature_schema_catalogue() -> serde_json::Value {
19    serde_json::json!({
20        "version": 1,
21        "assemblyConstraints": super::assembly::constraint_schema_catalogue(),
22        "features": [
23            super::features::datum::schema(),
24            super::features::plane::schema(),
25            super::features::cube::schema(),
26            super::features::cylinder::schema(),
27            super::features::cone::schema(),
28            super::features::sphere::schema(),
29            super::features::torus::schema(),
30            super::features::pyramid::schema(),
31            super::features::nurbs_solid::schema(),
32            super::features::import3d::schema(),
33            super::features::sketch::schema(),
34            super::features::sketch3d::schema(),
35            super::features::spline::schema(),
36            super::features::waypoint::schema(),
37            super::features::weld::schema(),
38            super::features::weld::groove::schema(),
39            super::features::weld::tack_schema(),
40            super::features::weld::lap::spot_schema(),
41            super::features::weld::lap::seam_schema(),
42            super::features::weld::lap::plug_schema(),
43            super::features::weld::groove::edge::edge_schema(),
44            super::features::weld::groove::edge::corner_schema(),
45            super::features::weld::groove::edge::surfacing_schema(),
46            super::features::gear::spur::schema(),
47            super::features::gear::helical::schema(),
48            super::features::gear::helical::herringbone_schema(),
49            super::features::gear::rack::schema(),
50            super::features::gear::ring::schema(),
51            super::features::gear::sprocket::schema(),
52            super::features::gear::timing_pulley::schema(),
53            super::features::gear::straight_spline::schema(),
54            super::features::gear::involute_spline::schema(),
55            super::features::gear::ratchet::schema(),
56            super::features::gear::geneva::schema(),
57            super::features::gear::worm::schema(),
58            super::features::gear::cycloidal::disc_schema(),
59            super::features::gear::cycloidal::ring_schema(),
60            super::features::gear::cycloidal_gear::schema(),
61            super::features::helix::schema(),
62            super::features::extrude::schema(),
63            super::features::boolean::schema(),
64            super::features::fillet::schema(),
65            super::features::chamfer::schema(),
66            super::features::offset_shell::schema(),
67            super::features::offset_face::schema(),
68            super::features::push_face::schema(),
69            super::features::transform_face::schema(),
70            super::features::delete_face::schema(),
71            super::features::refit_faces::schema(),
72            super::features::deform_face::schema(),
73            super::features::sew_to_solid::schema(),
74            super::features::thicken::schema(),
75            super::features::sheet_metal_tab::schema(),
76            super::features::sheet_metal_contour_flange::schema(),
77            super::features::sheet_metal_flange::schema(),
78            super::features::sheet_metal_hem::schema(),
79            super::features::sheet_metal_closed_corner::schema(),
80            super::features::sheet_metal_mirror::schema(),
81            super::features::sheet_metal_corner::schema_fillet(),
82            super::features::sheet_metal_corner::schema_chamfer(),
83            super::features::sheet_metal_cutout::schema(),
84            super::features::loft::schema(),
85            super::features::fill::schema(),
86            super::features::mirror::schema(),
87            super::features::split::schema(),
88            super::features::revolve::schema(),
89            super::features::rib::schema(),
90            super::features::sweep::schema(),
91            super::features::path_sweep::schema(),
92            super::features::hole::schema(),
93            super::features::tube::schema(),
94            super::features::transform::schema(),
95            super::features::pattern::schema(),
96            super::features::assembly_component::schema(),
97            super::features::assembly_pattern::schema()
98        ]
99    })
100}
101
102/// wasm boundary: the whole feature-schema catalogue as JSON.
103#[wasm_bindgen]
104pub fn feature_schemas_json() -> String {
105    feature_schema_catalogue().to_string()
106}
107
108/// The DIALOG FIELD-VISIBILITY hook, kernel-owned like the schemas themselves.
109///
110/// Given a feature's `type` (its `shortName`, e.g. `"H"`) and the dialog's
111/// CURRENT param values, return the param keys that should be HIDDEN for those
112/// values — the choke point every schema-driven dialog consults to decide which
113/// fields to draw. A feature opts in by exposing its own `hidden_params(values)`
114/// beside its `schema()` (see `features::hole::hidden_params`); the mechanism is
115/// uniform across every dialog, and a feature that declares no hook (or an
116/// unknown type) hides nothing, so all its fields stay visible.
117///
118/// The form engine is immediate-mode and re-runs this every frame against the
119/// live values, which is what makes one pure function serve both "the dialog was
120/// just opened" and "a field just changed" — there is no separate event to wire.
121pub fn feature_hidden_params(feature_type: &str, values: &serde_json::Value) -> Vec<String> {
122    let keys: Vec<&'static str> = match feature_type {
123        "H" => super::features::hole::hidden_params(values),
124        "SM.CLOSED_CORNER" => super::features::sheet_metal_closed_corner::hidden_params(values),
125        "WELD" => super::features::weld::hidden_params(values),
126        "WELD.GROOVE" => super::features::weld::groove::hidden_params(values),
127        "WELD.TACK" => super::features::weld::tack_hidden_params(values),
128        "GEAR.SPUR" => super::features::gear::spur::hidden_params(values),
129        "GEAR.RACK" => super::features::gear::rack::hidden_params(values),
130        "GEAR.HELICAL" | "GEAR.HERRINGBONE" => super::features::gear::helical::hidden_params(values),
131        "GEAR.RING" => super::features::gear::ring::hidden_params(values),
132        "GEAR.SPLINE_STRAIGHT" => super::features::gear::straight_spline::hidden_params(values),
133        "GEAR.SPLINE_INV" => super::features::gear::involute_spline::hidden_params(values),
134        "GEAR.TIMING_PULLEY" => super::features::gear::timing_pulley::hidden_params(values),
135        "GEAR.RATCHET" => super::features::gear::ratchet::hidden_params(values),
136        _ => Vec::new(),
137    };
138    keys.into_iter().map(str::to_owned).collect()
139}
140