@@ -32,13 +32,16 @@ import '../../action-icon.js';
32
32
import {
33
33
SIEMENS_SITIPE_IED_REF ,
34
34
SIEMENS_SITIPE_BAY_TEMPLATE ,
35
+ SIEMENS_SITIPE_IED_TEMPLATE_REF ,
35
36
} from './foundation.js' ;
36
37
37
38
import {
38
39
BayTypical ,
40
+ BTComponent ,
39
41
getBayTypicalComponents ,
40
42
getImportedBTComponentData ,
41
43
getImportedBtComponents ,
44
+ ImportedBTComponent ,
42
45
} from './sitipe-service.js' ;
43
46
import { defaultNamingStrategy , NamingStrategy } from './sitipe-substation.js' ;
44
47
import { get } from 'lit-translate' ;
@@ -371,6 +374,11 @@ export class SitipeBay extends LitElement {
371
374
@property ( )
372
375
bayTypicals : BayTypical [ ] = [ ] ;
373
376
377
+ @property ( {
378
+ type : Number ,
379
+ } )
380
+ editCount = - 1 ;
381
+
374
382
@property ( )
375
383
namingStrategy : NamingStrategy = defaultNamingStrategy ;
376
384
@@ -461,6 +469,7 @@ export class SitipeBay extends LitElement {
461
469
actions : [ ] ,
462
470
title : 'Sitipe' ,
463
471
} ;
472
+
464
473
const bayTypicalElement : Element = createElement ( this . doc , 'Private' , {
465
474
type : SIEMENS_SITIPE_BAY_TEMPLATE ,
466
475
} ) ;
@@ -497,7 +506,9 @@ export class SitipeBay extends LitElement {
497
506
'application/xml'
498
507
) ;
499
508
500
- this . prepareImport ( doc , iedName ) ;
509
+ if ( this . isValidDoc ( doc ) ) {
510
+ this . prepareImport ( doc , iedName , btComponent ) ;
511
+ }
501
512
} ) ;
502
513
} ) ;
503
514
} ) ;
@@ -506,15 +517,15 @@ export class SitipeBay extends LitElement {
506
517
} ) ;
507
518
}
508
519
509
- public prepareImport ( doc : Document , iedName : string ) : void {
520
+ private isValidDoc ( doc : Document ) : boolean {
510
521
if ( ! doc ) {
511
522
this . dispatchEvent (
512
523
newLogEvent ( {
513
524
kind : 'error' ,
514
525
title : get ( 'import.log.loaderror' ) ,
515
526
} )
516
527
) ;
517
- return ;
528
+ return false ;
518
529
}
519
530
520
531
if ( doc . querySelector ( 'parsererror' ) ) {
@@ -524,11 +535,23 @@ export class SitipeBay extends LitElement {
524
535
title : get ( 'import.log.parsererror' ) ,
525
536
} )
526
537
) ;
527
- return ;
538
+ return false ;
528
539
}
529
540
530
- const ieds = Array . from ( doc . querySelectorAll ( ':root > IED' ) ) ;
531
- if ( ieds . length === 0 ) {
541
+ return true ;
542
+ }
543
+
544
+ private getIeds ( doc : Document ) : Element [ ] {
545
+ return Array . from ( doc . querySelectorAll ( ':root > IED' ) ) ;
546
+ }
547
+
548
+ protected prepareImport (
549
+ doc : Document ,
550
+ iedName : string ,
551
+ btComponent : BTComponent
552
+ ) : void {
553
+ const ieds : Element [ ] = this . getIeds ( doc ) ;
554
+ if ( ! ieds . length ) {
532
555
this . dispatchEvent (
533
556
newLogEvent ( {
534
557
kind : 'error' ,
@@ -537,15 +560,41 @@ export class SitipeBay extends LitElement {
537
560
) ;
538
561
return ;
539
562
}
540
-
541
- if ( ieds . length === 1 ) {
542
- this . importIED ( ieds [ 0 ] , iedName ) ;
563
+ if ( ieds . length > 1 ) {
543
564
return ;
544
565
}
545
- }
546
566
547
- private importIED ( ied : Element , iedName : string ) : void {
567
+ const ied : Element = ieds [ 0 ] ;
568
+
569
+ const oldIEDName : string = ied . getAttribute ( 'name' ) || '' ;
548
570
ied . setAttribute ( 'name' , iedName ) ;
571
+
572
+ this . importIED ( ied ) ;
573
+
574
+ if ( iedName || oldIEDName ) {
575
+ const privateIEDRef : Element = createElement ( this . doc , 'Private' , {
576
+ type : SIEMENS_SITIPE_IED_TEMPLATE_REF ,
577
+ } ) ;
578
+ privateIEDRef . textContent = btComponent . name || oldIEDName ;
579
+
580
+ this . dispatchEvent (
581
+ newActionEvent ( {
582
+ title : get ( 'editing.import' , { name : ied . getAttribute ( 'name' ) ! } ) ,
583
+ actions : [
584
+ {
585
+ new : {
586
+ parent : ied ,
587
+ element : privateIEDRef ,
588
+ } ,
589
+ } ,
590
+ ] ,
591
+ } )
592
+ ) ;
593
+ }
594
+ return ;
595
+ }
596
+
597
+ private importIED ( ied : Element ) : void {
549
598
if ( ! isIedNameUnique ( ied , this . doc ) ) {
550
599
this . dispatchEvent (
551
600
newLogEvent ( {
0 commit comments