Skip to content

Commit

Permalink
fix(zeroline-pane/foundation): improve ied allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Vogelsang committed Jul 16, 2021
1 parent 033aef6 commit 54e0532
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/zeroline/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ function isMultiparent(element: Element, iedName: string): boolean {
);
}

function isUniquechild(element: Element, iedName: string): boolean {
const isUnique =
(<Element[]>Array.from(element.children)).filter(element =>
containsReference(element, iedName)
).length === 1;

if (!isUnique) return false;
if (element.parentNode instanceof XMLDocument) return isUnique;
if (isUnique) return isUniquechild(element.parentElement!, iedName);

return true;
}

function isReference(element: Element, iedName: string): boolean {
return (
(<Element[]>Array.from(element.children)).filter(
Expand All @@ -50,9 +63,9 @@ export function attachedIeds(element: Element): Element[] {
const iedName = ied.getAttribute('name')!;
if (
(isMultiparent(element, iedName) &&
!isMultiparent(element.parentElement!, iedName)) ||
isUniquechild(element.parentElement!, iedName)) ||
(isReference(element, iedName) &&
!isMultiparent(element.parentElement!, iedName))
isUniquechild(element.parentElement!, iedName))
)
attachedIeds.push(ied);
});
Expand Down

0 comments on commit 54e0532

Please sign in to comment.