Skip to main content

cimstructs/
VoltageLevel.rs

1/// A collection of equipment at one common system voltage forming a switchgear. The equipment typically consists of breakers, busbars, instrumentation, control, regulation and protection devices as well as assemblies of all these.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct VoltageLevel {
4    #[serde(flatten)]
5    pub base: super::EquipmentContainer,
6    /// The base voltage used for all equipment within the voltage level.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub base_voltage: Option<super::base::MridRef>,
9    /// The substation of the voltage level.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub substation: Option<super::base::MridRef>,
12    /// The bus bar's high voltage limit. The limit applies to all equipment and nodes contained in a given VoltageLevel. It is not required that it is exchanged in pair with lowVoltageLimit. It is preferable to use operational VoltageLimit, which prevails, if present.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub high_voltage_limit: Option<f64>,
15    /// The bus bar's low voltage limit. The limit applies to all equipment and nodes contained in a given VoltageLevel. It is not required that it is exchanged in pair with highVoltageLimit. It is preferable to use operational VoltageLimit, which prevails, if present.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub low_voltage_limit: Option<f64>,
18}
19impl crate::base::CimElement for VoltageLevel {
20    fn mrid(&self) -> &str { &self.base.base.base.base.id }
21    fn type_name(&self) -> &'static str { "VoltageLevel" }
22    fn as_any(&self) -> &dyn std::any::Any { self }
23    fn to_json_value(&self) -> serde_json::Value {
24        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
25    }
26    fn to_block(&self) -> crate::base::RdfBlock {
27        let mut block = self.base.to_block();
28        block.type_name = "VoltageLevel".to_string();
29        if let Some(ref v) = self.base_voltage {
30            block.fields.insert("VoltageLevel.BaseVoltage".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(ref v) = self.substation {
33            block.fields.insert("VoltageLevel.Substation".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
34        }
35        if let Some(v) = self.high_voltage_limit {
36            block.fields.insert("VoltageLevel.highVoltageLimit".into(), crate::base::FieldValue::Text(v.to_string()));
37        }
38        if let Some(v) = self.low_voltage_limit {
39            block.fields.insert("VoltageLevel.lowVoltageLimit".into(), crate::base::FieldValue::Text(v.to_string()));
40        }
41        block
42    }
43}
44
45impl VoltageLevel {
46    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
47        let mut obj = Self::default();
48        obj.base.base.base.base.id.clone_from(&b.mrid);
49        for (key, val) in &b.fields {
50            match key.as_str() {
51                "VoltageLevel.BaseVoltage" => {
52                    if let crate::base::FieldValue::Resource(sv) = val {
53                        obj.base_voltage = Some(crate::base::MridRef { mrid: sv.clone() });
54                    }
55                }
56                "VoltageLevel.Substation" => {
57                    if let crate::base::FieldValue::Resource(sv) = val {
58                        obj.substation = Some(crate::base::MridRef { mrid: sv.clone() });
59                    }
60                }
61                "VoltageLevel.highVoltageLimit" => {
62                    match val {
63                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.high_voltage_limit = Some(v); } }
64                        crate::base::FieldValue::TextList(svs) => {
65                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.high_voltage_limit = Some(v); } }
66                        }
67                        _ => {}
68                    }
69                }
70                "VoltageLevel.lowVoltageLimit" => {
71                    match val {
72                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.low_voltage_limit = Some(v); } }
73                        crate::base::FieldValue::TextList(svs) => {
74                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.low_voltage_limit = Some(v); } }
75                        }
76                        _ => {}
77                    }
78                }
79                "IdentifiedObject.description" => {
80                    match val {
81                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.description = sv.clone(); }
82                        crate::base::FieldValue::TextList(svs) => {
83                            if let Some(sv) = svs.last() { obj.base.base.base.base.description = sv.clone(); }
84                        }
85                        _ => {}
86                    }
87                }
88                "IdentifiedObject.energyIdentCodeEic" => {
89                    match val {
90                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
91                        crate::base::FieldValue::TextList(svs) => {
92                            if let Some(sv) = svs.last() { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
93                        }
94                        _ => {}
95                    }
96                }
97                "IdentifiedObject.mRID" => {
98                    match val {
99                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.m_rid = sv.clone(); }
100                        crate::base::FieldValue::TextList(svs) => {
101                            if let Some(sv) = svs.last() { obj.base.base.base.base.m_rid = sv.clone(); }
102                        }
103                        _ => {}
104                    }
105                }
106                "IdentifiedObject.name" => {
107                    match val {
108                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.name = sv.clone(); }
109                        crate::base::FieldValue::TextList(svs) => {
110                            if let Some(sv) = svs.last() { obj.base.base.base.base.name = sv.clone(); }
111                        }
112                        _ => {}
113                    }
114                }
115                "IdentifiedObject.shortName" => {
116                    match val {
117                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.short_name = sv.clone(); }
118                        crate::base::FieldValue::TextList(svs) => {
119                            if let Some(sv) = svs.last() { obj.base.base.base.base.short_name = sv.clone(); }
120                        }
121                        _ => {}
122                    }
123                }
124                _ => {}
125            }
126        }
127        obj
128    }
129}