Skip to main content

cimstructs/
DCLineSegment.rs

1/// A wire or combination of wires not insulated from one another, with consistent electrical characteristics, used to carry direct current between points in the DC region of the power system.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct DCLineSegment {
4    #[serde(flatten)]
5    pub base: super::DCConductingEquipment,
6    /// Capacitance of the DC line segment. Significant for cables only.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub capacitance: Option<f64>,
9    /// Inductance of the DC line segment. Negligible compared with DCSeriesDevice used for smoothing.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub inductance: Option<f64>,
12    /// Segment length for calculating line section capabilities.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub length: Option<f64>,
15    /// Resistance of the DC line segment.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub resistance: Option<f64>,
18}
19impl crate::base::CimElement for DCLineSegment {
20    fn mrid(&self) -> &str { &self.base.base.base.base.id }
21    fn type_name(&self) -> &'static str { "DCLineSegment" }
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 = "DCLineSegment".to_string();
29        if let Some(v) = self.capacitance {
30            block.fields.insert("DCLineSegment.capacitance".into(), crate::base::FieldValue::Text(v.to_string()));
31        }
32        if let Some(v) = self.inductance {
33            block.fields.insert("DCLineSegment.inductance".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        if let Some(v) = self.length {
36            block.fields.insert("DCLineSegment.length".into(), crate::base::FieldValue::Text(v.to_string()));
37        }
38        if let Some(v) = self.resistance {
39            block.fields.insert("DCLineSegment.resistance".into(), crate::base::FieldValue::Text(v.to_string()));
40        }
41        block
42    }
43}
44
45impl DCLineSegment {
46    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
47        let mut obj = Self::default();
48        obj.base.base.base.base.id.clone_from(&b.mrid);
49        for (key, val) in &b.fields {
50            match key.as_str() {
51                "DCLineSegment.capacitance" => {
52                    match val {
53                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.capacitance = Some(v); } }
54                        crate::base::FieldValue::TextList(svs) => {
55                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.capacitance = Some(v); } }
56                        }
57                        _ => {}
58                    }
59                }
60                "DCLineSegment.inductance" => {
61                    match val {
62                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.inductance = Some(v); } }
63                        crate::base::FieldValue::TextList(svs) => {
64                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.inductance = Some(v); } }
65                        }
66                        _ => {}
67                    }
68                }
69                "DCLineSegment.length" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.length = Some(v); } }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.length = Some(v); } }
74                        }
75                        _ => {}
76                    }
77                }
78                "DCLineSegment.resistance" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.resistance = Some(v); } }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.resistance = Some(v); } }
83                        }
84                        _ => {}
85                    }
86                }
87                "DCConductingEquipment.ratedUdc" => {
88                    match val {
89                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.rated_udc = Some(v); } }
90                        crate::base::FieldValue::TextList(svs) => {
91                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.rated_udc = Some(v); } }
92                        }
93                        _ => {}
94                    }
95                }
96                "Equipment.EquipmentContainer" => {
97                    if let crate::base::FieldValue::Resource(sv) = val {
98                        obj.base.base.equipment_container = Some(crate::base::MridRef { mrid: sv.clone() });
99                    }
100                }
101                "Equipment.aggregate" => {
102                    match val {
103                        crate::base::FieldValue::Text(sv) => { obj.base.base.aggregate = Some(sv.trim() == "true"); }
104                        crate::base::FieldValue::TextList(svs) => {
105                            if let Some(sv) = svs.last() { obj.base.base.aggregate = Some(sv.trim() == "true"); }
106                        }
107                        _ => {}
108                    }
109                }
110                "Equipment.inService" => {
111                    match val {
112                        crate::base::FieldValue::Text(sv) => { obj.base.base.in_service = Some(sv.trim() == "true"); }
113                        crate::base::FieldValue::TextList(svs) => {
114                            if let Some(sv) = svs.last() { obj.base.base.in_service = Some(sv.trim() == "true"); }
115                        }
116                        _ => {}
117                    }
118                }
119                "Equipment.normallyInService" => {
120                    match val {
121                        crate::base::FieldValue::Text(sv) => { obj.base.base.normally_in_service = Some(sv.trim() == "true"); }
122                        crate::base::FieldValue::TextList(svs) => {
123                            if let Some(sv) = svs.last() { obj.base.base.normally_in_service = Some(sv.trim() == "true"); }
124                        }
125                        _ => {}
126                    }
127                }
128                "IdentifiedObject.description" => {
129                    match val {
130                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.description = sv.clone(); }
131                        crate::base::FieldValue::TextList(svs) => {
132                            if let Some(sv) = svs.last() { obj.base.base.base.base.description = sv.clone(); }
133                        }
134                        _ => {}
135                    }
136                }
137                "IdentifiedObject.energyIdentCodeEic" => {
138                    match val {
139                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
140                        crate::base::FieldValue::TextList(svs) => {
141                            if let Some(sv) = svs.last() { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
142                        }
143                        _ => {}
144                    }
145                }
146                "IdentifiedObject.mRID" => {
147                    match val {
148                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.m_rid = sv.clone(); }
149                        crate::base::FieldValue::TextList(svs) => {
150                            if let Some(sv) = svs.last() { obj.base.base.base.base.m_rid = sv.clone(); }
151                        }
152                        _ => {}
153                    }
154                }
155                "IdentifiedObject.name" => {
156                    match val {
157                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.name = sv.clone(); }
158                        crate::base::FieldValue::TextList(svs) => {
159                            if let Some(sv) = svs.last() { obj.base.base.base.base.name = sv.clone(); }
160                        }
161                        _ => {}
162                    }
163                }
164                "IdentifiedObject.shortName" => {
165                    match val {
166                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.short_name = sv.clone(); }
167                        crate::base::FieldValue::TextList(svs) => {
168                            if let Some(sv) = svs.last() { obj.base.base.base.base.short_name = sv.clone(); }
169                        }
170                        _ => {}
171                    }
172                }
173                _ => {}
174            }
175        }
176        obj
177    }
178}