diff --git a/public/js/init.js b/public/js/init.js
new file mode 100644
index 000000000..e69de29bb
diff --git a/public/js/plugins.js b/public/js/plugins.js
index 7bfc64909..1c2dd0043 100644
--- a/public/js/plugins.js
+++ b/public/js/plugins.js
@@ -322,7 +322,7 @@ export const officialPlugins = [
},
{
name: 'Sitipe',
- src: '/src/editors/Sitipe.js',
+ src: '/src/compas-editors/Sitipe.js',
icon: 'precision_manufacturing',
default: true,
kind: 'editor',
diff --git a/src/compas-editors/Sitipe.ts b/src/compas-editors/Sitipe.ts
index 36055cf00..f7fa485ed 100644
--- a/src/compas-editors/Sitipe.ts
+++ b/src/compas-editors/Sitipe.ts
@@ -9,6 +9,11 @@ export default class SitipePlugin extends LitElement {
@property({ attribute: false })
doc!: XMLDocument;
+ @property({
+ type: Number,
+ })
+ editCount = -1;
+
header(): string {
return 'Sitipe';
}
@@ -23,6 +28,7 @@ export default class SitipePlugin extends LitElement {
html``
)}
`
diff --git a/src/compas-editors/sitipe/foundation.ts b/src/compas-editors/sitipe/foundation.ts
index 8fff0de33..bd4d355a5 100644
--- a/src/compas-editors/sitipe/foundation.ts
+++ b/src/compas-editors/sitipe/foundation.ts
@@ -13,3 +13,5 @@ export const selectors = >(
export const SIEMENS_SITIPE_IED_REF = 'Siemens-SITIPE-IEDRef';
export const SIEMENS_SITIPE_BAY_TEMPLATE = 'Siemens-SITIPE-BayTemplate';
+
+export const SIEMENS_SITIPE_IED_TEMPLATE_REF = 'Siemens-SITIPE-IEDTemplateRef';
diff --git a/src/compas-editors/sitipe/sitipe-bay.ts b/src/compas-editors/sitipe/sitipe-bay.ts
index c71770ed6..8dee95067 100644
--- a/src/compas-editors/sitipe/sitipe-bay.ts
+++ b/src/compas-editors/sitipe/sitipe-bay.ts
@@ -32,13 +32,16 @@ import '../../action-icon.js';
import {
SIEMENS_SITIPE_IED_REF,
SIEMENS_SITIPE_BAY_TEMPLATE,
+ SIEMENS_SITIPE_IED_TEMPLATE_REF,
} from './foundation.js';
import {
BayTypical,
+ BTComponent,
getBayTypicalComponents,
getImportedBTComponentData,
getImportedBtComponents,
+ ImportedBTComponent,
} from './sitipe-service.js';
import { defaultNamingStrategy, NamingStrategy } from './sitipe-substation.js';
import { get } from 'lit-translate';
@@ -371,6 +374,11 @@ export class SitipeBay extends LitElement {
@property()
bayTypicals: BayTypical[] = [];
+ @property({
+ type: Number,
+ })
+ editCount = -1;
+
@property()
namingStrategy: NamingStrategy = defaultNamingStrategy;
@@ -461,6 +469,7 @@ export class SitipeBay extends LitElement {
actions: [],
title: 'Sitipe',
};
+
const bayTypicalElement: Element = createElement(this.doc, 'Private', {
type: SIEMENS_SITIPE_BAY_TEMPLATE,
});
@@ -497,7 +506,9 @@ export class SitipeBay extends LitElement {
'application/xml'
);
- this.prepareImport(doc, iedName);
+ if (this.isValidDoc(doc)) {
+ this.prepareImport(doc, iedName, btComponent);
+ }
});
});
});
@@ -506,7 +517,7 @@ export class SitipeBay extends LitElement {
});
}
- public prepareImport(doc: Document, iedName: string): void {
+ private isValidDoc(doc: Document): boolean {
if (!doc) {
this.dispatchEvent(
newLogEvent({
@@ -514,7 +525,7 @@ export class SitipeBay extends LitElement {
title: get('import.log.loaderror'),
})
);
- return;
+ return false;
}
if (doc.querySelector('parsererror')) {
@@ -524,11 +535,23 @@ export class SitipeBay extends LitElement {
title: get('import.log.parsererror'),
})
);
- return;
+ return false;
}
- const ieds = Array.from(doc.querySelectorAll(':root > IED'));
- if (ieds.length === 0) {
+ return true;
+ }
+
+ private getIeds(doc: Document): Element[] {
+ return Array.from(doc.querySelectorAll(':root > IED'));
+ }
+
+ protected prepareImport(
+ doc: Document,
+ iedName: string,
+ btComponent: BTComponent
+ ): void {
+ const ieds: Element[] = this.getIeds(doc);
+ if (!ieds.length) {
this.dispatchEvent(
newLogEvent({
kind: 'error',
@@ -537,15 +560,41 @@ export class SitipeBay extends LitElement {
);
return;
}
-
- if (ieds.length === 1) {
- this.importIED(ieds[0], iedName);
+ if (ieds.length > 1) {
return;
}
- }
- private importIED(ied: Element, iedName: string): void {
+ const ied: Element = ieds[0];
+
+ const oldIEDName: string = ied.getAttribute('name') || '';
ied.setAttribute('name', iedName);
+
+ this.importIED(ied);
+
+ if (iedName || oldIEDName) {
+ const privateIEDRef: Element = createElement(this.doc, 'Private', {
+ type: SIEMENS_SITIPE_IED_TEMPLATE_REF,
+ });
+ privateIEDRef.textContent = btComponent.name || oldIEDName;
+
+ this.dispatchEvent(
+ newActionEvent({
+ title: get('editing.import', { name: ied.getAttribute('name')! }),
+ actions: [
+ {
+ new: {
+ parent: ied,
+ element: privateIEDRef,
+ },
+ },
+ ],
+ })
+ );
+ }
+ return;
+ }
+
+ private importIED(ied: Element): void {
if (!isIedNameUnique(ied, this.doc)) {
this.dispatchEvent(
newLogEvent({
diff --git a/src/compas-editors/sitipe/sitipe-substation.ts b/src/compas-editors/sitipe/sitipe-substation.ts
index 967aa871e..ab14b4934 100644
--- a/src/compas-editors/sitipe/sitipe-substation.ts
+++ b/src/compas-editors/sitipe/sitipe-substation.ts
@@ -57,6 +57,11 @@ export class SitipeSubstation extends LitElement {
@property({ attribute: false })
element!: Element;
+ @property({
+ type: Number,
+ })
+ editCount = -1;
+
@property()
namingStrategy: NamingStrategy = defaultNamingStrategy;
@@ -104,6 +109,7 @@ export class SitipeSubstation extends LitElement {
.bayTypicals=${this.bayTypicals}
.doc=${this.doc}
.namingStrategy=${this.namingStrategy}
+ .editCount=${this.editCount}
>`;
}
diff --git a/src/translations/de.ts b/src/translations/de.ts
index b1e7b0d9c..ac7b18a76 100644
--- a/src/translations/de.ts
+++ b/src/translations/de.ts
@@ -690,6 +690,7 @@ export const de: Translations = {
loaderror: 'Datei kann nicht geladen werden',
importerror: 'IED Element kann nicht importiert werden',
missingied: 'Kein IED Element in der Datei',
+ multipleied: 'Mehrere IED-Elemente in einer Datei',
nouniqueied: 'IED Element {{ name }} bereits geladen',
},
},
diff --git a/src/translations/en.ts b/src/translations/en.ts
index f5060a8be..7d1f7e89f 100644
--- a/src/translations/en.ts
+++ b/src/translations/en.ts
@@ -689,6 +689,7 @@ export const en = {
loaderror: 'Could not load file',
importerror: 'Could not import IED',
missingied: 'No IED element in the file',
+ multipleied: 'Multiple IED elements found',
nouniqueied: 'IED element {{ name }} already in the file',
},
},