Skip to content

Commit

Permalink
Merge branch 'main' into core_6_5_0_RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
flo-dup authored Oct 9, 2024
2 parents 81f0977 + 562f13f commit 75a805c
Show file tree
Hide file tree
Showing 111 changed files with 194 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected LabelPosition getBusLabelPosition() {
}

@Override
public List<ElectricalNodeInfo> getElectricalNodesInfos(VoltageLevelGraph graph) {
public List<BusLegendInfo> getBusLegendInfos(VoltageLevelGraph graph) {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package com.powsybl.sld.svg;

import java.util.List;

/**
* @author Kevin Le Saulnier {@literal <kevin.lesaulnier at rte-france.com>}
*/
public record BusLegendInfo(String busId, List<Caption> captions) {
public record Caption(String label, String type) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ public List<NodeDecorator> getNodeDecorators(Node node, Direction direction) {
}

@Override
public List<ElectricalNodeInfo> getElectricalNodesInfos(VoltageLevelGraph graph) {
public List<BusLegendInfo> getBusLegendInfos(VoltageLevelGraph graph) {
VoltageLevel vl = network.getVoltageLevel(graph.getVoltageLevelInfos().getId());
return vl.getBusView().getBusStream()
.map(b -> new ElectricalNodeInfo(b.getId(), b.getV(), b.getAngle()))
.map(b -> new BusLegendInfo(b.getId(), List.of(
new BusLegendInfo.Caption(valueFormatter.formatVoltage(b.getV(), "kV"), "v"),
new BusLegendInfo.Caption(valueFormatter.formatAngleInDegrees(b.getAngle()), "angle")
)))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.sld.svg;

import com.powsybl.diagram.util.ValueFormatter;
import com.powsybl.sld.layout.LayoutParameters;
import com.powsybl.sld.library.AnchorPoint;
import com.powsybl.sld.library.Component;
Expand Down Expand Up @@ -82,13 +81,11 @@ public class DefaultSVGWriter implements SVGWriter {
protected final ComponentLibrary componentLibrary;

protected final LayoutParameters layoutParameters;
private final ValueFormatter valueFormatter;
protected final SvgParameters svgParameters;

public DefaultSVGWriter(ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters) {
this.componentLibrary = Objects.requireNonNull(componentLibrary);
this.layoutParameters = Objects.requireNonNull(layoutParameters);
this.valueFormatter = svgParameters.createValueFormatter();
this.svgParameters = svgParameters;
}

Expand Down Expand Up @@ -135,7 +132,7 @@ private double getDiagramWidth(Graph graph, LayoutParameters layoutParameters) {

private double getDiagramHeight(Graph graph, LayoutParameters layoutParameters) {
double height = graph.getHeight() + layoutParameters.getDiagramPadding().getTop() + layoutParameters.getDiagramPadding().getBottom();
if (graph instanceof VoltageLevelGraph && svgParameters.isAddNodesInfos()) {
if (graph instanceof VoltageLevelGraph && svgParameters.isBusesLegendAdded()) {
height += 6 * CIRCLE_RADIUS_NODE_INFOS_SIZE;
}
return height;
Expand Down Expand Up @@ -266,8 +263,8 @@ protected void drawVoltageLevel(VoltageLevelGraph graph,
// Drawing the nodes outside the voltageLevel graphs (multi-terminal nodes)
drawNodes(root, graph, new Point(0, 0), metadata, initProvider, styleProvider, graph.getMultiTermNodes());

if (graph.isForVoltageLevelDiagram() && svgParameters.isAddNodesInfos()) {
drawNodesInfos(root, graph, metadata, initProvider, styleProvider);
if (graph.isForVoltageLevelDiagram() && svgParameters.isBusesLegendAdded()) {
drawBusesLegend(root, graph, metadata, initProvider, styleProvider);
}
}

Expand Down Expand Up @@ -1178,10 +1175,11 @@ private void drawZone(ZoneGraph graph,
/*
* Drawing the voltageLevel nodes infos
*/
private void drawNodeInfos(ElectricalNodeInfo nodeInfo, double xShift, double yShift,
Element g, String idNode, List<String> styles) {
private void drawBusLegendInfo(BusLegendInfo busLegendInfo, double xShift, double yShift,
Element g, String idNode, List<String> styles) {
Element circle = g.getOwnerDocument().createElement("circle");

// colored circle
circle.setAttribute("id", idNode + "_circle");
circle.setAttribute("cx", String.valueOf(xShift));
circle.setAttribute("cy", String.valueOf(yShift));
Expand All @@ -1190,33 +1188,25 @@ private void drawNodeInfos(ElectricalNodeInfo nodeInfo, double xShift, double yS
circle.setAttribute(CLASS, String.join(" ", styles));
g.appendChild(circle);

// v
Element labelV = g.getOwnerDocument().createElement("text");
labelV.setAttribute("id", idNode + "_v");
String valueV = valueFormatter.formatVoltage(nodeInfo.getV(), "kV");

labelV.setAttribute("x", String.valueOf(xShift - CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelV.setAttribute("y", String.valueOf(yShift + 2.5 * CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelV.setAttribute(CLASS, StyleClassConstants.VOLTAGE);
Text textV = g.getOwnerDocument().createTextNode(valueV);
labelV.appendChild(textV);
g.appendChild(labelV);

// angle
Element labelAngle = g.getOwnerDocument().createElement("text");
labelAngle.setAttribute("id", idNode + "_angle");
String valueAngle = valueFormatter.formatAngleInDegrees(nodeInfo.getAngle());
// legend nodes
double padding = 2.5;
for (BusLegendInfo.Caption caption : busLegendInfo.captions()) {
Element label = g.getOwnerDocument().createElement("text");
label.setAttribute("id", idNode + "_" + caption.type());

label.setAttribute("x", String.valueOf(xShift - CIRCLE_RADIUS_NODE_INFOS_SIZE));
label.setAttribute("y", String.valueOf(yShift + padding * CIRCLE_RADIUS_NODE_INFOS_SIZE));
label.setAttribute(CLASS, StyleClassConstants.BUS_LEGEND_INFO);
Text textNode = g.getOwnerDocument().createTextNode(caption.label());
label.appendChild(textNode);
g.appendChild(label);

labelAngle.setAttribute("x", String.valueOf(xShift - CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelAngle.setAttribute("y", String.valueOf(yShift + 4 * CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelAngle.setAttribute(CLASS, StyleClassConstants.ANGLE);
Text textAngle = g.getOwnerDocument().createTextNode(valueAngle);
labelAngle.appendChild(textAngle);
g.appendChild(labelAngle);
padding += 1.5;
}
}

private void drawNodesInfos(Element root, VoltageLevelGraph graph,
GraphMetadata metadata, LabelProvider initProvider, StyleProvider styleProvider) {
private void drawBusesLegend(Element root, VoltageLevelGraph graph,
GraphMetadata metadata, LabelProvider labelProvider, StyleProvider styleProvider) {

Element nodesInfosNode = root.getOwnerDocument().createElement(GROUP);
root.appendChild(nodesInfosNode);
Expand All @@ -1226,17 +1216,17 @@ private void drawNodesInfos(Element root, VoltageLevelGraph graph,
double yPos = graph.getY() - layoutParameters.getVoltageLevelPadding().getTop() + graph.getHeight() + CIRCLE_RADIUS_NODE_INFOS_SIZE;

double xShift = graph.getX() + xInitPos;
for (ElectricalNodeInfo node : initProvider.getElectricalNodesInfos(graph)) {
String idNode = metadata.getSvgParameters().getPrefixId() + "NODE_" + node.getBusId();
for (BusLegendInfo busLegendInfo : labelProvider.getBusLegendInfos(graph)) {
String idNode = metadata.getSvgParameters().getPrefixId() + "NODE_" + busLegendInfo.busId();
Element gNode = nodesInfosNode.getOwnerDocument().createElement(GROUP);
gNode.setAttribute("id", idNode);

List<String> styles = styleProvider.getBusStyles(node.getBusId(), graph);
drawNodeInfos(node, xShift, yPos, gNode, idNode, styles);
List<String> styles = styleProvider.getBusStyles(busLegendInfo.busId(), graph);
drawBusLegendInfo(busLegendInfo, xShift, yPos, gNode, idNode, styles);

nodesInfosNode.appendChild(gNode);

metadata.addElectricalNodeInfoMetadata(new GraphMetadata.ElectricalNodeInfoMetadata(idNode, node.getUserDefinedId()));
metadata.addBusLegendInfoMetadata(new GraphMetadata.BusLegendInfoMetadata(idNode));

xShift += 2 * CIRCLE_RADIUS_NODE_INFOS_SIZE + 50;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -322,25 +322,18 @@ public String getUserDefinedId() {
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ElectricalNodeInfoMetadata {
public static class BusLegendInfoMetadata {

private final String id;

private final String userDefinedId;

@JsonCreator
public ElectricalNodeInfoMetadata(@JsonProperty("id") String id, @JsonProperty("userDefinedId") String userDefinedId) {
public BusLegendInfoMetadata(@JsonProperty("id") String id) {
this.id = Objects.requireNonNull(id);
this.userDefinedId = userDefinedId;
}

public String getId() {
return id;
}

public String getUserDefinedId() {
return userDefinedId;
}
}

private final Map<String, Component> componentByType = new HashMap<>();
Expand All @@ -356,7 +349,7 @@ public String getUserDefinedId() {

private final Map<String, FeederInfoMetadata> feederInfoMetadataMap = new HashMap<>();

private final Map<String, ElectricalNodeInfoMetadata> electricalNodeInfoMetadataMap = new HashMap<>();
private final Map<String, BusLegendInfoMetadata> busLegendInfoMetadataMap = new HashMap<>();

private final Map<String, BusInfoMetadata> busInfoMetadataMap = new HashMap<>();

Expand All @@ -370,7 +363,7 @@ public GraphMetadata(@JsonProperty("components") List<Component> componentList,
@JsonProperty("wires") List<WireMetadata> wireMetadataList,
@JsonProperty("lines") List<LineMetadata> lineMetadataList,
@JsonProperty("feederInfos") List<FeederInfoMetadata> feederInfoMetadataList,
@JsonProperty("electricalNodeInfos") List<ElectricalNodeInfoMetadata> electricalNodeInfoMetadataList,
@JsonProperty("busLegendInfos") List<BusLegendInfoMetadata> busLegendInfoMetadataList,
@JsonProperty("busInfos") List<BusInfoMetadata> busInfoMetadataList,
@JsonProperty("layoutParams") LayoutParameters layoutParams,
@JsonProperty("svgParams") SvgParameters svgParams) {
Expand All @@ -389,8 +382,8 @@ public GraphMetadata(@JsonProperty("components") List<Component> componentList,
for (FeederInfoMetadata feederInfoMetadata : feederInfoMetadataList) {
addFeederInfoMetadata(feederInfoMetadata);
}
for (ElectricalNodeInfoMetadata electricalNodeInfoMetadata : electricalNodeInfoMetadataList) {
addElectricalNodeInfoMetadata(electricalNodeInfoMetadata);
for (BusLegendInfoMetadata busLegendInfoMetadata : busLegendInfoMetadataList) {
addBusLegendInfoMetadata(busLegendInfoMetadata);
}
for (BusInfoMetadata busInfoMetadata : busInfoMetadataList) {
addBusInfoMetadata(busInfoMetadata);
Expand Down Expand Up @@ -542,19 +535,19 @@ public List<BusInfoMetadata> getBusInfoMetadata() {
return ImmutableList.copyOf(busInfoMetadataMap.values());
}

public void addElectricalNodeInfoMetadata(ElectricalNodeInfoMetadata metadata) {
public void addBusLegendInfoMetadata(BusLegendInfoMetadata metadata) {
Objects.requireNonNull(metadata);
electricalNodeInfoMetadataMap.put(metadata.getId(), metadata);
busLegendInfoMetadataMap.put(metadata.getId(), metadata);
}

public ElectricalNodeInfoMetadata getElectricalNodeInfoMetadata(String id) {
public BusLegendInfoMetadata getBusLegendInfoMetadata(String id) {
Objects.requireNonNull(id);
return electricalNodeInfoMetadataMap.get(id);
return busLegendInfoMetadataMap.get(id);
}

@JsonProperty("electricalNodeInfos")
public List<ElectricalNodeInfoMetadata> getElectricalNodeInfoMetadata() {
return ImmutableList.copyOf(electricalNodeInfoMetadataMap.values());
@JsonProperty("busLegendInfos")
public List<BusLegendInfoMetadata> getBusLegendInfoMetadata() {
return ImmutableList.copyOf(busLegendInfoMetadataMap.values());
}

@JsonProperty("layoutParams")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ enum LabelDirection {

List<NodeDecorator> getNodeDecorators(Node node, Direction direction);

List<ElectricalNodeInfo> getElectricalNodesInfos(VoltageLevelGraph graph);
List<BusLegendInfo> getBusLegendInfos(VoltageLevelGraph graph);

Optional<BusInfo> getBusInfo(BusNode node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SvgParameters {
private double feederInfosIntraMargin = 10;
private double feederInfosOuterMargin = 20;
private boolean feederInfoSymmetry = false;
private boolean addNodesInfos = false;
private boolean busesLegendAdded = false;
private boolean useName = false;
private double angleLabelShift = 15.;
private boolean labelCentered = false;
Expand Down Expand Up @@ -72,7 +72,7 @@ public SvgParameters(SvgParameters other) {
this.feederInfosIntraMargin = other.feederInfosIntraMargin;
this.feederInfosOuterMargin = other.feederInfosOuterMargin;
this.feederInfoSymmetry = other.feederInfoSymmetry;
this.addNodesInfos = other.addNodesInfos;
this.busesLegendAdded = other.busesLegendAdded;
this.useName = other.useName;
this.angleLabelShift = other.angleLabelShift;
this.labelCentered = other.labelCentered;
Expand Down Expand Up @@ -227,12 +227,12 @@ public SvgParameters setFeederInfoSymmetry(boolean feederInfoSymmetry) {
return this;
}

public boolean isAddNodesInfos() {
return addNodesInfos;
public boolean isBusesLegendAdded() {
return busesLegendAdded;
}

public SvgParameters setAddNodesInfos(boolean addNodesInfos) {
this.addNodesInfos = addNodesInfos;
public SvgParameters setBusesLegendAdded(boolean busesLegendAdded) {
this.busesLegendAdded = busesLegendAdded;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
public final class StyleClassConstants {
public static final String STYLE_PREFIX = "sld-";
public static final String FEEDER_INFO = STYLE_PREFIX + "feeder-info";
public static final String ANGLE = STYLE_PREFIX + "angle";
public static final String VOLTAGE = STYLE_PREFIX + "voltage";
public static final String LEGEND = STYLE_PREFIX + "legend";
public static final String BUS_LEGEND_INFO = STYLE_PREFIX + "bus-legend-info";
public static final String CELL_DIRECTION_PREFIX = STYLE_PREFIX + "cell-direction-";
public static final String CELL_SHAPE_PREFIX = STYLE_PREFIX + "cell-shape-";
public static final String SHUNT_CELL = STYLE_PREFIX + "shunt-cell";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
.sld-unknown {stroke: none; fill: black}
/* Fonts */
.sld-label {stroke: none; fill: black; font: 8px serif}
.sld-angle, .sld-voltage {font: 10px serif}
.sld-bus-legend-info {font: 10px serif}
.sld-graph-label {font: 12px serif}
/* Specific */
.sld-grid {stroke: #003700; stroke-dasharray: 1,10}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.sld-unknown {stroke: none; fill: black}
/* Fonts */
.sld-label {stroke: none; fill: black; font: 8px serif}
.sld-angle, .sld-voltage {font: 10px serif}
.sld-bus-legend-info {font: 10px serif}
.sld-graph-label {font: 12px serif}
/* Specific */
.sld-grid {stroke: #003700; stroke-dasharray: 1,10}
Expand Down
Loading

0 comments on commit 75a805c

Please sign in to comment.