diff --git a/src/main/java/com/powsybl/sld/server/CommonLabelProvider.java b/src/main/java/com/powsybl/sld/server/CommonLabelProvider.java new file mode 100644 index 0000000..59afcb3 --- /dev/null +++ b/src/main/java/com/powsybl/sld/server/CommonLabelProvider.java @@ -0,0 +1,31 @@ +package com.powsybl.sld.server; + +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.sld.layout.LayoutParameters; +import com.powsybl.sld.library.ComponentLibrary; +import com.powsybl.sld.model.graphs.VoltageLevelGraph; +import com.powsybl.sld.svg.BusLegendInfo; +import com.powsybl.sld.svg.DefaultLabelProvider; +import com.powsybl.sld.svg.SvgParameters; + +import java.util.List; +import java.util.stream.Collectors; + +public class CommonLabelProvider extends DefaultLabelProvider { + public CommonLabelProvider(Network network, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters) { + super(network, componentLibrary, layoutParameters, svgParameters); + } + + @Override + public List getBusLegendInfos(VoltageLevelGraph graph) { + VoltageLevel vl = network.getVoltageLevel(graph.getVoltageLevelInfos().getId()); + return vl.getBusView().getBusStream() + .map(b -> new BusLegendInfo(b.getId(), List.of( + new BusLegendInfo.Caption(b.getNameOrId(), "busId"), + new BusLegendInfo.Caption(valueFormatter.formatVoltage(b.getV(), "kV"), "v"), + new BusLegendInfo.Caption(valueFormatter.formatAngleInDegrees(b.getAngle()), "angle") + ))) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java b/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java index de7aeca..851e8ac 100644 --- a/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java +++ b/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java @@ -16,10 +16,7 @@ import com.powsybl.sld.model.nodes.EquipmentNode; import com.powsybl.sld.model.nodes.FeederNode; import com.powsybl.sld.model.nodes.Node; -import com.powsybl.sld.svg.DefaultLabelProvider; -import com.powsybl.sld.svg.LabelPosition; -import com.powsybl.sld.svg.LabelProviderFactory; -import com.powsybl.sld.svg.SvgParameters; +import com.powsybl.sld.svg.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +29,7 @@ /** * @author Ben Daamer ahmed */ -public class PositionDiagramLabelProvider extends DefaultLabelProvider { +public class PositionDiagramLabelProvider extends CommonLabelProvider { private static final Logger LOGGER = LoggerFactory.getLogger(PositionDiagramLabelProvider.class); diff --git a/src/main/java/com/powsybl/sld/server/SingleLineDiagramService.java b/src/main/java/com/powsybl/sld/server/SingleLineDiagramService.java index 501a7b0..21ec1ec 100644 --- a/src/main/java/com/powsybl/sld/server/SingleLineDiagramService.java +++ b/src/main/java/com/powsybl/sld/server/SingleLineDiagramService.java @@ -102,7 +102,7 @@ SvgAndMetadata generateSvgAndMetadata(UUID networkUuid, String variantId, String sldParameters.setLabelProviderFactory(PositionDiagramLabelProvider.newLabelProviderFactory(id)); } else if (diagParams.getSldDisplayMode() == SldDisplayMode.STATE_VARIABLE) { svgParameters.setBusesLegendAdded(true); - sldParameters.setLabelProviderFactory(DefaultLabelProvider::new); + sldParameters.setLabelProviderFactory(CommonLabelProvider::new); } else { throw new PowsyblException(String.format("Given sld display mode %s doesn't exist", diagParams.getSldDisplayMode())); }