Skip to main content

cimstructs/
WindContQLimIEC.rs

1/// Constant Q limitation model. Reference: IEC 61400-27-1:2015, 5.6.5.9.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct WindContQLimIEC {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// Maximum reactive power (qmax) (> WindContQLimIEC.qmin). It is a type-dependent parameter.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub qmax: Option<f64>,
9    /// Minimum reactive power (qmin) (< WindContQLimIEC.qmax). It is a type-dependent parameter.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub qmin: Option<f64>,
12}
13impl crate::base::CimElement for WindContQLimIEC {
14    fn mrid(&self) -> &str { &self.base.id }
15    fn type_name(&self) -> &'static str { "WindContQLimIEC" }
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 = "WindContQLimIEC".to_string();
23        if let Some(v) = self.qmax {
24            block.fields.insert("WindContQLimIEC.qmax".into(), crate::base::FieldValue::Text(v.to_string()));
25        }
26        if let Some(v) = self.qmin {
27            block.fields.insert("WindContQLimIEC.qmin".into(), crate::base::FieldValue::Text(v.to_string()));
28        }
29        block
30    }
31}
32
33impl WindContQLimIEC {
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                "WindContQLimIEC.qmax" => {
40                    match val {
41                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.qmax = Some(v); } }
42                        crate::base::FieldValue::TextList(svs) => {
43                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.qmax = Some(v); } }
44                        }
45                        _ => {}
46                    }
47                }
48                "WindContQLimIEC.qmin" => {
49                    match val {
50                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.qmin = Some(v); } }
51                        crate::base::FieldValue::TextList(svs) => {
52                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.qmin = Some(v); } }
53                        }
54                        _ => {}
55                    }
56                }
57                "IdentifiedObject.description" => {
58                    match val {
59                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
60                        crate::base::FieldValue::TextList(svs) => {
61                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
62                        }
63                        _ => {}
64                    }
65                }
66                "IdentifiedObject.energyIdentCodeEic" => {
67                    match val {
68                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
69                        crate::base::FieldValue::TextList(svs) => {
70                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
71                        }
72                        _ => {}
73                    }
74                }
75                "IdentifiedObject.mRID" => {
76                    match val {
77                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
78                        crate::base::FieldValue::TextList(svs) => {
79                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
80                        }
81                        _ => {}
82                    }
83                }
84                "IdentifiedObject.name" => {
85                    match val {
86                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
87                        crate::base::FieldValue::TextList(svs) => {
88                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
89                        }
90                        _ => {}
91                    }
92                }
93                "IdentifiedObject.shortName" => {
94                    match val {
95                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
96                        crate::base::FieldValue::TextList(svs) => {
97                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
98                        }
99                        _ => {}
100                    }
101                }
102                _ => {}
103            }
104        }
105        obj
106    }
107}