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
Show file tree
Hide file tree
Changes from 7 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.nad.build.iidm.IdProvider;
import com.powsybl.nad.build.iidm.IntIdProvider;
import com.powsybl.nad.build.iidm.NetworkGraphBuilder;
import com.powsybl.nad.build.iidm.VoltageLevelFilter;
import com.powsybl.nad.layout.BasicForceLayoutFactory;
import com.powsybl.nad.layout.LayoutFactory;
import com.powsybl.nad.layout.LayoutParameters;
import com.powsybl.nad.model.Graph;
import com.powsybl.nad.svg.LabelProvider;
import com.powsybl.nad.svg.StyleProvider;
import com.powsybl.nad.svg.SvgParameters;
import com.powsybl.nad.svg.SvgWriter;
import com.powsybl.nad.svg.iidm.DefaultLabelProvider;
import com.powsybl.nad.svg.iidm.TopologicalStyleProvider;

import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -35,116 +31,91 @@
/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public class NetworkAreaDiagram {
public final class NetworkAreaDiagram {

private final Network network;
private final Predicate<VoltageLevel> voltageLevelFilter;

public NetworkAreaDiagram(Network network) {
this(network, VoltageLevelFilter.NO_FILTER);
}

public NetworkAreaDiagram(Network network, String voltageLevelId, int depth) {
this(network, VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth));
}

public NetworkAreaDiagram(Network network, List<String> voltageLevelIds) {
this(network, VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds));
}

public NetworkAreaDiagram(Network network, List<String> voltageLevelIds, int depth) {
this(network, VoltageLevelFilter.createVoltageLevelsDepthFilter(network, voltageLevelIds, depth));
}

public NetworkAreaDiagram(Network network, Predicate<VoltageLevel> voltageLevelFilter) {
this.network = Objects.requireNonNull(network);
this.voltageLevelFilter = Objects.requireNonNull(voltageLevelFilter);
private NetworkAreaDiagram() {
}

public Network getNetwork() {
return network;
}
/* ------------------------------------------------------------------------------------------------ */
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
// Network, Path and different options of filtering
/* ------------------------------------------------------------------------------------------------ */

public void draw(Path svgFile) {
draw(svgFile, new SvgParameters());
public static void draw(Network network, Path svgFile) {
draw(network, svgFile, new ParamBuilder().build(), VoltageLevelFilter.NO_FILTER);
}

public void draw(Path svgFile, SvgParameters svgParameters) {
draw(svgFile, svgParameters, new LayoutParameters());
public static void draw(Network network, Path svgFile, String voltageLevelId, int depth) {
draw(network, svgFile, new ParamBuilder().build(), VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth));
}

public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters) {
draw(svgFile, svgParameters, layoutParameters, new TopologicalStyleProvider(network));
public static void draw(Network network, Path svgFile, List<String> voltageLevelIds) {
draw(network, svgFile, new ParamBuilder().build(), VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds));
}

public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider) {
draw(svgFile, svgParameters, layoutParameters, styleProvider, new DefaultLabelProvider(network, svgParameters));
public static void draw(Network network, Path svgFile, List<String> voltageLevelIds, int depth) {
draw(network, svgFile, new ParamBuilder().build(), VoltageLevelFilter.createVoltageLevelsDepthFilter(network, voltageLevelIds, depth));
}

public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider, LabelProvider labelProvider) {
draw(svgFile, svgParameters, layoutParameters, styleProvider, labelProvider, new BasicForceLayoutFactory());
}
/* ---------------------------------------------------------------- */
// Network, Path, Param, Predicate
/* ---------------------------------------------------------------- */

public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider, LabelProvider labelProvider, LayoutFactory layoutFactory) {
draw(svgFile, svgParameters, layoutParameters, styleProvider, labelProvider, layoutFactory, new IntIdProvider());
}
public static void draw(Network network, Path svgFile, Param param, Predicate<VoltageLevel> voltageLevelFilter) {

public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider, LabelProvider labelProvider, LayoutFactory layoutFactory,
IdProvider idProvider) {
Objects.requireNonNull(network);
Objects.requireNonNull(svgFile);
LayoutParameters layoutParameters = param.getLayoutParameters();
SvgParameters svgParameters = param.getSvgParameters();
StyleProvider styleProvider = param.createStyleProvider(network);
LayoutFactory layoutFactory = param.getLayoutFactory();
IdProvider idProvider = param.createIdProvider();
LabelProvider labelProvider = param.createLabelProvider(network);
Objects.requireNonNull(layoutParameters);
Objects.requireNonNull(svgParameters);
Objects.requireNonNull(styleProvider);
Objects.requireNonNull(layoutFactory);
Objects.requireNonNull(idProvider);
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
Objects.requireNonNull(voltageLevelFilter);

Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter, idProvider).buildGraph();
layoutFactory.create().run(graph, layoutParameters);
new SvgWriter(svgParameters, styleProvider, labelProvider).writeSvg(graph, svgFile);
}

