diff --git a/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index 0a22d9fe..deb068a7 100644 --- a/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -25,6 +25,7 @@ import java.io.UncheckedIOException; import java.io.Writer; import java.nio.file.Path; +import java.util.List; import java.util.Objects; import java.util.function.Predicate; @@ -44,6 +45,14 @@ public NetworkAreaDiagram(Network network, String voltageLevelId, int depth) { this(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth)); } + public NetworkAreaDiagram(Network network, List voltageLevelIds) { + this(network, VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds)); + } + + public NetworkAreaDiagram(Network network, List voltageLevelIds, int depth) { + this(network, VoltageLevelFilter.createVoltageLevelsDepthFilter(network, voltageLevelIds, depth)); + } + public NetworkAreaDiagram(Network network, Predicate voltageLevelFilter) { this.network = Objects.requireNonNull(network); this.voltageLevelFilter = Objects.requireNonNull(voltageLevelFilter); diff --git a/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java b/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java index c4a5c3cb..d452a814 100644 --- a/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java +++ b/src/main/java/com/powsybl/nad/build/iidm/VoltageLevelFilter.java @@ -11,6 +11,7 @@ import com.powsybl.nad.utils.iidm.IidmUtils; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.function.Predicate; @@ -49,6 +50,27 @@ public static VoltageLevelFilter createVoltageLevelDepthFilter(Network network, return new VoltageLevelFilter(voltageLevels); } + public static VoltageLevelFilter createVoltageLevelsDepthFilter(Network network, List voltageLevelIds, int depth) { + Objects.requireNonNull(network); + Objects.requireNonNull(voltageLevelIds); + Set startingSet = new HashSet<>(); + for (String voltageLevelId : voltageLevelIds) { + VoltageLevel vl = network.getVoltageLevel(voltageLevelId); + if (vl == null) { + throw new PowsyblException("Unknown voltage level id '" + voltageLevelId + "'"); + } + startingSet.add(vl); + } + + Set voltageLevels = new HashSet<>(); + traverseVoltageLevels(startingSet, depth, voltageLevels); + return new VoltageLevelFilter(voltageLevels); + } + + public static VoltageLevelFilter createVoltageLevelsFilter(Network network, List voltageLevelIds) { + return createVoltageLevelsDepthFilter(network, voltageLevelIds, 0); + } + private static void traverseVoltageLevels(Set voltageLevelsDepth, int depth, Set visitedVoltageLevels) { if (depth < 0) { return; diff --git a/src/test/java/com/powsybl/nad/svg/NominalVoltageStyleTest.java b/src/test/java/com/powsybl/nad/svg/NominalVoltageStyleTest.java index 84c731f6..b9445a3f 100644 --- a/src/test/java/com/powsybl/nad/svg/NominalVoltageStyleTest.java +++ b/src/test/java/com/powsybl/nad/svg/NominalVoltageStyleTest.java @@ -23,6 +23,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Collections; + import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -129,7 +131,7 @@ void test3wt() { @Test void testPartial3wt() { Network network = ThreeWindingsTransformerNetworkFactory.create(); - VoltageLevelFilter filter = VoltageLevelFilter.createVoltageLevelDepthFilter(network, "VL_11", 0); + VoltageLevelFilter filter = VoltageLevelFilter.createVoltageLevelsFilter(network, Collections.singletonList("VL_11")); assertEquals(toString("/3wt_partial.svg"), generateSvgString(network, filter, "/3wt_partial.svg")); } diff --git a/src/test/java/com/powsybl/nad/svg/TopologicalStyleTest.java b/src/test/java/com/powsybl/nad/svg/TopologicalStyleTest.java index d0096d15..0553b141 100644 --- a/src/test/java/com/powsybl/nad/svg/TopologicalStyleTest.java +++ b/src/test/java/com/powsybl/nad/svg/TopologicalStyleTest.java @@ -16,6 +16,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Arrays; + import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -71,4 +73,11 @@ void testIEEE118PartialGraph() { VoltageLevelFilter vlDepthFilter = VoltageLevelFilter.createVoltageLevelDepthFilter(network, "VL54", 2); assertEquals(toString("/IEEE_118_bus_partial.svg"), generateSvgString(network, vlDepthFilter, "/IEEE_118_bus_partial.svg")); } + + @Test + void testIEEE118PartialNonConnectedGraph() { + Network network = IeeeCdfNetworkFactory.create118(); + VoltageLevelFilter vlDepthFilter = VoltageLevelFilter.createVoltageLevelsDepthFilter(network, Arrays.asList("VL32", "VL38"), 1); + assertEquals(toString("/IEEE_118_bus_partial_non_connected.svg"), generateSvgString(network, vlDepthFilter, "/IEEE_118_bus_partial_non_connected.svg")); + } } diff --git a/src/test/resources/IEEE_118_bus_partial_non_connected.svg b/src/test/resources/IEEE_118_bus_partial_non_connected.svg new file mode 100644 index 00000000..8350e88c --- /dev/null +++ b/src/test/resources/IEEE_118_bus_partial_non_connected.svg @@ -0,0 +1,929 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + + + + + 0 + + + + + + + + + + + + + + + + + + + VL23 + VL27 + VL30 + VL31 + VL32 + VL37 + VL38 + VL65 + VL113 + VL114 + +