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