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

First piece of SLD Editor #366

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2a9617d
feat(auto-align): initial push
Oct 18, 2021
6e14aef
refactor(auto-align): some improvements
Oct 20, 2021
ab58276
add web-compoent per layer
Oct 25, 2021
4ec3a6d
Added BusBar line
Flurb Oct 26, 2021
927f1e7
Added separate CSS
Flurb Oct 26, 2021
f783bf5
Fixing build
Flurb Oct 26, 2021
8696cef
Added busbar-sld
Flurb Oct 27, 2021
b92a18f
Added Connectivity Nodes
Flurb Oct 29, 2021
6a0f637
Implemented routing between CN/Terminals
Flurb Oct 29, 2021
88bbd0e
Added Connectivity Node icon
Flurb Oct 29, 2021
490ed9c
Small fixes
Flurb Oct 30, 2021
5ce1f34
Added ConnectivityNode editor
Flurb Oct 31, 2021
6f27ed4
Made SVG bigger of Bay
Flurb Oct 31, 2021
59d442f
Added better ConnectivityNode logo
Flurb Nov 1, 2021
4f464e7
Made placing elements prettier
Flurb Nov 1, 2021
0ff3bde
Added BusBar icon
Flurb Nov 1, 2021
84acc32
Made code a bit prettier
Flurb Nov 2, 2021
62e3220
Made code prettier
Flurb Nov 2, 2021
2e1b26a
First full rebuild attempt
Flurb Nov 3, 2021
625ae05
Right before implementing routing again
Flurb Nov 3, 2021
9385979
Added routing
Flurb Nov 4, 2021
bb5e5e6
drawRoute only has 2 points as parameters instead of including offset
Flurb Nov 4, 2021
f435f28
First version routes to busbar
Flurb Nov 4, 2021
a2ad11a
Small changes
Flurb Nov 4, 2021
a0331af
Small changes
Flurb Nov 4, 2021
f9825e0
Little refactoring
Flurb Nov 5, 2021
97e14b1
Added first version of route 'algorithm'
Flurb Nov 7, 2021
7b15fa4
Refactored BusBar icon
Flurb Nov 7, 2021
3f64818
small route refactor
Flurb Nov 8, 2021
ad29303
refactoring
Flurb Nov 8, 2021
81f71f7
Small refactoring
Flurb Nov 8, 2021
c71aaff
Small refactoring
Flurb Nov 8, 2021
ba023b7
Added first basic unit tests
Flurb Nov 10, 2021
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
16 changes: 16 additions & 0 deletions __snapshots__/open-scd.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,22 @@
</mwc-icon>
Substation
</mwc-check-list-item>
<mwc-check-list-item
aria-disabled="false"
class="official"
graphic="control"
hasmeta=""
left=""
mwc-list-item=""
selected=""
tabindex="-1"
value="/src/editors/Sld.js"
>
<mwc-icon slot="meta">
edit
</mwc-icon>
SLD
</mwc-check-list-item>
<mwc-check-list-item
aria-disabled="false"
class="official"
Expand Down
4,208 changes: 1,495 additions & 2,713 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"lit-element": "2.5.1",
"lit-html": "1.4.1",
"lit-translate": "^1.2.1",
"marked": "^3.0.0"
"marked": "^3.0.0",
"panzoom": "^9.4.2"
},
"scripts": {
"lint:eslint": "eslint --ext .ts,.html . --ignore-path .gitignore",
Expand Down
8 changes: 8 additions & 0 deletions public/js/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ export const officialPlugins = [
default: true,
kind: 'editor',
},
{
name: 'SLD',
src: '/src/editors/Sld.js',
icon: 'edit',
default: true,
kind: 'editor',

},
{
name: 'Communication',
src: '/src/editors/Communication.js',
Expand Down
224 changes: 224 additions & 0 deletions src/editors/SLD/bay-sld.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import {
css,
customElement,
html,
LitElement,
property,
TemplateResult,
} from 'lit-element';

import { getChildElementsByTagName } from '../../foundation.js';
import { drawRoute, XYPosition, getPosition, Point, SldElement } from './foundation.js';

/**
* SLD component of a Bay component.
*/
@customElement('bay-sld')
export class BaySld extends LitElement implements XYPosition {

/**
* Property holding the Bay XML element.
*/
@property()
element!: Element;

get name() {
return this.element.getAttribute('name');
}

/**
* Holding a reference to the Substation SVG to draw routes between elements on.
*/
@property()
svg!: HTMLElement;

/**
* True if this Bay is built up downwards.
*/
@property()
downer: boolean = false;

/**
* The space multiplyer of elements within a single bay.
*/
@property()
baySpaceMultiply: number = 1;

/**
* Overridden from XYPosition
*/
// --------------------------
@property()
fullParentOffset!: Point

get myOwnFullOffset(): Point {
const {x, y} = getPosition(this.element);
return {x: (x! - 1) + this.fullParentOffset.x!, y: (y! - 1) + this.fullParentOffset.y!};
}
// --------------------------

/**
* Get all the unconnected Nodes of this particular Bay.
*/
get unconnectedElements(): Element[] {
return getChildElementsByTagName(
this.element,
'ConductingEquipment'
).filter(
child =>
Array.from(child.querySelectorAll('Terminal')).filter(
terminal => terminal.getAttribute('cNodeName') !== 'grounded'
).length === 0
);
}

/**
* Get all the Equipment Nodes of this particular Bay.
*/
get equipmentElements(): SldElement[] {
const elements: SldElement[] = [];

Array.from(this.element.children)
.filter(
child =>
Array.from(child.querySelectorAll('Terminal')).filter(
terminal => terminal.getAttribute('cNodeName') !== 'grounded'
).length !== 0
)
.forEach(child => {
const {x, y} = getPosition(child);
elements.push({ element: child, pos: { x, y } });
});

return elements;
}

/**
* Get all the Connectivity Nodes of this particular Bay.
*/
get connectivityNodeElements(): SldElement[] {
const sldelements: SldElement[] = [];

Array.from(getChildElementsByTagName(this.element, 'ConnectivityNode'))
.forEach(child => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this need another filter like so:

.filter(cNode => cNode.getAttribute('name')!=='grounded')

this is a predefined ground terminal that we don't need to draw is it is indicated with the icon of the equipment already

const pathName = child.getAttribute('pathName');
let nrOfConnections = 0;
let totalX = 0;
let totalY = 0;

getChildElementsByTagName(this.element, 'ConductingEquipment')
.filter(equipment => equipment.querySelector(`Terminal[connectivityNode="${pathName}"]`) != null)
.forEach(equipment => {
nrOfConnections++;

const {x, y} = getPosition(equipment)

if (x != null && y != null) {
totalX += x;
totalY += y;
}
})

const [x, y] = [Math.round(totalX / nrOfConnections), Math.round(totalY / nrOfConnections)];
sldelements.push({ element: child, pos: {x, y} });
});

return sldelements;
}

/**
* Draw all the ConnectivityNode routes in this Bay.
*/
drawConnectivityNodeConnections(): void {
this.connectivityNodeElements.forEach(cn => {
const pathName = cn.element.getAttribute('pathName');
this.equipmentElements
.filter(element => element.element.querySelector(`Terminal[connectivityNode="${pathName}"]`))
.forEach(element => {
const cnX = (cn.pos.x! * this.baySpaceMultiply - 1) + this.myOwnFullOffset.x!;
const cnY = (cn.pos.y! * this.baySpaceMultiply - 1) + this.myOwnFullOffset.y!;

const elementX = (element.pos.x! * this.baySpaceMultiply - 1) + this.myOwnFullOffset.x!;
const elementY = (element.pos.y! * this.baySpaceMultiply - 1) + this.myOwnFullOffset.y!;

if ((elementY > cnY)) {
drawRoute({x: cnX, y: cnY}, {x: elementX, y: elementY}, this.svg)
} else {
drawRoute({x: elementX, y: elementY}, {x: cnX, y: cnY}, this.svg)
}
});
});
}

firstUpdated(): void {
this.drawConnectivityNodeConnections();
}

getElementPositionAdjustedWithMultiplyer(xYposition: number) {
return xYposition * this.baySpaceMultiply;
}

/**
<!--
<div class="unconnectedcontainer">
${this.unconnectedElements.map(
element =>
html`<div class="element">${element.getAttribute('name')}</div>`
)}
</div>
-->
*/

render(): TemplateResult {
return html`<section>
<div style="grid-template-columns: repeat(100, 64px);grid-template-rows: repeat(100, 64px)">
${this.equipmentElements.map(
element =>
html`<conducting-equipment-editor
.element=${element.element}
class="element"
style="grid-column:${this.getElementPositionAdjustedWithMultiplyer(element.pos.x!)};grid-row:${this.downer
? this.getElementPositionAdjustedWithMultiplyer(element.pos.y!)
: this.getElementPositionAdjustedWithMultiplyer(-element.pos.y!)};"
>
</conducting-equipment-editor>`
)}
${this.connectivityNodeElements.map(
element =>
html`<connectivity-node-editor
.element=${element.element}
class="element"
style="grid-column:${this.getElementPositionAdjustedWithMultiplyer(element.pos.x!)};grid-row:${this.downer
? this.getElementPositionAdjustedWithMultiplyer(element.pos.y!)
: this.getElementPositionAdjustedWithMultiplyer(-element.pos.y!)};"
>
</connectivity-node-editor>`
)}

</div>
</section>`;
}

