Skip to main content

cimstructs/
BusNameMarker.rs

1/// Used to apply user standard names to TopologicalNodes. Associated with one or more terminals that are normally connected with the bus name. The associated terminals are normally connected by non-retained switches. For a ring bus station configuration, all BusbarSection terminals in the ring are typically associated. For a breaker and a half scheme, both BusbarSections would normally be associated. For a ring bus, all BusbarSections would normally be associated. For a 'straight' busbar configuration, normally only the main terminal at the BusbarSection would be associated.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct BusNameMarker {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// The reporting group to which this bus name marker belongs.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub reporting_group: Option<super::base::MridRef>,
9    /// Priority of bus name marker for use as topology bus name. Use 0 for do not care. Use 1 for highest priority. Use 2 as priority is less than 1 and so on.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub priority: Option<i64>,
12}
13impl crate::base::CimElement for BusNameMarker {
14    fn mrid(&self) -> &str { &self.base.id }
15    fn type_name(&self) -> &'static str { "BusNameMarker" }
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 = "BusNameMarker".to_string();
23        if let Some(ref v) = self.reporting_group {
24            block.fields.insert("BusNameMarker.ReportingGroup".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
25        }
26        if let Some(v) = self.priority {
27            block.fields.insert("BusNameMarker.priority".into(), crate::base::FieldValue::Text(v.to_string()));
28        }
29        block
30    }
31}
32
33impl BusNameMarker {
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                "BusNameMarker.ReportingGroup" => {
40                    if let crate::base::FieldValue::Resource(sv) = val {
41                        obj.reporting_group = Some(crate::base::MridRef { mrid: sv.clone() });
42                    }
43                }
44                "BusNameMarker.priority" => {
45                    match val {
46                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.priority = Some(v); } }
47                        crate::base::FieldValue::TextList(svs) => {
48                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.priority = Some(v); } }
49                        }
50                        _ => {}
51                    }
52                }
53                "IdentifiedObject.description" => {
54                    match val {
55                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
56                        crate::base::FieldValue::TextList(svs) => {
57                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
58                        }
59                        _ => {}
60                    }
61                }
62                "IdentifiedObject.energyIdentCodeEic" => {
63                    match val {
64                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
65                        crate::base::FieldValue::TextList(svs) => {
66                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
67                        }
68                        _ => {}
69                    }
70                }
71                "IdentifiedObject.mRID" => {
72                    match val {
73                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
74                        crate::base::FieldValue::TextList(svs) => {
75                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
76                        }
77                        _ => {}
78                    }
79                }
80                "IdentifiedObject.name" => {
81                    match val {
82                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
83                        crate::base::FieldValue::TextList(svs) => {
84                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
85                        }
86                        _ => {}
87                    }
88                }
89                "IdentifiedObject.shortName" => {
90                    match val {
91                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
92                        crate::base::FieldValue::TextList(svs) => {
93                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
94                        }
95                        _ => {}
96                    }
97                }
98                _ => {}
99            }
100        }
101        obj
102    }
103}