1mod components;
2mod sources;
3mod control;
4mod subckt;
5
6pub use components::*;
7use reda_unit::{Number, Suffix, Unit, UnitNumber};
8pub use sources::*;
9pub use control::*;
10pub use subckt::*;
11
12use std::path::Path;
13use crate::parse::{load_spice, ParseError};
14
15#[derive(Debug, Default)]
16pub struct Spice {
17 pub components: Vec<Component>,
18 pub sources: Vec<Source>,
19 pub simulation: Vec<SimCommand>,
20 pub measures: Vec<MeasureCommand>,
21 pub subckts: Vec<Subckt>,
22 pub instances: Vec<Instance>,
23 pub model: Vec<Model>,
24}
25
26impl Spice {
27 pub fn load_from<P: AsRef<Path>>(path: P) -> Result<Self, ParseError> {
28 load_spice(path)
29 }
30
31 pub fn new() -> Self {
32 Self::default()
33 }
34}
35
36pub trait ToSpice {
37 fn to_spice(&self) -> String;
38}
39
40impl ToSpice for Number {
41 fn to_spice(&self) -> String {
42 if self.suffix == Suffix::Mega {
43 format!("{}{}", self.value, "Meg")
44 } else {
45 self.to_string()
46 }
47 }
48}
49
50impl<U: Unit> ToSpice for UnitNumber<U> {
51 fn to_spice(&self) -> String {
52 format!("{}{}", self.value().to_spice(), U::name())
53 }
54}