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..f5bf6a4 --- /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.getId(), "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 3eede1d..2561a07 100644 --- a/src/main/java/com/powsybl/sld/server/SingleLineDiagramService.java +++ b/src/main/java/com/powsybl/sld/server/SingleLineDiagramService.java @@ -21,7 +21,6 @@ import com.powsybl.sld.server.dto.SvgAndMetadata; import com.powsybl.sld.server.dto.VoltageLevelInfos; import com.powsybl.sld.server.utils.SldDisplayMode; -import com.powsybl.sld.svg.DefaultLabelProvider; import com.powsybl.sld.svg.SvgParameters; import com.powsybl.sld.svg.styles.NominalVoltageStyleProvider; import com.powsybl.sld.svg.styles.StyleProvidersList; @@ -103,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())); } diff --git a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java index 6d83abe..6e289e8 100644 --- a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java +++ b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java @@ -439,6 +439,86 @@ void testSubstationSingleLineDiagramAdditionalMetadata() { assertEquals("FR", convertedMetadata.get("country")); } + /** + * @return a network with 2 voltage level - vl1 with 2 calculated buses, vl2 with 1 calculated bus + */ + public static Network createTwoVoltageLevels() { + Network network = Network.create("dl", "test"); + Substation s = network.newSubstation().setId("s1").setName("Substation 1").add(); + VoltageLevel vl1 = s.newVoltageLevel() + .setId("vl1") + .setName("Voltage level 1") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl1.getBusBreakerView().newBus() + .setId("busId11") + .add(); + vl1.newGenerator() + .setId("g11") + .setConnectableBus("busId11") + .setBus("busId11") + .setTargetP(101.3664) + .setTargetV(390) + .setMinP(0) + .setMaxP(150) + .setVoltageRegulatorOn(true) + .add(); + vl1.getBusBreakerView().newBus() + .setId("busId12") + .add(); + vl1.newGenerator() + .setId("g12") + .setConnectableBus("busId12") + .setBus("busId12") + .setTargetP(101.3664) + .setTargetV(390) + .setMinP(0) + .setMaxP(150) + .setVoltageRegulatorOn(true) + .add(); + VoltageLevel vl2 = s.newVoltageLevel() + .setId("vl2") + .setName("Voltage level 2") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl2.getBusBreakerView().newBus() + .setId("busId2") + .add(); + vl2.newDanglingLine() + .setId("dl1") + .setConnectableBus("busId2") + .setBus("busId2") + .setR(0.7) + .setX(1) + .setG(1e-6) + .setB(3e-6) + .setP0(101) + .setQ0(150) + .newGeneration() + .setTargetP(0) + .setTargetQ(0) + .setTargetV(390) + .setVoltageRegulationOn(false) + .add() + .add(); + network.newLine() + .setId("l1") + .setVoltageLevel1("vl1") + .setBus1("busId11") + .setVoltageLevel2("vl2") + .setBus2("busId2") + .setR(1) + .setX(3) + .setG1(0) + .setG2(0) + .setB1(0) + .setB2(0) + .add(); + return network; + } + private static Network createNetwork() { Network network = Network.create("test", "test"); Substation substationFr1 = network.newSubstation() @@ -583,6 +663,31 @@ void testNetworkAreaDiagramWithMissingVoltageLevel() throws Exception { .andExpect(status().isNotFound()); } + @Test + void testBusLegendContainsBusId() throws Exception { + UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); + given(networkStoreService.getNetwork(testNetworkId, null)).willReturn(createTwoVoltageLevels()); + + MvcResult result = mvc.perform(get("/v1/svg/{networkUuid}/{voltageLevelId}", testNetworkId, "vl1")) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(SingleLineDiagramController.IMAGE_SVG_PLUS_XML)) + .andReturn(); + String stringResult = result.getResponse().getContentAsString(); + assertEquals("vl1_0<")); + assertTrue(stringResult.contains(">vl1_1<")); + + result = mvc.perform(get("/v1/svg/{networkUuid}/{voltageLevelId}", testNetworkId, "vl2")) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(SingleLineDiagramController.IMAGE_SVG_PLUS_XML)) + .andReturn(); + stringResult = result.getResponse().getContentAsString(); + assertEquals("vl2_0<")); + } + private static String toString(String resourceName) throws IOException { return new String(ByteStreams.toByteArray(Objects.requireNonNull(SingleLineDiagramTest.class.getResourceAsStream(resourceName))), StandardCharsets.UTF_8); }