Skip to main content

cimstructs/
Cut.rs

1/// A cut separates a line segment into two parts. The cut appears as a switch inserted between these two parts and connects them together. As the cut is normally open there is no galvanic connection between the two line segment parts. But it is possible to close the cut to get galvanic connection. The cut terminals are oriented towards the line segment terminals with the same sequence number. Hence the cut terminal with sequence number equal to 1 is oriented to the line segment's terminal with sequence number equal to 1. The cut terminals also act as connection points for jumpers and other equipment, e.g. a mobile generator. To enable this, connectivity nodes are placed at the cut terminals. Once the connectivity nodes are in place any conducting equipment can be connected at them.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct Cut {
4    #[serde(flatten)]
5    pub base: super::Switch,
6    /// The line segment to which the cut is applied.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub ac_line_segment: Option<super::base::MridRef>,
9    /// The length to the place where the cut is located starting from side one of the cut line segment, i.e. the line segment Terminal with sequenceNumber equal to 1.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub length_from_terminal1: Option<f64>,
12}
13impl crate::base::CimElement for Cut {
14    fn mrid(&self) -> &str { &self.base.base.base.base.base.id }
15    fn type_name(&self) -> &'static str { "Cut" }
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 = "Cut".to_string();
23        if let Some(ref v) = self.ac_line_segment {
24            block.fields.insert("Cut.ACLineSegment".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
25        }
26        if let Some(v) = self.length_from_terminal1 {
27            block.fields.insert("Cut.lengthFromTerminal1".into(), crate::base::FieldValue::Text(v.to_string()));
28        }
29        block
30    }
31}
32
33impl Cut {
34    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
35        let mut obj = Self::default();
36        obj.base.base.base.base.base.id.clone_from(&b.mrid);
37        for (key, val) in &b.fields {
38            match key.as_str() {
39                "Cut.ACLineSegment" => {
40                    if let crate::base::FieldValue::Resource(sv) = val {
41                        obj.ac_line_segment = Some(crate::base::MridRef { mrid: sv.clone() });
42                    }
43                }
44                "Cut.lengthFromTerminal1" => {
45                    match val {
46                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.length_from_terminal1 = Some(v); } }
47                        crate::base::FieldValue::TextList(svs) => {
48                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.length_from_terminal1 = Some(v); } }
49                        }
50                        _ => {}
51                    }
52                }
53                "Switch.locked" => {
54                    match val {
55                        crate::base::FieldValue::Text(sv) => { obj.base.locked = Some(sv.trim() == "true"); }
56                        crate::base::FieldValue::TextList(svs) => {
57                            if let Some(sv) = svs.last() { obj.base.locked = Some(sv.trim() == "true"); }
58                        }
59                        _ => {}
60                    }
61                }
62                "Switch.normalOpen" => {
63                    match val {
64                        crate::base::FieldValue::Text(sv) => { obj.base.normal_open = Some(sv.trim() == "true"); }
65                        crate::base::FieldValue::TextList(svs) => {
66                            if let Some(sv) = svs.last() { obj.base.normal_open = Some(sv.trim() == "true"); }
67                        }
68                        _ => {}
69                    }
70                }
71                "Switch.open" => {
72                    match val {
73                        crate::base::FieldValue::Text(sv) => { obj.base.open = Some(sv.trim() == "true"); }
74                        crate::base::FieldValue::TextList(svs) => {
75                            if let Some(sv) = svs.last() { obj.base.open = Some(sv.trim() == "true"); }
76                        }
77                        _ => {}
78                    }
79                }
80                "Switch.ratedCurrent" => {
81                    match val {
82                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.rated_current = Some(v); } }
83                        crate::base::FieldValue::TextList(svs) => {
84                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.rated_current = Some(v); } }
85                        }
86                        _ => {}
87                    }
88                }
89                "Switch.retained" => {
90                    match val {
91                        crate::base::FieldValue::Text(sv) => { obj.base.retained = Some(sv.trim() == "true"); }
92                        crate::base::FieldValue::TextList(svs) => {
93                            if let Some(sv) = svs.last() { obj.base.retained = Some(sv.trim() == "true"); }
94                        }
95                        _ => {}
96                    }
97                }
98                "ConductingEquipment.BaseVoltage" => {
99                    if let crate::base::FieldValue::Resource(sv) = val {
100                        obj.base.base.base_voltage = Some(crate::base::MridRef { mrid: sv.clone() });
101                    }
102                }
103                "Equipment.EquipmentContainer" => {
104                    if let crate::base::FieldValue::Resource(sv) = val {
105                        obj.base.base.base.equipment_container = Some(crate::base::MridRef { mrid: sv.clone() });
106                    }
107                }
108                "Equipment.aggregate" => {
109                    match val {
110                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.aggregate = Some(sv.trim() == "true"); }
111                        crate::base::FieldValue::TextList(svs) => {
112                            if let Some(sv) = svs.last() { obj.base.base.base.aggregate = Some(sv.trim() == "true"); }
113                        }
114                        _ => {}
115                    }
116                }
117                "Equipment.inService" => {
118                    match val {
119                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.in_service = Some(sv.trim() == "true"); }
120                        crate::base::FieldValue::TextList(svs) => {
121                            if let Some(sv) = svs.last() { obj.base.base.base.in_service = Some(sv.trim() == "true"); }
122                        }
123                        _ => {}
124                    }
125                }
126                "Equipment.normallyInService" => {
127                    match val {
128                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.normally_in_service = Some(sv.trim() == "true"); }
129                        crate::base::FieldValue::TextList(svs) => {
130                            if let Some(sv) = svs.last() { obj.base.base.base.normally_in_service = Some(sv.trim() == "true"); }
131                        }
132                        _ => {}
133                    }
134                }
135                "IdentifiedObject.description" => {
136                    match val {
137                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.base.description = sv.clone(); }
138                        crate::base::FieldValue::TextList(svs) => {
139                            if let Some(sv) = svs.last() { obj.base.base.base.base.base.description = sv.clone(); }
140                        }
141                        _ => {}
142                    }
143                }
144                "IdentifiedObject.energyIdentCodeEic" => {
145                    match val {
146                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.base.energy_ident_code_eic = sv.clone(); }
147                        crate::base::FieldValue::TextList(svs) => {
148                            if let Some(sv) = svs.last() { obj.base.base.base.base.base.energy_ident_code_eic = sv.clone(); }
149                        }
150                        _ => {}
151                    }
152                }
153                "IdentifiedObject.mRID" => {
154                    match val {
155                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.base.m_rid = sv.clone(); }
156                        crate::base::FieldValue::TextList(svs) => {
157                            if let Some(sv) = svs.last() { obj.base.base.base.base.base.m_rid = sv.clone(); }
158                        }
159                        _ => {}
160                    }
161                }
162                "IdentifiedObject.name" => {
163                    match val {
164                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.base.name = sv.clone(); }
165                        crate::base::FieldValue::TextList(svs) => {
166                            if let Some(sv) = svs.last() { obj.base.base.base.base.base.name = sv.clone(); }
167                        }
168                        _ => {}
169                    }
170                }
171                "IdentifiedObject.shortName" => {
172                    match val {
173                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.base.short_name = sv.clone(); }
174                        crate::base::FieldValue::TextList(svs) => {
175                            if let Some(sv) = svs.last() { obj.base.base.base.base.base.short_name = sv.clone(); }
176                        }
177                        _ => {}
178                    }
179                }
180                _ => {}
181            }
182        }
183        obj
184    }
185}