Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added Private section for ied #256

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added public/js/init.js
Empty file.
2 changes: 1 addition & 1 deletion public/js/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions src/compas-editors/Sitipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export default class SitipePlugin extends LitElement {
@property({ attribute: false })
doc!: XMLDocument;

@property({
type: Number,
})
editCount = -1;

header(): string {
return 'Sitipe';
}
Expand All @@ -23,6 +28,7 @@ export default class SitipePlugin extends LitElement {
html`<sitipe-substation
.doc=${this.doc}
.element=${substation}
.editCount=${this.editCount}
></sitipe-substation>`
)}
</section>`
Expand Down
2 changes: 2 additions & 0 deletions src/compas-editors/sitipe/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const selectors = <Record<SubstationTag, string>>(
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';
71 changes: 60 additions & 11 deletions src/compas-editors/sitipe/sitipe-bay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -371,6 +374,11 @@ export class SitipeBay extends LitElement {
@property()
bayTypicals: BayTypical[] = [];

@property({
type: Number,
})
editCount = -1;

@property()
namingStrategy: NamingStrategy = defaultNamingStrategy;

Expand Down Expand Up @@ -461,6 +469,7 @@ export class SitipeBay extends LitElement {
actions: [],
title: 'Sitipe',
};

const bayTypicalElement: Element = createElement(this.doc, 'Private', {
type: SIEMENS_SITIPE_BAY_TEMPLATE,
});
Expand Down Expand Up @@ -497,7 +506,9 @@ export class SitipeBay extends LitElement {
'application/xml'
);

this.prepareImport(doc, iedName);
if (this.isValidDoc(doc)) {
this.prepareImport(doc, iedName, btComponent);
}
});
});
});
Expand All @@ -506,15 +517,15 @@ export class SitipeBay extends LitElement {
});
}

public prepareImport(doc: Document, iedName: string): void {
private isValidDoc(doc: Document): boolean {
if (!doc) {
this.dispatchEvent(
newLogEvent({
kind: 'error',
title: get('import.log.loaderror'),
})
);
return;
return false;
}

if (doc.querySelector('parsererror')) {
Expand All @@ -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',
Expand All @@ -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({
Expand Down
6 changes: 6 additions & 0 deletions src/compas-editors/sitipe/sitipe-substation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export class SitipeSubstation extends LitElement {
@property({ attribute: false })
element!: Element;

@property({
type: Number,
})
editCount = -1;

@property()
namingStrategy: NamingStrategy = defaultNamingStrategy;

Expand Down Expand Up @@ -104,6 +109,7 @@ export class SitipeSubstation extends LitElement {
.bayTypicals=${this.bayTypicals}
.doc=${this.doc}
.namingStrategy=${this.namingStrategy}
.editCount=${this.editCount}
></sitipe-bay>`;
}

Expand Down
1 change: 1 addition & 0 deletions src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
Expand Down
Loading