Skip to main content

cimstructs/
SvShuntCompensatorSections.rs

1/// State variable for the number of sections in service for a shunt compensator.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct SvShuntCompensatorSections {
4    pub id: String,
5    /// The shunt compensator for which the state applies.
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub shunt_compensator: Option<super::base::MridRef>,
8    /// The number of sections in service as a continuous variable. The attribute shall be a positive value or zero. To get integer value scale with ShuntCompensator.bPerSection.
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub sections: Option<f64>,
11}
12impl crate::base::CimElement for SvShuntCompensatorSections {
13    fn mrid(&self) -> &str { &self.id }
14    fn type_name(&self) -> &'static str { "SvShuntCompensatorSections" }
15    fn as_any(&self) -> &dyn std::any::Any { self }
16    fn to_json_value(&self) -> serde_json::Value {
17        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
18    }
19    fn to_block(&self) -> crate::base::RdfBlock {
20        let mut block = crate::base::RdfBlock {
21            type_name: "SvShuntCompensatorSections".to_string(),
22            mrid: self.id.clone(),
23            fields: std::collections::HashMap::new(),
24            duplicate_fields: std::collections::HashSet::new(),
25        };
26        if let Some(ref v) = self.shunt_compensator {
27            block.fields.insert("SvShuntCompensatorSections.ShuntCompensator".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        if let Some(v) = self.sections {
30            block.fields.insert("SvShuntCompensatorSections.sections".into(), crate::base::FieldValue::Text(v.to_string()));
31        }
32        block
33    }
34}
35
36impl SvShuntCompensatorSections {
37    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
38        let mut obj = Self::default();
39        obj.id.clone_from(&b.mrid);
40        for (key, val) in &b.fields {
41            match key.as_str() {
42                "SvShuntCompensatorSections.ShuntCompensator" => {
43                    if let crate::base::FieldValue::Resource(sv) = val {
44                        obj.shunt_compensator = Some(crate::base::MridRef { mrid: sv.clone() });
45                    }
46                }
47                "SvShuntCompensatorSections.sections" => {
48                    match val {
49                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.sections = Some(v); } }
50                        crate::base::FieldValue::TextList(svs) => {
51                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.sections = Some(v); } }
52                        }
53                        _ => {}
54                    }
55                }
56                _ => {}
57            }
58        }
59        obj
60    }
61}