Skip to main content

cimstructs/
DCNode.rs

1/// DC nodes are points where terminals of DC conducting equipment are connected together with zero impedance.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct DCNode {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// The DC container for the DC nodes.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub dc_equipment_container: Option<super::base::MridRef>,
9    /// The DC topological node to which this DC connectivity node is assigned. May depend on the current state of switches in the network.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub dc_topological_node: Option<super::base::MridRef>,
12}
13impl crate::base::CimElement for DCNode {
14    fn mrid(&self) -> &str { &self.base.id }
15    fn type_name(&self) -> &'static str { "DCNode" }
16    fn as_any(&self) -> &dyn std::any::Any { self }
17    fn to_json_value(&self) -> serde_json::Value {
18        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
19    }
20    fn to_block(&self) -> crate::base::RdfBlock {
21        let mut block = self.base.to_block();
22        block.type_name = "DCNode".to_string();
23        if let Some(ref v) = self.dc_equipment_container {
24            block.fields.insert("DCNode.DCEquipmentContainer".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
25        }
26        if let Some(ref v) = self.dc_topological_node {
27            block.fields.insert("DCNode.DCTopologicalNode".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        block
30    }
31}
32
33impl DCNode {
34    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
35        let mut obj = Self::default();
36        obj.base.id.clone_from(&b.mrid);
37        for (key, val) in &b.fields {
38            match key.as_str() {
39                "DCNode.DCEquipmentContainer" => {
40                    if let crate::base::FieldValue::Resource(sv) = val {
41                        obj.dc_equipment_container = Some(crate::base::MridRef { mrid: sv.clone() });
42                    }
43                }
44                "DCNode.DCTopologicalNode" => {
45                    if let crate::base::FieldValue::Resource(sv) = val {
46                        obj.dc_topological_node = Some(crate::base::MridRef { mrid: sv.clone() });
47                    }
48                }
49                "IdentifiedObject.description" => {
50                    match val {
51                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
52                        crate::base::FieldValue::TextList(svs) => {
53                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
54                        }
55                        _ => {}
56                    }
57                }
58                "IdentifiedObject.energyIdentCodeEic" => {
59                    match val {
60                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
61                        crate::base::FieldValue::TextList(svs) => {
62                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
63                        }
64                        _ => {}
65                    }
66                }
67                "IdentifiedObject.mRID" => {
68                    match val {
69                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
70                        crate::base::FieldValue::TextList(svs) => {
71                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
72                        }
73                        _ => {}
74                    }
75                }
76                "IdentifiedObject.name" => {
77                    match val {
78                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
79                        crate::base::FieldValue::TextList(svs) => {
80                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
81                        }
82                        _ => {}
83                    }
84                }
85                "IdentifiedObject.shortName" => {
86                    match val {
87                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
88                        crate::base::FieldValue::TextList(svs) => {
89                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
90                        }
91                        _ => {}
92                    }
93                }
94                _ => {}
95            }
96        }
97        obj
98    }
99}