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 movement of bays #478

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 25 additions & 1 deletion src/editors/SingleLineDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
createBusBarElement,
createVoltageLevelElement,
createBayElement,
createBayOutlineElement,
createConductingEquipmentElement,
createConnectivityNodeElement,
getBusBarLength,
Expand Down Expand Up @@ -197,6 +198,22 @@ export default class SingleLineDiagramPlugin extends LitElement {
});
}

/**
* Draw outline rectangle for Bay and include name in <g> element
* Should only be a <g> element.
* @param bayGroup - The SVG <g> element containing all Bay icons/elements.
* @param bayElement - The Bay which the rectangle represents.
* */
private drawBayOutline(bayGroup: SVGGraphicsElement, bayElement: Element): void {
const outlineElement = createBayOutlineElement(bayGroup,
bayElement,
(event: Event) => this.openEditWizard(event, bayElement!));
if (bayGroup.parentNode !== null) {
// must be prepended as SVG z-order is based on element order in DOM
bayGroup.parentNode.prepend(outlineElement);
}
}

/**
* Draw all available Bays of the passed Voltage Level Element.
* Should only be a <g> element.
Expand All @@ -208,10 +225,11 @@ export default class SingleLineDiagramPlugin extends LitElement {
.forEach(bayElement => {
const bayGroup = createBayElement(bayElement);
voltageLevelGroup.appendChild(bayGroup);

this.drawPowerTransformers(bayElement, bayGroup);
this.drawConductingEquipments(bayElement, bayGroup);
this.drawConnectivityNodes(bayElement, bayGroup);
this.drawBayOutline(bayGroup, bayElement);
});
}

Expand Down Expand Up @@ -529,6 +547,12 @@ export default class SingleLineDiagramPlugin extends LitElement {
pointer-events: bounding-box;
}

.bayOutline {
fill: var(--mdc-theme-surface);
fill-opacity: 0.5;
}

text.bayName:hover,
g[type='Busbar']:hover,
g[type='ConductingEquipment']:hover,
g[type='ConnectivityNode']:hover,
Expand Down
37 changes: 34 additions & 3 deletions src/editors/singlelinediagram/sld-drawing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function getConnectivityNodesDrawingPosition(
* @param element - The element.
* @returns The <g> element.
*/
function createGroupElement(element: Element): SVGElement {
function createGroupElement(element: Element): SVGGraphicsElement {
const finalElement = document.createElementNS(
'http://www.w3.org/2000/svg',
'g'
Expand Down Expand Up @@ -205,7 +205,6 @@ function createGroupElement(element: Element): SVGElement {
export function createSubstationElement(substation: Element): SVGElement {
return createGroupElement(substation);
}

/**
* Create a Voltage Level <g> element.
* @param voltageLevel - The Voltage Level from the SCL document to use.
Expand All @@ -220,10 +219,42 @@ export function createVoltageLevelElement(voltageLevel: Element): SVGElement {
* @param bay - The Bay from the SCL document to use.
* @returns A Bay <g> element.
*/
export function createBayElement(bay: Element): SVGElement {
export function createBayElement(bay: Element): SVGGraphicsElement {
return createGroupElement(bay);
}

/**
* Create an outline rect and name for bays and add to the <g> element
* @param groupElement - The SVG group element with the SVG data comprising the bay.
* @param bayElement - The SCL element Bay.
* @returns The bay SVG objects <g> element including outline and the title.
*/
export function createBayOutlineElement(
groupElement: SVGGraphicsElement,
bayElement: Element,
clickAction?: (event: Event) => void
): SVGGraphicsElement {
const outlineGroup = createGroupElement(groupElement);
const boundingBox = groupElement.getBBox();

const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
rect.setAttribute('x', `${boundingBox.x}`);
rect.setAttribute('width', `${boundingBox.width}`);
rect.setAttribute('height', `${boundingBox.height}`);
rect.setAttribute('rx', '5');
rect.setAttribute('class', 'bayOutline');
outlineGroup.appendChild(rect);

const text = createTextElement(bayElement.getAttribute('name') || 'Unknown Bay',
{ x: boundingBox.x, y: boundingBox.y - 18 },
'small');
text.setAttribute('class', 'bayName');
outlineGroup.appendChild(text);

if (clickAction) text.addEventListener('click', clickAction);
return outlineGroup;
}

/**
* Create a basic caption.
* @param textContent - The content of the caption.
Expand Down