geop_ops_drawing/
parts.rs1use geop_core_math::geop_error::GeopResult;
5use geop_core_program::reader::Reader;
6use geop_ops_model::placed::bom::{LineKind, Structure, bom};
7
8use crate::{DrawingArgs, PartsListLine};
9
10pub fn parts_list(
14 reader: &Reader,
15 file: &str,
16 args: &DrawingArgs,
17) -> GeopResult<Vec<PartsListLine>> {
18 if !args.bom {
19 return Ok(Vec::new());
20 }
21 let bom = bom(reader, file, Structure::Flat)?;
22 Ok((bom.lines.into_iter())
23 .map(|line| PartsListLine {
24 item: line.item,
25 quantity: line.quantity,
26 name: line.name,
27 designation: line.designation.unwrap_or_default(),
28 material: match line.kind {
29 LineKind::Part { material, .. } => material.unwrap_or_default(),
30 LineKind::Wire { colour, .. } => format!("wire, {colour}"),
31 },
32 placements: line.placements,
33 })
34 .collect())
35}