Skip to main content

cimstructs/
SvVoltage.rs

1/// State variable for voltage.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct SvVoltage {
4    pub id: String,
5    /// The topological node associated with the voltage state.
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub topological_node: Option<super::base::MridRef>,
8    /// The voltage angle of the topological node complex voltage with respect to system reference.
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub angle: Option<f64>,
11    /// The voltage magnitude at the topological node. The attribute shall be a positive value.
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub v: Option<f64>,
14}
15impl crate::base::CimElement for SvVoltage {
16    fn mrid(&self) -> &str { &self.id }
17    fn type_name(&self) -> &'static str { "SvVoltage" }
18    fn as_any(&self) -> &dyn std::any::Any { self }
19    fn to_json_value(&self) -> serde_json::Value {
20        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
21    }
22    fn to_block(&self) -> crate::base::RdfBlock {
23        let mut block = crate::base::RdfBlock {
24            type_name: "SvVoltage".to_string(),
25            mrid: self.id.clone(),
26            fields: std::collections::HashMap::new(),
27            duplicate_fields: std::collections::HashSet::new(),
28        };
29        if let Some(ref v) = self.topological_node {
30            block.fields.insert("SvVoltage.TopologicalNode".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(v) = self.angle {
33            block.fields.insert("SvVoltage.angle".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        if let Some(v) = self.v {
36            block.fields.insert("SvVoltage.v".into(), crate::base::FieldValue::Text(v.to_string()));
37        }
38        block
39    }
40}
41
42impl SvVoltage {
43    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
44        let mut obj = Self::default();
45        obj.id.clone_from(&b.mrid);
46        for (key, val) in &b.fields {
47            match key.as_str() {
48                "SvVoltage.TopologicalNode" => {
49                    if let crate::base::FieldValue::Resource(sv) = val {
50                        obj.topological_node = Some(crate::base::MridRef { mrid: sv.clone() });
51                    }
52                }
53                "SvVoltage.angle" => {
54                    match val {
55                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.angle = Some(v); } }
56                        crate::base::FieldValue::TextList(svs) => {
57                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.angle = Some(v); } }
58                        }
59                        _ => {}
60                    }
61                }
62                "SvVoltage.v" => {
63                    match val {
64                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.v = Some(v); } }
65                        crate::base::FieldValue::TextList(svs) => {
66                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.v = Some(v); } }
67                        }
68                        _ => {}
69                    }
70                }
71                _ => {}
72            }
73        }
74        obj
75    }
76}