brep_kernel/feature_pipeline/pmi/annotations/
note.rs1use super::{id_field, params, reference_field, schema_entry, string_field, PmiTypeDef};
5use crate::feature_pipeline::pmi::resolve::{a3, resolve_reference};
6use crate::feature_pipeline::pmi::{PmiAnnotation, PmiContext, PmiGeometry, Resolved};
7use crate::feature_pipeline::SelectionProbe;
8
9pub const DEF: PmiTypeDef = PmiTypeDef {
10 type_id: "note",
11 short_name: "NOTE",
12 icon: "\u{1F5CE}",
13 long_name: "\u{1F5CE} Note",
14 label: "Note",
15 applicable,
16 schema,
17 resolve,
18};
19
20fn applicable(probe: &SelectionProbe) -> bool {
22 probe.faces + probe.edges + probe.vertices + probe.planes + probe.solids >= 1
23}
24
25fn schema() -> serde_json::Value {
26 schema_entry(
27 &DEF,
28 params(vec![
29 ("id", id_field()),
30 ("text", string_field("Text", "NOTE", "The note text")),
31 (
32 "anchor",
33 reference_field("Anchor", &["VERTEX", "EDGE", "FACE"], false, 0, 1, "Optional: the element whose point seeds the note position"),
34 ),
35 ]),
36 )
37}
38
39fn resolve(annotation: &PmiAnnotation, context: &PmiContext<'_>) -> Result<Resolved, String> {
40 let anchors = annotation.references("anchor");
41 let seed = match anchors.first() {
42 Some(anchor) => resolve_reference(context.scene, anchor)?.representative_point(),
43 None => crate::Vec3::new(0.0, 0.0, 0.0),
44 };
45 let position = annotation.label_world.unwrap_or(a3(seed));
46 Ok(Resolved {
47 text: annotation.text("text").to_string(),
48 value: None,
49 unit: "",
50 references: anchors,
51 geometry: PmiGeometry::Note { position },
52 default_label: a3(seed),
53 })
54}