Skip to main content

cimstructs/
EquivalentNetwork.rs

1/// A class that groups electrical equivalents, including internal nodes, of a network that has been reduced. The ConnectivityNodes contained in the equivalent are intended to reflect internal nodes of the equivalent. The boundary Connectivity nodes where the equivalent connects outside itself are not contained by the equivalent.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct EquivalentNetwork {
4    #[serde(flatten)]
5    pub base: super::ConnectivityNodeContainer,
6}
7impl crate::base::CimElement for EquivalentNetwork {
8    fn mrid(&self) -> &str { &self.base.base.base.id }
9    fn type_name(&self) -> &'static str { "EquivalentNetwork" }
10    fn as_any(&self) -> &dyn std::any::Any { self }
11    fn to_json_value(&self) -> serde_json::Value {
12        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
13    }
14    fn to_block(&self) -> crate::base::RdfBlock {
15        let mut block = self.base.to_block();
16        block.type_name = "EquivalentNetwork".to_string();
17        block
18    }
19}
20
21impl EquivalentNetwork {
22    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
23        let mut obj = Self::default();
24        obj.base.base.base.id.clone_from(&b.mrid);
25        for (key, val) in &b.fields {
26            match key.as_str() {
27                "IdentifiedObject.description" => {
28                    match val {
29                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
30                        crate::base::FieldValue::TextList(svs) => {
31                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
32                        }
33                        _ => {}
34                    }
35                }
36                "IdentifiedObject.energyIdentCodeEic" => {
37                    match val {
38                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
39                        crate::base::FieldValue::TextList(svs) => {
40                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
41                        }
42                        _ => {}
43                    }
44                }
45                "IdentifiedObject.mRID" => {
46                    match val {
47                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
48                        crate::base::FieldValue::TextList(svs) => {
49                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
50                        }
51                        _ => {}
52                    }
53                }
54                "IdentifiedObject.name" => {
55                    match val {
56                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
57                        crate::base::FieldValue::TextList(svs) => {
58                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
59                        }
60                        _ => {}
61                    }
62                }
63                "IdentifiedObject.shortName" => {
64                    match val {
65                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
66                        crate::base::FieldValue::TextList(svs) => {
67                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
68                        }
69                        _ => {}
70                    }
71                }
72                _ => {}
73            }
74        }
75        obj
76    }
77}