public void draw(Writer writer) {
draw(writer, new SvgParameters());
}
/* ------------------------------------------------------------------------------------------------ */
// Network, Writer and different options of filtering
/* ------------------------------------------------------------------------------------------------ */

public void draw(Writer writer, SvgParameters svgParameters) {
draw(writer, svgParameters, new LayoutParameters());
public static void draw(Network network, Writer writer) {
draw(network, writer, new ParamBuilder().build(), VoltageLevelFilter.NO_FILTER);
}

public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters) {
draw(writer, svgParameters, layoutParameters, new TopologicalStyleProvider(network));
public static void draw(Network network, Writer writer, String voltageLevelId, int depth) {
draw(network, writer, new ParamBuilder().build(), VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth));
}

public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider) {
draw(writer, svgParameters, layoutParameters, styleProvider, new DefaultLabelProvider(network, svgParameters));
public static void draw(Network network, Writer writer, List<String> voltageLevelIds) {
draw(network, writer, new ParamBuilder().build(), VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds));
}

public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider, LabelProvider labelProvider) {
draw(writer, svgParameters, layoutParameters, styleProvider, labelProvider, new BasicForceLayoutFactory());
public void draw(Network network, Writer writer, Predicate<VoltageLevel> voltageLevelFilter) {
draw(network, writer, new ParamBuilder().build(), voltageLevelFilter);
}

public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider, LabelProvider labelProvider, LayoutFactory layoutFactory) {
draw(writer, svgParameters, layoutParameters, styleProvider, labelProvider, layoutFactory, new IntIdProvider());
}
/* ----------------------------------------------------------------------------------------------- */
// Network, Writer, Param, Predicate
/* ----------------------------------------------------------------------------------------------- */

public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters,
StyleProvider styleProvider, LabelProvider labelProvider, LayoutFactory layoutFactory,
IdProvider idProvider) {
Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter, idProvider).buildGraph();
layoutFactory.create().run(graph, layoutParameters);
new SvgWriter(svgParameters, styleProvider, labelProvider).writeSvg(graph, writer);
public static void draw(Network network, Writer writer, Param param, Predicate<VoltageLevel> voltageLevelFilter) {
Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter, param.createIdProvider()).buildGraph();
param.getLayoutFactory().create().run(graph, param.getLayoutParameters());
new SvgWriter(param.getSvgParameters(), param.createStyleProvider(network), param.createLabelProvider(network)).writeSvg(graph, writer);
}

