-
Notifications
You must be signed in to change notification settings - Fork 39
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
Closed
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
6e14aef
refactor(auto-align): some improvements
ab58276
add web-compoent per layer
4ec3a6d
Added BusBar line
Flurb 927f1e7
Added separate CSS
Flurb f783bf5
Fixing build
Flurb 8696cef
Added busbar-sld
Flurb b92a18f
Added Connectivity Nodes
Flurb 6a0f637
Implemented routing between CN/Terminals
Flurb 88bbd0e
Added Connectivity Node icon
Flurb 490ed9c
Small fixes
Flurb 5ce1f34
Added ConnectivityNode editor
Flurb 6f27ed4
Made SVG bigger of Bay
Flurb 59d442f
Added better ConnectivityNode logo
Flurb 4f464e7
Made placing elements prettier
Flurb 0ff3bde
Added BusBar icon
Flurb 84acc32
Made code a bit prettier
Flurb 62e3220
Made code prettier
Flurb 2e1b26a
First full rebuild attempt
Flurb 625ae05
Right before implementing routing again
Flurb 9385979
Added routing
Flurb bb5e5e6
drawRoute only has 2 points as parameters instead of including offset
Flurb f435f28
First version routes to busbar
Flurb a2ad11a
Small changes
Flurb a0331af
Small changes
Flurb f9825e0
Little refactoring
Flurb 97e14b1
Added first version of route 'algorithm'
Flurb 7b15fa4
Refactored BusBar icon
Flurb 3f64818
small route refactor
Flurb ad29303
refactoring
Flurb 81f71f7
Small refactoring
Flurb c71aaff
Small refactoring
Flurb ba023b7
Added first basic unit tests
Flurb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { | ||
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; | ||
} | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
`; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
this is a predefined ground terminal that we don't need to draw is it is indicated with the icon of the equipment already