1mod drive;
2mod emit_intensity;
3mod error;
4mod phase;
5
6use std::collections::HashMap;
7
8pub type BitVec = bit_vec::BitVec<u32>;
10
11pub use drive::Drive;
12pub use emit_intensity::EmitIntensity;
13pub use error::GainError;
14pub use phase::Phase;
15
16use crate::{
17 datagram::{Segment, TransitionMode},
18 geometry::{Device, Geometry, Transducer},
19};
20
21pub trait GainCalculator: Send + Sync {
25 #[must_use]
27 fn calc(&self, tr: &Transducer) -> Drive;
28}
29
30impl GainCalculator for Box<dyn GainCalculator> {
31 fn calc(&self, tr: &Transducer) -> Drive {
32 self.as_ref().calc(tr)
33 }
34}
35
36pub trait GainCalculatorGenerator {
38 type Calculator: GainCalculator;
40
41 #[must_use]
43 fn generate(&mut self, device: &Device) -> Self::Calculator;
44}
45
46pub trait Gain: std::fmt::Debug + Sized {
52 type G: GainCalculatorGenerator;
54
55 fn init(
60 self,
61 geometry: &Geometry,
62 filter: Option<&HashMap<usize, BitVec>>,
63 ) -> Result<Self::G, GainError>;
64}
65
66#[doc(hidden)]
67pub struct GainOperationGenerator<G: GainCalculatorGenerator> {
68 pub generator: G,
69 pub segment: Segment,
70 pub transition: Option<TransitionMode>,
71}
72
73impl<G: GainCalculatorGenerator> GainOperationGenerator<G> {
74 pub fn new<T: Gain<G = G>>(
75 gain: T,
76 geometry: &Geometry,
77 segment: Segment,
78 transition: Option<TransitionMode>,
79 ) -> Result<Self, GainError> {
80 Ok(Self {
81 generator: gain.init(geometry, None)?,
82 segment,
83 transition,
84 })
85 }
86}
87
88#[derive(Debug, Clone, PartialEq)]
89pub struct GainInspectionResult {
91 pub name: String,
93 pub data: Vec<Drive>,
95 pub segment: Segment,
97 pub transition_mode: Option<TransitionMode>,
99}