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(editors/SingleLineDiagram): allow selecting the Substation element #449

Merged
merged 5 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
526 changes: 352 additions & 174 deletions src/editors/SingleLineDiagram.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/editors/singlelinediagram/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ export function getConnectedTerminals(element: Element): Element[] {
return Array.from(substationElement.getElementsByTagName('Terminal')).filter(
terminal =>
terminal.getAttribute('connectivityNode') === path &&
terminal.getAttribute('substationName') === substationName &&
terminal.getAttribute('voltageLevelName') === voltageLevelName &&
terminal.getAttribute('bayName') === bayName &&
terminal.getAttribute('cNodeName') === getNameAttribute(element)
terminal.getAttribute('cNodeName') === getNameAttribute(element) &&
(!terminal.hasAttribute('substationName') || terminal.getAttribute('substationName') === substationName) &&
(!terminal.hasAttribute('voltageLevelName') || terminal.getAttribute('voltageLevelName') === voltageLevelName) &&
(!terminal.hasAttribute('bayName') || terminal.getAttribute('bayName') === bayName)
);
}

Expand Down
18 changes: 9 additions & 9 deletions src/editors/singlelinediagram/sld-drawing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export function getAbsolutePositionConnectivityNode(element: Element): Point {
* Calculate the absolute offset of a terminal next to an element.
* @param parentElementPosition - The position of the parent element of the terminal.
* @param elementOffset - The offset of the parent element.
* @param terminalSide - The side of the parent element where the terminal should be placed.
* @param terminalSide - The side of the parent element where the terminal should be placed.
* @param customTerminalOffset - An optional parameter containing the offset of the terminal next to the parent element.
* This may vary, for example for Connectivity Nodes.
*
*
* @returns The absolute position of the terminal.
*/
function absoluteOffsetTerminal(
Expand Down Expand Up @@ -433,12 +433,12 @@ export function createConnectivityNodeElement(
* Draw a route from ConnectivityNode to equipments Terminal (ConductingEquipment or PowerTransformer)
* @param cNodesTerminalPosition - The start position in px of the SCL element ConnectivityNode.
* @param equipmentsTerminalPosition - The end position in px of the SCL element ConductingEquipment or PowerTransformer.
* @param svgToDrawOn - The SVG to draw the route on.
* @param svgElementToDrawOn - The SVG Element to draw the route on.
*/
export function drawCNodeConnections(
cNodesTerminalPosition: Point,
equipmentsTerminalPosition: Point,
svgToDrawOn: HTMLElement
svgElementToDrawOn: SVGElement
): void {
const path = getOrthogonalPath(
equipmentsTerminalPosition,
Expand All @@ -464,19 +464,19 @@ export function drawCNodeConnections(
// Inserting elements like this works kind of like z-index (not supported in SVG yet),
// these elements are placed behind all other elements.
// By doing it like this, all other elements are hoverable for example.
svgToDrawOn.insertAdjacentElement('afterbegin', line);
svgElementToDrawOn.insertAdjacentElement('afterbegin', line);
}

/**
* Draw a route from the bus bar to elements terminal position.
* @param busbarsTerminalPosition - The start position in px the bus bar.
* @param equipmentsTerminalPosition - The end position in px of the SCL element ConductingEquipment or PowerTransformer.
* @param svgToDrawOn - The SVG to draw the route on.
* @param svgElementToDrawOn - The SVG Element to draw the route on.
*/
export function drawBusBarRoute(
busbarsTerminalPosition: Point,
equipmentsTerminalPosition: Point,
svgToDrawOn: HTMLElement
svgElementToDrawOn: SVGElement
): void {
const path = [busbarsTerminalPosition].concat([equipmentsTerminalPosition]);

Expand All @@ -495,7 +495,7 @@ export function drawBusBarRoute(
line.setAttribute('stroke', 'currentColor');
line.setAttribute('stroke-width', '1.5');

svgToDrawOn.appendChild(line);
svgElementToDrawOn.appendChild(line);
}

/**
Expand Down Expand Up @@ -555,7 +555,7 @@ export function getParentElementName(
* @param root - Either the whole SCL file or the voltage level where the bus bar resides
* @returns - the length of the bus bar
*/
export function getBusBarLength(root: Element | XMLDocument): number {
export function getBusBarLength(root: Element): number {
return (
Math.max(
...Array.from(
Expand Down
28 changes: 19 additions & 9 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export function newEmptySCD(
return new DOMParser().parseFromString(markup, 'application/xml');
}

export const SCL_NAMESPACE= "http://www.iec.ch/61850/2003/SCL";

/**
* Check if the namespace of tjhe passed element is the standard SCL Namespace.
dlabordus marked this conversation as resolved.
Show resolved Hide resolved
* @param element - The element to check.
*/
export function isSCLNamespace(element: Element): boolean {
return element.namespaceURI === SCL_NAMESPACE;
}

export interface ValidationError {
file: string;
line: number;
Expand Down Expand Up @@ -2367,9 +2377,9 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.

Implemented Ed. 2 Tissues: 658, 668, 687, 768, 779, 789, 804, 806, 807, 822, 824, 845, 853, 855, 856, 857, 886, 936, 1175, 1189, 1208.
Tissues not relevant for the SCL schema: 660, 661 (Ed.3), 663, 678, 699, 700, 705, 706 (Ed.3), 718, 719, 721, 731, 733, 752, 769, 787, 788, 815, 823, 825, 837, 847, 865, 873, 883, 884, 885, 901, 914, 915, 918, 927 (Ed.3), 930, 938, 949, 961, 1048, 1054, 1059, 1118, 1130, 1131, 1147, 1161, 1168, 1170 (Ed.3), 1173, 1188, 1195, 1200, 1204, 1207, 1221, 1224, 1241 (Ed.3), 1255, 1257 (Ed.3), 1284.
</xs:documentation>
Expand Down Expand Up @@ -2444,7 +2454,7 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.
</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -3174,7 +3184,7 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.
</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -3325,7 +3335,7 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.
</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -4021,7 +4031,7 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.
</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -4203,7 +4213,7 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.
</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -5090,7 +5100,7 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.
</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -5449,7 +5459,7 @@ export const schemas = {
<xs:annotation>
<xs:documentation xml:lang="en">
SCL schema version "2007" revision "B" release 1, for IEC 61850-6 Ed. 2.1. Draft 2014-07-18.

COPYRIGHT (c) IEC, 2014. All rights reserved. Disclaimer: The IEC disclaims liability for any personal injury, property or other damages of any nature whatsoever, whether special, indirect, consequential or compensatory, directly or indirectly resulting from this software and the document upon which its methods are based, use of, or reliance upon.
</xs:documentation>
</xs:annotation>
Expand Down
3 changes: 3 additions & 0 deletions src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ export const de: Translations = {
updatedesc: {
abb: 'Signalbeschreibungen zu ABB IEDs hinzugefügt',
},
sld: {
substationSelector: 'Schaltanlage auswählen',
},
add: 'Hinzufügen',
new: 'Neu',
remove: 'Entfernen',
Expand Down
3 changes: 3 additions & 0 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ export const en = {
updatedesc: {
abb: 'Added signal descriptions to ABB IEDs',
},
sld: {
substationSelector: 'Select a substation',
},
add: 'Add',
new: 'New',
remove: 'Remove',
Expand Down
9 changes: 1 addition & 8 deletions test/unit/editors/singlelinediagram/sld-drawing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,13 @@ describe('Single Line Diagram drawing', () => {

describe('defines a getBusBarLength function that', () => {
it('returns a correct length for the bus bar given voltage level as root', () => {
const element = doc.querySelector('VoltageLevel[name="J1"]') ?? doc;
const element = doc.querySelector('VoltageLevel[name="J1"]')!;
expect(getBusBarLength(element)).to.eql(
18 * 2 * SVG_GRID_SIZE +
(SVG_GRID_SIZE - EQUIPMENT_SIZE) / 2 +
SVG_GRID_SIZE
);
});
it('returns a correct length for the bus bar given XMLDocument as root', () => {
expect(getBusBarLength(doc)).to.eql(
18 * 2 * SVG_GRID_SIZE +
(SVG_GRID_SIZE - EQUIPMENT_SIZE) / 2 +
SVG_GRID_SIZE
);
});
});

describe('creates a group element for every given PowerTransformer element that', () => {
Expand Down
19 changes: 19 additions & 0 deletions test/unit/schema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {expect} from "@open-wc/testing";

import {isSCLNamespace, SCL_NAMESPACE} from "../../src/schemas.js";

describe('schema', () => {
it('when element belongs to SCL Namespace, function should return true', () => {
const doc = document.implementation.createDocument(SCL_NAMESPACE, null, null);
const element = doc.createElementNS(SCL_NAMESPACE, "SCL");

expect(isSCLNamespace(element)).to.be.true;
});

it('when element not belonging to SCL Namespace, function should return false', () => {
const doc = document.implementation.createDocument(SCL_NAMESPACE, null, null);
const element = doc.createElementNS("https://someother.namespace.com", "SCL");

expect(isSCLNamespace(element)).to.be.false;
});
});