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

Modify diagram apis #522

Merged
merged 47 commits into from
Sep 28, 2023
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
39b4eb0
Bump to v4.0.0-SNAPSHOT
So-Fras Apr 6, 2023
f05813c
Remove test jars usage (#515)
tadam50 May 31, 2023
472c544
change on network-area-diagram
So-Fras May 31, 2023
90ed0a8
change in single-line-diagram-cgmes
So-Fras May 31, 2023
e541a67
changes on single line diagram
So-Fras Jun 4, 2023
7a32a6d
make Config network agnostic (for SLD, already done for NAD)
So-Fras Jun 5, 2023
919a381
rename Config in Param
So-Fras Jun 5, 2023
79b6b66
fix omissions in Config -> Param renaming
So-Fras Jun 5, 2023
c7f2ad1
decrease code smell number
So-Fras Jun 6, 2023
ca8a44c
change on network-area-diagram
So-Fras May 31, 2023
1b7e1d1
change in single-line-diagram-cgmes
So-Fras May 31, 2023
a44deed
changes on single line diagram
So-Fras Jun 4, 2023
6941f1c
make Config network agnostic (for SLD, already done for NAD)
So-Fras Jun 5, 2023
4c3ebd1
rename Config in Param
So-Fras Jun 5, 2023
e9bcd3f
fix omissions in Config -> Param renaming
So-Fras Jun 5, 2023
34a8f9c
decrease code smell number
So-Fras Jun 6, 2023
1d31539
fix problems following rebase of main
So-Fras Jun 9, 2023
bcab707
changes following review
So-Fras Jun 19, 2023
1628b6a
update test references following svgParameters addition in metadata
So-Fras Jun 19, 2023
7a0547e
add @FunctionalInterface annotations + add missing ownership and auth…
So-Fras Jun 27, 2023
1ca0a62
following review: default VoltageLevelLayoutFactory should be the Sma…
So-Fras Jun 27, 2023
1682303
Merge branch 'main' into modify_diagram_apis
So-Fras Jul 11, 2023
f48f439
fix problem following update of branch with respect to main
So-Fras Jul 11, 2023
20b5e43
Merge branch 'main' into modify_diagram_apis
geofjamg Jul 13, 2023
eea4c52
add a StyleProviderFactory to be used in pypowsybl
So-Fras Jul 21, 2023
9d163fe
Merge branch 'main' into modify_diagram_apis
So-Fras Jul 28, 2023
575db17
Merge branch 'main' into modify_diagram_apis
So-Fras Jul 31, 2023
8691940
Merge branch 'modify_diagram_apis' of https://github.com/powsybl/pows…
So-Fras Aug 28, 2023
4869f4a
Merge branch 'main' into modify_diagram_apis
So-Fras Aug 28, 2023
d924398
Merge branch 'modify_diagram_apis' of https://github.com/powsybl/pows…
So-Fras Aug 28, 2023
bfbb02a
fix remaining problems following merge
So-Fras Aug 30, 2023
7cb337c
classify functions in SingleLineDiagram and NetworkAreaDiagram classe…
So-Fras Aug 30, 2023
616165f
add license identifier
So-Fras Aug 30, 2023
cc17f7d
add non null checks in SLD SvgParameters
So-Fras Aug 30, 2023
d8a1a43
factorize preDrawVoltageLevel and preDrawSubstation functions
So-Fras Aug 30, 2023
f5943b5
remove the builder classes for SldParameters and NadParameters
So-Fras Aug 31, 2023
ba52595
Merge branch 'main' into modify_diagram_apis
So-Fras Aug 31, 2023
4e971ca
create DefaultSvgWriter inside draw function to clean test code
So-Fras Sep 5, 2023
f881c80
Merge branch 'main' into modify_diagram_apis
So-Fras Sep 12, 2023
32a66b8
fix new test in TieLineTest to fit with new API design
So-Fras Sep 12, 2023
7478e4e
Merge branch 'main' into modifyd-iagram_apis
So-Fras Sep 25, 2023
4935442
Add multi substation draw functions to API
So-Fras Sep 25, 2023
5762046
Improve VoltageLevelLayoutFactoryCreator user-friendliness
So-Fras Sep 26, 2023
b659685
Merge branch 'main' into modify_diagram_apis
So-Fras Sep 26, 2023
71ab128
Merge branch 'main' into modify_diagram_apis
So-Fras Sep 27, 2023
9fe2fa8
Clean
geofjamg Sep 27, 2023
0e505fd
Clean
geofjamg Sep 27, 2023
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
Prev Previous commit
Next Next commit
Add multi substation draw functions to API
Signed-off-by: Sophie Frasnedo <[email protected]>
  • Loading branch information
So-Fras committed Sep 25, 2023
commit 4935442e3c8a090822af6a64ed33f1988c02d193
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.sld.builders.NetworkGraphBuilder;
import com.powsybl.sld.layout.LayoutParameters;
import com.powsybl.sld.layout.SubstationLayoutFactory;
import com.powsybl.sld.layout.VoltageLevelLayoutFactory;
import com.powsybl.sld.library.ComponentLibrary;
import com.powsybl.sld.model.graphs.Graph;
import com.powsybl.sld.model.graphs.SubstationGraph;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import com.powsybl.sld.model.graphs.ZoneGraph;
import com.powsybl.sld.svg.*;
import com.powsybl.sld.svg.styles.StyleProvider;
import org.slf4j.Logger;
@@ -29,6 +29,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

import static com.powsybl.iidm.network.IdentifiableType.SUBSTATION;
@@ -133,6 +134,22 @@ public static void drawSubstation(Network network, String substationId, Writer w
draw(substationGraph, writerForSvg, metadataWriter, svgWriter, sldParameters.createLabelProvider(network), sldParameters.getStyleProviderFactory().create(network));
}

public static void drawMultiSubstations(Network network, List<String> substationIdList, Path svgFile) {
drawMultiSubstations(network, substationIdList, svgFile, new SldParameters());
}

public static void drawMultiSubstations(Network network, List<String> substationIdList, Path svgFile, SldParameters sldParameters) {
ZoneGraph zoneGraph = new NetworkGraphBuilder(network).buildZoneGraph(substationIdList);
DefaultSVGWriter svgWriter = preDraw(zoneGraph, sldParameters, network);
draw(zoneGraph, svgFile, svgWriter, sldParameters.createLabelProvider(network), sldParameters.getStyleProviderFactory().create(network));
}

public static void drawMultiSubstations(Network network, List<String> substationIdList, Writer writerForSvg, Writer metadataWriter, SldParameters sldParameters) {
ZoneGraph zoneGraph = new NetworkGraphBuilder(network).buildZoneGraph(substationIdList);
DefaultSVGWriter svgWriter = preDraw(zoneGraph, sldParameters, network);
draw(zoneGraph, writerForSvg, metadataWriter, svgWriter, sldParameters.createLabelProvider(network), sldParameters.getStyleProviderFactory().create(network));
}

public static void draw(Graph graph, Path svgFile, DefaultSVGWriter svgWriter, LabelProvider labelProvider, StyleProvider styleProvider) {
Objects.requireNonNull(svgFile);

@@ -177,8 +194,9 @@ private static DefaultSVGWriter preDraw(Graph graph, SldParameters sldParameters
if (graph instanceof VoltageLevelGraph voltageLevelGraph) {
voltageLevelLayoutFactory.create(voltageLevelGraph).run(layoutParameters);
} else if (graph instanceof SubstationGraph substationGraph) {
SubstationLayoutFactory substationLayoutFactory = sldParameters.getSubstationLayoutFactory();
substationLayoutFactory.create(substationGraph, voltageLevelLayoutFactory).run(layoutParameters);
sldParameters.getSubstationLayoutFactory().create(substationGraph, voltageLevelLayoutFactory).run(layoutParameters);
} else if (graph instanceof ZoneGraph zoneGraph) {
sldParameters.getZoneLayoutFactory().create(zoneGraph, sldParameters.getSubstationLayoutFactory(), voltageLevelLayoutFactory).run(layoutParameters);
} else {
throw new PowsyblException("First argument is an instance of an unexpected class");
}
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ public class SldParameters {
private StyleProviderFactory styleProviderFactory = new DefaultStyleProviderFactory();
private VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = SmartVoltageLevelLayoutFactory::new;
private SubstationLayoutFactory substationLayoutFactory = new HorizontalSubstationLayoutFactory();
private ZoneLayoutFactory zoneLayoutFactory = new HorizontalZoneLayoutFactory();

public SvgParameters getSvgParameters() {
return svgParameters;
@@ -95,4 +96,13 @@ public SldParameters setSubstationLayoutFactory(SubstationLayoutFactory substati
return this;
}

public ZoneLayoutFactory getZoneLayoutFactory() {
return zoneLayoutFactory;
}

public SldParameters setZoneLayoutFactory(ZoneLayoutFactory zoneLayoutFactory) {
this.zoneLayoutFactory = zoneLayoutFactory;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
import com.powsybl.sld.SldParameters;
import com.powsybl.sld.SingleLineDiagram;
import com.powsybl.sld.builders.NetworkGraphBuilder;
import com.powsybl.sld.layout.VerticalSubstationLayout;
import com.powsybl.sld.layout.VerticalZoneLayoutFactory;
import org.apache.commons.io.output.NullWriter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -28,6 +30,8 @@
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -149,6 +153,23 @@ void testIdNotFound() {
assertEquals("Network element 'foo' not found", exception.getMessage());
}

@Test
void testMultiSubstations() throws IOException {
String expected = toString("/TestCase13ZoneGraphVV.svg");
network = Networks.createNetworkWithManySubstations();
List<String> substationIdList = Arrays.asList("A", "B", "C", "D", "E");
Path svgPath = tmpDir.resolve("result.svg");
layoutParameters.setDiagrammPadding(1.0, 1.0, 1.0, 1.0);
SldParameters sldParameters = new SldParameters()
.setLayoutParameters(layoutParameters)
.setSvgParameters(svgParameters)
.setSubstationLayoutFactory(VerticalSubstationLayout::new)
.setZoneLayoutFactory(new VerticalZoneLayoutFactory());

SingleLineDiagram.drawMultiSubstations(network, substationIdList, svgPath, sldParameters);
assertEquals(expected, toString(Files.newInputStream(svgPath)));
}

private String toDefaultSVG(Network network, String id, String filename, String jsonFilename) {
try (StringWriter writer = new StringWriter();
StringWriter metadataWriter = new StringWriter()) {