kicad_monkey_core/pcb/primary/
batch.rs1use super::*;
4
5pub type PcbFootprintPrimaryFieldResults =
9 [(&'static str, Result<Option<PcbFootprintProperty>, Error>); 3];
10
11#[derive(Debug)]
14pub struct PcbFootprintPrimaryBatch {
15 version: i64,
16 values: BTreeMap<String, String>,
17 fields: PcbFootprintPrimaryFieldResults,
18}
19
20impl PcbFootprintPrimaryBatch {
21 pub fn version(&self) -> i64 {
23 self.version
24 }
25
26 pub fn values(&self) -> &BTreeMap<String, String> {
28 &self.values
29 }
30
31 pub fn into_parts(self) -> (BTreeMap<String, String>, PcbFootprintPrimaryFieldResults) {
33 (self.values, self.fields)
34 }
35}
36
37impl PcbView<'_> {
38 pub fn effective_footprint_primary_batch(
43 &self,
44 footprint_index: usize,
45 ) -> Result<PcbFootprintPrimaryBatch, Error> {
46 let (properties, texts) = event_indices(self, footprint_index)?;
47 let version = self.metadata()?.version;
48 let events = events_from_indexed(self.source, properties, texts, version, self.limits)?;
49 let footprint =
50 footprint_from_span(self.source, &self.footprints[footprint_index], self.limits)?;
51 let mut values = BTreeMap::new();
52 let mut histories: [Vec<Event>; 3] = std::array::from_fn(|_| Vec::new());
53 for event in events {
54 let index = PRIMARY
55 .iter()
56 .position(|name| *name == event.row.name)
57 .expect("acquired primary events have an existing standard role");
58 values.insert(event.row.name.clone(), event.row.value.clone());
59 histories[index].push(event);
60 }
61 let fields = std::array::from_fn(|index| {
62 let name = PRIMARY[index];
63 (
64 name,
65 reduce(
66 self.source,
67 std::mem::take(&mut histories[index]),
68 &footprint,
69 Some(version),
70 name,
71 self.limits,
72 ),
73 )
74 });
75 Ok(PcbFootprintPrimaryBatch {
76 version,
77 values,
78 fields,
79 })
80 }
81}