public String drawToString(SvgParameters svgParameters) {
public String drawToString(Network network, SvgParameters svgParameters) {
try (StringWriter writer = new StringWriter()) {
draw(writer, svgParameters);
Param param = new ParamBuilder().withSvgParameters(svgParameters).build();
draw(network, writer, param, VoltageLevelFilter.NO_FILTER);
return writer.toString();
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down
63 changes: 63 additions & 0 deletions network-area-diagram/src/main/java/com/powsybl/nad/Param.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (c) 2023, 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/.
*/
package com.powsybl.nad;

import com.powsybl.iidm.network.Network;
import com.powsybl.nad.build.iidm.IdProvider;
import com.powsybl.nad.layout.LayoutFactory;
import com.powsybl.nad.layout.LayoutParameters;
import com.powsybl.nad.svg.LabelProvider;
import com.powsybl.nad.svg.StyleProvider;
import com.powsybl.nad.svg.SvgParameters;

/**
*
* @author Sophie Frasnedo <sophie.frasnedo at rte-france.com>
*/
public class Param {
So-Fras marked this conversation as resolved.
Show resolved Hide resolved

SvgParameters svgParameters;
LayoutParameters layoutParameters;
ParamBuilder.StyleProviderFactory styleProviderFactory;
ParamBuilder.LabelProviderFactory labelProviderFactory;
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
LayoutFactory layoutFactory;
ParamBuilder.IdProviderFactory idProviderFactory;
So-Fras marked this conversation as resolved.
Show resolved Hide resolved

public Param(SvgParameters svgParameters, LayoutParameters layoutParameters, ParamBuilder.StyleProviderFactory styleProviderFactory, ParamBuilder.LabelProviderFactory labelProviderFactory, LayoutFactory layoutFactory, ParamBuilder.IdProviderFactory idProviderFactory) {
this.svgParameters = svgParameters;
this.layoutParameters = layoutParameters;
this.styleProviderFactory = styleProviderFactory;
this.labelProviderFactory = labelProviderFactory;
this.layoutFactory = layoutFactory;
this.idProviderFactory = idProviderFactory;
}

public SvgParameters getSvgParameters() {
return svgParameters;
}

public LayoutParameters getLayoutParameters() {
return layoutParameters;
}

public StyleProvider createStyleProvider(Network network) {
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
return styleProviderFactory.create(network);
}

public LabelProvider createLabelProvider(Network network) {
return labelProviderFactory.create(network, svgParameters);
}

public LayoutFactory getLayoutFactory() {
return layoutFactory;
}

public IdProvider createIdProvider() {
return idProviderFactory.create();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (c) 2023, 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/.
*/
package com.powsybl.nad;

import com.powsybl.iidm.network.Network;
import com.powsybl.nad.build.iidm.IdProvider;
import com.powsybl.nad.build.iidm.IntIdProvider;
import com.powsybl.nad.layout.BasicForceLayoutFactory;
import com.powsybl.nad.layout.LayoutFactory;
import com.powsybl.nad.layout.LayoutParameters;
import com.powsybl.nad.svg.LabelProvider;
import com.powsybl.nad.svg.StyleProvider;
import com.powsybl.nad.svg.SvgParameters;
import com.powsybl.nad.svg.iidm.DefaultLabelProvider;
import com.powsybl.nad.svg.iidm.TopologicalStyleProvider;

/**
*
* @author Sophie Frasnedo <sophie.frasnedo at rte-france.com>
*/
public class ParamBuilder {
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
SvgParameters svgParameters = new SvgParameters();
LayoutParameters layoutParameters = new LayoutParameters();
StyleProviderFactory styleProviderFactory = TopologicalStyleProvider::new;
LabelProviderFactory labelProviderFactory = DefaultLabelProvider::new;
LayoutFactory layoutFactory = new BasicForceLayoutFactory();
IdProviderFactory idProviderFactory = IntIdProvider::new;
So-Fras marked this conversation as resolved.
Show resolved Hide resolved

@FunctionalInterface
public interface LabelProviderFactory {
LabelProvider create(Network network, SvgParameters svgParameters);
}

@FunctionalInterface
public interface IdProviderFactory {
IdProvider create();
}

@FunctionalInterface
public interface StyleProviderFactory {
StyleProvider create(Network network);
}

public ParamBuilder() {
/* This builder is network-agnostic */
}
So-Fras marked this conversation as resolved.
Show resolved Hide resolved

public ParamBuilder withSvgParameters(SvgParameters svgParameters) {
this.svgParameters = svgParameters;
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
return this;
}

public ParamBuilder withLayoutParameters(LayoutParameters layoutParameters) {
this.layoutParameters = layoutParameters;
return this;
}

public ParamBuilder withStyleProviderFactory(StyleProviderFactory styleProviderFactory) {
this.styleProviderFactory = styleProviderFactory;
return this;
}

public ParamBuilder withLabelProviderFactory(LabelProviderFactory labelProviderFactory) {
this.labelProviderFactory = labelProviderFactory;
return this;
}

public ParamBuilder withLayoutFactory(LayoutFactory layoutFactory) {
this.layoutFactory = layoutFactory;
return this;
}

public ParamBuilder withIdProviderFactory(IdProviderFactory idProviderFactory) {
this.idProviderFactory = idProviderFactory;
return this;
}

public Param build() {
return new Param(svgParameters, layoutParameters, styleProviderFactory, labelProviderFactory, layoutFactory, idProviderFactory);
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022, RTE (http://www.rte-france.com)
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
* 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/.
*/
package com.powsybl.nad.layout;

import com.powsybl.nad.model.*;
Expand All @@ -6,6 +12,10 @@
import java.util.*;
import java.util.stream.Stream;

/**
*
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public abstract class AbstractLayout implements Layout {

private Map<String, Point> initialNodePositions = Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package com.powsybl.nad.svg.metadata;

/**
* Copyright (c) 2022, 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/.
*/
import javax.xml.stream.XMLStreamReader;

/**
*
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/

public class BusNodeMetadata extends AbstractMetadataItem {
private static final String ELEMENT_NAME = "busNode";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022, 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/.
*/
package com.powsybl.nad.utils.iidm;

import com.powsybl.iidm.network.*;
Expand All @@ -7,6 +13,12 @@

import java.util.Objects;

/**
*
* @author Florian Dupuy <florian.dupuy at rte-france.com>
* @author Luma Zamarreño <zamarrenolm at aia.es>
*/

public final class IidmUtils {

private IidmUtils() {
Expand Down
Loading