1
1
import { css , LitElement , query } from 'lit-element' ;
2
- import { compareNames , createElement } from '../../foundation.js' ;
2
+ import {
3
+ cloneElement ,
4
+ compareNames ,
5
+ createElement ,
6
+ getSclSchemaVersion ,
7
+ } from '../../foundation.js' ;
3
8
import { getFcdaReferences } from '../../foundation/ied.js' ;
4
9
5
10
export enum View {
@@ -96,26 +101,30 @@ const serviceTypes: Partial<Record<string, string>> = {
96
101
} ;
97
102
98
103
/**
99
- * @param controlBlock - `ReportControl`, `GSEControl` or `SamepldValueControl` source element
100
- * @param fCDA - the source data. can be data attribute or data obejct (missing daName)
101
- * @returns ExtRef element
104
+ * Create a new ExtRef Element depending on the SCL Edition copy attributes from the Control Element,
105
+ * FCDA Element and related Elements.
106
+ *
107
+ * @param controlElement - `ReportControl`, `GSEControl` or `SampledValueControl` source element
108
+ * @param fcdaElement - The source data attribute element.
109
+ * @returns The new created ExtRef element, which can be added to the document.
102
110
*/
103
111
export function createExtRefElement (
104
- controlBlock : Element | undefined ,
105
- fCDA : Element
112
+ controlElement : Element | undefined ,
113
+ fcdaElement : Element
106
114
) : Element {
107
- const iedName = fCDA . closest ( 'IED' ) ?. getAttribute ( 'name' ) ?? null ;
115
+ const iedName = fcdaElement . closest ( 'IED' ) ?. getAttribute ( 'name' ) ?? null ;
108
116
const [ ldInst , prefix , lnClass , lnInst , doName , daName ] = [
109
117
'ldInst' ,
110
118
'prefix' ,
111
119
'lnClass' ,
112
120
'lnInst' ,
113
121
'doName' ,
114
122
'daName' ,
115
- ] . map ( attr => fCDA . getAttribute ( attr ) ) ;
116
- if ( fCDA . ownerDocument . documentElement . getAttribute ( 'version' ) !== '2007' )
117
- //Ed1 does not define serviceType and its MCD attribute starting with src...
118
- return createElement ( fCDA . ownerDocument , 'ExtRef' , {
123
+ ] . map ( attr => fcdaElement . getAttribute ( attr ) ) ;
124
+
125
+ if ( getSclSchemaVersion ( fcdaElement . ownerDocument ) === '2003' ) {
126
+ // Edition 2003(1) does not define serviceType and its MCD attribute starting with src...
127
+ return createElement ( fcdaElement . ownerDocument , 'ExtRef' , {
119
128
iedName,
120
129
ldInst,
121
130
lnClass,
@@ -124,10 +133,11 @@ export function createExtRefElement(
124
133
doName,
125
134
daName,
126
135
} ) ;
136
+ }
127
137
128
- if ( ! controlBlock || ! serviceTypes [ controlBlock . tagName ] )
138
+ if ( ! controlElement || ! serviceTypes [ controlElement . tagName ] ) {
129
139
//for invalid control block tag name assume polling
130
- return createElement ( fCDA . ownerDocument , 'ExtRef' , {
140
+ return createElement ( fcdaElement . ownerDocument , 'ExtRef' , {
131
141
iedName,
132
142
serviceType : 'Poll' ,
133
143
ldInst,
@@ -137,19 +147,109 @@ export function createExtRefElement(
137
147
doName,
138
148
daName,
139
149
} ) ;
150
+ }
151
+
152
+ // default is empty string as attributes are mandatory acc to IEC 61850-6 >Ed2
153
+ const srcLDInst =
154
+ controlElement . closest ( 'LDevice' ) ?. getAttribute ( 'inst' ) ?? '' ;
155
+ const srcPrefix =
156
+ controlElement . closest ( 'LN0,LN' ) ?. getAttribute ( 'prefix' ) ?? '' ;
157
+ const srcLNClass =
158
+ controlElement . closest ( 'LN0,LN' ) ?. getAttribute ( 'lnClass' ) ?? '' ;
159
+ const srcLNInst = controlElement . closest ( 'LN0,LN' ) ?. getAttribute ( 'inst' ) ;
160
+ const srcCBName = controlElement . getAttribute ( 'name' ) ?? '' ;
161
+
162
+ return createElement ( fcdaElement . ownerDocument , 'ExtRef' , {
163
+ iedName,
164
+ serviceType : serviceTypes [ controlElement . tagName ] ! ,
165
+ ldInst,
166
+ lnClass,
167
+ lnInst,
168
+ prefix,
169
+ doName,
170
+ daName,
171
+ srcLDInst,
172
+ srcPrefix,
173
+ srcLNClass,
174
+ srcLNInst : srcLNInst ? srcLNInst : null ,
175
+ srcCBName,
176
+ } ) ;
177
+ }
178
+
179
+ /**
180
+ * Create a clone of the passed ExtRefElement and updated or set the required attributes on the cloned element
181
+ * depending on the Edition and type of Control Element.
182
+ *
183
+ * @param extRefElement - The ExtRef Element to clone and update.
184
+ * @param controlElement - `ReportControl`, `GSEControl` or `SampledValueControl` source element
185
+ * @param fcdaElement - The source data attribute element.
186
+ * @returns A cloned ExtRef Element with updated information to be used for example in a Replace Action.
187
+ */
188
+ export function updateExtRefElement (
189
+ extRefElement : Element ,
190
+ controlElement : Element | undefined ,
191
+ fcdaElement : Element
192
+ ) : Element {
193
+ const iedName = fcdaElement . closest ( 'IED' ) ?. getAttribute ( 'name' ) ?? null ;
194
+ const [ ldInst , prefix , lnClass , lnInst , doName , daName ] = [
195
+ 'ldInst' ,
196
+ 'prefix' ,
197
+ 'lnClass' ,
198
+ 'lnInst' ,
199
+ 'doName' ,
200
+ 'daName' ,
201
+ ] . map ( attr => fcdaElement . getAttribute ( attr ) ) ;
202
+
203
+ if ( getSclSchemaVersion ( fcdaElement . ownerDocument ) === '2003' ) {
204
+ // Edition 2003(1) does not define serviceType and its MCD attribute starting with src...
205
+ return cloneElement ( extRefElement , {
206
+ iedName,
207
+ serviceType : null ,
208
+ ldInst,
209
+ lnClass,
210
+ lnInst,
211
+ prefix,
212
+ doName,
213
+ daName,
214
+ srcLDInst : null ,
215
+ srcPrefix : null ,
216
+ srcLNClass : null ,
217
+ srcLNInst : null ,
218
+ srcCBName : null ,
219
+ } ) ;
220
+ }
221
+
222
+ if ( ! controlElement || ! serviceTypes [ controlElement . tagName ] ) {
223
+ //for invalid control block tag name assume polling
224
+ return cloneElement ( extRefElement , {
225
+ iedName,
226
+ serviceType : 'Poll' ,
227
+ ldInst,
228
+ lnClass,
229
+ lnInst,
230
+ prefix,
231
+ doName,
232
+ daName,
233
+ srcLDInst : null ,
234
+ srcPrefix : null ,
235
+ srcLNClass : null ,
236
+ srcLNInst : null ,
237
+ srcCBName : null ,
238
+ } ) ;
239
+ }
140
240
141
- // default is empty string as attributes are mendaroty acc to IEC 61850-6 >Ed2
142
- const srcLDInst = controlBlock . closest ( 'LDevice' ) ?. getAttribute ( 'inst' ) ?? '' ;
241
+ const srcLDInst =
242
+ controlElement . closest ( 'LDevice' ) ?. getAttribute ( 'inst' ) ?? '' ;
143
243
const srcPrefix =
144
- controlBlock . closest ( 'LN0,LN' ) ?. getAttribute ( 'prefix' ) ?? '' ;
244
+ controlElement . closest ( 'LN0,LN' ) ?. getAttribute ( 'prefix' ) ?? '' ;
145
245
const srcLNClass =
146
- controlBlock . closest ( 'LN0,LN' ) ?. getAttribute ( 'lnClass' ) ?? '' ;
147
- const srcLNInst = controlBlock . closest ( 'LN0,LN' ) ?. getAttribute ( 'inst' ) ?? '' ;
148
- const srcCBName = controlBlock . getAttribute ( 'name' ) ?? '' ;
246
+ controlElement . closest ( 'LN0,LN' ) ?. getAttribute ( 'lnClass' ) ?? '' ;
247
+ const srcLNInst = controlElement . closest ( 'LN0,LN' ) ?. getAttribute ( 'inst' ) ;
248
+ const srcCBName = controlElement . getAttribute ( 'name' ) ?? '' ;
149
249
150
- return createElement ( fCDA . ownerDocument , 'ExtRef' , {
250
+ return cloneElement ( extRefElement , {
151
251
iedName,
152
- serviceType : serviceTypes [ controlBlock . tagName ] ! ,
252
+ serviceType : serviceTypes [ controlElement . tagName ] ! ,
153
253
ldInst,
154
254
lnClass,
155
255
lnInst,
@@ -159,7 +259,7 @@ export function createExtRefElement(
159
259
srcLDInst,
160
260
srcPrefix,
161
261
srcLNClass,
162
- srcLNInst,
262
+ srcLNInst : srcLNInst ? srcLNInst : null ,
163
263
srcCBName,
164
264
} ) ;
165
265
}
0 commit comments