static styles = css`
.unconnectedcontainer {
display: grid;
grid-gap: 64px;
box-sizing: border-box;
grid-template-columns: repeat(auto-fit, minmax(64px, 64px));
}

div {
display: grid;
}

.element {
width: 64px;
height: 64px;
}

.element:hover {
outline: 2px dashed var(--mdc-theme-primary);
transition: transform 200ms linear, box-shadow 250ms linear;
}
`;
}
66 changes: 66 additions & 0 deletions src/editors/SLD/busbar-sld.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
css,
CSSResult,
customElement,
html,
LitElement,
property,
TemplateResult,
} from 'lit-element';
import { busBarIcon } from '../../icons';

/**
* SLD component of a BusBar component.
*/
@customElement('busbar-sld')
export class BusBasSld extends LitElement {
@property()
element!: Element;

/**
* True if this Bay is built up downwards.
*/
@property()
downer: boolean = false;

/**
* The 'justify-content' draws all elements within the div from bottom up ('flex-end')
* or top down ('flex-start).
* This depends if the busbar is drawn up or down.
*/
render(): TemplateResult {
return html`<div
style="justify-content: ${this.downer ? css`flex-end;` : css`flex-start`}">
${this.downer ? html`<h4>${this.element.getAttribute('name')}</h4>
${busBarIcon}` : html`${busBarIcon}<h4>${this.element.getAttribute('name')}</h4>`}
</div>`;
}

static styles = css`
div {
grid-template-columns: repeat(1, 1fr);
width: 100%;
height: 64px;
display: flex;
justify-content: flex-end;
flex-direction: column;
}

div svg {
width: 100%;
}

h4 {
color: var(--mdc-theme-on-surface);
font-family: 'Roboto', sans-serif;
font-weight: 300;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin: 0px;
opacity: 1;
transition: opacity 200ms linear;
text-align: left;
}
`;
}
Loading