Skip to main content

cimstructs/
Location.rs

1/// The place, scene, or point of something where someone or something has been, is, and/or will be at a given moment in time. It can be defined with one or more position points (coordinates) in a given coordinate system.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct Location {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// Coordinate system used to describe position points of this location.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub coordinate_system: Option<super::base::MridRef>,
9    /// All power system resources at this location.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub power_system_resources: Option<super::base::MridRef>,
12    /// Main address of the location.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub main_address: Option<super::base::MridRef>,
15}
16impl crate::base::CimElement for Location {
17    fn mrid(&self) -> &str { &self.base.id }
18    fn type_name(&self) -> &'static str { "Location" }
19    fn as_any(&self) -> &dyn std::any::Any { self }
20    fn to_json_value(&self) -> serde_json::Value {
21        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
22    }
23    fn to_block(&self) -> crate::base::RdfBlock {
24        let mut block = self.base.to_block();
25        block.type_name = "Location".to_string();
26        if let Some(ref v) = self.coordinate_system {
27            block.fields.insert("Location.CoordinateSystem".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        if let Some(ref v) = self.power_system_resources {
30            block.fields.insert("Location.PowerSystemResources".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(ref v) = self.main_address {
33            block.fields.insert("Location.mainAddress".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
34        }
35        block
36    }
37}
38
39impl Location {
40    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
41        let mut obj = Self::default();
42        obj.base.id.clone_from(&b.mrid);
43        for (key, val) in &b.fields {
44            match key.as_str() {
45                "Location.CoordinateSystem" => {
46                    if let crate::base::FieldValue::Resource(sv) = val {
47                        obj.coordinate_system = Some(crate::base::MridRef { mrid: sv.clone() });
48                    }
49                }
50                "Location.PowerSystemResources" => {
51                    if let crate::base::FieldValue::Resource(sv) = val {
52                        obj.power_system_resources = Some(crate::base::MridRef { mrid: sv.clone() });
53                    }
54                }
55                "Location.mainAddress" => {
56                    if let crate::base::FieldValue::Resource(sv) = val {
57                        obj.main_address = Some(crate::base::MridRef { mrid: sv.clone() });
58                    }
59                }
60                "IdentifiedObject.description" => {
61                    match val {
62                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
63                        crate::base::FieldValue::TextList(svs) => {
64                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
65                        }
66                        _ => {}
67                    }
68                }
69                "IdentifiedObject.energyIdentCodeEic" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
74                        }
75                        _ => {}
76                    }
77                }
78                "IdentifiedObject.mRID" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
83                        }
84                        _ => {}
85                    }
86                }
87                "IdentifiedObject.name" => {
88                    match val {
89                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
90                        crate::base::FieldValue::TextList(svs) => {
91                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
92                        }
93                        _ => {}
94                    }
95                }
96                "IdentifiedObject.shortName" => {
97                    match val {
98                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
99                        crate::base::FieldValue::TextList(svs) => {
100                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
101                        }
102                        _ => {}
103                    }
104                }
105                _ => {}
106            }
107        }
108        obj
109    }
110}