Skip to main content

cimstructs/
Terminal.rs

1/// An AC electrical connection point to a piece of conducting equipment. Terminals are connected at physical connection points called connectivity nodes.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct Terminal {
4    #[serde(flatten)]
5    pub base: super::ACDCTerminal,
6    /// The conducting equipment of the terminal. Conducting equipment have terminals that may be connected to other conducting equipment terminals via connectivity nodes or topological nodes.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub conducting_equipment: Option<super::base::MridRef>,
9    /// The connectivity node to which this terminal connects with zero impedance.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub connectivity_node: Option<super::base::MridRef>,
12    /// The topological node associated with the terminal. This can be used as an alternative to the connectivity node path to topological node, thus making it unnecessary to model connectivity nodes in some cases. Note that the if connectivity nodes are in the model, this association would probably not be used as an input specification.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub topological_node: Option<super::base::MridRef>,
15    /// Represents the normal network phasing condition. If the attribute is missing, three phases (ABC) shall be assumed, except for terminals of grounding classes (specializations of EarthFaultCompensator, GroundDisconnector, and Ground) which will be assumed to be N. Therefore, phase code ABCN is explicitly declared when needed, e.g. for star point grounding equipment. The phase code on terminals connecting same ConnectivityNode or same TopologicalNode as well as for equipment between two terminals shall be consistent.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub phases: Option<super::base::UriRef>,
18}
19impl crate::base::CimElement for Terminal {
20    fn mrid(&self) -> &str { &self.base.base.id }
21    fn type_name(&self) -> &'static str { "Terminal" }
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 = "Terminal".to_string();
29        if let Some(ref v) = self.conducting_equipment {
30            block.fields.insert("Terminal.ConductingEquipment".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(ref v) = self.connectivity_node {
33            block.fields.insert("Terminal.ConnectivityNode".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
34        }
35        if let Some(ref v) = self.topological_node {
36            block.fields.insert("Terminal.TopologicalNode".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
37        }
38        if let Some(ref v) = self.phases {
39            block.fields.insert("Terminal.phases".into(), crate::base::FieldValue::Resource(v.uri.clone()));
40        }
41        block
42    }
43}
44
45impl Terminal {
46    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
47        let mut obj = Self::default();
48        obj.base.base.id.clone_from(&b.mrid);
49        for (key, val) in &b.fields {
50            match key.as_str() {
51                "Terminal.ConductingEquipment" => {
52                    if let crate::base::FieldValue::Resource(sv) = val {
53                        obj.conducting_equipment = Some(crate::base::MridRef { mrid: sv.clone() });
54                    }
55                }
56                "Terminal.ConnectivityNode" => {
57                    if let crate::base::FieldValue::Resource(sv) = val {
58                        obj.connectivity_node = Some(crate::base::MridRef { mrid: sv.clone() });
59                    }
60                }
61                "Terminal.TopologicalNode" => {
62                    if let crate::base::FieldValue::Resource(sv) = val {
63                        obj.topological_node = Some(crate::base::MridRef { mrid: sv.clone() });
64                    }
65                }
66                "Terminal.phases" => {
67                    if let crate::base::FieldValue::Resource(sv) = val {
68                        obj.phases = Some(crate::base::UriRef { uri: sv.clone() });
69                    }
70                }
71                "ACDCTerminal.BusNameMarker" => {
72                    if let crate::base::FieldValue::Resource(sv) = val {
73                        obj.base.bus_name_marker = Some(crate::base::MridRef { mrid: sv.clone() });
74                    }
75                }
76                "ACDCTerminal.connected" => {
77                    match val {
78                        crate::base::FieldValue::Text(sv) => { obj.base.connected = Some(sv.trim() == "true"); }
79                        crate::base::FieldValue::TextList(svs) => {
80                            if let Some(sv) = svs.last() { obj.base.connected = Some(sv.trim() == "true"); }
81                        }
82                        _ => {}
83                    }
84                }
85                "ACDCTerminal.sequenceNumber" => {
86                    match val {
87                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.sequence_number = Some(v); } }
88                        crate::base::FieldValue::TextList(svs) => {
89                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.sequence_number = Some(v); } }
90                        }
91                        _ => {}
92                    }
93                }
94                "IdentifiedObject.description" => {
95                    match val {
96                        crate::base::FieldValue::Text(sv) => { obj.base.base.description = sv.clone(); }
97                        crate::base::FieldValue::TextList(svs) => {
98                            if let Some(sv) = svs.last() { obj.base.base.description = sv.clone(); }
99                        }
100                        _ => {}
101                    }
102                }
103                "IdentifiedObject.energyIdentCodeEic" => {
104                    match val {
105                        crate::base::FieldValue::Text(sv) => { obj.base.base.energy_ident_code_eic = sv.clone(); }
106                        crate::base::FieldValue::TextList(svs) => {
107                            if let Some(sv) = svs.last() { obj.base.base.energy_ident_code_eic = sv.clone(); }
108                        }
109                        _ => {}
110                    }
111                }
112                "IdentifiedObject.mRID" => {
113                    match val {
114                        crate::base::FieldValue::Text(sv) => { obj.base.base.m_rid = sv.clone(); }
115                        crate::base::FieldValue::TextList(svs) => {
116                            if let Some(sv) = svs.last() { obj.base.base.m_rid = sv.clone(); }
117                        }
118                        _ => {}
119                    }
120                }
121                "IdentifiedObject.name" => {
122                    match val {
123                        crate::base::FieldValue::Text(sv) => { obj.base.base.name = sv.clone(); }
124                        crate::base::FieldValue::TextList(svs) => {
125                            if let Some(sv) = svs.last() { obj.base.base.name = sv.clone(); }
126                        }
127                        _ => {}
128                    }
129                }
130                "IdentifiedObject.shortName" => {
131                    match val {
132                        crate::base::FieldValue::Text(sv) => { obj.base.base.short_name = sv.clone(); }
133                        crate::base::FieldValue::TextList(svs) => {
134                            if let Some(sv) = svs.last() { obj.base.base.short_name = sv.clone(); }
135                        }
136                        _ => {}
137                    }
138                }
139                _ => {}
140            }
141        }
142        obj
143    }
144}