Skip to main content

cimstructs/
ConformLoadGroup.rs

1/// A group of loads conforming to an allocation pattern.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct ConformLoadGroup {
4    #[serde(flatten)]
5    pub base: super::LoadGroup,
6}
7impl crate::base::CimElement for ConformLoadGroup {
8    fn mrid(&self) -> &str { &self.base.base.id }
9    fn type_name(&self) -> &'static str { "ConformLoadGroup" }
10    fn as_any(&self) -> &dyn std::any::Any { self }
11    fn to_json_value(&self) -> serde_json::Value {
12        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
13    }
14    fn to_block(&self) -> crate::base::RdfBlock {
15        let mut block = self.base.to_block();
16        block.type_name = "ConformLoadGroup".to_string();
17        block
18    }
19}
20
21impl ConformLoadGroup {
22    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
23        let mut obj = Self::default();
24        obj.base.base.id.clone_from(&b.mrid);
25        for (key, val) in &b.fields {
26            match key.as_str() {
27                "LoadGroup.SubLoadArea" => {
28                    if let crate::base::FieldValue::Resource(sv) = val {
29                        obj.base.sub_load_area = Some(crate::base::MridRef { mrid: sv.clone() });
30                    }
31                }
32                "IdentifiedObject.description" => {
33                    match val {
34                        crate::base::FieldValue::Text(sv) => { obj.base.base.description = sv.clone(); }
35                        crate::base::FieldValue::TextList(svs) => {
36                            if let Some(sv) = svs.last() { obj.base.base.description = sv.clone(); }
37                        }
38                        _ => {}
39                    }
40                }
41                "IdentifiedObject.energyIdentCodeEic" => {
42                    match val {
43                        crate::base::FieldValue::Text(sv) => { obj.base.base.energy_ident_code_eic = sv.clone(); }
44                        crate::base::FieldValue::TextList(svs) => {
45                            if let Some(sv) = svs.last() { obj.base.base.energy_ident_code_eic = sv.clone(); }
46                        }
47                        _ => {}
48                    }
49                }
50                "IdentifiedObject.mRID" => {
51                    match val {
52                        crate::base::FieldValue::Text(sv) => { obj.base.base.m_rid = sv.clone(); }
53                        crate::base::FieldValue::TextList(svs) => {
54                            if let Some(sv) = svs.last() { obj.base.base.m_rid = sv.clone(); }
55                        }
56                        _ => {}
57                    }
58                }
59                "IdentifiedObject.name" => {
60                    match val {
61                        crate::base::FieldValue::Text(sv) => { obj.base.base.name = sv.clone(); }
62                        crate::base::FieldValue::TextList(svs) => {
63                            if let Some(sv) = svs.last() { obj.base.base.name = sv.clone(); }
64                        }
65                        _ => {}
66                    }
67                }
68                "IdentifiedObject.shortName" => {
69                    match val {
70                        crate::base::FieldValue::Text(sv) => { obj.base.base.short_name = sv.clone(); }
71                        crate::base::FieldValue::TextList(svs) => {
72                            if let Some(sv) = svs.last() { obj.base.base.short_name = sv.clone(); }
73                        }
74                        _ => {}
75                    }
76                }
77                _ => {}
78            }
79        }
80        obj
81    }
82}