Skip to content

Commit ffee09a

Browse files
Merge pull request #256 from com-pas/Fetch_BTComponents
Feat: Added Private section for ied
2 parents 117d51c + 0a584b7 commit ffee09a

File tree

8 files changed

+77
-12
lines changed

8 files changed

+77
-12
lines changed

public/js/init.js

Whitespace-only changes.

public/js/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export const officialPlugins = [
322322
},
323323
{
324324
name: 'Sitipe',
325-
src: '/src/editors/Sitipe.js',
325+
src: '/src/compas-editors/Sitipe.js',
326326
icon: 'precision_manufacturing',
327327
default: true,
328328
kind: 'editor',

src/compas-editors/Sitipe.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export default class SitipePlugin extends LitElement {
99
@property({ attribute: false })
1010
doc!: XMLDocument;
1111

12+
@property({
13+
type: Number,
14+
})
15+
editCount = -1;
16+
1217
header(): string {
1318
return 'Sitipe';
1419
}
@@ -23,6 +28,7 @@ export default class SitipePlugin extends LitElement {
2328
html`<sitipe-substation
2429
.doc=${this.doc}
2530
.element=${substation}
31+
.editCount=${this.editCount}
2632
></sitipe-substation>`
2733
)}
2834
</section>`

src/compas-editors/sitipe/foundation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export const selectors = <Record<SubstationTag, string>>(
1313
export const SIEMENS_SITIPE_IED_REF = 'Siemens-SITIPE-IEDRef';
1414

1515
export const SIEMENS_SITIPE_BAY_TEMPLATE = 'Siemens-SITIPE-BayTemplate';
16+
17+
export const SIEMENS_SITIPE_IED_TEMPLATE_REF = 'Siemens-SITIPE-IEDTemplateRef';

src/compas-editors/sitipe/sitipe-bay.ts

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ import '../../action-icon.js';
3232
import {
3333
SIEMENS_SITIPE_IED_REF,
3434
SIEMENS_SITIPE_BAY_TEMPLATE,
35+
SIEMENS_SITIPE_IED_TEMPLATE_REF,
3536
} from './foundation.js';
3637

3738
import {
3839
BayTypical,
40+
BTComponent,
3941
getBayTypicalComponents,
4042
getImportedBTComponentData,
4143
getImportedBtComponents,
44+
ImportedBTComponent,
4245
} from './sitipe-service.js';
4346
import { defaultNamingStrategy, NamingStrategy } from './sitipe-substation.js';
4447
import { get } from 'lit-translate';
@@ -371,6 +374,11 @@ export class SitipeBay extends LitElement {
371374
@property()
372375
bayTypicals: BayTypical[] = [];
373376

377+
@property({
378+
type: Number,
379+
})
380+
editCount = -1;
381+
374382
@property()
375383
namingStrategy: NamingStrategy = defaultNamingStrategy;
376384

@@ -461,6 +469,7 @@ export class SitipeBay extends LitElement {
461469
actions: [],
462470
title: 'Sitipe',
463471
};
472+
464473
const bayTypicalElement: Element = createElement(this.doc, 'Private', {
465474
type: SIEMENS_SITIPE_BAY_TEMPLATE,
466475
});
@@ -497,7 +506,9 @@ export class SitipeBay extends LitElement {
497506
'application/xml'
498507
);
499508

500-
this.prepareImport(doc, iedName);
509+
if (this.isValidDoc(doc)) {
510+
this.prepareImport(doc, iedName, btComponent);
511+
}
501512
});
502513
});
503514
});
@@ -506,15 +517,15 @@ export class SitipeBay extends LitElement {
506517
});
507518
}
508519

509-
public prepareImport(doc: Document, iedName: string): void {
520+
private isValidDoc(doc: Document): boolean {
510521
if (!doc) {
511522
this.dispatchEvent(
512523
newLogEvent({
513524
kind: 'error',
514525
title: get('import.log.loaderror'),
515526
})
516527
);
517-
return;
528+
return false;
518529
}
519530

520531
if (doc.querySelector('parsererror')) {
@@ -524,11 +535,23 @@ export class SitipeBay extends LitElement {
524535
title: get('import.log.parsererror'),
525536
})
526537
);
527-
return;
538+
return false;
528539
}
529540

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) {
532555
this.dispatchEvent(
533556
newLogEvent({
534557
kind: 'error',
@@ -537,15 +560,41 @@ export class SitipeBay extends LitElement {
537560
);
538561
return;
539562
}
540-
541-
if (ieds.length === 1) {
542-
this.importIED(ieds[0], iedName);
563+
if (ieds.length > 1) {
543564
return;
544565
}
545-
}
546566

547-
private importIED(ied: Element, iedName: string): void {
567+
const ied: Element = ieds[0];
568+
569+
const oldIEDName: string = ied.getAttribute('name') || '';
548570
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 {
549598
if (!isIedNameUnique(ied, this.doc)) {
550599
this.dispatchEvent(
551600
newLogEvent({

src/compas-editors/sitipe/sitipe-substation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export class SitipeSubstation extends LitElement {
5757
@property({ attribute: false })
5858
element!: Element;
5959

60+
@property({
61+
type: Number,
62+
})
63+
editCount = -1;
64+
6065
@property()
6166
namingStrategy: NamingStrategy = defaultNamingStrategy;
6267

@@ -104,6 +109,7 @@ export class SitipeSubstation extends LitElement {
104109
.bayTypicals=${this.bayTypicals}
105110
.doc=${this.doc}
106111
.namingStrategy=${this.namingStrategy}
112+
.editCount=${this.editCount}
107113
></sitipe-bay>`;
108114
}
109115

src/translations/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ export const de: Translations = {
690690
loaderror: 'Datei kann nicht geladen werden',
691691
importerror: 'IED Element kann nicht importiert werden',
692692
missingied: 'Kein IED Element in der Datei',
693+
multipleied: 'Mehrere IED-Elemente in einer Datei',
693694
nouniqueied: 'IED Element {{ name }} bereits geladen',
694695
},
695696
},

src/translations/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ export const en = {
689689
loaderror: 'Could not load file',
690690
importerror: 'Could not import IED',
691691
missingied: 'No IED element in the file',
692+
multipleied: 'Multiple IED elements found',
692693
nouniqueied: 'IED element {{ name }} already in the file',
693694
},
694695
},

0 commit comments

Comments
 (0)